diff --git a/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/AccountSelectedEvent.kt b/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/AccountSelectedEvent.kt deleted file mode 100644 index 65d398a5..00000000 --- a/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/AccountSelectedEvent.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts - -import com.redmadrobot.debug.core.internal.DebugEvent -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount - -data class AccountSelectedEvent(val debugAccount: DebugAccount) : DebugEvent diff --git a/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/AccountsPlugin.kt b/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/AccountsPlugin.kt deleted file mode 100644 index 4215e26f..00000000 --- a/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/AccountsPlugin.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts - -import com.redmadrobot.debug.core.data.DebugDataProvider -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount -import java.util.Collections.emptyList - -class AccountsPlugin( - private val preInstalledAccounts: List = emptyList(), - val debugAuthenticator: Any? = null -) { - constructor( - debugDataProvider: DebugDataProvider>, - debugAuthenticator: Any? = null - ) : this( - preInstalledAccounts = debugDataProvider.provideData(), - debugAuthenticator = debugAuthenticator - ) -} diff --git a/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/DebugAccount.kt b/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/DebugAccount.kt deleted file mode 100644 index 5f94318b..00000000 --- a/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/DebugAccount.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.data.model - -data class DebugAccount( - val id: Int = 0, - val login: String, - val password: String, - val pin: String = "" -) diff --git a/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/DebugAuthenticator.kt b/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/DebugAuthenticator.kt deleted file mode 100644 index 0f522ffe..00000000 --- a/panel-no-op/src/main/kotlin/com/redmadrobot/debug/noop/plugin/accounts/DebugAuthenticator.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.authenticator - -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount - -interface DebugAuthenticator { - fun onAccountSelected(account: DebugAccount) -} diff --git a/plugins/plugin-accounts/.gitignore b/plugins/plugin-accounts/.gitignore deleted file mode 100644 index 796b96d1..00000000 --- a/plugins/plugin-accounts/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/plugins/plugin-accounts/build.gradle.kts b/plugins/plugin-accounts/build.gradle.kts deleted file mode 100644 index 7fe98d50..00000000 --- a/plugins/plugin-accounts/build.gradle.kts +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id("convention.debug.panel.plugin") - alias(stack.plugins.ksp) - alias(stack.plugins.kotlin.compose) -} - -description = "Plugin for switching user accounts" - -android { - ksp { - arg("room.schemaLocation", "$projectDir/schemas") - } - - namespace = "com.redmadrobot.debug.plugin.accounts" -} - -dependencies { - ksp(androidx.room.compiler) -} diff --git a/plugins/plugin-accounts/proguard-rules.pro b/plugins/plugin-accounts/proguard-rules.pro deleted file mode 100644 index 0ee62cf3..00000000 --- a/plugins/plugin-accounts/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle.kts.kts.kts.kts.kts. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountSelectedEvent.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountSelectedEvent.kt deleted file mode 100644 index 32602d7d..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountSelectedEvent.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts - -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount -import com.redmadrobot.debug.core.DebugEvent - -public data class AccountSelectedEvent(val debugAccount: DebugAccount) : DebugEvent diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountsPlugin.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountsPlugin.kt deleted file mode 100644 index e5f8627b..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountsPlugin.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts - -import androidx.compose.runtime.Composable -import com.redmadrobot.debug.core.data.DebugDataProvider -import com.redmadrobot.debug.core.internal.CommonContainer -import com.redmadrobot.debug.core.internal.PluginDependencyContainer -import com.redmadrobot.debug.core.internal.EditablePlugin -import com.redmadrobot.debug.core.plugin.Plugin -import com.redmadrobot.debug.plugin.accounts.authenticator.DebugAuthenticator -import com.redmadrobot.debug.plugin.accounts.authenticator.DefaultAuthenticator -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount -import com.redmadrobot.debug.plugin.accounts.ui.AccountsScreen - -public class AccountsPlugin( - private val preInstalledAccounts: List = emptyList(), - public val debugAuthenticator: DebugAuthenticator = DefaultAuthenticator() -) : Plugin(), EditablePlugin { - - internal companion object { - const val NAME = "ACCOUNTS" - } - - public constructor( - preInstalledAccounts: DebugDataProvider>, - debugAuthenticator: DebugAuthenticator = DefaultAuthenticator() - ) : this( - preInstalledAccounts = preInstalledAccounts.provideData(), - debugAuthenticator = debugAuthenticator - ) - - override fun getName(): String = NAME - - override fun getPluginContainer(commonContainer: CommonContainer): PluginDependencyContainer { - return AccountsPluginContainer(preInstalledAccounts, commonContainer) - } - - @Composable - override fun content() { - AccountsScreen(isEditMode = false) - } - - @Composable - override fun settingsContent() { - AccountsScreen(isEditMode = true) - } -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountsPluginContainer.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountsPluginContainer.kt deleted file mode 100644 index 56c7bf24..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountsPluginContainer.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts - -import com.redmadrobot.debug.core.internal.CommonContainer -import com.redmadrobot.debug.core.internal.PluginDependencyContainer -import com.redmadrobot.debug.plugin.accounts.data.LocalDebugAccountRepository -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount -import com.redmadrobot.debug.plugin.accounts.data.storage.AccountsPluginDatabase -import com.redmadrobot.debug.plugin.accounts.ui.AccountsViewModel - -internal class AccountsPluginContainer( - private val preInstalledAccounts: List, - private val container: CommonContainer -) : PluginDependencyContainer { - - - private val pluginStorage by lazy { AccountsPluginDatabase.getInstance(container.context) } - - private val debugAccountRepository by lazy { - LocalDebugAccountRepository( - pluginStorage.getDebugAccountsDao(), - preInstalledAccounts - ) - } - - fun createAccountsViewModel(): AccountsViewModel { - return AccountsViewModel(container.context, debugAccountRepository) - } -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/authenticator/DebugAuthenticator.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/authenticator/DebugAuthenticator.kt deleted file mode 100644 index d0f32a3e..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/authenticator/DebugAuthenticator.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.authenticator - -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount - -public interface DebugAuthenticator { - public fun onAccountSelected(account: DebugAccount) -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/authenticator/DefaultAuthenticator.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/authenticator/DefaultAuthenticator.kt deleted file mode 100644 index 8446b339..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/authenticator/DefaultAuthenticator.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.authenticator - -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount - -internal class DefaultAuthenticator : DebugAuthenticator { - override fun onAccountSelected(account: DebugAccount) = Unit -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/DebugAccountRepository.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/DebugAccountRepository.kt deleted file mode 100644 index efae8fe5..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/DebugAccountRepository.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.data - -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount - -internal interface DebugAccountRepository { - suspend fun addAccount(account: DebugAccount) - - suspend fun updateAccount(account: DebugAccount) - - suspend fun getAccounts(): List - - suspend fun getPreInstalledAccounts(): List - - suspend fun removeAccount(user: DebugAccount) -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/LocalDebugAccountRepository.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/LocalDebugAccountRepository.kt deleted file mode 100644 index bc13f7c0..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/LocalDebugAccountRepository.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.data - -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount -import com.redmadrobot.debug.plugin.accounts.data.storage.DebugAccountDao -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext - -internal class LocalDebugAccountRepository( - private val debugAccountDao: DebugAccountDao, - private val preInstalledAccounts: List -) : DebugAccountRepository { - - override suspend fun addAccount(account: DebugAccount) { - withContext(Dispatchers.IO) { - debugAccountDao.insert(account) - } - } - - override suspend fun updateAccount(account: DebugAccount) { - withContext(Dispatchers.IO) { - debugAccountDao.update(account) - } - } - - override suspend fun getAccounts(): List { - return withContext(Dispatchers.IO) { - debugAccountDao.getAll() - } - } - - override suspend fun getPreInstalledAccounts(): List { - return preInstalledAccounts - } - - override suspend fun removeAccount(user: DebugAccount) { - return withContext(Dispatchers.IO) { - debugAccountDao.remove(user) - } - } -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/model/DebugAccount.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/model/DebugAccount.kt deleted file mode 100644 index 9d5dc576..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/model/DebugAccount.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.data.model - -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.PrimaryKey - -@Entity(tableName = DebugAccount.TABLE_NAME) -public data class DebugAccount( - @PrimaryKey(autoGenerate = true) - val id: Int = 0, - - @ColumnInfo(name = "login") - val login: String, - - @ColumnInfo(name = "password") - val password: String, - - @ColumnInfo(name = "pin") - val pin: String = "" -) { - internal companion object { - const val TABLE_NAME: String = "debug_account" - } -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/storage/AccountsPluginDatabase.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/storage/AccountsPluginDatabase.kt deleted file mode 100644 index 7caa3135..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/storage/AccountsPluginDatabase.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.data.storage - -import android.content.Context -import androidx.room.Database -import androidx.room.Room -import androidx.room.RoomDatabase -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount - -@Database( - entities = [DebugAccount::class], - version = 1 -) - internal abstract class AccountsPluginDatabase : RoomDatabase() { - abstract fun getDebugAccountsDao(): DebugAccountDao - - companion object { - private const val DATABASE_NAME = "accounts_plugin_db" - - fun getInstance(context: Context): AccountsPluginDatabase { - return Room.databaseBuilder( - context.applicationContext, - AccountsPluginDatabase::class.java, - DATABASE_NAME - ).build() - } - } -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/storage/DebugAccountDao.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/storage/DebugAccountDao.kt deleted file mode 100644 index be9d681d..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/data/storage/DebugAccountDao.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.data.storage - -import androidx.room.* -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount - -@Dao -internal interface DebugAccountDao { - - @Query("SELECT * FROM ${DebugAccount.TABLE_NAME}") - suspend fun getAll(): List - - @Insert(onConflict = OnConflictStrategy.REPLACE) - suspend fun insert(account: DebugAccount) - - @Delete - suspend fun remove(account: DebugAccount) - - @Update - suspend fun update(account: DebugAccount) -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/ui/AccountsScreen.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/ui/AccountsScreen.kt deleted file mode 100644 index c5cb44d8..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/ui/AccountsScreen.kt +++ /dev/null @@ -1,270 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.ui - -import android.annotation.SuppressLint -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Button -import androidx.compose.material.Card -import androidx.compose.material.ExtendedFloatingActionButton -import androidx.compose.material.Icon -import androidx.compose.material.IconButton -import androidx.compose.material.MaterialTheme -import androidx.compose.material.OutlinedTextField -import androidx.compose.material.Scaffold -import androidx.compose.material.Surface -import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import androidx.compose.ui.window.Dialog -import com.redmadrobot.debug.core.extension.getPlugin -import com.redmadrobot.debug.core.extension.provideViewModel -import com.redmadrobot.debug.plugin.accounts.AccountsPlugin -import com.redmadrobot.debug.plugin.accounts.AccountsPluginContainer -import com.redmadrobot.debug.plugin.accounts.R -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount - -@SuppressLint("UnusedMaterialScaffoldPaddingParameter") -@Composable -internal fun AccountsScreen( - viewModel: AccountsViewModel = provideViewModel { - getPlugin() - .getContainer() - .createAccountsViewModel() - }, - isEditMode: Boolean -) { - val state by viewModel.state.collectAsState() - var showDialog by remember { mutableStateOf(false) } - var editableAccount by remember { mutableStateOf(null) } - - Scaffold( - floatingActionButton = { - if (isEditMode) { - ExtendedFloatingActionButton( - onClick = { showDialog = true }, - text = { Text("Add") }, - icon = { - Icon( - painterResource(R.drawable.icon_add_account), - contentDescription = null - ) - } - ) - } - } - ) { - AccountScreenLayout( - state = state, - isEditMode = isEditMode, - onSelectedClick = viewModel::setAccountAsCurrent, - onOpenDialogClick = { - showDialog = true - editableAccount = it - }, - onDeleteClick = viewModel::removeAccount, - ) - if (showDialog) { - AccountDetailsDialog( - onDismiss = { - showDialog = false - editableAccount = null - }, - onSaveClick = viewModel::saveAccount, - account = editableAccount - ) - } - } - - LaunchedEffect(viewModel) { - viewModel.loadAccounts() - } -} - -@Composable -private fun AccountScreenLayout( - state: AccountsViewState, - isEditMode: Boolean, - onSelectedClick: (DebugAccount) -> Unit, - onDeleteClick: (DebugAccount) -> Unit, - onOpenDialogClick: (DebugAccount?) -> Unit, -) { - LazyColumn( - modifier = Modifier - .fillMaxSize() - .padding(horizontal = 16.dp), - verticalArrangement = Arrangement.spacedBy(8.dp) - ) { - state.allItems.forEach { item -> - item { - when (item) { - is DebugAccountItem.Header -> { - Text( - item.header.uppercase(), - modifier = Modifier - .fillParentMaxWidth() - .padding(vertical = 16.dp), - fontSize = 16.sp - ) - } - - is DebugAccountItem.PreinstalledAccount -> { - AccountItem( - item.account, - false, - onItemClick = { if (!isEditMode) onSelectedClick(it) } - ) - } - - is DebugAccountItem.AddedAccount -> { - AccountItem( - account = item.account, - showDelete = isEditMode, - onItemClick = { - if (isEditMode) onOpenDialogClick(it) else onSelectedClick(it) - }, - onDeleteClick = onDeleteClick, - ) - } - } - } - } - } -} - -@Composable -private fun AccountItem( - account: DebugAccount, - showDelete: Boolean, - onItemClick: (DebugAccount) -> Unit, - onDeleteClick: (DebugAccount) -> Unit = {}, -) { - Card( - modifier = Modifier - .fillMaxWidth() - .height(56.dp) - .clickable { onItemClick(account) } - ) { - Box( - modifier = Modifier - .fillMaxSize() - .padding(horizontal = 16.dp) - ) { - Row( - modifier = Modifier.fillMaxSize(), - horizontalArrangement = Arrangement.spacedBy(32.dp), - verticalAlignment = Alignment.CenterVertically - ) { - Icon( - painter = painterResource(R.drawable.icon_account), - contentDescription = null, - tint = MaterialTheme.colors.primary - ) - Text(account.login) - } - if (showDelete) { - IconButton( - modifier = Modifier.align(Alignment.CenterEnd), - onClick = { onDeleteClick(account) }, - ) { - Icon( - painterResource(R.drawable.icon_delete), - contentDescription = null, - tint = Color.Red - ) - } - } - } - } -} - -@Composable -private fun AccountDetailsDialog( - onDismiss: () -> Unit, - onSaveClick: (DebugAccount) -> Unit, - account: DebugAccount? = null, -) { - var login by remember { mutableStateOf(account?.login.orEmpty()) } - var password by remember { mutableStateOf(account?.password.orEmpty()) } - var pin by remember { mutableStateOf(account?.pin.orEmpty()) } - - Dialog(onDismissRequest = onDismiss) { - Surface( - shape = RoundedCornerShape(16.dp), - color = Color.White - ) { - Box(modifier = Modifier.padding(16.dp)) { - Column { - OutlinedTextField( - value = login, - onValueChange = { login = it }, - label = { Text(stringResource(R.string.login_hint)) } - ) - Spacer(modifier = Modifier.height(24.dp)) - OutlinedTextField( - value = password, - onValueChange = { password = it }, - label = { Text(stringResource(R.string.password_hint)) } - ) - Spacer(modifier = Modifier.height(24.dp)) - OutlinedTextField( - value = pin, - onValueChange = { pin = it }, - label = { Text(stringResource(R.string.pin)) } - ) - Spacer(modifier = Modifier.height(24.dp)) - Button( - onClick = { - val debugAccount = DebugAccount( - id = account?.id ?: 0, - login = login, - password = password, - pin = pin - ) - onSaveClick(debugAccount) - onDismiss() - }, - modifier = Modifier.align(Alignment.End) - ) { - Text(stringResource(R.string.save_account_text).uppercase()) - } - } - } - } - } -} - -internal sealed class DebugAccountItem { - internal data class Header(val header: String) : DebugAccountItem() - internal data class PreinstalledAccount(val account: DebugAccount) : DebugAccountItem() - internal data class AddedAccount(var account: DebugAccount) : DebugAccountItem() -} - - -@Preview -@Composable -private fun DialogPreview() { - AccountDetailsDialog({}, {}) -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/ui/AccountsViewModel.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/ui/AccountsViewModel.kt deleted file mode 100644 index 2a580578..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/ui/AccountsViewModel.kt +++ /dev/null @@ -1,108 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.ui - -import android.content.Context -import androidx.lifecycle.viewModelScope -import com.redmadrobot.debug.core.extension.getPlugin -import com.redmadrobot.debug.core.extension.safeLaunch -import com.redmadrobot.debug.core.internal.PluginViewModel -import com.redmadrobot.debug.plugin.accounts.AccountSelectedEvent -import com.redmadrobot.debug.plugin.accounts.AccountsPlugin -import com.redmadrobot.debug.plugin.accounts.R -import com.redmadrobot.debug.plugin.accounts.data.DebugAccountRepository -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.update - -internal class AccountsViewModel( - private val context: Context, - private val debugAccountsRepository: DebugAccountRepository -) : PluginViewModel() { - - val state = MutableStateFlow( - value = AccountsViewState( - preInstalledAccounts = emptyList(), - addedAccounts = emptyList() - ) - ) - - fun loadAccounts() { - viewModelScope.safeLaunch { - loadPreInstalledAccounts() - loadAddedAccounts() - } - } - - fun saveAccount(debugAccount: DebugAccount) { - viewModelScope.safeLaunch { - if (debugAccount.id != 0) { - debugAccountsRepository.updateAccount(debugAccount) - } else { - debugAccountsRepository.addAccount(debugAccount) - } - loadAddedAccounts() - } - } - - fun updateAccount( - id: Int, - newLogin: String, - newPassword: String, - pin: String - ) { - val newAccount = DebugAccount( - id = id, - login = newLogin, - password = newPassword, - pin = pin - ) - viewModelScope.safeLaunch { - debugAccountsRepository.updateAccount(newAccount) - loadAddedAccounts() - } - - } - - fun removeAccount(account: DebugAccount) { - viewModelScope.safeLaunch { - debugAccountsRepository.removeAccount(account) - loadAddedAccounts() - } - } - - fun setAccountAsCurrent(account: DebugAccount) { - getPlugin().apply { - debugAuthenticator.onAccountSelected(account) - pushEvent(AccountSelectedEvent(account)) - } - } - - private suspend fun loadPreInstalledAccounts() { - val accounts = debugAccountsRepository.getPreInstalledAccounts() - val preInstalledAccounts = if (accounts.isNotEmpty()) { - val items = accounts.map { account -> - DebugAccountItem.PreinstalledAccount(account) - } - val header = context.getString(R.string.pre_installed_accounts) - listOf(/*Header item*/DebugAccountItem.Header(header)).plus(items) - } else { - emptyList() - } - - state.update { state.value.copy(preInstalledAccounts = preInstalledAccounts) } - } - - private suspend fun loadAddedAccounts() { - val accounts = debugAccountsRepository.getAccounts() - val addedAccountItems = if (accounts.isNotEmpty()) { - val items = accounts.map { account -> - DebugAccountItem.AddedAccount(account) - } - val header = context.getString(R.string.added_accounts) - listOf(/*Header item*/DebugAccountItem.Header(header)).plus(items) - } else { - emptyList() - } - - state.update { state.value.copy(addedAccounts = addedAccountItems) } - } -} diff --git a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/ui/AccountsViewState.kt b/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/ui/AccountsViewState.kt deleted file mode 100644 index 58af1d20..00000000 --- a/plugins/plugin-accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/ui/AccountsViewState.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.redmadrobot.debug.plugin.accounts.ui - -import androidx.compose.runtime.Stable - -@Stable -internal data class AccountsViewState( - val preInstalledAccounts: List = emptyList(), - val addedAccounts: List = emptyList(), -) { - val allItems = preInstalledAccounts.plus(addedAccounts) -} diff --git a/plugins/plugin-accounts/src/main/res/drawable/icon_account.xml b/plugins/plugin-accounts/src/main/res/drawable/icon_account.xml deleted file mode 100644 index 4649894e..00000000 --- a/plugins/plugin-accounts/src/main/res/drawable/icon_account.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/plugins/plugin-accounts/src/main/res/drawable/icon_add_account.xml b/plugins/plugin-accounts/src/main/res/drawable/icon_add_account.xml deleted file mode 100644 index e3979cd7..00000000 --- a/plugins/plugin-accounts/src/main/res/drawable/icon_add_account.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/plugins/plugin-accounts/src/main/res/drawable/icon_delete.xml b/plugins/plugin-accounts/src/main/res/drawable/icon_delete.xml deleted file mode 100644 index fc6ac2be..00000000 --- a/plugins/plugin-accounts/src/main/res/drawable/icon_delete.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/plugins/plugin-accounts/src/main/res/values/color.xml b/plugins/plugin-accounts/src/main/res/values/color.xml deleted file mode 100644 index 3ea04e70..00000000 --- a/plugins/plugin-accounts/src/main/res/values/color.xml +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/plugins/plugin-accounts/src/main/res/values/public.xml b/plugins/plugin-accounts/src/main/res/values/public.xml deleted file mode 100644 index 2b0d6805..00000000 --- a/plugins/plugin-accounts/src/main/res/values/public.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - diff --git a/plugins/plugin-accounts/src/main/res/values/strings.xml b/plugins/plugin-accounts/src/main/res/values/strings.xml deleted file mode 100644 index 51464bec..00000000 --- a/plugins/plugin-accounts/src/main/res/values/strings.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - Login - Password - save - Added - Pre-installed - Pin - Done - diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index e8642462..63b962ce 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -45,7 +45,6 @@ dependencies { implementation(androidx.lifecycle.runtime) debugImplementation(project(":panel-core")) debugImplementation(project(":plugins:plugin-servers")) - debugImplementation(project(":plugins:plugin-accounts")) debugImplementation(project(":plugins:plugin-app-settings")) debugImplementation(project(":plugins:plugin-about-app")) diff --git a/sample/src/debug/kotlin/com/redmadrobot/debug_sample/debug_data/DebugAccountsProvider.kt b/sample/src/debug/kotlin/com/redmadrobot/debug_sample/debug_data/DebugAccountsProvider.kt deleted file mode 100644 index 98611429..00000000 --- a/sample/src/debug/kotlin/com/redmadrobot/debug_sample/debug_data/DebugAccountsProvider.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.redmadrobot.debug_sample.debug_data - -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount -import com.redmadrobot.debug.core.data.DebugDataProvider - -class DebugAccountsProvider : DebugDataProvider> { - - override fun provideData(): List { - return listOf( - DebugAccount( - login = "7882340482", - password = "Qq!11111" - ), - DebugAccount( - login = "2777248041", - password = "Qq!11111" - ), - DebugAccount( - login = "4183730054", - password = "Ww!11111", - pin = "112" - ), - DebugAccount( - login = "1944647499", - password = "Qq!11111", - pin = "1111" - ) - ) - } -} diff --git a/sample/src/main/kotlin/com/redmadrobot/debug_sample/App.kt b/sample/src/main/kotlin/com/redmadrobot/debug_sample/App.kt index c4f844e1..c3da1aa6 100644 --- a/sample/src/main/kotlin/com/redmadrobot/debug_sample/App.kt +++ b/sample/src/main/kotlin/com/redmadrobot/debug_sample/App.kt @@ -4,14 +4,11 @@ import android.app.Application import com.redmadrobot.debug.core.DebugPanel import com.redmadrobot.debug.core.DebugPanelConfig import com.redmadrobot.debug.plugin.aboutapp.AboutAppPlugin -import com.redmadrobot.debug.plugin.accounts.AccountsPlugin import com.redmadrobot.debug.plugin.appsettings.AppSettingsPlugin import com.redmadrobot.debug.plugin.konfeature.KonfeatureDebugPanelInterceptor import com.redmadrobot.debug.plugin.konfeature.KonfeaturePlugin import com.redmadrobot.debug.plugin.servers.ServersPlugin -import com.redmadrobot.debug_sample.account.DebugUserAuthenticator import com.redmadrobot.debug_sample.debug_data.DebugAboutAppInfoProvider -import com.redmadrobot.debug_sample.debug_data.DebugAccountsProvider import com.redmadrobot.debug_sample.debug_data.DebugServersProvider import com.redmadrobot.debug_sample.storage.AppTestSettings import com.redmadrobot.debug_sample.storage.TestKonfeatureProvider @@ -26,10 +23,6 @@ class App : Application() { application = this, config = DebugPanelConfig(shakerMode = false), plugins = listOf( - AccountsPlugin( - preInstalledAccounts = DebugAccountsProvider().provideData(), - debugAuthenticator = DebugUserAuthenticator() - ), ServersPlugin( preInstalledServers = DebugServersProvider().provideData() ), diff --git a/sample/src/main/kotlin/com/redmadrobot/debug_sample/MainActivity.kt b/sample/src/main/kotlin/com/redmadrobot/debug_sample/MainActivity.kt index 886d37c3..315868b6 100644 --- a/sample/src/main/kotlin/com/redmadrobot/debug_sample/MainActivity.kt +++ b/sample/src/main/kotlin/com/redmadrobot/debug_sample/MainActivity.kt @@ -6,7 +6,6 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope import com.redmadrobot.debug.core.DebugPanel -import com.redmadrobot.debug.plugin.accounts.AccountSelectedEvent import com.redmadrobot.debug.plugin.servers.ServerSelectedEvent import com.redmadrobot.debug_sample.network.ApiFactory import com.redmadrobot.debugpanel.databinding.ActivityMainBinding @@ -30,10 +29,6 @@ class MainActivity : AppCompatActivity() { DebugPanel.subscribeToEvents(this) { event -> when (event) { - is AccountSelectedEvent -> { - //Обработка выбора аккаунта - } - is ServerSelectedEvent -> { //Обработка выбора сервера } @@ -43,10 +38,6 @@ class MainActivity : AppCompatActivity() { DebugPanel.observeEvents() .onEach { event -> when (event) { - is AccountSelectedEvent -> { - showSelectedAccount(event.debugAccount.login) - } - is ServerSelectedEvent -> { //Обработка выбора сервера } @@ -101,14 +92,6 @@ class MainActivity : AppCompatActivity() { ).show() } - private fun showSelectedAccount(account: String) { - Toast.makeText( - this, - "Account $account selected", - Toast.LENGTH_LONG - ).show() - } - private fun openDebugPanel() { DebugPanel.showPanel(this) } diff --git a/sample/src/main/kotlin/com/redmadrobot/debug_sample/account/DebugUserAuthenticator.kt b/sample/src/main/kotlin/com/redmadrobot/debug_sample/account/DebugUserAuthenticator.kt deleted file mode 100644 index bb2c1631..00000000 --- a/sample/src/main/kotlin/com/redmadrobot/debug_sample/account/DebugUserAuthenticator.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.redmadrobot.debug_sample.account - -import com.redmadrobot.debug.plugin.accounts.authenticator.DebugAuthenticator -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount -import timber.log.Timber - -class DebugUserAuthenticator : DebugAuthenticator { - - override fun onAccountSelected(account: DebugAccount) { - Timber.i("Login - ${account.login}, Password - ${account.password} Pin - ${account.pin}") - } -} diff --git a/sample/src/release/kotlin/com/redmadrobot/debug_sample/debug_data/DebugAccountsProvider.kt b/sample/src/release/kotlin/com/redmadrobot/debug_sample/debug_data/DebugAccountsProvider.kt deleted file mode 100644 index fc81f4f6..00000000 --- a/sample/src/release/kotlin/com/redmadrobot/debug_sample/debug_data/DebugAccountsProvider.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.redmadrobot.debug_sample.debug_data - -import com.redmadrobot.debug.core.data.DebugDataProvider -import com.redmadrobot.debug.plugin.accounts.data.model.DebugAccount - -class DebugAccountsProvider : DebugDataProvider> { - - override fun provideData(): List { - return emptyList() - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 13390702..48b27fc2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -53,7 +53,6 @@ include( // Plugins include( - ":plugins:plugin-accounts", ":plugins:plugin-servers", ":plugins:plugin-app-settings", ":plugins:plugin-konfeature",