some improvements

This commit is contained in:
2024-07-15 16:36:03 +03:00
parent eaf609c475
commit ad9a3e0c12
8 changed files with 107 additions and 58 deletions
@@ -8,6 +8,7 @@ import android.content.Intent
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
@@ -21,6 +22,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.lifecycle.compose.LifecycleResumeEffect
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -43,7 +45,6 @@ import com.meloda.app.fast.service.longpolling.LongPollingService
import org.koin.androidx.compose.koinViewModel
import org.koin.compose.KoinContext
import org.koin.compose.koinInject
import com.meloda.app.fast.designsystem.R as UiR
class MainActivity : AppCompatActivity() {
@@ -52,6 +53,11 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
SettingsController.deviceId = Settings.Secure.getString(
contentResolver,
Settings.Secure.ANDROID_ID
)
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
val systemBarStyle = when (currentNightMode) {
Configuration.UI_MODE_NIGHT_NO -> SystemBarStyle.light(
@@ -175,25 +181,40 @@ class MainActivity : AppCompatActivity() {
private fun createNotificationChannels() {
isSdkAtLeast(Build.VERSION_CODES.O) {
val noCategoryName = getString(UiR.string.notification_channel_no_category_name)
val noCategoryDescriptionText = getString(UiR.string.notification_channel_no_category_description)
val noCategoryImportance = NotificationManager.IMPORTANCE_HIGH
val noCategoryDescriptionText =
getString(UiR.string.notification_channel_no_category_description)
val noCategoryImportance = NotificationManagerCompat.IMPORTANCE_HIGH
val noCategoryChannel =
NotificationChannel(AppConstants.NOTIFICATION_CHANNEL_UNCATEGORIZED, noCategoryName, noCategoryImportance).apply {
NotificationChannel(
AppConstants.NOTIFICATION_CHANNEL_UNCATEGORIZED,
noCategoryName,
noCategoryImportance
).apply {
description = noCategoryDescriptionText
}
val longPollName = getString(UiR.string.notification_channel_long_polling_service_name)
val longPollDescriptionText = getString(UiR.string.notification_channel_long_polling_service_description)
val longPollImportance = NotificationManager.IMPORTANCE_NONE
val longPollDescriptionText =
getString(UiR.string.notification_channel_long_polling_service_description)
val longPollImportance = NotificationManagerCompat.IMPORTANCE_NONE
val longPollChannel =
NotificationChannel(AppConstants.NOTIFICATION_CHANNEL_LONG_POLLING, longPollName, longPollImportance).apply {
NotificationChannel(
AppConstants.NOTIFICATION_CHANNEL_LONG_POLLING,
longPollName,
longPollImportance
).apply {
description = longPollDescriptionText
}
val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannels(listOf(noCategoryChannel, longPollChannel))
notificationManager.createNotificationChannels(
listOf(
noCategoryChannel,
longPollChannel
)
)
}
}
-4
View File
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
@@ -1,15 +1,21 @@
package com.meloda.app.fast.data.api.account
import com.meloda.app.fast.model.api.requests.AccountSetOfflineRequest
import com.meloda.app.fast.model.api.requests.AccountSetOnlineRequest
import com.meloda.app.fast.network.RestApiErrorDomain
import com.slack.eithernet.ApiResult
interface AccountRepository {
suspend fun setOnline(
params: AccountSetOnlineRequest
): Boolean
accessToken: String? = null,
voip: Boolean = false
): ApiResult<Int, RestApiErrorDomain>
suspend fun setOffline(
params: AccountSetOfflineRequest
): Boolean
accessToken: String? = null
): ApiResult<Int, RestApiErrorDomain>
suspend fun registerDevice(
token: String,
deviceId: String
): ApiResult<Int, RestApiErrorDomain>
}
@@ -1,19 +1,54 @@
package com.meloda.app.fast.data.api.account
import com.meloda.app.fast.model.api.requests.AccountSetOfflineRequest
import com.meloda.app.fast.model.api.requests.AccountSetOnlineRequest
import android.os.Build
import com.meloda.app.fast.model.api.asInt
import com.meloda.app.fast.network.RestApiErrorDomain
import com.meloda.app.fast.network.mapApiDefault
import com.meloda.app.fast.network.service.account.AccountService
import com.slack.eithernet.ApiResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
// TODO: 05/05/2024, Danil Nikolaev: implement
class AccountRepositoryImpl(
private val accountService: AccountService
) : com.meloda.app.fast.data.api.account.AccountRepository {
private val service: AccountService
) : AccountRepository {
override suspend fun setOnline(params: AccountSetOnlineRequest): Boolean {
return false
override suspend fun setOnline(
accessToken: String?,
voip: Boolean
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
service.setOnline(
mutableMapOf(
"voip" to voip.asInt().toString()
).apply {
accessToken?.let { this["access_token"] = it }
}
).mapApiDefault()
}
override suspend fun setOffline(params: AccountSetOfflineRequest): Boolean {
return false
override suspend fun setOffline(
accessToken: String?
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
service.setOffline(
accessToken?.let { mapOf("access_token" to it) } ?: emptyMap()
).mapApiDefault()
}
override suspend fun registerDevice(
token: String,
deviceId: String
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
service.registerDevice(
mapOf(
"token" to token,
"pushes_granted" to "1",
"app_version" to "15271",
"push_provider" to "fcm",
"companion_apps" to "vk_client",
"type" to "4",
"device_id" to deviceId,
"system_version" to Build.VERSION.RELEASE
)
).mapApiDefault()
}
}
@@ -51,14 +51,14 @@ object SettingsController {
}
}
var isLongPollInBackgroundEnabled: Boolean =
SettingsKeys.DEFAULT_VALUE_FEATURES_LONG_POLL_IN_BACKGROUND
var isLongPollInBackgroundEnabled: Boolean
get() = getBoolean(
SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND,
SettingsKeys.DEFAULT_VALUE_FEATURES_LONG_POLL_IN_BACKGROUND
)
set(value) {
field = value
put(SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND, value)
}
set(value) = put(SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND, value)
var deviceId: String
get() = getString("device_id", "").orEmpty()
set(value) = put("device_id", value)
}
@@ -1,20 +0,0 @@
package com.meloda.app.fast.model.api.requests
import com.meloda.app.fast.model.api.asInt
data class AccountSetOnlineRequest(
val voip: Boolean,
val accessToken: String
) {
val map
get() = mutableMapOf(
"voip" to voip.asInt().toString(),
"access_token" to accessToken
)
}
data class AccountSetOfflineRequest(val accessToken: String) {
val map get() = mutableMapOf("access_token" to accessToken)
}
@@ -3,6 +3,8 @@ package com.meloda.app.fast.network.service.account
import com.meloda.app.fast.network.ApiResponse
import com.meloda.app.fast.network.RestApiError
import com.slack.eithernet.ApiResult
import retrofit2.http.FieldMap
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.QueryMap
@@ -12,10 +14,16 @@ interface AccountService {
@GET(AccountUrls.SET_ONLINE)
suspend fun setOnline(
@QueryMap params: Map<String, String>
): ApiResult<ApiResponse<Any>, RestApiError>
): ApiResult<ApiResponse<Int>, RestApiError>
@POST(AccountUrls.SET_OFFLINE)
@GET(AccountUrls.SET_OFFLINE)
suspend fun setOffline(
@QueryMap params: Map<String, String>
): ApiResult<ApiResponse<Any>, RestApiError>
): ApiResult<ApiResponse<Int>, RestApiError>
@FormUrlEncoded
@POST(AccountUrls.REGISTER_DEVICE)
suspend fun registerDevice(
@FieldMap params: Map<String, String>
): ApiResult<ApiResponse<Int>, RestApiError>
}
@@ -3,6 +3,9 @@ package com.meloda.app.fast.network.service.account
import com.meloda.app.fast.common.AppConstants
object AccountUrls {
const val SET_ONLINE = "${AppConstants.URL_API}/account.setOnline"
const val SET_OFFLINE = "${AppConstants.URL_API}/account.setOffline"
private const val URL = AppConstants.URL_API
const val SET_ONLINE = "$URL/account.setOnline"
const val SET_OFFLINE = "$URL/account.setOffline"
const val REGISTER_DEVICE = "$URL/account.registerDevice"
}