domain module
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
alias(libs.plugins.fast.android.library)
|
||||
alias(libs.plugins.fast.android.library.compose)
|
||||
// alias(libs.plugins.fast.jvm.library)
|
||||
// alias(libs.plugins.fast.koin)
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -8,23 +9,8 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.core.ktx)
|
||||
implementation(libs.preference.ktx)
|
||||
implementation(libs.kotlinx.coroutines.core)
|
||||
implementation(libs.bundles.nanokt)
|
||||
|
||||
implementation(libs.lifecycle.viewmodel.ktx)
|
||||
implementation(libs.lifecycle.runtime.ktx)
|
||||
|
||||
implementation(libs.koin.android)
|
||||
implementation(libs.koin.androidx.compose)
|
||||
implementation(libs.koin.androidx.compose.navigation)
|
||||
|
||||
implementation(libs.coil.compose)
|
||||
|
||||
implementation(libs.nanokt.jvm)
|
||||
implementation(libs.nanokt.android)
|
||||
implementation(libs.nanokt)
|
||||
|
||||
implementation(libs.androidx.navigation.compose)
|
||||
|
||||
implementation(libs.kotlin.serialization)
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package dev.meloda.fast.common
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
object UserConfig {
|
||||
|
||||
private const val ARG_CURRENT_USER_ID = "current_user_id"
|
||||
|
||||
private var preferences: SharedPreferences by Delegates.notNull()
|
||||
|
||||
fun init(preferences: SharedPreferences) {
|
||||
this.preferences = preferences
|
||||
}
|
||||
|
||||
var currentUserId: Int = -1
|
||||
get() = preferences.getInt(ARG_CURRENT_USER_ID, -1)
|
||||
set(value) {
|
||||
field = value
|
||||
preferences.edit { putInt(ARG_CURRENT_USER_ID, value) }
|
||||
}
|
||||
|
||||
var userId: Int = -1
|
||||
var accessToken: String = ""
|
||||
var fastToken: String? = ""
|
||||
var trustedHash: String? = null
|
||||
|
||||
fun clear() {
|
||||
currentUserId = -1
|
||||
accessToken = ""
|
||||
fastToken = ""
|
||||
userId = -1
|
||||
}
|
||||
|
||||
fun isLoggedIn(): Boolean {
|
||||
return currentUserId > 0 && userId > 0 && accessToken.isNotBlank()
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package dev.meloda.fast.common.di
|
||||
|
||||
import coil.ImageLoader
|
||||
import dev.meloda.fast.common.LongPollController
|
||||
import dev.meloda.fast.common.LongPollControllerImpl
|
||||
import dev.meloda.fast.common.provider.ResourceProvider
|
||||
import dev.meloda.fast.common.provider.ResourceProviderImpl
|
||||
import org.koin.core.module.dsl.singleOf
|
||||
import org.koin.dsl.bind
|
||||
import org.koin.dsl.module
|
||||
|
||||
val commonModule = module {
|
||||
single {
|
||||
ImageLoader.Builder(get())
|
||||
.crossfade(true)
|
||||
.build()
|
||||
}
|
||||
|
||||
singleOf(::LongPollControllerImpl) bind LongPollController::class
|
||||
singleOf(::ResourceProviderImpl) bind ResourceProvider::class
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package dev.meloda.fast.common.extensions
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import androidx.core.os.BundleCompat
|
||||
import androidx.navigation.NavType
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
inline fun <reified T : Parcelable> customNavType(
|
||||
isNullableAllowed: Boolean = false,
|
||||
json: Json = Json
|
||||
) = object : NavType<T>(isNullableAllowed = isNullableAllowed) {
|
||||
override fun get(bundle: Bundle, key: String) =
|
||||
BundleCompat.getParcelable(bundle, key, T::class.java)
|
||||
|
||||
override fun parseValue(value: String): T = json.decodeFromString(value)
|
||||
|
||||
override fun serializeAsValue(value: T): String = json.encodeToString(value)
|
||||
|
||||
override fun put(bundle: Bundle, key: String, value: T) = bundle.putParcelable(key, value)
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
package dev.meloda.fast.common.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import androidx.annotation.ChecksSdkIntAtLeast
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -21,18 +16,6 @@ import kotlinx.coroutines.flow.update
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
fun Context.restartApp() {
|
||||
(this as? Activity)?.let { activity ->
|
||||
activity.finishAffinity()
|
||||
activity.startActivity(
|
||||
Intent(
|
||||
this,
|
||||
Class.forName("dev.meloda.fast.MainActivity")
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T> Iterable<T>.findWithIndex(predicate: (T) -> Boolean): Pair<Int, T>? {
|
||||
val value = firstOrNull(predicate) ?: return null
|
||||
return indexOf(value).let { index -> if (index == -1) null else index to value }
|
||||
@@ -115,13 +98,3 @@ fun <T> Any.toList(mapper: (old: Any) -> T): List<T> {
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
@ChecksSdkIntAtLeast(parameter = 0, lambda = 1)
|
||||
fun isSdkAtLeast(sdkInt: Int, action: (() -> Unit)? = null): Boolean {
|
||||
return if (Build.VERSION.SDK_INT >= sdkInt) {
|
||||
action?.invoke()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package dev.meloda.fast.common.extensions.navigation
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.navigation.NavBackStackEntry
|
||||
import androidx.navigation.NavController
|
||||
import org.koin.androidx.compose.koinViewModel
|
||||
import org.koin.androidx.compose.navigation.koinNavViewModel
|
||||
|
||||
@Composable
|
||||
inline fun <reified T : ViewModel> NavBackStackEntry.sharedViewModel(navController: NavController): T {
|
||||
val navGraphRoute = destination.parent?.route ?: return koinViewModel()
|
||||
val parentEntry = remember(this) {
|
||||
navController.getBackStackEntry(navGraphRoute)
|
||||
}
|
||||
return koinNavViewModel(viewModelStoreOwner = parentEntry)
|
||||
}
|
||||
@@ -4,14 +4,10 @@ import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.FileProvider
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
||||
object AndroidUtils {
|
||||
|
||||
@@ -96,61 +92,61 @@ object AndroidUtils {
|
||||
})
|
||||
}
|
||||
|
||||
fun getInstallPackageIntent(
|
||||
context: Context,
|
||||
providerPath: String,
|
||||
fileToRead: File,
|
||||
): Intent {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
// fun getInstallPackageIntent(
|
||||
// context: Context,
|
||||
// providerPath: String,
|
||||
// fileToRead: File,
|
||||
// ): Intent {
|
||||
// val intent = Intent(Intent.ACTION_VIEW)
|
||||
//
|
||||
// intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
// intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
|
||||
// intent.data = FileProvider.getUriForFile(
|
||||
// context,
|
||||
// "dev.meloda.fast$providerPath",
|
||||
// fileToRead
|
||||
// )
|
||||
//
|
||||
// return intent
|
||||
// }
|
||||
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
|
||||
intent.data = FileProvider.getUriForFile(
|
||||
context,
|
||||
"dev.meloda.fast$providerPath",
|
||||
fileToRead
|
||||
)
|
||||
// fun getImageToShare(context: Context, existingFile: File): Uri? {
|
||||
// val imageFolder = File(context.cacheDir, "images")
|
||||
//
|
||||
// return try {
|
||||
// imageFolder.mkdirs()
|
||||
//
|
||||
// val copyToFile = File(imageFolder, "shared_image.png")
|
||||
// if (copyToFile.exists()) {
|
||||
// copyToFile.delete()
|
||||
// }
|
||||
//
|
||||
// val file = existingFile.copyTo(copyToFile)
|
||||
// FileProvider.getUriForFile(context, "dev.meloda.fast.provider", file)
|
||||
// } catch (e: Exception) {
|
||||
// e.printStackTrace()
|
||||
// null
|
||||
// }
|
||||
// }
|
||||
|
||||
return intent
|
||||
}
|
||||
|
||||
fun getImageToShare(context: Context, existingFile: File): Uri? {
|
||||
val imageFolder = File(context.cacheDir, "images")
|
||||
|
||||
return try {
|
||||
imageFolder.mkdirs()
|
||||
|
||||
val copyToFile = File(imageFolder, "shared_image.png")
|
||||
if (copyToFile.exists()) {
|
||||
copyToFile.delete()
|
||||
}
|
||||
|
||||
val file = existingFile.copyTo(copyToFile)
|
||||
FileProvider.getUriForFile(context, "dev.meloda.fast.provider", file)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun getImageToShare(context: Context, bitmap: Bitmap): Uri? {
|
||||
val imageFolder = File(context.cacheDir, "images")
|
||||
|
||||
return try {
|
||||
imageFolder.mkdirs()
|
||||
|
||||
val file = File(imageFolder, "shared_image.png")
|
||||
val outputStream = FileOutputStream(file)
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream)
|
||||
outputStream.flush()
|
||||
outputStream.close()
|
||||
FileProvider.getUriForFile(context, "dev.meloda.fast.fileprovider", file)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
}
|
||||
// fun getImageToShare(context: Context, bitmap: Bitmap): Uri? {
|
||||
// val imageFolder = File(context.cacheDir, "images")
|
||||
//
|
||||
// return try {
|
||||
// imageFolder.mkdirs()
|
||||
//
|
||||
// val file = File(imageFolder, "shared_image.png")
|
||||
// val outputStream = FileOutputStream(file)
|
||||
// bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream)
|
||||
// outputStream.flush()
|
||||
// outputStream.close()
|
||||
// FileProvider.getUriForFile(context, "dev.meloda.fast.fileprovider", file)
|
||||
// } catch (e: Exception) {
|
||||
// e.printStackTrace()
|
||||
// null
|
||||
// }
|
||||
// }
|
||||
|
||||
fun showShareSheet(context: Context, content: ShareContent) {
|
||||
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||
|
||||
Reference in New Issue
Block a user