forked from melod1n/fast-messenger
more fixes
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
@@ -8,11 +8,9 @@ import androidx.annotation.ChecksSdkIntAtLeast
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
@@ -20,10 +18,6 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
@@ -98,26 +92,6 @@ fun createTimerFlow(
|
||||
}
|
||||
}
|
||||
|
||||
context(ViewModel)
|
||||
fun <T> MutableSharedFlow<T>.emitOnMainScope(value: T) = emitOnScope(Dispatchers.Main) { value }
|
||||
|
||||
context(ViewModel)
|
||||
fun <T> MutableSharedFlow<T>.emitOnScope(
|
||||
coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
value: () -> T,
|
||||
) {
|
||||
viewModelScope.launch(coroutineContext) {
|
||||
emit(value())
|
||||
}
|
||||
}
|
||||
|
||||
context(CoroutineScope)
|
||||
suspend fun <T> MutableSharedFlow<T>.emitWithMain(value: T) {
|
||||
withContext(Dispatchers.Main) {
|
||||
emit(value)
|
||||
}
|
||||
}
|
||||
|
||||
context(ViewModel)
|
||||
fun <T> MutableStateFlow<T>.updateValue(newValue: T) = this.update { newValue }
|
||||
|
||||
|
||||
@@ -13,11 +13,6 @@ import androidx.core.content.FileProvider
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
||||
private object BuildConfig {
|
||||
const val DEBUG = true
|
||||
const val APPLICATION_ID = "dev.meloda.fast"
|
||||
}
|
||||
|
||||
object AndroidUtils {
|
||||
|
||||
fun copyText(
|
||||
@@ -95,7 +90,7 @@ object AndroidUtils {
|
||||
action = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
Settings.ACTION_SECURITY_SETTINGS
|
||||
} else {
|
||||
data = Uri.parse("package:${BuildConfig.APPLICATION_ID}")
|
||||
data = Uri.parse("package:dev.meloda.fast")
|
||||
Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES
|
||||
}
|
||||
})
|
||||
@@ -113,7 +108,7 @@ object AndroidUtils {
|
||||
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
|
||||
intent.data = FileProvider.getUriForFile(
|
||||
context,
|
||||
BuildConfig.APPLICATION_ID + providerPath,
|
||||
"dev.meloda.fast$providerPath",
|
||||
fileToRead
|
||||
)
|
||||
|
||||
@@ -132,7 +127,7 @@ object AndroidUtils {
|
||||
}
|
||||
|
||||
val file = existingFile.copyTo(copyToFile)
|
||||
FileProvider.getUriForFile(context, "${BuildConfig.APPLICATION_ID}.provider", file)
|
||||
FileProvider.getUriForFile(context, "dev.meloda.fast.provider", file)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
@@ -150,7 +145,7 @@ object AndroidUtils {
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream)
|
||||
outputStream.flush()
|
||||
outputStream.close()
|
||||
FileProvider.getUriForFile(context, "${BuildConfig.APPLICATION_ID}.fileprovider", file)
|
||||
FileProvider.getUriForFile(context, "dev.meloda.fast.fileprovider", file)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
@@ -188,7 +183,6 @@ object AndroidUtils {
|
||||
}
|
||||
val chooserIntent = Intent.createChooser(intent, "Share $contentType")
|
||||
|
||||
|
||||
context.startActivity(chooserIntent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ interface AccountUseCase {
|
||||
suspend fun setOnline(
|
||||
voip: Boolean,
|
||||
accessToken: String
|
||||
): Flow<State<Unit>>
|
||||
): Flow<State<Int>>
|
||||
|
||||
suspend fun setOffline(
|
||||
accessToken: String
|
||||
): Flow<State<Unit>>
|
||||
): Flow<State<Int>>
|
||||
}
|
||||
|
||||
@@ -1,49 +1,30 @@
|
||||
package dev.meloda.fast.data.api.account
|
||||
|
||||
import dev.meloda.fast.data.State
|
||||
import dev.meloda.fast.data.mapToState
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
|
||||
// TODO: 05/05/2024, Danil Nikolaev: implement
|
||||
class AccountUseCaseImpl(
|
||||
private val accountRepository: dev.meloda.fast.data.api.account.AccountRepository
|
||||
) : dev.meloda.fast.data.api.account.AccountUseCase {
|
||||
private val repository: AccountRepository
|
||||
) : AccountUseCase {
|
||||
|
||||
override suspend fun setOnline(
|
||||
voip: Boolean,
|
||||
accessToken: String
|
||||
): Flow<State<Unit>> = flow {
|
||||
// emit(dev.meloda.fast.data.State.Loading)
|
||||
//
|
||||
// val newState = accountRepository.setOnline(
|
||||
// params = AccountSetOnlineRequest(
|
||||
// voip = voip,
|
||||
// accessToken = accessToken
|
||||
// )
|
||||
// ).fold(
|
||||
// onSuccess = { response -> dev.meloda.fast.data.State.Success(response) },
|
||||
// onNetworkFailure = { dev.meloda.fast.data.State.Error.ConnectionError },
|
||||
// onUnknownFailure = { dev.meloda.fast.data.State.UNKNOWN_ERROR },
|
||||
// onHttpFailure = { result -> result.error.toStateApiError() },
|
||||
// onApiFailure = { result -> result.error.toStateApiError() }
|
||||
// )
|
||||
// emit(newState)
|
||||
): Flow<State<Int>> = flow {
|
||||
emit(State.Loading)
|
||||
|
||||
val newState = repository.setOnline(voip = voip).mapToState()
|
||||
emit(newState)
|
||||
}
|
||||
|
||||
override suspend fun setOffline(
|
||||
accessToken: String
|
||||
): Flow<dev.meloda.fast.data.State<Unit>> = flow {
|
||||
emit(dev.meloda.fast.data.State.Loading)
|
||||
): Flow<State<Int>> = flow {
|
||||
emit(State.Loading)
|
||||
|
||||
// val newState = accountRepository.setOffline(
|
||||
// params = AccountSetOfflineRequest(accessToken = accessToken)
|
||||
// ).fold(
|
||||
// onSuccess = { response -> dev.meloda.fast.data.State.Success(response) },
|
||||
// onNetworkFailure = { dev.meloda.fast.data.State.Error.ConnectionError },
|
||||
// onUnknownFailure = { dev.meloda.fast.data.State.UNKNOWN_ERROR },
|
||||
// onHttpFailure = { result -> result.error.toStateApiError() },
|
||||
// onApiFailure = { result -> result.error.toStateApiError() }
|
||||
// )
|
||||
// emit(newState)
|
||||
val newState = repository.setOffline().mapToState()
|
||||
emit(newState)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.meloda.fast.model;
|
||||
package dev.meloda.fast.model
|
||||
|
||||
enum class ApiEvent(val value: Int) {
|
||||
MESSAGE_SET_FLAGS(2),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.meloda.fast.model.api;
|
||||
package dev.meloda.fast.model.api
|
||||
|
||||
enum class PeerType(val value: String) {
|
||||
USER("user"),
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
@@ -11,5 +11,4 @@ data class ApiResponse<T>(
|
||||
val isSuccessful get() = error == null && response != null
|
||||
|
||||
fun requireResponse(): T = requireNotNull(response)
|
||||
fun requireError(): RestApiError = requireNotNull(error)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.meloda.fast.network;
|
||||
package dev.meloda.fast.network
|
||||
|
||||
enum class ValidationType(val value: String) {
|
||||
APP("2fa_app"),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.meloda.fast.network;
|
||||
package dev.meloda.fast.network
|
||||
|
||||
enum class VkOAuthErrorType(val value: String) {
|
||||
WRONG_OTP_FORMAT("otp_format_is_incorrect"),
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
Reference in New Issue
Block a user