Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f11b8dc6f4 | |||
| 167f980f29 | |||
| d428af4ac4 | |||
| 63bae014c5 | |||
| ad54477d11 | |||
| c8bd485724 | |||
| 26a0630393 | |||
| 3d153df79c | |||
| 9061a39407 | |||
| d8c8820b32 | |||
| abfe25d051 | |||
| 574b230b26 | |||
| b31c0f30c5 |
@@ -0,0 +1,56 @@
|
|||||||
|
name: Android CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
env:
|
||||||
|
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||||
|
RELEASE_SIGN_KEY_ALIAS: ${{ secrets.RELEASE_SIGN_KEY_ALIAS }}
|
||||||
|
RELEASE_SIGN_KEY_PASSWORD: ${{ secrets.RELEASE_SIGN_KEY_PASSWORD }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
android:
|
||||||
|
runs-on: android-jdk21
|
||||||
|
name: Build artifacts
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Make Gradle executable
|
||||||
|
run: chmod +x ./gradlew
|
||||||
|
|
||||||
|
- name: Build and sign release APK
|
||||||
|
run: ./gradlew assembleRelease
|
||||||
|
|
||||||
|
- name: Find generated release APK name
|
||||||
|
id: find_apk_release
|
||||||
|
run: |
|
||||||
|
APK_PATH=$(find app/build/outputs/apk/release -name "*.apk" | head -n 1)
|
||||||
|
echo "APK_PATH=$APK_PATH" >> $GITEA_ENV
|
||||||
|
echo "APK_NAME=$(basename $APK_PATH)" >> $GITEA_ENV
|
||||||
|
|
||||||
|
- name: Upload APK with original name
|
||||||
|
uses: christopherhx/gitea-upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ env.APK_NAME }}
|
||||||
|
path: ${{ env.APK_PATH }}
|
||||||
|
|
||||||
|
- name: Build and sign debug APK
|
||||||
|
run: ./gradlew assembleDebug
|
||||||
|
|
||||||
|
- name: Find generated debug APK name
|
||||||
|
id: find_apk_debug
|
||||||
|
run: |
|
||||||
|
APK_PATH=$(find app/build/outputs/apk/debug -name "*.apk" | head -n 1)
|
||||||
|
echo "APK_PATH=$APK_PATH" >> $GITEA_ENV
|
||||||
|
echo "APK_NAME=$(basename $APK_PATH)" >> $GITEA_ENV
|
||||||
|
|
||||||
|
- name: Upload APK with original name
|
||||||
|
uses: christopherhx/gitea-upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: ${{ env.APK_NAME }}
|
||||||
|
path: ${{ env.APK_PATH }}
|
||||||
@@ -15,3 +15,5 @@ build/
|
|||||||
local.properties
|
local.properties
|
||||||
.idea
|
.idea
|
||||||
/.kotlin
|
/.kotlin
|
||||||
|
.hotswan/
|
||||||
|
.java-version
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ Unofficial messenger for russian social network VKontakte
|
|||||||
- [ ] Forwarded messages
|
- [ ] Forwarded messages
|
||||||
- [ ] Wall post
|
- [ ] Wall post
|
||||||
- [ ] Comment in wall post
|
- [ ] Comment in wall post
|
||||||
|
- [ ] Comment in channel
|
||||||
- [ ] Poll
|
- [ ] Poll
|
||||||
- [ ] TODO
|
- [ ] TODO
|
||||||
- [x] Send messages
|
- [x] Send messages
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ android {
|
|||||||
applicationIdSuffix = ".debug"
|
applicationIdSuffix = ".debug"
|
||||||
}
|
}
|
||||||
named("release") {
|
named("release") {
|
||||||
signingConfig = signingConfigs.getByName("release")
|
signingConfig = signingConfigs.getByName("debugSigning")
|
||||||
|
|
||||||
isMinifyEnabled = true
|
isMinifyEnabled = true
|
||||||
isShrinkResources = true
|
isShrinkResources = true
|
||||||
@@ -79,9 +79,6 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.acra.email)
|
|
||||||
implementation(libs.acra.dialog)
|
|
||||||
|
|
||||||
implementation(projects.feature.auth)
|
implementation(projects.feature.auth)
|
||||||
|
|
||||||
implementation(projects.feature.chatmaterials)
|
implementation(projects.feature.chatmaterials)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:tools="http://schemas.android.com/tools"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
@@ -37,6 +37,12 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name="dev.meloda.fast.presentation.CrashActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:process=":error_handler"
|
||||||
|
android:theme="@style/CrashDialogTheme" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name="dev.meloda.fast.service.longpolling.LongPollingService"
|
android:name="dev.meloda.fast.service.longpolling.LongPollingService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package dev.meloda.fast.common
|
package dev.meloda.fast.common
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
import coil.ImageLoaderFactory
|
import coil.ImageLoaderFactory
|
||||||
@@ -8,14 +10,14 @@ import com.skydoves.compose.stability.runtime.ComposeStabilityAnalyzer
|
|||||||
import dev.meloda.fast.auth.BuildConfig
|
import dev.meloda.fast.auth.BuildConfig
|
||||||
import dev.meloda.fast.common.di.applicationModule
|
import dev.meloda.fast.common.di.applicationModule
|
||||||
import dev.meloda.fast.datastore.AppSettings
|
import dev.meloda.fast.datastore.AppSettings
|
||||||
import org.acra.config.dialog
|
import dev.meloda.fast.presentation.CrashActivity
|
||||||
import org.acra.config.mailSender
|
|
||||||
import org.acra.data.StringFormat
|
|
||||||
import org.acra.ktx.initAcra
|
|
||||||
import org.koin.android.ext.android.get
|
import org.koin.android.ext.android.get
|
||||||
import org.koin.android.ext.koin.androidContext
|
import org.koin.android.ext.koin.androidContext
|
||||||
import org.koin.android.ext.koin.androidLogger
|
import org.koin.android.ext.koin.androidLogger
|
||||||
import org.koin.core.context.GlobalContext.startKoin
|
import org.koin.core.context.GlobalContext.startKoin
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
class AppGlobal : Application(), ImageLoaderFactory {
|
class AppGlobal : Application(), ImageLoaderFactory {
|
||||||
|
|
||||||
@@ -27,7 +29,7 @@ class AppGlobal : Application(), ImageLoaderFactory {
|
|||||||
ComposeStabilityAnalyzer.setEnabled(BuildConfig.DEBUG)
|
ComposeStabilityAnalyzer.setEnabled(BuildConfig.DEBUG)
|
||||||
|
|
||||||
initKoin()
|
initKoin()
|
||||||
initAcra()
|
initCrashHandler()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun newImageLoader(): ImageLoader = get()
|
override fun newImageLoader(): ImageLoader = get()
|
||||||
@@ -40,20 +42,36 @@ class AppGlobal : Application(), ImageLoaderFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initAcra() {
|
private fun initCrashHandler() {
|
||||||
initAcra {
|
val defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
|
||||||
buildConfigClass = BuildConfig::class.java
|
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
|
||||||
reportFormat = StringFormat.JSON
|
val crashLogsDirectory = File(filesDir.absolutePath + "/crashlogs")
|
||||||
|
if (!crashLogsDirectory.exists()) {
|
||||||
mailSender {
|
crashLogsDirectory.mkdirs()
|
||||||
mailTo = "lischenkodev@gmail.com"
|
|
||||||
reportAsFile = true
|
|
||||||
reportFileName = "Crash.txt"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog {
|
val crashLogFileName = "crash_" + System.currentTimeMillis() + ".txt"
|
||||||
text = "App crashed"
|
val crashLogFile = File(crashLogsDirectory.absolutePath + "/" + crashLogFileName)
|
||||||
enabled = true
|
|
||||||
|
FileOutputStream(crashLogFile).use { stream ->
|
||||||
|
stream.write(throwable.stackTraceToString().toByteArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AppSettings.Debug.showAlertAfterCrash) {
|
||||||
|
try {
|
||||||
|
val intent = Intent(this, CrashActivity::class.java)
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||||
|
intent.putExtra("CRASH_LOG_FILE_URI", Uri.fromFile(crashLogFile))
|
||||||
|
startActivity(intent)
|
||||||
|
|
||||||
|
exitProcess(0)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (e !is RuntimeException) {
|
||||||
|
defaultExceptionHandler?.uncaughtException(thread, throwable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
defaultExceptionHandler?.uncaughtException(thread, throwable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package dev.meloda.fast.presentation
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
import dev.meloda.fast.ui.R
|
||||||
|
import dev.meloda.fast.ui.components.MaterialDialog
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun AppCrashedDialog(
|
||||||
|
stacktrace: String,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
onShare: () -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
var showTrace by rememberSaveable { mutableStateOf(false) }
|
||||||
|
|
||||||
|
MaterialDialog(
|
||||||
|
modifier = modifier,
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = stringResource(R.string.title_error),
|
||||||
|
text = if (showTrace) stacktrace else stringResource(R.string.error_occurred),
|
||||||
|
confirmText = stringResource(R.string.action_share),
|
||||||
|
confirmAction = onShare,
|
||||||
|
cancelText = stringResource(if (showTrace) R.string.action_hide_stacktrace else R.string.action_show_stacktrace),
|
||||||
|
cancelAction = { showTrace = !showTrace },
|
||||||
|
neutralText = stringResource(R.string.action_close),
|
||||||
|
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package dev.meloda.fast.presentation
|
||||||
|
|
||||||
|
import android.content.ClipData
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.activity.compose.setContent
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
|
import androidx.core.net.toFile
|
||||||
|
import dev.meloda.fast.datastore.UserSettings
|
||||||
|
import dev.meloda.fast.ui.theme.AppTheme
|
||||||
|
import dev.meloda.fast.ui.util.isNeedToEnableDarkMode
|
||||||
|
import org.koin.compose.koinInject
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class CrashActivity : ComponentActivity() {
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
|
||||||
|
val crashLogFileUri = intent.getParcelableExtra<Uri>("CRASH_LOG_FILE_URI") ?: run {
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val crashLogFile = crashLogFileUri.toFile().takeIf(File::exists) ?: run {
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val stacktrace = crashLogFile.bufferedReader().readText()
|
||||||
|
|
||||||
|
setContent {
|
||||||
|
val userSettings: UserSettings = koinInject()
|
||||||
|
|
||||||
|
AppTheme(
|
||||||
|
useDarkTheme = isNeedToEnableDarkMode(darkMode = userSettings.darkMode.collectAsState().value),
|
||||||
|
useDynamicColors = userSettings.enableDynamicColors.collectAsState().value,
|
||||||
|
selectedColorScheme = 0,
|
||||||
|
useAmoledBackground = userSettings.enableAmoledDark.collectAsState().value,
|
||||||
|
useSystemFont = userSettings.useSystemFont.collectAsState().value
|
||||||
|
) {
|
||||||
|
AppCrashedDialog(
|
||||||
|
stacktrace = stacktrace,
|
||||||
|
onDismiss = { finish() },
|
||||||
|
onShare = {
|
||||||
|
val uri = FileProvider.getUriForFile(
|
||||||
|
this,
|
||||||
|
"$packageName.provider",
|
||||||
|
crashLogFile
|
||||||
|
)
|
||||||
|
|
||||||
|
val sendIntent = Intent().apply {
|
||||||
|
action = Intent.ACTION_SEND
|
||||||
|
type = "text/plain"
|
||||||
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
putExtra(Intent.EXTRA_STREAM, uri)
|
||||||
|
clipData = ClipData.newRawUri(null, uri)
|
||||||
|
}
|
||||||
|
|
||||||
|
val chooserIntent = Intent.createChooser(sendIntent, null)
|
||||||
|
chooserIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
startActivity(chooserIntent)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,7 +38,7 @@ import dev.chrisbanes.haze.HazeState
|
|||||||
import dev.chrisbanes.haze.hazeEffect
|
import dev.chrisbanes.haze.hazeEffect
|
||||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||||
import dev.chrisbanes.haze.materials.HazeMaterials
|
import dev.chrisbanes.haze.materials.HazeMaterials
|
||||||
import dev.meloda.fast.convos.navigation.ConvoGraph
|
import dev.meloda.fast.convos.model.ConvoNavigationIntent
|
||||||
import dev.meloda.fast.convos.navigation.convosGraph
|
import dev.meloda.fast.convos.navigation.convosGraph
|
||||||
import dev.meloda.fast.friends.navigation.Friends
|
import dev.meloda.fast.friends.navigation.Friends
|
||||||
import dev.meloda.fast.friends.navigation.friendsScreen
|
import dev.meloda.fast.friends.navigation.friendsScreen
|
||||||
@@ -198,19 +198,20 @@ fun MainScreen(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
convosGraph(
|
convosGraph(
|
||||||
|
handleNavigationIntent = { intent ->
|
||||||
|
when (intent) {
|
||||||
|
ConvoNavigationIntent.Back -> {}
|
||||||
|
ConvoNavigationIntent.Archive -> {}
|
||||||
|
ConvoNavigationIntent.CreateChat -> onNavigateToCreateChat()
|
||||||
|
is ConvoNavigationIntent.MessagesHistory -> {
|
||||||
|
onNavigateToMessagesHistory(intent.convoId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
activity = activity,
|
activity = activity,
|
||||||
onError = onError,
|
|
||||||
onNavigateToMessagesHistory = onNavigateToMessagesHistory,
|
|
||||||
onNavigateToCreateChat = onNavigateToCreateChat,
|
|
||||||
onScrolledToTop = {
|
|
||||||
tabReselected = tabReselected.toMutableMap().also {
|
|
||||||
it[ConvoGraph] = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
profileScreen(
|
profileScreen(
|
||||||
activity = activity,
|
activity = activity,
|
||||||
onError = onError,
|
|
||||||
onSettingsButtonClicked = onSettingsButtonClicked,
|
onSettingsButtonClicked = onSettingsButtonClicked,
|
||||||
onPhotoClicked = onPhotoClicked
|
onPhotoClicked = onPhotoClicked
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
|
|||||||
compileSdk = getVersionInt("compileSdk")
|
compileSdk = getVersionInt("compileSdk")
|
||||||
targetSdk = getVersionInt("targetSdk")
|
targetSdk = getVersionInt("targetSdk")
|
||||||
}
|
}
|
||||||
|
lint {
|
||||||
|
abortOnError = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import com.android.build.api.dsl.LibraryExtension
|
|||||||
import com.android.build.api.variant.LibraryAndroidComponentsExtension
|
import com.android.build.api.variant.LibraryAndroidComponentsExtension
|
||||||
import dev.meloda.fast.configureKotlinAndroid
|
import dev.meloda.fast.configureKotlinAndroid
|
||||||
import dev.meloda.fast.disableUnnecessaryAndroidTests
|
import dev.meloda.fast.disableUnnecessaryAndroidTests
|
||||||
|
import dev.meloda.fast.getVersionInt
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.kotlin.dsl.configure
|
import org.gradle.kotlin.dsl.configure
|
||||||
@@ -20,7 +21,13 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
|
|||||||
extensions.configure<LibraryExtension> {
|
extensions.configure<LibraryExtension> {
|
||||||
configureKotlinAndroid(this)
|
configureKotlinAndroid(this)
|
||||||
androidResources.enable = false
|
androidResources.enable = false
|
||||||
defaultConfig.testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
defaultConfig {
|
||||||
|
minSdk = getVersionInt("minSdk")
|
||||||
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
}
|
||||||
|
lint {
|
||||||
|
abortOnError = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
extensions.configure<LibraryAndroidComponentsExtension> {
|
extensions.configure<LibraryAndroidComponentsExtension> {
|
||||||
disableUnnecessaryAndroidTests(target)
|
disableUnnecessaryAndroidTests(target)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ object AppConstants {
|
|||||||
|
|
||||||
const val INSTALL_APP_MIME_TYPE = "application/vnd.android.package-archive"
|
const val INSTALL_APP_MIME_TYPE = "application/vnd.android.package-archive"
|
||||||
|
|
||||||
const val API_VERSION = "5.238"
|
const val API_VERSION = "5.263"
|
||||||
const val URL_OAUTH = "https://oauth.vk.ru"
|
const val URL_OAUTH = "https://oauth.vk.ru"
|
||||||
const val URL_API = "https://api.vk.ru/method"
|
const val URL_API = "https://api.vk.ru/method"
|
||||||
|
|
||||||
|
|||||||
@@ -598,6 +598,7 @@ private fun getAttachmentIconByType(attachmentType: AttachmentType): UiImage? {
|
|||||||
AttachmentType.VIDEO_MESSAGE -> null
|
AttachmentType.VIDEO_MESSAGE -> null
|
||||||
AttachmentType.GROUP_CHAT_STICKER -> R.drawable.ic_sticker_fill_round_24
|
AttachmentType.GROUP_CHAT_STICKER -> R.drawable.ic_sticker_fill_round_24
|
||||||
AttachmentType.STICKER_PACK_PREVIEW -> null
|
AttachmentType.STICKER_PACK_PREVIEW -> null
|
||||||
|
AttachmentType.CHANNEL_MESSAGE -> null
|
||||||
}?.let(UiImage::Resource)
|
}?.let(UiImage::Resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,6 +688,7 @@ fun getAttachmentUiText(
|
|||||||
AttachmentType.VIDEO_MESSAGE -> R.string.message_attachments_video_message
|
AttachmentType.VIDEO_MESSAGE -> R.string.message_attachments_video_message
|
||||||
AttachmentType.GROUP_CHAT_STICKER -> R.string.message_attachments_group_sticker
|
AttachmentType.GROUP_CHAT_STICKER -> R.string.message_attachments_group_sticker
|
||||||
AttachmentType.STICKER_PACK_PREVIEW -> R.string.message_attachments_sticker_pack_preview
|
AttachmentType.STICKER_PACK_PREVIEW -> R.string.message_attachments_sticker_pack_preview
|
||||||
|
AttachmentType.CHANNEL_MESSAGE -> R.string.message_attachments_channel_message
|
||||||
}.let(UiText::Resource)
|
}.let(UiText::Resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ enum class AttachmentType(var value: String) {
|
|||||||
ARTICLE("article"),
|
ARTICLE("article"),
|
||||||
VIDEO_MESSAGE("video_message"),
|
VIDEO_MESSAGE("video_message"),
|
||||||
GROUP_CHAT_STICKER("ugc_sticker"),
|
GROUP_CHAT_STICKER("ugc_sticker"),
|
||||||
STICKER_PACK_PREVIEW("sticker_pack_preview")
|
STICKER_PACK_PREVIEW("sticker_pack_preview"),
|
||||||
|
CHANNEL_MESSAGE("channel_message")
|
||||||
;
|
;
|
||||||
|
|
||||||
fun isMultiple(): Boolean = this in listOf(PHOTO, VIDEO, AUDIO, FILE)
|
fun isMultiple(): Boolean = this in listOf(PHOTO, VIDEO, AUDIO, FILE)
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ data class VkAttachmentItemData(
|
|||||||
@Json(name = "article") val article: VkArticleData?,
|
@Json(name = "article") val article: VkArticleData?,
|
||||||
@Json(name = "video_message") val videoMessage: VkVideoMessageData?,
|
@Json(name = "video_message") val videoMessage: VkVideoMessageData?,
|
||||||
@Json(name = "ugc_sticker") val groupSticker: VkGroupStickerData?,
|
@Json(name = "ugc_sticker") val groupSticker: VkGroupStickerData?,
|
||||||
@Json(name = "sticker_pack_preview") val stickerPackPreview: VkStickerPackPreviewData?
|
@Json(name = "sticker_pack_preview") val stickerPackPreview: VkStickerPackPreviewData?,
|
||||||
|
@Json(name = "channel_message") val channelMessageData: VkChannelMessageData?
|
||||||
) {
|
) {
|
||||||
fun toDomain(): VkAttachment = when (AttachmentType.parse(type)) {
|
fun toDomain(): VkAttachment = when (AttachmentType.parse(type)) {
|
||||||
AttachmentType.UNKNOWN -> VkUnknownAttachment
|
AttachmentType.UNKNOWN -> VkUnknownAttachment
|
||||||
@@ -66,5 +67,6 @@ data class VkAttachmentItemData(
|
|||||||
AttachmentType.VIDEO_MESSAGE -> videoMessage?.toDomain()
|
AttachmentType.VIDEO_MESSAGE -> videoMessage?.toDomain()
|
||||||
AttachmentType.GROUP_CHAT_STICKER -> groupSticker?.toDomain()
|
AttachmentType.GROUP_CHAT_STICKER -> groupSticker?.toDomain()
|
||||||
AttachmentType.STICKER_PACK_PREVIEW -> stickerPackPreview?.toDomain()
|
AttachmentType.STICKER_PACK_PREVIEW -> stickerPackPreview?.toDomain()
|
||||||
|
AttachmentType.CHANNEL_MESSAGE -> channelMessageData?.toDomain()
|
||||||
} ?: VkUnknownAttachment
|
} ?: VkUnknownAttachment
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package dev.meloda.fast.model.api.data
|
||||||
|
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
import dev.meloda.fast.model.api.domain.VkChannelMessage
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class VkChannelMessageData(
|
||||||
|
@Json(name = "channel_id") val channelId: Long,
|
||||||
|
@Json(name = "cmid") val cmId: Long,
|
||||||
|
@Json(name = "author_id") val authorId: Long,
|
||||||
|
@Json(name = "channel_info") val channelInfo: ChannelInfo,
|
||||||
|
@Json(name = "channel_type") val channelType: String,
|
||||||
|
@Json(name = "guid") val guid: String,
|
||||||
|
@Json(name = "text") val text: String?,
|
||||||
|
@Json(name = "time") val time: Long,
|
||||||
|
@Json(name = "attachments") val attachments: List<VkAttachmentItemData> = emptyList(),
|
||||||
|
) : VkAttachmentData {
|
||||||
|
|
||||||
|
@JsonClass(generateAdapter = true)
|
||||||
|
data class ChannelInfo(
|
||||||
|
@Json(name = "photo_base") val photoBase: String?,
|
||||||
|
@Json(name = "title") val title: String
|
||||||
|
)
|
||||||
|
|
||||||
|
fun toDomain(): VkChannelMessage = VkChannelMessage(
|
||||||
|
channelId = channelId,
|
||||||
|
cmId = cmId,
|
||||||
|
authorId = authorId,
|
||||||
|
channelInfo = VkChannelMessage.ChannelInfo(
|
||||||
|
title = channelInfo.title,
|
||||||
|
photoBase = channelInfo.photoBase
|
||||||
|
),
|
||||||
|
channelType = channelType,
|
||||||
|
guid = guid,
|
||||||
|
text = text,
|
||||||
|
time = time,
|
||||||
|
attachments = attachments.map(VkAttachmentItemData::toDomain),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package dev.meloda.fast.model.api.domain
|
||||||
|
|
||||||
|
import dev.meloda.fast.model.api.data.AttachmentType
|
||||||
|
|
||||||
|
data class VkChannelMessage(
|
||||||
|
val channelId: Long,
|
||||||
|
val cmId: Long,
|
||||||
|
val authorId: Long,
|
||||||
|
val channelInfo: ChannelInfo,
|
||||||
|
val channelType: String,
|
||||||
|
val guid: String,
|
||||||
|
val text: String?,
|
||||||
|
val time: Long,
|
||||||
|
val attachments: List<VkAttachment>?,
|
||||||
|
) : VkAttachment {
|
||||||
|
|
||||||
|
data class ChannelInfo(
|
||||||
|
val title: String,
|
||||||
|
val photoBase: String?
|
||||||
|
)
|
||||||
|
|
||||||
|
override val type: AttachmentType = AttachmentType.CHANNEL_MESSAGE
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package dev.meloda.fast.ui.components
|
package dev.meloda.fast.ui.components
|
||||||
|
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.Indication
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.combinedClickable
|
import androidx.compose.foundation.combinedClickable
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
@@ -20,6 +21,8 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.Shape
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3ExpressiveApi::class)
|
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||||
@@ -30,27 +33,32 @@ fun FastIconButton(
|
|||||||
onLongClick: (() -> Unit)? = null,
|
onLongClick: (() -> Unit)? = null,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
colors: IconButtonColors = IconButtonDefaults.iconButtonColors(),
|
colors: IconButtonColors = IconButtonDefaults.iconButtonColors(),
|
||||||
|
containerColor: Color = colors.containerColor(enabled),
|
||||||
|
contentColor: Color = colors.contentColor(enabled),
|
||||||
|
size: Dp = IconButtonTokens.StateLayerSize,
|
||||||
|
shape: Shape = IconButtonTokens.StateLayerShape,
|
||||||
|
alignment: Alignment = Alignment.Center,
|
||||||
interactionSource: MutableInteractionSource? = null,
|
interactionSource: MutableInteractionSource? = null,
|
||||||
|
indication: Indication = ripple(),
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
modifier
|
modifier
|
||||||
.minimumInteractiveComponentSize()
|
.minimumInteractiveComponentSize()
|
||||||
.size(IconButtonTokens.StateLayerSize)
|
.size(size)
|
||||||
.clip(IconButtonTokens.StateLayerShape)
|
.clip(shape)
|
||||||
.background(color = colors.containerColor(enabled))
|
.background(containerColor)
|
||||||
.combinedClickable(
|
.combinedClickable(
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
onLongClick = onLongClick,
|
onLongClick = onLongClick,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
interactionSource = interactionSource,
|
interactionSource = interactionSource,
|
||||||
indication = ripple()
|
indication = indication
|
||||||
),
|
),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = alignment
|
||||||
) {
|
) {
|
||||||
val contentColor = colors.contentColor(enabled)
|
CompositionLocalProvider(LocalContentColor provides contentColor) { content() }
|
||||||
CompositionLocalProvider(LocalContentColor provides contentColor, content = content)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package dev.meloda.fast.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.border
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.sizeIn
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.foundation.shape.CornerBasedShape
|
||||||
|
import androidx.compose.foundation.shape.CornerSize
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.VerticalDivider
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.Shape
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import dev.meloda.fast.ui.util.ImmutableList
|
||||||
|
|
||||||
|
data class SegmentedButtonItem(
|
||||||
|
val key: String,
|
||||||
|
val iconResId: Int
|
||||||
|
)
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SegmentedButtonsRow(
|
||||||
|
items: ImmutableList<SegmentedButtonItem>,
|
||||||
|
onClick: (index: Int) -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
containerShape: CornerBasedShape = RoundedCornerShape(24.dp),
|
||||||
|
containerColor: Color = MaterialTheme.colorScheme.background,
|
||||||
|
borderColor: Color = MaterialTheme.colorScheme.outlineVariant,
|
||||||
|
borderSize: Dp = 1.dp,
|
||||||
|
iconContainerWidth: Dp = 42.dp,
|
||||||
|
iconContainerHeight: Dp = 36.dp,
|
||||||
|
iconSize: Dp = 18.dp,
|
||||||
|
showDividers: Boolean = true
|
||||||
|
) {
|
||||||
|
SegmentedButtonsRow(
|
||||||
|
modifier = modifier.sizeIn(maxHeight = iconContainerHeight + borderSize),
|
||||||
|
items = items.mapIndexed { index, item ->
|
||||||
|
{
|
||||||
|
val first = index == 0
|
||||||
|
val last = index == items.lastIndex
|
||||||
|
|
||||||
|
if (showDividers && !first) {
|
||||||
|
VerticalDivider(modifier = Modifier.padding(vertical = iconContainerHeight / 4))
|
||||||
|
}
|
||||||
|
|
||||||
|
SegmentedButton(
|
||||||
|
onClick = { onClick(index) },
|
||||||
|
iconResId = item.iconResId,
|
||||||
|
modifier = Modifier.size(
|
||||||
|
iconContainerWidth,
|
||||||
|
iconContainerHeight
|
||||||
|
),
|
||||||
|
iconSize = iconSize,
|
||||||
|
shape = containerShape.copy(
|
||||||
|
topStart = if (!first) CornerSize(0.dp) else containerShape.topStart,
|
||||||
|
bottomStart = if (!first) CornerSize(0.dp) else containerShape.bottomStart,
|
||||||
|
topEnd = if (!last) CornerSize(0.dp) else containerShape.topEnd,
|
||||||
|
bottomEnd = if (!last) CornerSize(0.dp) else containerShape.bottomEnd
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
containerShape = containerShape,
|
||||||
|
containerColor = containerColor,
|
||||||
|
borderColor = borderColor,
|
||||||
|
borderSize = borderSize
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SegmentedButtonsRow(
|
||||||
|
items: ImmutableList<@Composable () -> Unit>,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
containerShape: CornerBasedShape = RoundedCornerShape(24.dp),
|
||||||
|
containerColor: Color = MaterialTheme.colorScheme.background,
|
||||||
|
borderColor: Color = MaterialTheme.colorScheme.outlineVariant,
|
||||||
|
borderSize: Dp = 1.dp,
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = modifier
|
||||||
|
.background(containerColor, containerShape)
|
||||||
|
.border(borderSize, borderColor, containerShape)
|
||||||
|
) {
|
||||||
|
items.forEach { it.invoke() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SegmentedButton(
|
||||||
|
onClick: () -> Unit,
|
||||||
|
iconResId: Int,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
iconSize: Dp = 18.dp,
|
||||||
|
shape: Shape = CircleShape
|
||||||
|
) {
|
||||||
|
FastIconButton(
|
||||||
|
onClick = onClick,
|
||||||
|
modifier = modifier,
|
||||||
|
shape = shape
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier.size(iconSize),
|
||||||
|
painter = painterResource(iconResId),
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,7 +58,7 @@ fun AppTheme(
|
|||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
val colorScheme: ColorScheme = when {
|
val colorScheme: ColorScheme = predefinedColorScheme ?: when {
|
||||||
useDynamicColors && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
useDynamicColors && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||||
if (useDarkTheme) dynamicDarkColorScheme(context)
|
if (useDarkTheme) dynamicDarkColorScheme(context)
|
||||||
else dynamicLightColorScheme(context)
|
else dynamicLightColorScheme(context)
|
||||||
@@ -82,10 +82,6 @@ fun AppTheme(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val colorPrimary by animateColorAsState(colorScheme.primary)
|
|
||||||
val colorSurface by animateColorAsState(colorScheme.surface)
|
|
||||||
val colorBackground by animateColorAsState(colorScheme.background)
|
|
||||||
|
|
||||||
val typography = if (useSystemFont) {
|
val typography = if (useSystemFont) {
|
||||||
MaterialTheme.typography
|
MaterialTheme.typography
|
||||||
} else {
|
} else {
|
||||||
@@ -118,12 +114,7 @@ fun AppTheme(
|
|||||||
}
|
}
|
||||||
|
|
||||||
MaterialExpressiveTheme(
|
MaterialExpressiveTheme(
|
||||||
colorScheme = (predefinedColorScheme ?: colorScheme)
|
colorScheme = colorScheme,
|
||||||
.copy(
|
|
||||||
primary = colorPrimary,
|
|
||||||
background = colorBackground,
|
|
||||||
surface = colorSurface
|
|
||||||
),
|
|
||||||
typography = typography,
|
typography = typography,
|
||||||
content = content
|
content = content
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import androidx.compose.ui.graphics.luminance
|
|||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import androidx.compose.ui.input.key.onKeyEvent
|
import androidx.compose.ui.input.key.onKeyEvent
|
||||||
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.colorResource
|
import androidx.compose.ui.res.colorResource
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
@@ -113,11 +114,12 @@ fun LazyListState.isScrollingUp(): Boolean {
|
|||||||
@Composable
|
@Composable
|
||||||
fun isNeedToEnableDarkMode(darkMode: DarkMode): Boolean {
|
fun isNeedToEnableDarkMode(darkMode: DarkMode): Boolean {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val configuration = LocalConfiguration.current
|
||||||
|
|
||||||
val appForceDarkMode = darkMode == DarkMode.ENABLED
|
val appForceDarkMode = darkMode == DarkMode.ENABLED
|
||||||
val appBatterySaver = darkMode == DarkMode.AUTO_BATTERY
|
val appBatterySaver = darkMode == DarkMode.AUTO_BATTERY
|
||||||
|
|
||||||
val systemUiNightMode = context.resources.configuration.uiMode
|
val systemUiNightMode = configuration.uiMode
|
||||||
|
|
||||||
val isSystemBatterySaver = context.getSystemService<PowerManager>()?.isPowerSaveMode == true
|
val isSystemBatterySaver = context.getSystemService<PowerManager>()?.isPowerSaveMode == true
|
||||||
val isSystemUsingDarkTheme =
|
val isSystemUsingDarkTheme =
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package dev.meloda.fast.ui.util
|
package dev.meloda.fast.ui.util
|
||||||
|
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
|
import dev.meloda.fast.ui.util.ImmutableList.Companion.toImmutableList
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
class ImmutableList<T>(val values: List<T>) : Collection<T> {
|
class ImmutableList<T>(val values: List<T>) : Collection<T> {
|
||||||
@@ -57,3 +58,9 @@ class ImmutableList<T>(val values: List<T>) : Collection<T> {
|
|||||||
fun <T> emptyImmutableList(): ImmutableList<T> = ImmutableList(emptyList())
|
fun <T> emptyImmutableList(): ImmutableList<T> = ImmutableList(emptyList())
|
||||||
|
|
||||||
fun <T> immutableListOf(vararg elements: T) = ImmutableList(listOf(elements = elements))
|
fun <T> immutableListOf(vararg elements: T) = ImmutableList(listOf(elements = elements))
|
||||||
|
|
||||||
|
inline fun <T> buildImmutableList(builderAction: MutableList<T>.() -> Unit): ImmutableList<T> {
|
||||||
|
val mutableList = mutableListOf<T>()
|
||||||
|
mutableList.apply(builderAction)
|
||||||
|
return mutableList.toImmutableList()
|
||||||
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@
|
|||||||
<string name="message_attachments_video_message">Video message</string>
|
<string name="message_attachments_video_message">Video message</string>
|
||||||
<string name="message_attachments_group_sticker">Group sticker</string>
|
<string name="message_attachments_group_sticker">Group sticker</string>
|
||||||
<string name="message_attachments_sticker_pack_preview">Sticker pack preview</string>
|
<string name="message_attachments_sticker_pack_preview">Sticker pack preview</string>
|
||||||
|
<string name="message_attachments_channel_message">Channel message</string>
|
||||||
|
|
||||||
<string name="chat_interaction_uploading_file">Uploading file</string>
|
<string name="chat_interaction_uploading_file">Uploading file</string>
|
||||||
<string name="chat_interaction_uploading_photo">Uploading photo</string>
|
<string name="chat_interaction_uploading_photo">Uploading photo</string>
|
||||||
@@ -305,4 +306,7 @@
|
|||||||
<string name="confirm_chat_create_empty_with_title">Are you sure you want to create chat «%s» only with yourself?</string>
|
<string name="confirm_chat_create_empty_with_title">Are you sure you want to create chat «%s» only with yourself?</string>
|
||||||
|
|
||||||
<string name="title_edit_message">Edit message</string>
|
<string name="title_edit_message">Edit message</string>
|
||||||
|
<string name="action_close">Close</string>
|
||||||
|
<string name="action_hide_stacktrace">Hide stacktrace</string>
|
||||||
|
<string name="action_show_stacktrace">Show stacktrace</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -2,4 +2,13 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar" />
|
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar" />
|
||||||
|
|
||||||
|
<style name="CrashDialogTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
|
||||||
|
<item name="android:windowIsTranslucent">true</item>
|
||||||
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
|
<item name="android:windowContentOverlay">@null</item>
|
||||||
|
<item name="android:windowNoTitle">true</item>
|
||||||
|
<item name="android:windowIsFloating">true</item>
|
||||||
|
<item name="android:backgroundDimEnabled">false</item>
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -100,7 +100,13 @@ class LoginViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onBackPressed() {
|
fun onBackPressed() {
|
||||||
_screenState.setValue { old -> old.copy(showLogo = true) }
|
_screenState.setValue { old ->
|
||||||
|
old.copy(
|
||||||
|
showLogo = true,
|
||||||
|
loginError = false,
|
||||||
|
passwordError = false
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onPasswordVisibilityButtonClicked() {
|
fun onPasswordVisibilityButtonClicked() {
|
||||||
|
|||||||
+17
-2
@@ -31,9 +31,13 @@ import androidx.compose.material3.ScaffoldDefaults
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.TextField
|
import androidx.compose.material3.TextField
|
||||||
|
import androidx.compose.material3.lightColorScheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.autofill.ContentType
|
import androidx.compose.ui.autofill.ContentType
|
||||||
@@ -58,7 +62,6 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import dev.meloda.fast.auth.login.LoginViewModel
|
import dev.meloda.fast.auth.login.LoginViewModel
|
||||||
import dev.meloda.fast.auth.login.model.CaptchaArguments
|
|
||||||
import dev.meloda.fast.auth.login.model.LoginDialog
|
import dev.meloda.fast.auth.login.model.LoginDialog
|
||||||
import dev.meloda.fast.auth.login.model.LoginScreenState
|
import dev.meloda.fast.auth.login.model.LoginScreenState
|
||||||
import dev.meloda.fast.auth.login.model.LoginUserBannedArguments
|
import dev.meloda.fast.auth.login.model.LoginUserBannedArguments
|
||||||
@@ -67,6 +70,8 @@ import dev.meloda.fast.ui.R
|
|||||||
import dev.meloda.fast.ui.common.LocalSizeConfig
|
import dev.meloda.fast.ui.common.LocalSizeConfig
|
||||||
import dev.meloda.fast.ui.components.MaterialDialog
|
import dev.meloda.fast.ui.components.MaterialDialog
|
||||||
import dev.meloda.fast.ui.components.TextFieldErrorText
|
import dev.meloda.fast.ui.components.TextFieldErrorText
|
||||||
|
import dev.meloda.fast.ui.theme.AppTheme
|
||||||
|
import dev.meloda.fast.ui.theme.ClassicColorScheme
|
||||||
import dev.meloda.fast.ui.util.handleEnterKey
|
import dev.meloda.fast.ui.util.handleEnterKey
|
||||||
import dev.meloda.fast.ui.util.handleTabKey
|
import dev.meloda.fast.ui.util.handleTabKey
|
||||||
import org.koin.androidx.compose.koinViewModel
|
import org.koin.androidx.compose.koinViewModel
|
||||||
@@ -114,6 +119,12 @@ fun LoginRoute(
|
|||||||
viewModel.onValidationCodeReceived(validationCode)
|
viewModel.onValidationCodeReceived(validationCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var useClassic by rememberSaveable { mutableStateOf(true) }
|
||||||
|
|
||||||
|
AppTheme(
|
||||||
|
predefinedColorScheme = if (useClassic) ClassicColorScheme.lightScheme
|
||||||
|
else lightColorScheme(),
|
||||||
|
) {
|
||||||
LoginScreen(
|
LoginScreen(
|
||||||
screenState = screenState,
|
screenState = screenState,
|
||||||
onLoginInputChanged = viewModel::onLoginInputChanged,
|
onLoginInputChanged = viewModel::onLoginInputChanged,
|
||||||
@@ -122,9 +133,13 @@ fun LoginRoute(
|
|||||||
onPasswordVisibilityButtonClicked = viewModel::onPasswordVisibilityButtonClicked,
|
onPasswordVisibilityButtonClicked = viewModel::onPasswordVisibilityButtonClicked,
|
||||||
onPasswordFieldGoAction = viewModel::onSignInButtonClicked,
|
onPasswordFieldGoAction = viewModel::onSignInButtonClicked,
|
||||||
onSignInButtonClicked = viewModel::onSignInButtonClicked,
|
onSignInButtonClicked = viewModel::onSignInButtonClicked,
|
||||||
onLogoClicked = viewModel::onLogoClicked,
|
onLogoClicked = {
|
||||||
|
viewModel.onLogoClicked()
|
||||||
|
useClassic = !useClassic
|
||||||
|
},
|
||||||
onLogoLongClicked = onNavigateToSettings
|
onLogoLongClicked = onNavigateToSettings
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
HandleDialogs(
|
HandleDialogs(
|
||||||
loginDialog = loginDialog,
|
loginDialog = loginDialog,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package dev.meloda.fast.convos
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.compose.runtime.Immutable
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
@@ -15,10 +16,12 @@ import dev.meloda.fast.common.extensions.listenValue
|
|||||||
import dev.meloda.fast.common.extensions.setValue
|
import dev.meloda.fast.common.extensions.setValue
|
||||||
import dev.meloda.fast.common.extensions.updateValue
|
import dev.meloda.fast.common.extensions.updateValue
|
||||||
import dev.meloda.fast.convos.model.ConvoDialog
|
import dev.meloda.fast.convos.model.ConvoDialog
|
||||||
import dev.meloda.fast.convos.model.ConvoNavigation
|
import dev.meloda.fast.convos.model.ConvoIntent
|
||||||
|
import dev.meloda.fast.convos.model.ConvoNavigationIntent
|
||||||
import dev.meloda.fast.convos.model.ConvosScreenState
|
import dev.meloda.fast.convos.model.ConvosScreenState
|
||||||
import dev.meloda.fast.convos.model.InteractionJob
|
import dev.meloda.fast.convos.model.InteractionJob
|
||||||
import dev.meloda.fast.convos.model.NewInteractionException
|
import dev.meloda.fast.convos.model.NewInteractionException
|
||||||
|
import dev.meloda.fast.data.UserConfig
|
||||||
import dev.meloda.fast.data.VkUtils
|
import dev.meloda.fast.data.VkUtils
|
||||||
import dev.meloda.fast.data.processState
|
import dev.meloda.fast.data.processState
|
||||||
import dev.meloda.fast.datastore.UserSettings
|
import dev.meloda.fast.datastore.UserSettings
|
||||||
@@ -28,25 +31,23 @@ import dev.meloda.fast.domain.LongPollUpdatesParser
|
|||||||
import dev.meloda.fast.domain.MessagesUseCase
|
import dev.meloda.fast.domain.MessagesUseCase
|
||||||
import dev.meloda.fast.domain.util.asPresentation
|
import dev.meloda.fast.domain.util.asPresentation
|
||||||
import dev.meloda.fast.domain.util.extractAvatar
|
import dev.meloda.fast.domain.util.extractAvatar
|
||||||
import dev.meloda.fast.model.BaseError
|
|
||||||
import dev.meloda.fast.model.ConvosFilter
|
import dev.meloda.fast.model.ConvosFilter
|
||||||
import dev.meloda.fast.model.InteractionType
|
import dev.meloda.fast.model.InteractionType
|
||||||
import dev.meloda.fast.model.LongPollParsedEvent
|
import dev.meloda.fast.model.LongPollParsedEvent
|
||||||
import dev.meloda.fast.model.api.domain.VkConvo
|
import dev.meloda.fast.model.api.domain.VkConvo
|
||||||
import dev.meloda.fast.ui.model.vk.ConvoOption
|
import dev.meloda.fast.ui.model.vk.ConvoOption
|
||||||
import dev.meloda.fast.ui.model.vk.UiConvo
|
import dev.meloda.fast.ui.model.vk.UiConvo
|
||||||
|
import dev.meloda.fast.ui.util.ImmutableList
|
||||||
import dev.meloda.fast.ui.util.ImmutableList.Companion.toImmutableList
|
import dev.meloda.fast.ui.util.ImmutableList.Companion.toImmutableList
|
||||||
|
import dev.meloda.fast.ui.util.buildImmutableList
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
import kotlinx.coroutines.flow.stateIn
|
|
||||||
import kotlinx.coroutines.flow.update
|
|
||||||
|
|
||||||
|
@Immutable
|
||||||
class ConvosViewModel(
|
class ConvosViewModel(
|
||||||
updatesParser: LongPollUpdatesParser,
|
updatesParser: LongPollUpdatesParser,
|
||||||
private val filter: ConvosFilter,
|
val filter: ConvosFilter,
|
||||||
private val convoUseCase: ConvoUseCase,
|
private val convoUseCase: ConvoUseCase,
|
||||||
private val messagesUseCase: MessagesUseCase,
|
private val messagesUseCase: MessagesUseCase,
|
||||||
private val resources: Resources,
|
private val resources: Resources,
|
||||||
@@ -55,43 +56,22 @@ class ConvosViewModel(
|
|||||||
private val applicationContext: Context,
|
private val applicationContext: Context,
|
||||||
private val loadConvosByIdUseCase: LoadConvosByIdUseCase
|
private val loadConvosByIdUseCase: LoadConvosByIdUseCase
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
private val _screenState = MutableStateFlow(ConvosScreenState.EMPTY)
|
|
||||||
val screenState = _screenState.asStateFlow()
|
|
||||||
|
|
||||||
private val _navigation = MutableStateFlow<ConvoNavigation?>(null)
|
private val screenState = MutableStateFlow(ConvosScreenState.EMPTY)
|
||||||
val navigation = _navigation.asStateFlow()
|
val screenStateFlow get() = screenState.asStateFlow()
|
||||||
|
|
||||||
private val _dialog = MutableStateFlow<ConvoDialog?>(null)
|
private val navigationIntent = MutableStateFlow<ConvoNavigationIntent?>(null)
|
||||||
val dialog = _dialog.asStateFlow()
|
val navigationIntentFlow get() = navigationIntent.asStateFlow()
|
||||||
|
|
||||||
private val _convos = MutableStateFlow<List<VkConvo>>(emptyList())
|
private val convos: MutableList<VkConvo> = mutableListOf()
|
||||||
val convos = _convos.asStateFlow()
|
|
||||||
|
|
||||||
private val _uiConvos = MutableStateFlow<List<UiConvo>>(emptyList())
|
private val pinnedConvosCount get() = convos.count(VkConvo::isPinned)
|
||||||
val uiConvos = _uiConvos.asStateFlow()
|
|
||||||
|
|
||||||
private val pinnedConvosCount = convos.map { convos ->
|
private var currentOffset = 0
|
||||||
convos.count(VkConvo::isPinned)
|
|
||||||
}.stateIn(viewModelScope, SharingStarted.Eagerly, 0)
|
|
||||||
|
|
||||||
private val _baseError = MutableStateFlow<BaseError?>(null)
|
|
||||||
val baseError = _baseError.asStateFlow()
|
|
||||||
|
|
||||||
private val _currentOffset = MutableStateFlow(0)
|
|
||||||
val currentOffset = _currentOffset.asStateFlow()
|
|
||||||
|
|
||||||
private val _canPaginate = MutableStateFlow(false)
|
|
||||||
val canPaginate = _canPaginate.asStateFlow()
|
|
||||||
|
|
||||||
private val expandedConvoId = MutableStateFlow(0L)
|
|
||||||
|
|
||||||
private val useContactNames: Boolean get() = userSettings.useContactNames.value
|
|
||||||
|
|
||||||
private val interactionsTimers = hashMapOf<Long, InteractionJob?>()
|
private val interactionsTimers = hashMapOf<Long, InteractionJob?>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
_screenState.updateValue { copy(isArchive = filter == ConvosFilter.ARCHIVE) }
|
|
||||||
|
|
||||||
loadConvos()
|
loadConvos()
|
||||||
|
|
||||||
updatesParser.onNewMessage(::handleNewMessage)
|
updatesParser.onNewMessage(::handleNewMessage)
|
||||||
@@ -109,100 +89,143 @@ class ConvosViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onNavigationConsumed() {
|
fun handleIntent(intent: ConvoIntent) {
|
||||||
_navigation.setValue { null }
|
when (intent) {
|
||||||
|
ConvoIntent.ArchiveClick -> {
|
||||||
|
navigationIntent.setValue { ConvoNavigationIntent.Archive }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDialogConfirmed(dialog: ConvoDialog, bundle: Bundle) {
|
ConvoIntent.Back -> {
|
||||||
onDialogDismissed(dialog)
|
navigationIntent.setValue { ConvoNavigationIntent.Back }
|
||||||
|
}
|
||||||
|
|
||||||
|
ConvoIntent.ConsumeScrollToTop -> Unit
|
||||||
|
ConvoIntent.CreateChatClick -> {
|
||||||
|
navigationIntent.setValue { ConvoNavigationIntent.CreateChat }
|
||||||
|
}
|
||||||
|
|
||||||
|
ConvoIntent.ErrorActionButtonClick -> {
|
||||||
|
onRefresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
is ConvoIntent.ItemClick -> {
|
||||||
|
onConvoItemClick(intent.convoId)
|
||||||
|
}
|
||||||
|
|
||||||
|
is ConvoIntent.ItemLongClick -> {
|
||||||
|
onConvoItemLongClick(intent.convoId)
|
||||||
|
}
|
||||||
|
|
||||||
|
is ConvoIntent.OptionItemClick -> {
|
||||||
|
onOptionClicked(intent.option)
|
||||||
|
}
|
||||||
|
|
||||||
|
ConvoIntent.PaginationConditionsMet -> {
|
||||||
|
onPaginationConditionsMet()
|
||||||
|
}
|
||||||
|
|
||||||
|
ConvoIntent.Refresh -> {
|
||||||
|
onRefresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
is ConvoIntent.SetScrollIndex -> {
|
||||||
|
setScrollIndex(intent.index)
|
||||||
|
}
|
||||||
|
|
||||||
|
is ConvoIntent.SetScrollOffset -> {
|
||||||
|
setScrollOffset(intent.offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
is ConvoIntent.Dialog -> {
|
||||||
|
when (intent) {
|
||||||
|
is ConvoIntent.Dialog.Cancel -> Unit
|
||||||
|
is ConvoIntent.Dialog.Confirm -> onDialogConfirmed(intent.bundle)
|
||||||
|
ConvoIntent.Dialog.Dismiss -> onDialogDismissed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onNavigationConsumed() {
|
||||||
|
navigationIntent.setValue { null }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onDialogConfirmed(bundle: Bundle?) {
|
||||||
|
val dialog = screenState.value.dialog ?: return
|
||||||
|
onDialogDismissed()
|
||||||
|
|
||||||
|
val convo = with(screenState.value) {
|
||||||
|
convos.find { it.id == expandedConvoId }
|
||||||
|
} ?: return
|
||||||
|
|
||||||
when (dialog) {
|
when (dialog) {
|
||||||
is ConvoDialog.ConvoDelete -> {
|
is ConvoDialog.Delete -> {
|
||||||
deleteConvo(dialog.convoId)
|
deleteConvo(convo.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
is ConvoDialog.ConvoPin -> {
|
is ConvoDialog.Pin -> {
|
||||||
pinConvo(dialog.convoId, true)
|
pinConvo(convo.id, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
is ConvoDialog.ConvoUnpin -> {
|
is ConvoDialog.Unpin -> {
|
||||||
pinConvo(dialog.convoId, false)
|
pinConvo(convo.id, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
is ConvoDialog.ConvoArchive -> {
|
is ConvoDialog.Archive -> {
|
||||||
archiveConvo(dialog.convoId, true)
|
archiveConvo(convo.id, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
is ConvoDialog.ConvoUnarchive -> {
|
is ConvoDialog.Unarchive -> {
|
||||||
archiveConvo(dialog.convoId, false)
|
archiveConvo(convo.id, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expandedConvoId.setValue { 0 }
|
collapseConvos(false)
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDialogDismissed(dialog: ConvoDialog) {
|
private fun onDialogDismissed() {
|
||||||
_dialog.setValue { null }
|
screenState.updateValue { copy(dialog = null) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDialogItemPicked(dialog: ConvoDialog, bundle: Bundle) {
|
private fun onPaginationConditionsMet() {
|
||||||
when (dialog) {
|
currentOffset = convos.size
|
||||||
is ConvoDialog.ConvoDelete -> Unit
|
|
||||||
is ConvoDialog.ConvoPin -> Unit
|
|
||||||
is ConvoDialog.ConvoUnpin -> Unit
|
|
||||||
is ConvoDialog.ConvoArchive -> Unit
|
|
||||||
is ConvoDialog.ConvoUnarchive -> Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onErrorButtonClicked() {
|
|
||||||
when (baseError.value) {
|
|
||||||
null -> Unit
|
|
||||||
|
|
||||||
is BaseError.ConnectionError,
|
|
||||||
is BaseError.InternalError,
|
|
||||||
is BaseError.SimpleError,
|
|
||||||
is BaseError.UnknownError -> onRefresh()
|
|
||||||
|
|
||||||
else -> Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onPaginationConditionsMet() {
|
|
||||||
_currentOffset.update { convos.value.size }
|
|
||||||
loadConvos()
|
loadConvos()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onRefresh() {
|
private fun onErrorConsumed() {
|
||||||
|
screenState.updateValue { copy(error = null) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onRefresh() {
|
||||||
onErrorConsumed()
|
onErrorConsumed()
|
||||||
loadConvos(offset = 0)
|
loadConvos(offset = 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onConvoItemClick(convo: UiConvo) {
|
private fun onConvoItemClick(convoId: Long) {
|
||||||
collapseConvos()
|
collapseConvos()
|
||||||
_navigation.setValue { ConvoNavigation.MessagesHistory(peerId = convo.id) }
|
navigationIntent.setValue { ConvoNavigationIntent.MessagesHistory(convoId) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onConvoItemLongClick(convo: UiConvo) {
|
private fun onConvoItemLongClick(convoId: Long) {
|
||||||
expandedConvoId.setValue {
|
val isExpanded = screenState.value.convos.find { it.id == convoId }?.isExpanded == true
|
||||||
if (convo.isExpanded) 0
|
|
||||||
else convo.id
|
screenState.updateValue { copy(expandedConvoId = if (isExpanded) 0L else convoId) }
|
||||||
}
|
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onOptionClicked(
|
private fun onOptionClicked(option: ConvoOption) {
|
||||||
convo: UiConvo,
|
val convo =
|
||||||
option: ConvoOption
|
screenState.value.convos.find { it.id == screenState.value.expandedConvoId } ?: return
|
||||||
) {
|
|
||||||
when (option) {
|
when (option) {
|
||||||
ConvoOption.Delete -> {
|
ConvoOption.Delete -> setDialog(ConvoDialog.Delete)
|
||||||
_dialog.setValue { ConvoDialog.ConvoDelete(convo.id) }
|
|
||||||
}
|
|
||||||
|
|
||||||
ConvoOption.MarkAsRead -> {
|
ConvoOption.MarkAsRead -> {
|
||||||
convo.lastMessageId?.let { lastMessageId ->
|
val lastMessageId =
|
||||||
|
screenState.value.convos.find { it.id == screenState.value.expandedConvoId }?.lastMessageId
|
||||||
|
|
||||||
|
if (lastMessageId != null) {
|
||||||
readConvo(
|
readConvo(
|
||||||
peerId = convo.id,
|
peerId = convo.id,
|
||||||
startMessageId = lastMessageId
|
startMessageId = lastMessageId
|
||||||
@@ -211,48 +234,39 @@ class ConvosViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConvoOption.Pin -> {
|
ConvoOption.Pin -> setDialog(ConvoDialog.Pin)
|
||||||
_dialog.setValue { ConvoDialog.ConvoPin(convo.id) }
|
ConvoOption.Unpin -> setDialog(ConvoDialog.Unpin)
|
||||||
}
|
ConvoOption.Archive -> setDialog(ConvoDialog.Archive)
|
||||||
|
ConvoOption.Unarchive -> setDialog(ConvoDialog.Unarchive)
|
||||||
ConvoOption.Unpin -> {
|
|
||||||
_dialog.setValue { ConvoDialog.ConvoUnpin(convo.id) }
|
|
||||||
}
|
|
||||||
|
|
||||||
ConvoOption.Archive -> {
|
|
||||||
_dialog.setValue { ConvoDialog.ConvoArchive(convo.id) }
|
|
||||||
}
|
|
||||||
|
|
||||||
ConvoOption.Unarchive -> {
|
|
||||||
_dialog.setValue { ConvoDialog.ConvoUnarchive(convo.id) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onErrorConsumed() {
|
private fun setScrollIndex(index: Int) {
|
||||||
_baseError.setValue { null }
|
screenState.setValue { old -> old.copy(scrollIndex = index) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setScrollIndex(index: Int) {
|
private fun setScrollOffset(offset: Int) {
|
||||||
_screenState.setValue { old -> old.copy(scrollIndex = index) }
|
screenState.setValue { old -> old.copy(scrollOffset = offset) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setScrollOffset(offset: Int) {
|
private fun setDialog(dialog: ConvoDialog?) {
|
||||||
_screenState.setValue { old -> old.copy(scrollOffset = offset) }
|
screenState.updateValue { copy(dialog = dialog) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onCreateChatButtonClicked() {
|
private fun replaceConvos(newConvos: List<VkConvo>) {
|
||||||
_navigation.setValue { ConvoNavigation.CreateChat }
|
convos.clear()
|
||||||
|
convos.addAll(newConvos)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun collapseConvos() {
|
private fun collapseConvos(sync: Boolean = true) {
|
||||||
expandedConvoId.setValue { 0 }
|
screenState.updateValue { copy(expandedConvoId = null) }
|
||||||
|
|
||||||
|
if (sync) {
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadConvos(
|
private fun loadConvos(offset: Int = currentOffset) {
|
||||||
offset: Int = currentOffset.value
|
|
||||||
) {
|
|
||||||
convoUseCase.getConvos(
|
convoUseCase.getConvos(
|
||||||
count = LOAD_COUNT,
|
count = LOAD_COUNT,
|
||||||
offset = offset,
|
offset = offset,
|
||||||
@@ -260,23 +274,20 @@ class ConvosViewModel(
|
|||||||
).listenValue(viewModelScope) { state ->
|
).listenValue(viewModelScope) { state ->
|
||||||
state.processState(
|
state.processState(
|
||||||
error = { error ->
|
error = { error ->
|
||||||
val newBaseError = VkUtils.parseError(error)
|
screenState.updateValue { copy(error = VkUtils.parseError(error)) }
|
||||||
_baseError.update { newBaseError }
|
|
||||||
},
|
},
|
||||||
success = { response ->
|
success = { response ->
|
||||||
val convos = response
|
val newConvos = if (offset == 0) {
|
||||||
val fullConvos = if (offset == 0) {
|
response
|
||||||
convos
|
|
||||||
} else {
|
} else {
|
||||||
this.convos.value.plus(convos)
|
convos.plus(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
val itemsCountSufficient = response.size == LOAD_COUNT
|
val itemsCountSufficient = response.size == LOAD_COUNT
|
||||||
|
|
||||||
val paginationExhausted = !itemsCountSufficient &&
|
val paginationExhausted = !itemsCountSufficient && convos.isNotEmpty()
|
||||||
this.convos.value.isNotEmpty()
|
|
||||||
|
|
||||||
_screenState.updateValue {
|
screenState.updateValue {
|
||||||
copy(isPaginationExhausted = paginationExhausted)
|
copy(isPaginationExhausted = paginationExhausted)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,13 +304,14 @@ class ConvosViewModel(
|
|||||||
|
|
||||||
convoUseCase.storeConvos(response)
|
convoUseCase.storeConvos(response)
|
||||||
|
|
||||||
_convos.emit(fullConvos)
|
replaceConvos(newConvos)
|
||||||
|
|
||||||
|
screenState.updateValue { copy(canPaginate = itemsCountSufficient) }
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
_canPaginate.setValue { itemsCountSufficient }
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
_screenState.setValue { old ->
|
screenState.setValue { old ->
|
||||||
old.copy(
|
old.copy(
|
||||||
isLoading = offset == 0 && state.isLoading(),
|
isLoading = offset == 0 && state.isLoading(),
|
||||||
isPaginating = offset > 0 && state.isLoading()
|
isPaginating = offset > 0 && state.isLoading()
|
||||||
@@ -313,17 +325,17 @@ class ConvosViewModel(
|
|||||||
state.processState(
|
state.processState(
|
||||||
error = {},
|
error = {},
|
||||||
success = {
|
success = {
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
val convoIndex =
|
val convoIndex =
|
||||||
newConvos.indexOfFirstOrNull { it.id == peerId }
|
newConvos.indexOfFirstOrNull { it.id == peerId }
|
||||||
?: return@processState
|
?: return@processState
|
||||||
|
|
||||||
newConvos.removeAt(convoIndex)
|
newConvos.removeAt(convoIndex)
|
||||||
_convos.update { newConvos.sorted() }
|
replaceConvos(newConvos.sorted())
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
_screenState.emit(screenState.value.copy(isLoading = state.isLoading()))
|
screenState.emit(screenStateFlow.value.copy(isLoading = state.isLoading()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -337,7 +349,7 @@ class ConvosViewModel(
|
|||||||
LongPollParsedEvent.ChatMajorChanged(
|
LongPollParsedEvent.ChatMajorChanged(
|
||||||
peerId = peerId,
|
peerId = peerId,
|
||||||
majorId = if (pin) {
|
majorId = if (pin) {
|
||||||
pinnedConvosCount.value.plus(1) * 16
|
pinnedConvosCount.plus(1) * 16
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
@@ -346,7 +358,7 @@ class ConvosViewModel(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
_screenState.setValue { old -> old.copy(isLoading = state.isLoading()) }
|
screenState.setValue { old -> old.copy(isLoading = state.isLoading()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +368,7 @@ class ConvosViewModel(
|
|||||||
state.processState(
|
state.processState(
|
||||||
error = {},
|
error = {},
|
||||||
success = {
|
success = {
|
||||||
convos.value.find { it.id == peerId }?.let { convo ->
|
convos.find { it.id == peerId }?.let { convo ->
|
||||||
handleChatArchived(
|
handleChatArchived(
|
||||||
LongPollParsedEvent.ChatArchived(
|
LongPollParsedEvent.ChatArchived(
|
||||||
convo = convo,
|
convo = convo,
|
||||||
@@ -373,7 +385,7 @@ class ConvosViewModel(
|
|||||||
private fun handleNewMessage(event: LongPollParsedEvent.NewMessage) {
|
private fun handleNewMessage(event: LongPollParsedEvent.NewMessage) {
|
||||||
val message = event.message
|
val message = event.message
|
||||||
|
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
val convoIndex =
|
val convoIndex =
|
||||||
newConvos.indexOfFirstOrNull { it.id == message.peerId }
|
newConvos.indexOfFirstOrNull { it.id == message.peerId }
|
||||||
|
|
||||||
@@ -391,8 +403,8 @@ class ConvosViewModel(
|
|||||||
val convo = (response.firstOrNull() ?: return@listenValue)
|
val convo = (response.firstOrNull() ?: return@listenValue)
|
||||||
.copy(lastMessage = message)
|
.copy(lastMessage = message)
|
||||||
|
|
||||||
newConvos.add(pinnedConvosCount.value, convo)
|
newConvos.add(pinnedConvosCount, convo)
|
||||||
_convos.update { newConvos.sorted() }
|
replaceConvos(newConvos.sorted())
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -428,19 +440,17 @@ class ConvosViewModel(
|
|||||||
newConvos[convoIndex] = newConvo
|
newConvos[convoIndex] = newConvo
|
||||||
} else {
|
} else {
|
||||||
newConvos.removeAt(convoIndex)
|
newConvos.removeAt(convoIndex)
|
||||||
|
newConvos.add(pinnedConvosCount, newConvo)
|
||||||
val toPosition = pinnedConvosCount.value
|
|
||||||
newConvos.add(toPosition, newConvo)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_convos.update { newConvos.sorted() }
|
replaceConvos(newConvos.sorted())
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleEditedMessage(event: LongPollParsedEvent.MessageEdited) {
|
private fun handleEditedMessage(event: LongPollParsedEvent.MessageEdited) {
|
||||||
val message = event.message
|
val message = event.message
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
|
|
||||||
val convoIndex = newConvos.indexOfFirstOrNull { it.id == message.peerId }
|
val convoIndex = newConvos.indexOfFirstOrNull { it.id == message.peerId }
|
||||||
if (convoIndex == null) { // диалога нет в списке
|
if (convoIndex == null) { // диалога нет в списке
|
||||||
@@ -452,13 +462,14 @@ class ConvosViewModel(
|
|||||||
lastMessageId = message.id,
|
lastMessageId = message.id,
|
||||||
lastCmId = message.cmId
|
lastCmId = message.cmId
|
||||||
)
|
)
|
||||||
_convos.update { newConvos }
|
|
||||||
|
replaceConvos(newConvos)
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleReadIncomingMessage(event: LongPollParsedEvent.IncomingMessageRead) {
|
private fun handleReadIncomingMessage(event: LongPollParsedEvent.IncomingMessageRead) {
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
|
|
||||||
val convoIndex =
|
val convoIndex =
|
||||||
newConvos.indexOfFirstOrNull { it.id == event.peerId }
|
newConvos.indexOfFirstOrNull { it.id == event.peerId }
|
||||||
@@ -472,13 +483,13 @@ class ConvosViewModel(
|
|||||||
unreadCount = event.unreadCount
|
unreadCount = event.unreadCount
|
||||||
)
|
)
|
||||||
|
|
||||||
_convos.update { newConvos }
|
replaceConvos(newConvos)
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleReadOutgoingMessage(event: LongPollParsedEvent.OutgoingMessageRead) {
|
private fun handleReadOutgoingMessage(event: LongPollParsedEvent.OutgoingMessageRead) {
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
|
|
||||||
val convoIndex =
|
val convoIndex =
|
||||||
newConvos.indexOfFirstOrNull { it.id == event.peerId }
|
newConvos.indexOfFirstOrNull { it.id == event.peerId }
|
||||||
@@ -492,7 +503,7 @@ class ConvosViewModel(
|
|||||||
unreadCount = event.unreadCount
|
unreadCount = event.unreadCount
|
||||||
)
|
)
|
||||||
|
|
||||||
_convos.update { newConvos }
|
replaceConvos(newConvos)
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,7 +513,7 @@ class ConvosViewModel(
|
|||||||
val peerId = event.peerId
|
val peerId = event.peerId
|
||||||
val userIds = event.userIds
|
val userIds = event.userIds
|
||||||
|
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
val convoAndIndex =
|
val convoAndIndex =
|
||||||
newConvos.findWithIndex { it.id == peerId }
|
newConvos.findWithIndex { it.id == peerId }
|
||||||
|
|
||||||
@@ -513,7 +524,7 @@ class ConvosViewModel(
|
|||||||
interactionIds = userIds
|
interactionIds = userIds
|
||||||
)
|
)
|
||||||
|
|
||||||
_convos.update { newConvos }
|
replaceConvos(newConvos)
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
|
|
||||||
interactionsTimers[peerId]?.let { interactionJob ->
|
interactionsTimers[peerId]?.let { interactionJob ->
|
||||||
@@ -545,7 +556,7 @@ class ConvosViewModel(
|
|||||||
private fun stopInteraction(peerId: Long, interactionJob: InteractionJob) {
|
private fun stopInteraction(peerId: Long, interactionJob: InteractionJob) {
|
||||||
interactionsTimers[peerId] ?: return
|
interactionsTimers[peerId] ?: return
|
||||||
|
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
val convoAndIndex =
|
val convoAndIndex =
|
||||||
newConvos.findWithIndex { it.id == peerId } ?: return
|
newConvos.findWithIndex { it.id == peerId } ?: return
|
||||||
|
|
||||||
@@ -555,7 +566,7 @@ class ConvosViewModel(
|
|||||||
interactionIds = emptyList()
|
interactionIds = emptyList()
|
||||||
)
|
)
|
||||||
|
|
||||||
_convos.update { newConvos }
|
replaceConvos(newConvos)
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
|
|
||||||
interactionJob.timerJob.cancel()
|
interactionJob.timerJob.cancel()
|
||||||
@@ -563,7 +574,7 @@ class ConvosViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleChatMajorChanged(event: LongPollParsedEvent.ChatMajorChanged) {
|
private fun handleChatMajorChanged(event: LongPollParsedEvent.ChatMajorChanged) {
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
val convoIndex =
|
val convoIndex =
|
||||||
newConvos.indexOfFirstOrNull { it.id == event.peerId }
|
newConvos.indexOfFirstOrNull { it.id == event.peerId }
|
||||||
|
|
||||||
@@ -573,13 +584,13 @@ class ConvosViewModel(
|
|||||||
newConvos[convoIndex] =
|
newConvos[convoIndex] =
|
||||||
newConvos[convoIndex].copy(majorId = event.majorId)
|
newConvos[convoIndex].copy(majorId = event.majorId)
|
||||||
|
|
||||||
_convos.setValue { newConvos.sorted() }
|
replaceConvos(newConvos.sorted())
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleChatMinorChanged(event: LongPollParsedEvent.ChatMinorChanged) {
|
private fun handleChatMinorChanged(event: LongPollParsedEvent.ChatMinorChanged) {
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
val convoIndex =
|
val convoIndex =
|
||||||
newConvos.indexOfFirstOrNull { it.id == event.peerId }
|
newConvos.indexOfFirstOrNull { it.id == event.peerId }
|
||||||
|
|
||||||
@@ -589,13 +600,13 @@ class ConvosViewModel(
|
|||||||
newConvos[convoIndex] =
|
newConvos[convoIndex] =
|
||||||
newConvos[convoIndex].copy(minorId = event.minorId)
|
newConvos[convoIndex].copy(minorId = event.minorId)
|
||||||
|
|
||||||
_convos.setValue { newConvos.sorted() }
|
replaceConvos(newConvos.sorted())
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleChatClearing(event: LongPollParsedEvent.ChatCleared) {
|
private fun handleChatClearing(event: LongPollParsedEvent.ChatCleared) {
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
|
|
||||||
val convoIndex = newConvos.indexOfFirstOrNull { it.id == event.peerId }
|
val convoIndex = newConvos.indexOfFirstOrNull { it.id == event.peerId }
|
||||||
|
|
||||||
@@ -604,7 +615,7 @@ class ConvosViewModel(
|
|||||||
} else {
|
} else {
|
||||||
newConvos.removeAt(convoIndex)
|
newConvos.removeAt(convoIndex)
|
||||||
|
|
||||||
_convos.setValue { newConvos.sorted() }
|
replaceConvos(newConvos.sorted())
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -612,7 +623,7 @@ class ConvosViewModel(
|
|||||||
private fun handleChatArchived(event: LongPollParsedEvent.ChatArchived) {
|
private fun handleChatArchived(event: LongPollParsedEvent.ChatArchived) {
|
||||||
val convo = event.convo
|
val convo = event.convo
|
||||||
|
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
|
|
||||||
when (filter) {
|
when (filter) {
|
||||||
ConvosFilter.BUSINESS_NOTIFY -> Unit
|
ConvosFilter.BUSINESS_NOTIFY -> Unit
|
||||||
@@ -627,7 +638,7 @@ class ConvosViewModel(
|
|||||||
newConvos.removeAt(index)
|
newConvos.removeAt(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
_convos.update { newConvos }
|
replaceConvos(newConvos)
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -638,10 +649,10 @@ class ConvosViewModel(
|
|||||||
|
|
||||||
newConvos.removeAt(index)
|
newConvos.removeAt(index)
|
||||||
} else {
|
} else {
|
||||||
newConvos.add(pinnedConvosCount.value, convo)
|
newConvos.add(pinnedConvosCount, convo)
|
||||||
}
|
}
|
||||||
|
|
||||||
_convos.update { newConvos.sorted() }
|
replaceConvos(newConvos.sorted())
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,7 +666,7 @@ class ConvosViewModel(
|
|||||||
state.processState(
|
state.processState(
|
||||||
error = {},
|
error = {},
|
||||||
success = {
|
success = {
|
||||||
val newConvos = convos.value.toMutableList()
|
val newConvos = convos.toMutableList()
|
||||||
val convoIndex =
|
val convoIndex =
|
||||||
newConvos.indexOfFirstOrNull { it.id == peerId }
|
newConvos.indexOfFirstOrNull { it.id == peerId }
|
||||||
?: return@listenValue
|
?: return@listenValue
|
||||||
@@ -663,7 +674,7 @@ class ConvosViewModel(
|
|||||||
newConvos[convoIndex] =
|
newConvos[convoIndex] =
|
||||||
newConvos[convoIndex].copy(inRead = startMessageId)
|
newConvos[convoIndex].copy(inRead = startMessageId)
|
||||||
|
|
||||||
_convos.update { newConvos }
|
replaceConvos(newConvos)
|
||||||
syncUiConvos()
|
syncUiConvos()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -695,47 +706,44 @@ class ConvosViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun syncUiConvos(): List<UiConvo> {
|
private fun syncUiConvos(): List<UiConvo> {
|
||||||
val convos = convos.value
|
|
||||||
|
|
||||||
val newUiConvos = convos.map { convo ->
|
val newUiConvos = convos.map { convo ->
|
||||||
val options = mutableListOf<ConvoOption>()
|
val options: ImmutableList<ConvoOption> = buildImmutableList {
|
||||||
convo.lastMessage?.run {
|
if (!convo.isRead() && convo.lastMessage != null && convo.lastMessage?.isOut == false) {
|
||||||
if (!convo.isRead() && !this.isOut) {
|
add(ConvoOption.MarkAsRead)
|
||||||
options += ConvoOption.MarkAsRead
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val convosSize = this.convos.value.size
|
|
||||||
val pinnedCount = pinnedConvosCount.value
|
|
||||||
|
|
||||||
val canPinOneMoreDialog =
|
|
||||||
convosSize > 4 && pinnedCount < 5 && !convo.isPinned()
|
|
||||||
|
|
||||||
if (convo.isPinned()) {
|
if (convo.isPinned()) {
|
||||||
options += ConvoOption.Unpin
|
add(ConvoOption.Unpin)
|
||||||
} else if (canPinOneMoreDialog) {
|
}
|
||||||
options += ConvoOption.Pin
|
|
||||||
|
if (convos.size > 4 && pinnedConvosCount < 5 && !convo.isPinned()) {
|
||||||
|
add(ConvoOption.Pin)
|
||||||
}
|
}
|
||||||
|
|
||||||
when (filter) {
|
when (filter) {
|
||||||
ConvosFilter.ARCHIVE -> ConvoOption.Unarchive
|
ConvosFilter.BUSINESS_NOTIFY -> Unit
|
||||||
|
ConvosFilter.ARCHIVE -> add(ConvoOption.Unarchive)
|
||||||
|
|
||||||
ConvosFilter.UNREAD,
|
ConvosFilter.ALL,
|
||||||
ConvosFilter.ALL -> ConvoOption.Archive
|
ConvosFilter.UNREAD -> {
|
||||||
|
if (convo.id != UserConfig.userId) {
|
||||||
|
add(ConvoOption.Archive)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ConvosFilter.BUSINESS_NOTIFY -> null
|
add(ConvoOption.Delete)
|
||||||
}?.let(options::add)
|
}
|
||||||
|
|
||||||
options += ConvoOption.Delete
|
|
||||||
|
|
||||||
convo.asPresentation(
|
convo.asPresentation(
|
||||||
resources = resources,
|
resources = resources,
|
||||||
useContactName = useContactNames,
|
useContactName = userSettings.useContactNames.value,
|
||||||
isExpanded = expandedConvoId.value == convo.id,
|
isExpanded = screenState.value.expandedConvoId == convo.id,
|
||||||
options = options.toImmutableList()
|
options = options
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_uiConvos.setValue { newUiConvos }
|
|
||||||
|
screenState.updateValue { copy(convos = newUiConvos.toImmutableList()) }
|
||||||
|
|
||||||
return newUiConvos
|
return newUiConvos
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import androidx.compose.runtime.Immutable
|
|||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
sealed class ConvoDialog {
|
sealed class ConvoDialog {
|
||||||
data class ConvoPin(val convoId: Long) : ConvoDialog()
|
data object Pin : ConvoDialog()
|
||||||
data class ConvoUnpin(val convoId: Long) : ConvoDialog()
|
data object Unpin : ConvoDialog()
|
||||||
data class ConvoDelete(val convoId: Long) : ConvoDialog()
|
data object Delete : ConvoDialog()
|
||||||
data class ConvoArchive(val convoId: Long) : ConvoDialog()
|
data object Archive : ConvoDialog()
|
||||||
data class ConvoUnarchive(val convoId: Long) : ConvoDialog()
|
data object Unarchive : ConvoDialog()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package dev.meloda.fast.convos.model
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import dev.meloda.fast.ui.model.vk.ConvoOption
|
||||||
|
|
||||||
|
sealed class ConvoIntent {
|
||||||
|
data class ItemClick(val convoId: Long) : ConvoIntent()
|
||||||
|
data class ItemLongClick(val convoId: Long) : ConvoIntent()
|
||||||
|
data class OptionItemClick(val option: ConvoOption) : ConvoIntent()
|
||||||
|
data object PaginationConditionsMet : ConvoIntent()
|
||||||
|
|
||||||
|
data object Back : ConvoIntent()
|
||||||
|
data object Refresh : ConvoIntent()
|
||||||
|
data object CreateChatClick : ConvoIntent()
|
||||||
|
data object ArchiveClick : ConvoIntent()
|
||||||
|
|
||||||
|
data class SetScrollIndex(val index: Int) : ConvoIntent()
|
||||||
|
data class SetScrollOffset(val offset: Int) : ConvoIntent()
|
||||||
|
|
||||||
|
data object ErrorActionButtonClick : ConvoIntent()
|
||||||
|
|
||||||
|
data object ConsumeScrollToTop : ConvoIntent()
|
||||||
|
|
||||||
|
sealed class Dialog : ConvoIntent() {
|
||||||
|
data object Dismiss : Dialog()
|
||||||
|
data class Confirm(val bundle: Bundle? = null) : Dialog()
|
||||||
|
data class Cancel(val bundle: Bundle? = null) : Dialog()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package dev.meloda.fast.convos.model
|
|
||||||
|
|
||||||
import androidx.compose.runtime.Immutable
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
sealed class ConvoNavigation {
|
|
||||||
|
|
||||||
data class MessagesHistory(val peerId: Long) : ConvoNavigation()
|
|
||||||
|
|
||||||
data object CreateChat : ConvoNavigation()
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package dev.meloda.fast.convos.model
|
||||||
|
|
||||||
|
sealed class ConvoNavigationIntent {
|
||||||
|
|
||||||
|
data object Back : ConvoNavigationIntent()
|
||||||
|
data class MessagesHistory(val convoId: Long) : ConvoNavigationIntent()
|
||||||
|
data object CreateChat : ConvoNavigationIntent()
|
||||||
|
data object Archive : ConvoNavigationIntent()
|
||||||
|
}
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package dev.meloda.fast.convos.model
|
package dev.meloda.fast.convos.model
|
||||||
|
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
|
import dev.meloda.fast.model.BaseError
|
||||||
|
import dev.meloda.fast.ui.model.vk.UiConvo
|
||||||
|
import dev.meloda.fast.ui.util.ImmutableList
|
||||||
|
import dev.meloda.fast.ui.util.emptyImmutableList
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
data class ConvosScreenState(
|
data class ConvosScreenState(
|
||||||
@@ -10,7 +14,13 @@ data class ConvosScreenState(
|
|||||||
val profileImageUrl: String?,
|
val profileImageUrl: String?,
|
||||||
val scrollIndex: Int,
|
val scrollIndex: Int,
|
||||||
val scrollOffset: Int,
|
val scrollOffset: Int,
|
||||||
val isArchive: Boolean
|
val canPaginate: Boolean,
|
||||||
|
val expandedConvoId: Long?,
|
||||||
|
val convos: ImmutableList<UiConvo>,
|
||||||
|
val dialog: ConvoDialog?,
|
||||||
|
|
||||||
|
// TODO: 30.05.2026, Danil Nikolaev: remove
|
||||||
|
val error: BaseError?
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -21,7 +31,11 @@ data class ConvosScreenState(
|
|||||||
profileImageUrl = null,
|
profileImageUrl = null,
|
||||||
scrollIndex = 0,
|
scrollIndex = 0,
|
||||||
scrollOffset = 0,
|
scrollOffset = 0,
|
||||||
isArchive = false
|
canPaginate = false,
|
||||||
|
expandedConvoId = null,
|
||||||
|
convos = emptyImmutableList(),
|
||||||
|
dialog = null,
|
||||||
|
error = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+44
-28
@@ -1,12 +1,16 @@
|
|||||||
package dev.meloda.fast.convos.navigation
|
package dev.meloda.fast.convos.navigation
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.navigation
|
import androidx.navigation.navigation
|
||||||
import dev.meloda.fast.convos.ConvosViewModel
|
import dev.meloda.fast.convos.ConvosViewModel
|
||||||
|
import dev.meloda.fast.convos.model.ConvoNavigationIntent
|
||||||
import dev.meloda.fast.convos.presentation.ConvosRoute
|
import dev.meloda.fast.convos.presentation.ConvosRoute
|
||||||
import dev.meloda.fast.model.BaseError
|
|
||||||
import dev.meloda.fast.model.ConvosFilter
|
import dev.meloda.fast.model.ConvosFilter
|
||||||
import dev.meloda.fast.ui.extensions.getOrThrow
|
import dev.meloda.fast.ui.extensions.getOrThrow
|
||||||
import dev.meloda.fast.ui.theme.LocalNavController
|
import dev.meloda.fast.ui.theme.LocalNavController
|
||||||
@@ -24,44 +28,56 @@ object Convos
|
|||||||
object Archive
|
object Archive
|
||||||
|
|
||||||
fun NavGraphBuilder.convosGraph(
|
fun NavGraphBuilder.convosGraph(
|
||||||
|
handleNavigationIntent: (ConvoNavigationIntent) -> Unit,
|
||||||
activity: AppCompatActivity,
|
activity: AppCompatActivity,
|
||||||
onError: (BaseError) -> Unit,
|
|
||||||
onNavigateToMessagesHistory: (id: Long) -> Unit,
|
|
||||||
onNavigateToCreateChat: () -> Unit,
|
|
||||||
onScrolledToTop: () -> Unit
|
|
||||||
) {
|
) {
|
||||||
navigation<ConvoGraph>(
|
navigation<ConvoGraph>(
|
||||||
startDestination = Convos
|
startDestination = Convos
|
||||||
) {
|
) {
|
||||||
val convosViewModel: ConvosViewModel = with(activity) {
|
|
||||||
getViewModel(qualifier = named(ConvosFilter.ALL))
|
|
||||||
}
|
|
||||||
composable<Convos> {
|
composable<Convos> {
|
||||||
val navController = LocalNavController.getOrThrow()
|
ConvosRootRoute(
|
||||||
|
handleNavigationIntent = handleNavigationIntent,
|
||||||
ConvosRoute(
|
viewModel = with(activity) {
|
||||||
viewModel = convosViewModel,
|
getViewModel(named(ConvosFilter.ALL))
|
||||||
onError = onError,
|
}
|
||||||
onNavigateToMessagesHistory = onNavigateToMessagesHistory,
|
|
||||||
onNavigateToCreateChat = onNavigateToCreateChat,
|
|
||||||
onNavigateToArchive = { navController.navigate(Archive) },
|
|
||||||
onScrolledToTop = onScrolledToTop
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable<Archive> {
|
composable<Archive> {
|
||||||
val navController = LocalNavController.getOrThrow()
|
ConvosRootRoute(
|
||||||
|
handleNavigationIntent = handleNavigationIntent,
|
||||||
ConvosRoute(
|
|
||||||
viewModel = with(activity) {
|
viewModel = with(activity) {
|
||||||
getViewModel<ConvosViewModel>(
|
getViewModel<ConvosViewModel>(named(ConvosFilter.ARCHIVE))
|
||||||
qualifier = named(ConvosFilter.ARCHIVE)
|
}
|
||||||
)
|
|
||||||
},
|
|
||||||
onBack = navController::navigateUp,
|
|
||||||
onError = onError,
|
|
||||||
onNavigateToMessagesHistory = onNavigateToMessagesHistory,
|
|
||||||
onScrolledToTop = onScrolledToTop
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ConvosRootRoute(
|
||||||
|
handleNavigationIntent: (ConvoNavigationIntent) -> Unit,
|
||||||
|
viewModel: ConvosViewModel
|
||||||
|
) {
|
||||||
|
val navController = LocalNavController.getOrThrow()
|
||||||
|
|
||||||
|
val screenState by viewModel.screenStateFlow.collectAsStateWithLifecycle()
|
||||||
|
val navigationIntent by viewModel.navigationIntentFlow.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
|
LaunchedEffect(navigationIntent) {
|
||||||
|
navigationIntent?.let {
|
||||||
|
when (navigationIntent) {
|
||||||
|
ConvoNavigationIntent.Back -> navController.navigateUp()
|
||||||
|
ConvoNavigationIntent.Archive -> navController.navigate(Archive)
|
||||||
|
else -> handleNavigationIntent(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel.onNavigationConsumed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ConvosRoute(
|
||||||
|
handleIntent = viewModel::handleIntent,
|
||||||
|
screenState = screenState,
|
||||||
|
isArchive = viewModel.filter == ConvosFilter.ARCHIVE,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
+18
-22
@@ -1,82 +1,78 @@
|
|||||||
package dev.meloda.fast.convos.presentation
|
package dev.meloda.fast.convos.presentation
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.res.vectorResource
|
import androidx.compose.ui.res.vectorResource
|
||||||
import androidx.core.os.bundleOf
|
|
||||||
import dev.meloda.fast.convos.model.ConvoDialog
|
import dev.meloda.fast.convos.model.ConvoDialog
|
||||||
|
import dev.meloda.fast.convos.model.ConvoIntent
|
||||||
import dev.meloda.fast.convos.model.ConvosScreenState
|
import dev.meloda.fast.convos.model.ConvosScreenState
|
||||||
import dev.meloda.fast.ui.R
|
import dev.meloda.fast.ui.R
|
||||||
import dev.meloda.fast.ui.components.MaterialDialog
|
import dev.meloda.fast.ui.components.MaterialDialog
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun HandleDialogs(
|
fun HandleDialogs(
|
||||||
|
handleIntent: (ConvoIntent) -> Unit,
|
||||||
screenState: ConvosScreenState,
|
screenState: ConvosScreenState,
|
||||||
dialog: ConvoDialog?,
|
|
||||||
onConfirmed: (ConvoDialog, Bundle) -> Unit = { _, _ -> },
|
|
||||||
onDismissed: (ConvoDialog) -> Unit = {},
|
|
||||||
onItemPicked: (ConvoDialog, Bundle) -> Unit = { _, _ -> }
|
|
||||||
) {
|
) {
|
||||||
when (dialog) {
|
when (screenState.dialog) {
|
||||||
null -> Unit
|
null -> Unit
|
||||||
|
|
||||||
is ConvoDialog.ConvoArchive -> {
|
is ConvoDialog.Archive -> {
|
||||||
MaterialDialog(
|
MaterialDialog(
|
||||||
onDismissRequest = { onDismissed(dialog) },
|
onDismissRequest = { handleIntent(ConvoIntent.Dialog.Dismiss) },
|
||||||
title = stringResource(id = R.string.confirm_archive_convo),
|
title = stringResource(id = R.string.confirm_archive_convo),
|
||||||
confirmAction = { onConfirmed(dialog, bundleOf()) },
|
confirmAction = { handleIntent(ConvoIntent.Dialog.Confirm()) },
|
||||||
confirmText = stringResource(id = R.string.action_archive),
|
confirmText = stringResource(id = R.string.action_archive),
|
||||||
cancelText = stringResource(id = R.string.cancel),
|
cancelText = stringResource(id = R.string.cancel),
|
||||||
icon = ImageVector.vectorResource(R.drawable.ic_archive_fill_round_24)
|
icon = ImageVector.vectorResource(R.drawable.ic_archive_fill_round_24)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is ConvoDialog.ConvoUnarchive -> {
|
is ConvoDialog.Unarchive -> {
|
||||||
MaterialDialog(
|
MaterialDialog(
|
||||||
onDismissRequest = { onDismissed(dialog) },
|
onDismissRequest = { handleIntent(ConvoIntent.Dialog.Dismiss) },
|
||||||
title = stringResource(id = R.string.confirm_unarchive_convo),
|
title = stringResource(id = R.string.confirm_unarchive_convo),
|
||||||
confirmAction = { onConfirmed(dialog, bundleOf()) },
|
confirmAction = { handleIntent(ConvoIntent.Dialog.Confirm()) },
|
||||||
confirmText = stringResource(id = R.string.action_unarchive),
|
confirmText = stringResource(id = R.string.action_unarchive),
|
||||||
cancelText = stringResource(id = R.string.cancel),
|
cancelText = stringResource(id = R.string.cancel),
|
||||||
icon = ImageVector.vectorResource(R.drawable.ic_unarchive_fill_round_24)
|
icon = ImageVector.vectorResource(R.drawable.ic_unarchive_fill_round_24)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is ConvoDialog.ConvoDelete -> {
|
is ConvoDialog.Delete -> {
|
||||||
val errorColor = MaterialTheme.colorScheme.error
|
val errorColor = MaterialTheme.colorScheme.error
|
||||||
|
|
||||||
MaterialDialog(
|
MaterialDialog(
|
||||||
onDismissRequest = { onDismissed(dialog) },
|
onDismissRequest = { handleIntent(ConvoIntent.Dialog.Dismiss) },
|
||||||
icon = ImageVector.vectorResource(R.drawable.ic_delete_fill_round_24),
|
icon = ImageVector.vectorResource(R.drawable.ic_delete_fill_round_24),
|
||||||
iconTint = errorColor,
|
iconTint = errorColor,
|
||||||
title = stringResource(id = R.string.confirm_delete_convo),
|
title = stringResource(id = R.string.confirm_delete_convo),
|
||||||
confirmAction = { onConfirmed(dialog, bundleOf()) },
|
confirmAction = { handleIntent(ConvoIntent.Dialog.Confirm()) },
|
||||||
confirmText = stringResource(id = R.string.action_delete),
|
confirmText = stringResource(id = R.string.action_delete),
|
||||||
confirmContainerColor = errorColor,
|
confirmContainerColor = errorColor,
|
||||||
cancelText = stringResource(id = R.string.cancel),
|
cancelText = stringResource(id = R.string.cancel),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is ConvoDialog.ConvoPin -> {
|
is ConvoDialog.Pin -> {
|
||||||
MaterialDialog(
|
MaterialDialog(
|
||||||
onDismissRequest = { onDismissed(dialog) },
|
onDismissRequest = { handleIntent(ConvoIntent.Dialog.Dismiss) },
|
||||||
icon = ImageVector.vectorResource(R.drawable.ic_keep_fill_round_24),
|
icon = ImageVector.vectorResource(R.drawable.ic_keep_fill_round_24),
|
||||||
title = stringResource(id = R.string.confirm_pin_convo),
|
title = stringResource(id = R.string.confirm_pin_convo),
|
||||||
confirmAction = { onConfirmed(dialog, bundleOf()) },
|
confirmAction = { handleIntent(ConvoIntent.Dialog.Confirm()) },
|
||||||
confirmText = stringResource(id = R.string.action_pin),
|
confirmText = stringResource(id = R.string.action_pin),
|
||||||
cancelText = stringResource(id = R.string.cancel),
|
cancelText = stringResource(id = R.string.cancel),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is ConvoDialog.ConvoUnpin -> {
|
is ConvoDialog.Unpin -> {
|
||||||
MaterialDialog(
|
MaterialDialog(
|
||||||
onDismissRequest = { onDismissed(dialog) },
|
onDismissRequest = { handleIntent(ConvoIntent.Dialog.Dismiss) },
|
||||||
icon = ImageVector.vectorResource(R.drawable.ic_keep_off_fill_round_24),
|
icon = ImageVector.vectorResource(R.drawable.ic_keep_off_fill_round_24),
|
||||||
title = stringResource(id = R.string.confirm_unpin_convo),
|
title = stringResource(id = R.string.confirm_unpin_convo),
|
||||||
confirmAction = { onConfirmed(dialog, bundleOf()) },
|
confirmAction = { handleIntent(ConvoIntent.Dialog.Confirm()) },
|
||||||
confirmText = stringResource(id = R.string.action_unpin),
|
confirmText = stringResource(id = R.string.action_unpin),
|
||||||
cancelText = stringResource(id = R.string.cancel),
|
cancelText = stringResource(id = R.string.cancel),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ val BirthdayColor = Color(0xffb00b69)
|
|||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ConvoItem(
|
fun ConvoItem(
|
||||||
onItemClick: (UiConvo) -> Unit,
|
onItemClick: (convoId: Long) -> Unit,
|
||||||
onItemLongClick: (convo: UiConvo) -> Unit,
|
onItemLongClick: (convoId: Long) -> Unit,
|
||||||
onOptionClicked: (UiConvo, ConvoOption) -> Unit,
|
onOptionClicked: (ConvoOption) -> Unit,
|
||||||
maxLines: Int,
|
maxLines: Int,
|
||||||
isUserAccount: Boolean,
|
isUserAccount: Boolean,
|
||||||
convo: UiConvo,
|
convo: UiConvo,
|
||||||
@@ -81,9 +81,9 @@ fun ConvoItem(
|
|||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.combinedClickable(
|
.combinedClickable(
|
||||||
onClick = { onItemClick(convo) },
|
onClick = { onItemClick(convo.id) },
|
||||||
onLongClick = {
|
onLongClick = {
|
||||||
onItemLongClick(convo)
|
onItemLongClick(convo.id)
|
||||||
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
|
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -281,7 +281,7 @@ fun ConvoItem(
|
|||||||
val builder =
|
val builder =
|
||||||
AnnotatedString.Builder(convo.message.text)
|
AnnotatedString.Builder(convo.message.text)
|
||||||
|
|
||||||
convo.message.spanStyles.map { spanStyleRange ->
|
convo.message.spanStyles.forEach { spanStyleRange ->
|
||||||
val updatedSpanStyle =
|
val updatedSpanStyle =
|
||||||
if (spanStyleRange.item.color == Color.Red) {
|
if (spanStyleRange.item.color == Color.Red) {
|
||||||
spanStyleRange.item.copy(color = MaterialTheme.colorScheme.primary)
|
spanStyleRange.item.copy(color = MaterialTheme.colorScheme.primary)
|
||||||
@@ -378,7 +378,7 @@ fun ConvoItem(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ElevatedAssistChip(
|
ElevatedAssistChip(
|
||||||
onClick = { onOptionClicked(convo, option) },
|
onClick = { onOptionClicked(option) },
|
||||||
leadingIcon = {
|
leadingIcon = {
|
||||||
option.icon.getResourcePainter()?.let { painter ->
|
option.icon.getResourcePainter()?.let { painter ->
|
||||||
Icon(
|
Icon(
|
||||||
|
|||||||
@@ -36,12 +36,12 @@ import kotlinx.coroutines.launch
|
|||||||
fun ConvosList(
|
fun ConvosList(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
convos: ImmutableList<UiConvo>,
|
convos: ImmutableList<UiConvo>,
|
||||||
onConvosClick: (UiConvo) -> Unit,
|
onConvosClick: (Long) -> Unit,
|
||||||
onConvosLongClick: (UiConvo) -> Unit,
|
onConvosLongClick: (Long) -> Unit,
|
||||||
screenState: ConvosScreenState,
|
screenState: ConvosScreenState,
|
||||||
state: LazyListState,
|
state: LazyListState,
|
||||||
maxLines: Int,
|
maxLines: Int,
|
||||||
onOptionClicked: (UiConvo, ConvoOption) -> Unit,
|
onOptionClicked: (ConvoOption) -> Unit,
|
||||||
padding: PaddingValues
|
padding: PaddingValues
|
||||||
) {
|
) {
|
||||||
val theme = LocalThemeConfig.current
|
val theme = LocalThemeConfig.current
|
||||||
|
|||||||
@@ -1,79 +1,23 @@
|
|||||||
package dev.meloda.fast.convos.presentation
|
package dev.meloda.fast.convos.presentation
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import dev.meloda.fast.convos.model.ConvoIntent
|
||||||
import androidx.compose.runtime.getValue
|
import dev.meloda.fast.convos.model.ConvosScreenState
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|
||||||
import dev.meloda.fast.convos.ConvosViewModel
|
|
||||||
import dev.meloda.fast.convos.model.ConvoNavigation
|
|
||||||
import dev.meloda.fast.model.BaseError
|
|
||||||
import dev.meloda.fast.ui.util.ImmutableList.Companion.toImmutableList
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ConvosRoute(
|
fun ConvosRoute(
|
||||||
viewModel: ConvosViewModel,
|
handleIntent: (ConvoIntent) -> Unit,
|
||||||
onBack: (() -> Unit)? = null,
|
screenState: ConvosScreenState,
|
||||||
onError: (BaseError) -> Unit,
|
isArchive: Boolean,
|
||||||
onNavigateToMessagesHistory: (convoId: Long) -> Unit,
|
|
||||||
onNavigateToCreateChat: (() -> Unit)? = null,
|
|
||||||
onNavigateToArchive: (() -> Unit)? = null,
|
|
||||||
onScrolledToTop: () -> Unit,
|
|
||||||
) {
|
) {
|
||||||
val screenState by viewModel.screenState.collectAsStateWithLifecycle()
|
|
||||||
val navigationEvent by viewModel.navigation.collectAsStateWithLifecycle()
|
|
||||||
val convos by viewModel.uiConvos.collectAsStateWithLifecycle()
|
|
||||||
val dialog by viewModel.dialog.collectAsStateWithLifecycle()
|
|
||||||
val baseError by viewModel.baseError.collectAsStateWithLifecycle()
|
|
||||||
val canPaginate by viewModel.canPaginate.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
LaunchedEffect(navigationEvent) {
|
|
||||||
val shouldBeConsumed: Boolean = when (val navigation = navigationEvent) {
|
|
||||||
null -> false
|
|
||||||
|
|
||||||
is ConvoNavigation.CreateChat -> {
|
|
||||||
onNavigateToCreateChat?.invoke()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
is ConvoNavigation.MessagesHistory -> {
|
|
||||||
onNavigateToMessagesHistory(navigation.peerId)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldBeConsumed) viewModel.onNavigationConsumed()
|
|
||||||
}
|
|
||||||
|
|
||||||
ConvosScreen(
|
ConvosScreen(
|
||||||
onBack = { onBack?.invoke() },
|
handleIntent = handleIntent,
|
||||||
screenState = screenState,
|
screenState = screenState,
|
||||||
convos = convos.toImmutableList(),
|
isArchive = isArchive,
|
||||||
baseError = baseError,
|
|
||||||
canPaginate = canPaginate,
|
|
||||||
onConvoItemClicked = viewModel::onConvoItemClick,
|
|
||||||
onConvoItemLongClicked = viewModel::onConvoItemLongClick,
|
|
||||||
onOptionClicked = viewModel::onOptionClicked,
|
|
||||||
onPaginationConditionsMet = viewModel::onPaginationConditionsMet,
|
|
||||||
onRefresh = viewModel::onRefresh,
|
|
||||||
onCreateChatButtonClicked = viewModel::onCreateChatButtonClicked,
|
|
||||||
onArchiveActionClicked = { onNavigateToArchive?.invoke() },
|
|
||||||
setScrollIndex = viewModel::setScrollIndex,
|
|
||||||
setScrollOffset = viewModel::setScrollOffset,
|
|
||||||
onConsumeReselection = onScrolledToTop,
|
|
||||||
onErrorViewButtonClicked = {
|
|
||||||
if (baseError in listOf(BaseError.AccountBlocked, BaseError.SessionExpired)) {
|
|
||||||
onError(requireNotNull(baseError))
|
|
||||||
} else {
|
|
||||||
viewModel.onErrorButtonClicked()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
HandleDialogs(
|
HandleDialogs(
|
||||||
|
handleIntent = handleIntent,
|
||||||
screenState = screenState,
|
screenState = screenState,
|
||||||
dialog = dialog,
|
|
||||||
onConfirmed = viewModel::onDialogConfirmed,
|
|
||||||
onDismissed = viewModel::onDialogDismissed,
|
|
||||||
onItemPicked = viewModel::onDialogItemPicked
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+65
-86
@@ -19,7 +19,6 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.foundation.layout.statusBars
|
import androidx.compose.foundation.layout.statusBars
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
|
||||||
import androidx.compose.material3.FloatingActionButton
|
import androidx.compose.material3.FloatingActionButton
|
||||||
@@ -53,53 +52,39 @@ import androidx.compose.ui.unit.DpOffset
|
|||||||
import androidx.compose.ui.unit.IntOffset
|
import androidx.compose.ui.unit.IntOffset
|
||||||
import androidx.compose.ui.unit.LayoutDirection
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.skydoves.compose.stability.runtime.TraceRecomposition
|
|
||||||
import dev.chrisbanes.haze.hazeEffect
|
import dev.chrisbanes.haze.hazeEffect
|
||||||
import dev.chrisbanes.haze.hazeSource
|
import dev.chrisbanes.haze.hazeSource
|
||||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||||
import dev.chrisbanes.haze.materials.HazeMaterials
|
import dev.chrisbanes.haze.materials.HazeMaterials
|
||||||
|
import dev.meloda.fast.convos.model.ConvoIntent
|
||||||
import dev.meloda.fast.convos.model.ConvosScreenState
|
import dev.meloda.fast.convos.model.ConvosScreenState
|
||||||
import dev.meloda.fast.convos.navigation.ConvoGraph
|
import dev.meloda.fast.convos.navigation.ConvoGraph
|
||||||
import dev.meloda.fast.datastore.AppSettings
|
import dev.meloda.fast.datastore.AppSettings
|
||||||
import dev.meloda.fast.model.BaseError
|
|
||||||
import dev.meloda.fast.ui.R
|
import dev.meloda.fast.ui.R
|
||||||
import dev.meloda.fast.ui.components.FullScreenContainedLoader
|
import dev.meloda.fast.ui.components.FullScreenContainedLoader
|
||||||
import dev.meloda.fast.ui.components.NoItemsView
|
import dev.meloda.fast.ui.components.NoItemsView
|
||||||
import dev.meloda.fast.ui.components.VkErrorView
|
import dev.meloda.fast.ui.components.SegmentedButtonItem
|
||||||
import dev.meloda.fast.ui.model.vk.ConvoOption
|
import dev.meloda.fast.ui.components.SegmentedButtonsRow
|
||||||
import dev.meloda.fast.ui.model.vk.UiConvo
|
|
||||||
import dev.meloda.fast.ui.theme.LocalBottomPadding
|
import dev.meloda.fast.ui.theme.LocalBottomPadding
|
||||||
import dev.meloda.fast.ui.theme.LocalHazeState
|
import dev.meloda.fast.ui.theme.LocalHazeState
|
||||||
import dev.meloda.fast.ui.theme.LocalReselectedTab
|
import dev.meloda.fast.ui.theme.LocalReselectedTab
|
||||||
import dev.meloda.fast.ui.theme.LocalThemeConfig
|
import dev.meloda.fast.ui.theme.LocalThemeConfig
|
||||||
import dev.meloda.fast.ui.util.ImmutableList
|
import dev.meloda.fast.ui.util.buildImmutableList
|
||||||
import dev.meloda.fast.ui.util.emptyImmutableList
|
|
||||||
import dev.meloda.fast.ui.util.isScrollingUp
|
import dev.meloda.fast.ui.util.isScrollingUp
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
|
|
||||||
@OptIn(
|
@OptIn(
|
||||||
ExperimentalMaterial3Api::class,
|
ExperimentalMaterial3Api::class,
|
||||||
ExperimentalHazeMaterialsApi::class, ExperimentalMaterial3ExpressiveApi::class,
|
ExperimentalHazeMaterialsApi::class,
|
||||||
|
ExperimentalMaterial3ExpressiveApi::class,
|
||||||
)
|
)
|
||||||
@Composable
|
@Composable
|
||||||
fun ConvosScreen(
|
fun ConvosScreen(
|
||||||
screenState: ConvosScreenState = ConvosScreenState.EMPTY,
|
handleIntent: (ConvoIntent) -> Unit,
|
||||||
convos: ImmutableList<UiConvo> = emptyImmutableList(),
|
screenState: ConvosScreenState,
|
||||||
baseError: BaseError? = null,
|
isArchive: Boolean,
|
||||||
canPaginate: Boolean = false,
|
|
||||||
onBack: () -> Unit = {},
|
|
||||||
onConvoItemClicked: (convo: UiConvo) -> Unit = {},
|
|
||||||
onConvoItemLongClicked: (convo: UiConvo) -> Unit = {},
|
|
||||||
onOptionClicked: (UiConvo, ConvoOption) -> Unit = { _, _ -> },
|
|
||||||
onPaginationConditionsMet: () -> Unit = {},
|
|
||||||
onRefresh: () -> Unit = {},
|
|
||||||
onCreateChatButtonClicked: () -> Unit = {},
|
|
||||||
onArchiveActionClicked: () -> Unit = {},
|
|
||||||
setScrollIndex: (Int) -> Unit = {},
|
|
||||||
setScrollOffset: (Int) -> Unit = {},
|
|
||||||
onConsumeReselection: () -> Unit = {},
|
|
||||||
onErrorViewButtonClicked: () -> Unit = {}
|
|
||||||
) {
|
) {
|
||||||
val currentTheme = LocalThemeConfig.current
|
val currentTheme = LocalThemeConfig.current
|
||||||
val maxLines = if (currentTheme.enableMultiline) 2 else 1
|
val maxLines = if (currentTheme.enableMultiline) 2 else 1
|
||||||
@@ -112,33 +97,33 @@ fun ConvosScreen(
|
|||||||
val currentTabReselected = LocalReselectedTab.current[ConvoGraph] == true
|
val currentTabReselected = LocalReselectedTab.current[ConvoGraph] == true
|
||||||
LaunchedEffect(currentTabReselected) {
|
LaunchedEffect(currentTabReselected) {
|
||||||
if (currentTabReselected) {
|
if (currentTabReselected) {
|
||||||
if (screenState.isArchive) {
|
if (isArchive) {
|
||||||
onBack.invoke()
|
handleIntent(ConvoIntent.Back)
|
||||||
} else {
|
} else {
|
||||||
if (listState.firstVisibleItemIndex > 14) {
|
if (listState.firstVisibleItemIndex > 14) {
|
||||||
listState.scrollToItem(14)
|
listState.scrollToItem(14)
|
||||||
}
|
}
|
||||||
listState.animateScrollToItem(0)
|
listState.animateScrollToItem(0)
|
||||||
onConsumeReselection()
|
handleIntent(ConvoIntent.ConsumeScrollToTop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(listState) {
|
LaunchedEffect(listState) {
|
||||||
snapshotFlow { listState.firstVisibleItemIndex }
|
snapshotFlow { listState.firstVisibleItemIndex }
|
||||||
.debounce(500L)
|
.debounce(500L.milliseconds)
|
||||||
.collectLatest(setScrollIndex)
|
.collectLatest { handleIntent(ConvoIntent.SetScrollIndex(it)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(listState) {
|
LaunchedEffect(listState) {
|
||||||
snapshotFlow { listState.firstVisibleItemScrollOffset }
|
snapshotFlow { listState.firstVisibleItemScrollOffset }
|
||||||
.debounce(500L)
|
.debounce(500L.milliseconds)
|
||||||
.collectLatest(setScrollOffset)
|
.collectLatest { handleIntent(ConvoIntent.SetScrollOffset(it)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val paginationConditionMet by remember(canPaginate, listState) {
|
val paginationConditionMet by remember(screenState.canPaginate, listState) {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
canPaginate &&
|
screenState.canPaginate &&
|
||||||
(listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index
|
(listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index
|
||||||
?: -9) >= (listState.layoutInfo.totalItemsCount - 6)
|
?: -9) >= (listState.layoutInfo.totalItemsCount - 6)
|
||||||
}
|
}
|
||||||
@@ -146,7 +131,7 @@ fun ConvosScreen(
|
|||||||
|
|
||||||
LaunchedEffect(paginationConditionMet) {
|
LaunchedEffect(paginationConditionMet) {
|
||||||
if (paginationConditionMet && !screenState.isPaginating) {
|
if (paginationConditionMet && !screenState.isPaginating) {
|
||||||
onPaginationConditionsMet()
|
handleIntent(ConvoIntent.PaginationConditionsMet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +166,7 @@ fun ConvosScreen(
|
|||||||
text = stringResource(
|
text = stringResource(
|
||||||
id = when {
|
id = when {
|
||||||
screenState.isLoading -> R.string.title_loading
|
screenState.isLoading -> R.string.title_loading
|
||||||
screenState.isArchive -> R.string.title_archive
|
isArchive -> R.string.title_archive
|
||||||
else -> R.string.title_convos
|
else -> R.string.title_convos
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
@@ -191,8 +176,8 @@ fun ConvosScreen(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
if (screenState.isArchive) {
|
if (isArchive) {
|
||||||
IconButton(onClick = onBack) {
|
IconButton(onClick = { handleIntent(ConvoIntent.Back) }) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(R.drawable.ic_arrow_back_round_24),
|
painter = painterResource(R.drawable.ic_arrow_back_round_24),
|
||||||
contentDescription = null
|
contentDescription = null
|
||||||
@@ -201,46 +186,38 @@ fun ConvosScreen(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
if (!screenState.isArchive) {
|
val dropDownItems: List<@Composable () -> Unit> = buildList {}
|
||||||
IconButton(onClick = onArchiveActionClicked) {
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(R.drawable.ic_archive_round_24),
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val dropDownItems = mutableListOf<@Composable () -> Unit>()
|
val items = buildImmutableList {
|
||||||
|
if (!isArchive) {
|
||||||
|
add(SegmentedButtonItem("archive", R.drawable.ic_archive_round_24))
|
||||||
|
}
|
||||||
|
|
||||||
if (AppSettings.General.showManualRefreshOptions) {
|
if (AppSettings.General.showManualRefreshOptions) {
|
||||||
dropDownItems += {
|
add(SegmentedButtonItem("refresh", R.drawable.ic_refresh_round_24))
|
||||||
DropdownMenuItem(
|
|
||||||
onClick = {
|
|
||||||
onRefresh()
|
|
||||||
dropDownMenuExpanded = false
|
|
||||||
},
|
|
||||||
text = {
|
|
||||||
Text(text = stringResource(id = R.string.action_refresh))
|
|
||||||
},
|
|
||||||
leadingIcon = {
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(R.drawable.ic_refresh_round_24),
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dropDownItems.isNotEmpty()) {
|
if (dropDownItems.isNotEmpty()) {
|
||||||
IconButton(onClick = { dropDownMenuExpanded = true }) {
|
add(SegmentedButtonItem("more", R.drawable.ic_more_vert_round_24))
|
||||||
Icon(
|
|
||||||
painter = painterResource(R.drawable.ic_more_vert_round_24),
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SegmentedButtonsRow(
|
||||||
|
modifier = Modifier.padding(end = 8.dp),
|
||||||
|
items = items,
|
||||||
|
onClick = { index ->
|
||||||
|
when (items[index].key) {
|
||||||
|
"archive" -> handleIntent(ConvoIntent.ArchiveClick)
|
||||||
|
"refresh" -> handleIntent(ConvoIntent.Refresh)
|
||||||
|
"more" -> dropDownMenuExpanded = true
|
||||||
|
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (dropDownItems.isNotEmpty()) {
|
||||||
DropdownMenu(
|
DropdownMenu(
|
||||||
modifier = Modifier.defaultMinSize(minWidth = 140.dp),
|
modifier = Modifier.defaultMinSize(minWidth = 140.dp),
|
||||||
expanded = dropDownMenuExpanded,
|
expanded = dropDownMenuExpanded,
|
||||||
@@ -249,6 +226,7 @@ fun ConvosScreen(
|
|||||||
) {
|
) {
|
||||||
dropDownItems.forEach { it.invoke() }
|
dropDownItems.forEach { it.invoke() }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
colors = TopAppBarDefaults.topAppBarColors(
|
colors = TopAppBarDefaults.topAppBarColors(
|
||||||
containerColor = toolbarContainerColor.copy(
|
containerColor = toolbarContainerColor.copy(
|
||||||
@@ -268,7 +246,7 @@ fun ConvosScreen(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val showHorizontalProgressBar by remember(screenState) {
|
val showHorizontalProgressBar by remember(screenState) {
|
||||||
derivedStateOf { screenState.isLoading && convos.isNotEmpty() }
|
derivedStateOf { screenState.isLoading && screenState.convos.isNotEmpty() }
|
||||||
}
|
}
|
||||||
AnimatedVisibility(showHorizontalProgressBar) {
|
AnimatedVisibility(showHorizontalProgressBar) {
|
||||||
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
|
||||||
@@ -279,14 +257,14 @@ fun ConvosScreen(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
if (!screenState.isArchive) {
|
if (!isArchive) {
|
||||||
val offsetY by animateIntAsState(
|
val offsetY by animateIntAsState(
|
||||||
targetValue = if (listState.isScrollingUp()) 0 else 600
|
targetValue = if (listState.isScrollingUp()) 0 else 600
|
||||||
)
|
)
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
onClick = onCreateChatButtonClicked,
|
onClick = { handleIntent(ConvoIntent.CreateChatClick) },
|
||||||
modifier = Modifier.offset {
|
modifier = Modifier.offset {
|
||||||
IntOffset(0, offsetY)
|
IntOffset(0, offsetY)
|
||||||
}
|
}
|
||||||
@@ -303,14 +281,15 @@ fun ConvosScreen(
|
|||||||
}
|
}
|
||||||
) { padding ->
|
) { padding ->
|
||||||
when {
|
when {
|
||||||
baseError != null -> {
|
// TODO: 30.05.2026, Danil Nikolaev: move to UI State
|
||||||
VkErrorView(
|
// baseError != null -> {
|
||||||
baseError = baseError,
|
// VkErrorView(
|
||||||
onButtonClick = onErrorViewButtonClicked
|
// baseError = baseError,
|
||||||
)
|
// onButtonClick = onErrorViewButtonClicked
|
||||||
}
|
// )
|
||||||
|
// }
|
||||||
|
|
||||||
screenState.isLoading && convos.isEmpty() -> FullScreenContainedLoader()
|
screenState.isLoading && screenState.convos.isEmpty() -> FullScreenContainedLoader()
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
val pullToRefreshState = rememberPullToRefreshState()
|
val pullToRefreshState = rememberPullToRefreshState()
|
||||||
@@ -323,7 +302,7 @@ fun ConvosScreen(
|
|||||||
.padding(bottom = padding.calculateBottomPadding()),
|
.padding(bottom = padding.calculateBottomPadding()),
|
||||||
state = pullToRefreshState,
|
state = pullToRefreshState,
|
||||||
isRefreshing = screenState.isLoading,
|
isRefreshing = screenState.isLoading,
|
||||||
onRefresh = onRefresh,
|
onRefresh = { handleIntent(ConvoIntent.Refresh) },
|
||||||
indicator = {
|
indicator = {
|
||||||
PullToRefreshDefaults.Indicator(
|
PullToRefreshDefaults.Indicator(
|
||||||
state = pullToRefreshState,
|
state = pullToRefreshState,
|
||||||
@@ -335,9 +314,9 @@ fun ConvosScreen(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
ConvosList(
|
ConvosList(
|
||||||
convos = convos,
|
convos = screenState.convos,
|
||||||
onConvosClick = onConvoItemClicked,
|
onConvosClick = { handleIntent(ConvoIntent.ItemClick(it)) },
|
||||||
onConvosLongClick = onConvoItemLongClicked,
|
onConvosLongClick = { handleIntent(ConvoIntent.ItemLongClick(it)) },
|
||||||
screenState = screenState,
|
screenState = screenState,
|
||||||
state = listState,
|
state = listState,
|
||||||
maxLines = maxLines,
|
maxLines = maxLines,
|
||||||
@@ -346,14 +325,14 @@ fun ConvosScreen(
|
|||||||
} else {
|
} else {
|
||||||
Modifier
|
Modifier
|
||||||
}.fillMaxSize(),
|
}.fillMaxSize(),
|
||||||
onOptionClicked = onOptionClicked,
|
onOptionClicked = { handleIntent(ConvoIntent.OptionItemClick(it)) },
|
||||||
padding = padding
|
padding = padding
|
||||||
)
|
)
|
||||||
|
|
||||||
if (convos.isEmpty()) {
|
if (screenState.convos.isEmpty()) {
|
||||||
NoItemsView(
|
NoItemsView(
|
||||||
buttonText = stringResource(R.string.action_refresh),
|
buttonText = stringResource(R.string.action_refresh),
|
||||||
onButtonClick = onRefresh
|
onButtonClick = { handleIntent(ConvoIntent.Refresh) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -38,6 +38,7 @@ import dev.meloda.fast.ui.theme.LocalThemeConfig
|
|||||||
import dev.meloda.fast.ui.util.ImmutableList
|
import dev.meloda.fast.ui.util.ImmutableList
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -47,7 +48,6 @@ fun FriendsScreen(
|
|||||||
orderType: String,
|
orderType: String,
|
||||||
padding: PaddingValues,
|
padding: PaddingValues,
|
||||||
tabIndex: Int,
|
tabIndex: Int,
|
||||||
onSessionExpiredLogOutButtonClicked: () -> Unit = {},
|
|
||||||
onPhotoClicked: (url: String) -> Unit = {},
|
onPhotoClicked: (url: String) -> Unit = {},
|
||||||
onMessageClicked: (userid: Long) -> Unit = {},
|
onMessageClicked: (userid: Long) -> Unit = {},
|
||||||
setCanScrollBackward: (Boolean) -> Unit = {},
|
setCanScrollBackward: (Boolean) -> Unit = {},
|
||||||
@@ -100,13 +100,13 @@ fun FriendsScreen(
|
|||||||
|
|
||||||
LaunchedEffect(listState) {
|
LaunchedEffect(listState) {
|
||||||
snapshotFlow { listState.firstVisibleItemIndex }
|
snapshotFlow { listState.firstVisibleItemIndex }
|
||||||
.debounce(250L)
|
.debounce(250L.milliseconds)
|
||||||
.collectLatest(viewModel::setScrollIndex)
|
.collectLatest(viewModel::setScrollIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(listState) {
|
LaunchedEffect(listState) {
|
||||||
snapshotFlow { listState.firstVisibleItemScrollOffset }
|
snapshotFlow { listState.firstVisibleItemScrollOffset }
|
||||||
.debounce(250L)
|
.debounce(250L.milliseconds)
|
||||||
.collectLatest(viewModel::setScrollOffset)
|
.collectLatest(viewModel::setScrollOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-12
@@ -9,12 +9,11 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.WindowInsets
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.statusBars
|
import androidx.compose.foundation.layout.statusBars
|
||||||
import androidx.compose.foundation.pager.HorizontalPager
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
import androidx.compose.foundation.pager.rememberPagerState
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.PrimaryTabRow
|
import androidx.compose.material3.PrimaryTabRow
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
@@ -34,7 +33,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -47,11 +45,14 @@ import dev.meloda.fast.model.BaseError
|
|||||||
import dev.meloda.fast.ui.R
|
import dev.meloda.fast.ui.R
|
||||||
import dev.meloda.fast.ui.components.ActionInvokeDismiss
|
import dev.meloda.fast.ui.components.ActionInvokeDismiss
|
||||||
import dev.meloda.fast.ui.components.MaterialDialog
|
import dev.meloda.fast.ui.components.MaterialDialog
|
||||||
|
import dev.meloda.fast.ui.components.SegmentedButtonItem
|
||||||
|
import dev.meloda.fast.ui.components.SegmentedButtonsRow
|
||||||
import dev.meloda.fast.ui.components.SelectionType
|
import dev.meloda.fast.ui.components.SelectionType
|
||||||
import dev.meloda.fast.ui.model.TabItem
|
import dev.meloda.fast.ui.model.TabItem
|
||||||
import dev.meloda.fast.ui.theme.LocalHazeState
|
import dev.meloda.fast.ui.theme.LocalHazeState
|
||||||
import dev.meloda.fast.ui.theme.LocalThemeConfig
|
import dev.meloda.fast.ui.theme.LocalThemeConfig
|
||||||
import dev.meloda.fast.ui.util.ImmutableList
|
import dev.meloda.fast.ui.util.ImmutableList
|
||||||
|
import dev.meloda.fast.ui.util.buildImmutableList
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalHazeMaterialsApi::class)
|
@OptIn(ExperimentalMaterial3Api::class, ExperimentalHazeMaterialsApi::class)
|
||||||
@@ -189,16 +190,24 @@ fun FriendsRoute(
|
|||||||
),
|
),
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(
|
val items = buildImmutableList {
|
||||||
onClick = {
|
add(
|
||||||
showOrderDialog = true
|
SegmentedButtonItem(
|
||||||
}
|
"filter",
|
||||||
) {
|
R.drawable.ic_filter_list_round_24
|
||||||
Icon(
|
)
|
||||||
painter = painterResource(R.drawable.ic_filter_list_round_24),
|
|
||||||
contentDescription = null
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SegmentedButtonsRow(
|
||||||
|
modifier = Modifier.padding(end = 8.dp),
|
||||||
|
items = items,
|
||||||
|
onClick = { index ->
|
||||||
|
when (items[index].key) {
|
||||||
|
"filter" -> showOrderDialog = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
PrimaryTabRow(
|
PrimaryTabRow(
|
||||||
@@ -234,7 +243,6 @@ fun FriendsRoute(
|
|||||||
orderType = orderType,
|
orderType = orderType,
|
||||||
padding = padding,
|
padding = padding,
|
||||||
tabIndex = index,
|
tabIndex = index,
|
||||||
onSessionExpiredLogOutButtonClicked = { onError(BaseError.SessionExpired) },
|
|
||||||
onPhotoClicked = onPhotoClicked,
|
onPhotoClicked = onPhotoClicked,
|
||||||
onMessageClicked = onMessageClicked,
|
onMessageClicked = onMessageClicked,
|
||||||
setCanScrollBackward = { canScrollBackward = it },
|
setCanScrollBackward = { canScrollBackward = it },
|
||||||
|
|||||||
+5
-2
@@ -119,12 +119,15 @@ fun Attachments(
|
|||||||
|
|
||||||
AttachmentType.STICKER -> {
|
AttachmentType.STICKER -> {
|
||||||
Sticker(
|
Sticker(
|
||||||
item = attachment as VkStickerDomain
|
url = (attachment as VkStickerDomain).getUrl(
|
||||||
|
width = 256,
|
||||||
|
withBackground = false
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachmentType.GIFT -> {
|
AttachmentType.GIFT -> {
|
||||||
Gift(item = attachment as VkGiftDomain)
|
Gift(url = (attachment as VkGiftDomain).getDefaultThumbSizeOrLess())
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachmentType.VIDEO_MESSAGE -> {
|
AttachmentType.VIDEO_MESSAGE -> {
|
||||||
|
|||||||
+6
-7
@@ -21,25 +21,24 @@ import androidx.compose.ui.res.vectorResource
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import dev.meloda.fast.model.api.domain.VkGiftDomain
|
|
||||||
import dev.meloda.fast.ui.R
|
import dev.meloda.fast.ui.R
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Gift(
|
fun Gift(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
item: VkGiftDomain
|
url: String
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier.width(192.dp),
|
modifier = modifier
|
||||||
|
.width(208.dp)
|
||||||
|
.padding(8.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||||
) {
|
) {
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = item.getDefaultThumbSizeOrLess(),
|
model = url,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.Crop,
|
||||||
modifier = Modifier
|
modifier = Modifier.size(192.dp)
|
||||||
.padding(8.dp)
|
|
||||||
.fillMaxWidth()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
+6
-10
@@ -10,27 +10,23 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import dev.meloda.fast.model.api.domain.VkStickerDomain
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Sticker(
|
fun Sticker(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
item: VkStickerDomain
|
url: String?
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier.size(192.dp),
|
modifier = modifier
|
||||||
|
.size(208.dp)
|
||||||
|
.padding(8.dp),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = item.getUrl(
|
model = url,
|
||||||
width = 256,
|
|
||||||
withBackground = false
|
|
||||||
),
|
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.Crop,
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxSize()
|
||||||
.padding(8.dp)
|
|
||||||
.fillMaxSize()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,49 +5,33 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import dev.meloda.fast.common.VkConstants
|
import dev.meloda.fast.common.VkConstants
|
||||||
import dev.meloda.fast.common.extensions.listenValue
|
import dev.meloda.fast.common.extensions.listenValue
|
||||||
import dev.meloda.fast.common.extensions.setValue
|
import dev.meloda.fast.common.extensions.setValue
|
||||||
import dev.meloda.fast.data.State
|
|
||||||
import dev.meloda.fast.data.UserConfig
|
import dev.meloda.fast.data.UserConfig
|
||||||
import dev.meloda.fast.data.processState
|
import dev.meloda.fast.data.processState
|
||||||
import dev.meloda.fast.domain.GetLocalUserByIdUseCase
|
import dev.meloda.fast.domain.GetLocalUserByIdUseCase
|
||||||
import dev.meloda.fast.domain.LoadUserByIdUseCase
|
import dev.meloda.fast.domain.LoadUserByIdUseCase
|
||||||
import dev.meloda.fast.model.BaseError
|
|
||||||
import dev.meloda.fast.network.VkErrorCode
|
|
||||||
import dev.meloda.fast.profile.model.ProfileScreenState
|
import dev.meloda.fast.profile.model.ProfileScreenState
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
|
||||||
interface ProfileViewModel {
|
class ProfileViewModel(
|
||||||
val screenState: StateFlow<ProfileScreenState>
|
|
||||||
val baseError: StateFlow<BaseError?>
|
|
||||||
}
|
|
||||||
|
|
||||||
class ProfileViewModelImpl(
|
|
||||||
private val getLocalUserByIdUseCase: GetLocalUserByIdUseCase,
|
private val getLocalUserByIdUseCase: GetLocalUserByIdUseCase,
|
||||||
private val loadUserByIdUseCase: LoadUserByIdUseCase
|
private val loadUserByIdUseCase: LoadUserByIdUseCase
|
||||||
) : ViewModel(), ProfileViewModel {
|
) : ViewModel() {
|
||||||
|
|
||||||
override val screenState = MutableStateFlow(ProfileScreenState.EMPTY)
|
private val screenState = MutableStateFlow(ProfileScreenState.EMPTY)
|
||||||
override val baseError = MutableStateFlow<BaseError?>(null)
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
getLocalAccountInfo()
|
getLocalAccountInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun screenStateFlow(): StateFlow<ProfileScreenState> = screenState.asStateFlow()
|
||||||
|
|
||||||
private fun getLocalAccountInfo() {
|
private fun getLocalAccountInfo() {
|
||||||
getLocalUserByIdUseCase(UserConfig.userId)
|
getLocalUserByIdUseCase(UserConfig.userId)
|
||||||
.listenValue(viewModelScope) { state ->
|
.listenValue(viewModelScope) { state ->
|
||||||
state.processState(
|
state.processState(
|
||||||
error = { error ->
|
error = {
|
||||||
if (error is State.Error.ApiError) {
|
|
||||||
when (error.errorCode) {
|
|
||||||
VkErrorCode.USER_AUTHORIZATION_FAILED -> {
|
|
||||||
baseError.setValue { BaseError.SessionExpired }
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
screenState.setValue { old ->
|
screenState.setValue { old ->
|
||||||
old.copy(
|
old.copy(
|
||||||
avatarUrl = null,
|
avatarUrl = null,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package dev.meloda.fast.profile.di
|
package dev.meloda.fast.profile.di
|
||||||
|
|
||||||
import dev.meloda.fast.profile.ProfileViewModelImpl
|
import dev.meloda.fast.profile.ProfileViewModel
|
||||||
import org.koin.core.module.dsl.viewModelOf
|
import org.koin.core.module.dsl.viewModelOf
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
val profileModule = module {
|
val profileModule = module {
|
||||||
viewModelOf(::ProfileViewModelImpl)
|
viewModelOf(::ProfileViewModel)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package dev.meloda.fast.profile.navigation
|
package dev.meloda.fast.profile.navigation
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import dev.meloda.fast.model.BaseError
|
|
||||||
import dev.meloda.fast.profile.ProfileViewModel
|
import dev.meloda.fast.profile.ProfileViewModel
|
||||||
import dev.meloda.fast.profile.ProfileViewModelImpl
|
|
||||||
import dev.meloda.fast.profile.presentation.ProfileRoute
|
import dev.meloda.fast.profile.presentation.ProfileRoute
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import org.koin.androidx.viewmodel.ext.android.getViewModel
|
import org.koin.androidx.viewmodel.ext.android.getViewModel
|
||||||
@@ -15,19 +15,18 @@ object Profile
|
|||||||
|
|
||||||
fun NavGraphBuilder.profileScreen(
|
fun NavGraphBuilder.profileScreen(
|
||||||
activity: AppCompatActivity,
|
activity: AppCompatActivity,
|
||||||
onError: (BaseError) -> Unit,
|
|
||||||
onSettingsButtonClicked: () -> Unit,
|
onSettingsButtonClicked: () -> Unit,
|
||||||
onPhotoClicked: (url: String) -> Unit
|
onPhotoClicked: (url: String) -> Unit
|
||||||
) {
|
) {
|
||||||
val viewModel: ProfileViewModel = with(activity) {
|
val viewModel: ProfileViewModel = with(activity) { getViewModel() }
|
||||||
getViewModel<ProfileViewModelImpl>()
|
|
||||||
}
|
|
||||||
composable<Profile> {
|
composable<Profile> {
|
||||||
|
val screenState by viewModel.screenStateFlow().collectAsStateWithLifecycle()
|
||||||
|
|
||||||
ProfileRoute(
|
ProfileRoute(
|
||||||
onError = onError,
|
screenState = screenState,
|
||||||
onSettingsButtonClicked = onSettingsButtonClicked,
|
onSettingsButtonClicked = onSettingsButtonClicked,
|
||||||
onPhotoClicked = onPhotoClicked,
|
onPhotoClicked = onPhotoClicked,
|
||||||
viewModel = viewModel
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-20
@@ -14,15 +14,12 @@ import androidx.compose.foundation.layout.statusBarsPadding
|
|||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
@@ -31,28 +28,21 @@ import androidx.compose.ui.layout.ContentScale
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.unit.LayoutDirection
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import dev.meloda.fast.model.BaseError
|
|
||||||
import dev.meloda.fast.profile.ProfileViewModel
|
|
||||||
import dev.meloda.fast.profile.ProfileViewModelImpl
|
|
||||||
import dev.meloda.fast.profile.model.ProfileScreenState
|
import dev.meloda.fast.profile.model.ProfileScreenState
|
||||||
import dev.meloda.fast.ui.R
|
import dev.meloda.fast.ui.R
|
||||||
import org.koin.androidx.compose.koinViewModel
|
import dev.meloda.fast.ui.components.SegmentedButtonItem
|
||||||
|
import dev.meloda.fast.ui.components.SegmentedButtonsRow
|
||||||
|
import dev.meloda.fast.ui.util.buildImmutableList
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ProfileRoute(
|
fun ProfileRoute(
|
||||||
onError: (BaseError) -> Unit,
|
screenState: ProfileScreenState,
|
||||||
onSettingsButtonClicked: () -> Unit,
|
onSettingsButtonClicked: () -> Unit,
|
||||||
onPhotoClicked: (url: String) -> Unit,
|
onPhotoClicked: (url: String) -> Unit,
|
||||||
viewModel: ProfileViewModel = koinViewModel<ProfileViewModelImpl>()
|
|
||||||
) {
|
) {
|
||||||
val screenState by viewModel.screenState.collectAsStateWithLifecycle()
|
|
||||||
val baseError by viewModel.baseError.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
ProfileScreen(
|
ProfileScreen(
|
||||||
screenState = screenState,
|
screenState = screenState,
|
||||||
baseError = baseError,
|
|
||||||
onSettingsButtonClicked = onSettingsButtonClicked,
|
onSettingsButtonClicked = onSettingsButtonClicked,
|
||||||
onPhotoClicked = onPhotoClicked
|
onPhotoClicked = onPhotoClicked
|
||||||
)
|
)
|
||||||
@@ -63,7 +53,6 @@ fun ProfileRoute(
|
|||||||
@Composable
|
@Composable
|
||||||
fun ProfileScreen(
|
fun ProfileScreen(
|
||||||
screenState: ProfileScreenState = ProfileScreenState.EMPTY,
|
screenState: ProfileScreenState = ProfileScreenState.EMPTY,
|
||||||
baseError: BaseError? = null,
|
|
||||||
onSettingsButtonClicked: () -> Unit = {},
|
onSettingsButtonClicked: () -> Unit = {},
|
||||||
onPhotoClicked: (url: String) -> Unit = {}
|
onPhotoClicked: (url: String) -> Unit = {}
|
||||||
) {
|
) {
|
||||||
@@ -72,12 +61,19 @@ fun ProfileScreen(
|
|||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = {},
|
title = {},
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(onClick = onSettingsButtonClicked) {
|
val items = buildImmutableList {
|
||||||
Icon(
|
add(SegmentedButtonItem("settings", R.drawable.ic_settings_round_24))
|
||||||
painter = painterResource(R.drawable.ic_settings_round_24),
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SegmentedButtonsRow(
|
||||||
|
modifier = Modifier.padding(end = 8.dp),
|
||||||
|
items = items,
|
||||||
|
onClick = { index ->
|
||||||
|
when (items[index].key) {
|
||||||
|
"settings" -> onSettingsButtonClicked()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
},
|
},
|
||||||
colors = TopAppBarDefaults.topAppBarColors(containerColor = Color.Transparent)
|
colors = TopAppBarDefaults.topAppBarColors(containerColor = Color.Transparent)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ kotlin = "2.3.21"
|
|||||||
ksp = "2.3.7"
|
ksp = "2.3.7"
|
||||||
moduleGraph = "2.9.1"
|
moduleGraph = "2.9.1"
|
||||||
versions = "0.54.0"
|
versions = "0.54.0"
|
||||||
stability-analyzer = "0.7.4"
|
stability-analyzer = "0.7.5"
|
||||||
|
|
||||||
compose-bom = "2026.04.01"
|
compose-bom = "2026.04.01"
|
||||||
koin = "4.2.1"
|
koin = "4.2.1"
|
||||||
@@ -36,13 +36,9 @@ nanokt = "1.3.0"
|
|||||||
androidx-navigation = "2.9.8"
|
androidx-navigation = "2.9.8"
|
||||||
serialization = "1.11.0"
|
serialization = "1.11.0"
|
||||||
|
|
||||||
acra = "5.13.1"
|
|
||||||
okhttp = "5.3.2"
|
okhttp = "5.3.2"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
acra-email = { module = "ch.acra:acra-mail", version.ref = "acra" }
|
|
||||||
acra-dialog = { module = "ch.acra:acra-dialog", version.ref = "acra" }
|
|
||||||
|
|
||||||
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
|
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
|
||||||
|
|
||||||
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" }
|
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" }
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
+2
@@ -2,6 +2,8 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
retries=0
|
||||||
|
retryBackOffMs=500
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright © 2015-2021 the original authors.
|
# Copyright © 2015 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -86,8 +86,7 @@ done
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
' "$PWD" ) || exit
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -115,7 +114,6 @@ case "$( uname )" in #(
|
|||||||
NONSTOP* ) nonstop=true ;;
|
NONSTOP* ) nonstop=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
@@ -173,7 +171,6 @@ fi
|
|||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
if "$cygwin" || "$msys" ; then
|
if "$cygwin" || "$msys" ; then
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
@@ -206,15 +203,14 @@ fi
|
|||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
# Collect all arguments for the java command:
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
# and any embedded shellness will be escaped.
|
# and any embedded shellness will be escaped.
|
||||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
# treated as '${Hostname}' itself on the command line.
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
-classpath "$CLASSPATH" \
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
# Stop when "xargs" is not available.
|
||||||
|
|||||||
Vendored
+10
-22
@@ -23,8 +23,8 @@
|
|||||||
@rem
|
@rem
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
@rem Set local scope for the variables, and ensure extensions are enabled
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
setlocal EnableExtensions
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
@@ -51,7 +51,7 @@ echo. 1>&2
|
|||||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation. 1>&2
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
"%COMSPEC%" /c exit 1
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
:findJavaFromJavaHome
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
@@ -65,30 +65,18 @@ echo. 1>&2
|
|||||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation. 1>&2
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
"%COMSPEC%" /c exit 1
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||||
|
@rem which allows us to clear the local environment before executing the java command
|
||||||
|
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
|
||||||
|
|
||||||
:end
|
:exitWithErrorLevel
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||||
|
|
||||||
:fail
|
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
||||||
rem the _cmd.exe /c_ return code!
|
|
||||||
set EXIT_CODE=%ERRORLEVEL%
|
|
||||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
|
||||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
|
||||||
exit /b %EXIT_CODE%
|
|
||||||
|
|
||||||
:mainEnd
|
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
|
||||||
|
|
||||||
:omega
|
|
||||||
|
|||||||
Reference in New Issue
Block a user