Приложение
This commit is contained in:
23
client-mobile/core/utils/FileUtils.kt
Normal file
23
client-mobile/core/utils/FileUtils.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
package core.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.util.UUID
|
||||
|
||||
fun copyUriToFile(context: Context, uri: Uri): File? {
|
||||
return try {
|
||||
val inputStream = context.contentResolver.openInputStream(uri)
|
||||
val file = File(context.cacheDir, "${UUID.randomUUID()}.tmp")
|
||||
val outputStream = FileOutputStream(file)
|
||||
inputStream?.use { input ->
|
||||
outputStream.use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
file
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
32
client-mobile/core/utils/ImageCropper.kt
Normal file
32
client-mobile/core/utils/ImageCropper.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
package core.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import com.yalantis.ucrop.UCrop
|
||||
import core.presentation.theme.Indigo500
|
||||
import java.io.File
|
||||
|
||||
object ImageCropper {
|
||||
fun getCropIntent(
|
||||
context: Context,
|
||||
sourceUri: Uri,
|
||||
destinationUri: Uri
|
||||
): UCrop {
|
||||
val options = UCrop.Options().apply {
|
||||
setCompressionQuality(90)
|
||||
setHideBottomControls(false)
|
||||
setFreeStyleCropEnabled(false) // Фиксированный аспект
|
||||
setToolbarColor(Indigo500.toArgb())
|
||||
setStatusBarColor(Indigo500.toArgb())
|
||||
setActiveControlsWidgetColor(Indigo500.toArgb())
|
||||
setToolbarTitle("Crop Avatar")
|
||||
// Настройка под "квадрат" (софт-сквайр эмулируется на стороне UI, кроп всегда 1:1)
|
||||
}
|
||||
|
||||
return UCrop.of(sourceUri, destinationUri)
|
||||
.withAspectRatio(1f, 1f)
|
||||
.withMaxResultSize(1000, 1000)
|
||||
.withOptions(options)
|
||||
}
|
||||
}
|
||||
19
client-mobile/core/utils/LinkParser.kt
Normal file
19
client-mobile/core/utils/LinkParser.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package core.utils
|
||||
|
||||
data class LinkMetadata(
|
||||
val url: String,
|
||||
val title: String? = null,
|
||||
val description: String? = null,
|
||||
val imageUrl: String? = null
|
||||
)
|
||||
|
||||
object LinkParser {
|
||||
private val URL_PATTERN = Regex(
|
||||
"(?:^|[\\s])((https?://)[\\w-]+(\\.[\\w-]+)+\\.?(:\\d+)?(/[\\w- ./?%&=]*)?)",
|
||||
RegexOption.IGNORE_CASE
|
||||
)
|
||||
|
||||
fun findLinks(text: String): List<String> {
|
||||
return URL_PATTERN.findAll(text).map { it.groupValues[1].trim() }.toList()
|
||||
}
|
||||
}
|
||||
34
client-mobile/core/utils/VoiceRecorder.kt
Normal file
34
client-mobile/core/utils/VoiceRecorder.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package core.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.media.MediaRecorder
|
||||
import android.os.Build
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
||||
class VoiceRecorder(private val context: Context) {
|
||||
private var recorder: MediaRecorder? = null
|
||||
|
||||
fun startRecording(outputFile: File) {
|
||||
recorder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
MediaRecorder(context)
|
||||
} else {
|
||||
MediaRecorder()
|
||||
}.apply {
|
||||
setAudioSource(MediaRecorder.AudioSource.MIC)
|
||||
setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
|
||||
setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
|
||||
setOutputFile(FileOutputStream(outputFile).fd)
|
||||
prepare()
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
fun stopRecording() {
|
||||
recorder?.apply {
|
||||
stop()
|
||||
release()
|
||||
}
|
||||
recorder = null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user