some improvements
This commit is contained in:
@@ -8,6 +8,7 @@ import android.content.Intent
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.provider.Settings
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.activity.SystemBarStyle
|
import androidx.activity.SystemBarStyle
|
||||||
import androidx.activity.compose.setContent
|
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.Color
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.compose.LifecycleResumeEffect
|
import androidx.lifecycle.compose.LifecycleResumeEffect
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
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.androidx.compose.koinViewModel
|
||||||
import org.koin.compose.KoinContext
|
import org.koin.compose.KoinContext
|
||||||
import org.koin.compose.koinInject
|
import org.koin.compose.koinInject
|
||||||
|
|
||||||
import com.meloda.app.fast.designsystem.R as UiR
|
import com.meloda.app.fast.designsystem.R as UiR
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
@@ -52,6 +53,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
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 currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||||
val systemBarStyle = when (currentNightMode) {
|
val systemBarStyle = when (currentNightMode) {
|
||||||
Configuration.UI_MODE_NIGHT_NO -> SystemBarStyle.light(
|
Configuration.UI_MODE_NIGHT_NO -> SystemBarStyle.light(
|
||||||
@@ -175,25 +181,40 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private fun createNotificationChannels() {
|
private fun createNotificationChannels() {
|
||||||
isSdkAtLeast(Build.VERSION_CODES.O) {
|
isSdkAtLeast(Build.VERSION_CODES.O) {
|
||||||
val noCategoryName = getString(UiR.string.notification_channel_no_category_name)
|
val noCategoryName = getString(UiR.string.notification_channel_no_category_name)
|
||||||
val noCategoryDescriptionText = getString(UiR.string.notification_channel_no_category_description)
|
val noCategoryDescriptionText =
|
||||||
val noCategoryImportance = NotificationManager.IMPORTANCE_HIGH
|
getString(UiR.string.notification_channel_no_category_description)
|
||||||
|
val noCategoryImportance = NotificationManagerCompat.IMPORTANCE_HIGH
|
||||||
val noCategoryChannel =
|
val noCategoryChannel =
|
||||||
NotificationChannel(AppConstants.NOTIFICATION_CHANNEL_UNCATEGORIZED, noCategoryName, noCategoryImportance).apply {
|
NotificationChannel(
|
||||||
|
AppConstants.NOTIFICATION_CHANNEL_UNCATEGORIZED,
|
||||||
|
noCategoryName,
|
||||||
|
noCategoryImportance
|
||||||
|
).apply {
|
||||||
description = noCategoryDescriptionText
|
description = noCategoryDescriptionText
|
||||||
}
|
}
|
||||||
|
|
||||||
val longPollName = getString(UiR.string.notification_channel_long_polling_service_name)
|
val longPollName = getString(UiR.string.notification_channel_long_polling_service_name)
|
||||||
val longPollDescriptionText = getString(UiR.string.notification_channel_long_polling_service_description)
|
val longPollDescriptionText =
|
||||||
val longPollImportance = NotificationManager.IMPORTANCE_NONE
|
getString(UiR.string.notification_channel_long_polling_service_description)
|
||||||
|
val longPollImportance = NotificationManagerCompat.IMPORTANCE_NONE
|
||||||
val longPollChannel =
|
val longPollChannel =
|
||||||
NotificationChannel(AppConstants.NOTIFICATION_CHANNEL_LONG_POLLING, longPollName, longPollImportance).apply {
|
NotificationChannel(
|
||||||
|
AppConstants.NOTIFICATION_CHANNEL_LONG_POLLING,
|
||||||
|
longPollName,
|
||||||
|
longPollImportance
|
||||||
|
).apply {
|
||||||
description = longPollDescriptionText
|
description = longPollDescriptionText
|
||||||
}
|
}
|
||||||
|
|
||||||
val notificationManager: NotificationManager =
|
val notificationManager: NotificationManager =
|
||||||
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
|
||||||
notificationManager.createNotificationChannels(listOf(noCategoryChannel, longPollChannel))
|
notificationManager.createNotificationChannels(
|
||||||
|
listOf(
|
||||||
|
noCategoryChannel,
|
||||||
|
longPollChannel
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
</manifest>
|
|
||||||
+12
-6
@@ -1,15 +1,21 @@
|
|||||||
package com.meloda.app.fast.data.api.account
|
package com.meloda.app.fast.data.api.account
|
||||||
|
|
||||||
import com.meloda.app.fast.model.api.requests.AccountSetOfflineRequest
|
import com.meloda.app.fast.network.RestApiErrorDomain
|
||||||
import com.meloda.app.fast.model.api.requests.AccountSetOnlineRequest
|
import com.slack.eithernet.ApiResult
|
||||||
|
|
||||||
interface AccountRepository {
|
interface AccountRepository {
|
||||||
|
|
||||||
suspend fun setOnline(
|
suspend fun setOnline(
|
||||||
params: AccountSetOnlineRequest
|
accessToken: String? = null,
|
||||||
): Boolean
|
voip: Boolean = false
|
||||||
|
): ApiResult<Int, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun setOffline(
|
suspend fun setOffline(
|
||||||
params: AccountSetOfflineRequest
|
accessToken: String? = null
|
||||||
): Boolean
|
): ApiResult<Int, RestApiErrorDomain>
|
||||||
|
|
||||||
|
suspend fun registerDevice(
|
||||||
|
token: String,
|
||||||
|
deviceId: String
|
||||||
|
): ApiResult<Int, RestApiErrorDomain>
|
||||||
}
|
}
|
||||||
|
|||||||
+44
-9
@@ -1,19 +1,54 @@
|
|||||||
package com.meloda.app.fast.data.api.account
|
package com.meloda.app.fast.data.api.account
|
||||||
|
|
||||||
import com.meloda.app.fast.model.api.requests.AccountSetOfflineRequest
|
import android.os.Build
|
||||||
import com.meloda.app.fast.model.api.requests.AccountSetOnlineRequest
|
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.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(
|
class AccountRepositoryImpl(
|
||||||
private val accountService: AccountService
|
private val service: AccountService
|
||||||
) : com.meloda.app.fast.data.api.account.AccountRepository {
|
) : AccountRepository {
|
||||||
|
|
||||||
override suspend fun setOnline(params: AccountSetOnlineRequest): Boolean {
|
override suspend fun setOnline(
|
||||||
return false
|
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 {
|
override suspend fun setOffline(
|
||||||
return false
|
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 =
|
var isLongPollInBackgroundEnabled: Boolean
|
||||||
SettingsKeys.DEFAULT_VALUE_FEATURES_LONG_POLL_IN_BACKGROUND
|
|
||||||
get() = getBoolean(
|
get() = getBoolean(
|
||||||
SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND,
|
SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND,
|
||||||
SettingsKeys.DEFAULT_VALUE_FEATURES_LONG_POLL_IN_BACKGROUND
|
SettingsKeys.DEFAULT_VALUE_FEATURES_LONG_POLL_IN_BACKGROUND
|
||||||
)
|
)
|
||||||
set(value) {
|
set(value) = put(SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND, value)
|
||||||
field = 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)
|
|
||||||
}
|
|
||||||
+11
-3
@@ -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.ApiResponse
|
||||||
import com.meloda.app.fast.network.RestApiError
|
import com.meloda.app.fast.network.RestApiError
|
||||||
import com.slack.eithernet.ApiResult
|
import com.slack.eithernet.ApiResult
|
||||||
|
import retrofit2.http.FieldMap
|
||||||
|
import retrofit2.http.FormUrlEncoded
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
import retrofit2.http.QueryMap
|
import retrofit2.http.QueryMap
|
||||||
@@ -12,10 +14,16 @@ interface AccountService {
|
|||||||
@GET(AccountUrls.SET_ONLINE)
|
@GET(AccountUrls.SET_ONLINE)
|
||||||
suspend fun setOnline(
|
suspend fun setOnline(
|
||||||
@QueryMap params: Map<String, String>
|
@QueryMap params: Map<String, String>
|
||||||
): ApiResult<ApiResponse<Any>, RestApiError>
|
): ApiResult<ApiResponse<Int>, RestApiError>
|
||||||
|
|
||||||
@POST(AccountUrls.SET_OFFLINE)
|
@GET(AccountUrls.SET_OFFLINE)
|
||||||
suspend fun setOffline(
|
suspend fun setOffline(
|
||||||
@QueryMap params: Map<String, String>
|
@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>
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -3,6 +3,9 @@ package com.meloda.app.fast.network.service.account
|
|||||||
import com.meloda.app.fast.common.AppConstants
|
import com.meloda.app.fast.common.AppConstants
|
||||||
|
|
||||||
object AccountUrls {
|
object AccountUrls {
|
||||||
const val SET_ONLINE = "${AppConstants.URL_API}/account.setOnline"
|
private const val URL = AppConstants.URL_API
|
||||||
const val SET_OFFLINE = "${AppConstants.URL_API}/account.setOffline"
|
|
||||||
|
const val SET_ONLINE = "$URL/account.setOnline"
|
||||||
|
const val SET_OFFLINE = "$URL/account.setOffline"
|
||||||
|
const val REGISTER_DEVICE = "$URL/account.registerDevice"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user