From 6d1ae46c7a5b1d82f67ac474c54e4df9a270b88b Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Fri, 4 Aug 2023 18:47:50 +0530 Subject: [PATCH] feat(feature_custom_rpc): add Share Config Option add new strinngs --- .../src/main/res/values-fil/strings.xml | 1 + .../src/main/res/values-fr/strings.xml | 1 + .../src/main/res/values-hr/strings.xml | 1 + .../src/main/res/values-in/strings.xml | 1 + .../src/main/res/values-it/strings.xml | 1 + .../src/main/res/values-mm/strings.xml | 1 + .../src/main/res/values-nl/strings.xml | 1 + .../src/main/res/values-pl/strings.xml | 1 + .../src/main/res/values-pt/strings.xml | 1 + .../src/main/res/values-ru/strings.xml | 1 + .../src/main/res/values-tr/strings.xml | 1 + .../src/main/res/values-vi/strings.xml | 1 + .../src/main/res/values-zh/strings.xml | 1 + .../resources/src/main/res/values/strings.xml | 1 + .../my/kizzy/feature_custom_rpc/CustomRpc.kt | 9 +++- .../CustomScreenViewModel.kt | 7 +++ .../my/kizzy/feature_custom_rpc/UiEvent.kt | 1 + .../my/kizzy/feature_custom_rpc/UiState.kt | 1 + .../components/BottomSheet.kt | 12 +++++ .../components/sheet/ShareConfigDialog.kt | 51 +++++++++++++++++++ 20 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/components/sheet/ShareConfigDialog.kt diff --git a/common/resources/src/main/res/values-fil/strings.xml b/common/resources/src/main/res/values-fil/strings.xml index d38fcf68..9c06cd89 100644 --- a/common/resources/src/main/res/values-fil/strings.xml +++ b/common/resources/src/main/res/values-fil/strings.xml @@ -88,4 +88,5 @@ Set Previous Run config to Custom Rpc Fields Automatically set fields in custom rpc from the last run rpc Clear All Fields + Share Config diff --git a/common/resources/src/main/res/values-fr/strings.xml b/common/resources/src/main/res/values-fr/strings.xml index e6baaf76..f6299185 100644 --- a/common/resources/src/main/res/values-fr/strings.xml +++ b/common/resources/src/main/res/values-fr/strings.xml @@ -88,4 +88,5 @@ Set Previous Run config to Custom Rpc Fields Automatically set fields in custom rpc from the last run rpc Clear All Fields + Share Config diff --git a/common/resources/src/main/res/values-hr/strings.xml b/common/resources/src/main/res/values-hr/strings.xml index f5a0d332..e54c66ce 100644 --- a/common/resources/src/main/res/values-hr/strings.xml +++ b/common/resources/src/main/res/values-hr/strings.xml @@ -89,4 +89,5 @@ Postavite zadnju konfiguraciju za pokretanje u polja prilagođenog Rpc-a Automatski postavite polja u prilagođenom rpc-u iz posljednjeg rpc-a Očisti sva polja + Share Config diff --git a/common/resources/src/main/res/values-in/strings.xml b/common/resources/src/main/res/values-in/strings.xml index c4faa682..1340a615 100644 --- a/common/resources/src/main/res/values-in/strings.xml +++ b/common/resources/src/main/res/values-in/strings.xml @@ -88,6 +88,7 @@ Setel ke Konfigurasi yang Dijalankan Sebelumnya ke Custom Rpc Fields Otomatis setel fields ke Kustom rpc dari rpc yang di Jalakan sebelunya Bersihkan Semua Fields + Share Config diff --git a/common/resources/src/main/res/values-it/strings.xml b/common/resources/src/main/res/values-it/strings.xml index 9ff56291..33ae2180 100644 --- a/common/resources/src/main/res/values-it/strings.xml +++ b/common/resources/src/main/res/values-it/strings.xml @@ -88,4 +88,5 @@ Set Previous Run config to Custom Rpc Fields Automatically set fields in custom rpc from the last run rpc Clear All Fields + Share Config diff --git a/common/resources/src/main/res/values-mm/strings.xml b/common/resources/src/main/res/values-mm/strings.xml index 83274318..05609a06 100644 --- a/common/resources/src/main/res/values-mm/strings.xml +++ b/common/resources/src/main/res/values-mm/strings.xml @@ -88,4 +88,5 @@ Set Previous Run config to Custom Rpc Fields Automatically set fields in custom rpc from the last run rpc Clear All Fields + Share Config diff --git a/common/resources/src/main/res/values-nl/strings.xml b/common/resources/src/main/res/values-nl/strings.xml index 996626b5..f5d3d438 100644 --- a/common/resources/src/main/res/values-nl/strings.xml +++ b/common/resources/src/main/res/values-nl/strings.xml @@ -88,6 +88,7 @@ Set Previous Run config to Custom Rpc Fields Automatically set fields in custom rpc from the last run rpc Clear All Fields + Share Config \ No newline at end of file diff --git a/common/resources/src/main/res/values-pl/strings.xml b/common/resources/src/main/res/values-pl/strings.xml index fa3f2078..a4e1c2d0 100644 --- a/common/resources/src/main/res/values-pl/strings.xml +++ b/common/resources/src/main/res/values-pl/strings.xml @@ -88,5 +88,6 @@ Ustaw poprzednio uruchomioną konfigurację do pól własnego RPC Automatycznie wypełnij pola w własnym rpc z ostatnio uruchomionego rpc Wyczyść wszystkie pola + Share Config diff --git a/common/resources/src/main/res/values-pt/strings.xml b/common/resources/src/main/res/values-pt/strings.xml index aa2920d5..16c049e2 100644 --- a/common/resources/src/main/res/values-pt/strings.xml +++ b/common/resources/src/main/res/values-pt/strings.xml @@ -88,5 +88,6 @@ Set Previous Run config to Custom Rpc Fields Automatically set fields in custom rpc from the last run rpc Clear All Fields + Share Config diff --git a/common/resources/src/main/res/values-ru/strings.xml b/common/resources/src/main/res/values-ru/strings.xml index 84fe5762..b5c3c9a5 100644 --- a/common/resources/src/main/res/values-ru/strings.xml +++ b/common/resources/src/main/res/values-ru/strings.xml @@ -88,4 +88,5 @@ Установить конфигурацию предыдущего запуска в поля Custom RPC Автоматически установить поля в Custom RPC из последнего запуска RPC Очистить все поля + Share Config diff --git a/common/resources/src/main/res/values-tr/strings.xml b/common/resources/src/main/res/values-tr/strings.xml index 9b7b2a9d..5ba20615 100644 --- a/common/resources/src/main/res/values-tr/strings.xml +++ b/common/resources/src/main/res/values-tr/strings.xml @@ -88,5 +88,6 @@ Özel RPC Alanlarında önceki RPC\'de çalıştırılan yapılandırmayı kullan Özel RPC\'deki ayarları son çalıştırılan RPC\'den uygula Tüm Alanları Temizle + Share Config diff --git a/common/resources/src/main/res/values-vi/strings.xml b/common/resources/src/main/res/values-vi/strings.xml index 80f5b4fa..9365f49c 100644 --- a/common/resources/src/main/res/values-vi/strings.xml +++ b/common/resources/src/main/res/values-vi/strings.xml @@ -88,4 +88,5 @@ Set Previous Run config to Custom Rpc Fields Automatically set fields in custom rpc from the last run rpc Clear All Fields + Share Config diff --git a/common/resources/src/main/res/values-zh/strings.xml b/common/resources/src/main/res/values-zh/strings.xml index fadf4033..6f136083 100644 --- a/common/resources/src/main/res/values-zh/strings.xml +++ b/common/resources/src/main/res/values-zh/strings.xml @@ -88,6 +88,7 @@ Set Previous Run config to Custom Rpc Fields Automatically set fields in custom rpc from the last run rpc Clear All Fields + Share Config diff --git a/common/resources/src/main/res/values/strings.xml b/common/resources/src/main/res/values/strings.xml index 6b17e885..2095c865 100644 --- a/common/resources/src/main/res/values/strings.xml +++ b/common/resources/src/main/res/values/strings.xml @@ -89,4 +89,5 @@ Set Previous Run config to Custom Rpc Fields Automatically set fields in custom rpc from the last run rpc Clear All Fields + Share Config diff --git a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/CustomRpc.kt b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/CustomRpc.kt index b3ef4492..a8860ed4 100644 --- a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/CustomRpc.kt +++ b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/CustomRpc.kt @@ -40,6 +40,7 @@ import com.my.kizzy.feature_custom_rpc.components.sheet.LoadConfig import com.my.kizzy.feature_custom_rpc.components.sheet.PreviewDialog import com.my.kizzy.feature_custom_rpc.components.sheet.RequestStoragePermissionDialog import com.my.kizzy.feature_custom_rpc.components.sheet.SaveConfigDialog +import com.my.kizzy.feature_custom_rpc.components.sheet.ShareConfig import com.my.kizzy.feature_custom_rpc.components.sheet.dataToString import com.my.kizzy.feature_rpc_base.AppUtils import com.my.kizzy.feature_rpc_base.services.AppDetectionService @@ -54,7 +55,6 @@ import com.my.kizzy.ui.components.SwitchBar import kotlinx.coroutines.launch import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json -import java.util.* @Composable fun CustomRPC( @@ -85,6 +85,13 @@ fun CustomRPC( } ) } + if (state.showShareDialog) { + ShareConfig( + onDismiss = { + onEvent(UiEvent.SheetEvent.TriggerShareDialog) + } + ) + } if (state.showStoragePermissionRequestDialog) { RequestStoragePermissionDialog( onDismiss = { onEvent(UiEvent.SheetEvent.TriggerStoragePermissionRequest) } diff --git a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/CustomScreenViewModel.kt b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/CustomScreenViewModel.kt index 28d8aadf..8d2a3340 100644 --- a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/CustomScreenViewModel.kt +++ b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/CustomScreenViewModel.kt @@ -121,6 +121,13 @@ class CustomScreenViewModel @Inject constructor( ) } + UiEvent.SheetEvent.TriggerShareDialog -> { + _uiState.value = _uiState.value.copy( + showShareDialog = !_uiState.value.showShareDialog, + showBottomSheet = false + ) + } + UiEvent.SheetEvent.TriggerPreviewDialog -> { _uiState.value = _uiState.value.copy( showPreviewDialog = !_uiState.value.showPreviewDialog, diff --git a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/UiEvent.kt b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/UiEvent.kt index 98b16c61..25437f96 100644 --- a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/UiEvent.kt +++ b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/UiEvent.kt @@ -25,6 +25,7 @@ sealed interface UiEvent { sealed interface SheetEvent: UiEvent { object TriggerLoadDialog: SheetEvent + object TriggerShareDialog: SheetEvent object TriggerSaveDialog: SheetEvent object TriggerDeleteDialog: SheetEvent object TriggerPreviewDialog: SheetEvent diff --git a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/UiState.kt b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/UiState.kt index ba8293e4..52d94746 100644 --- a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/UiState.kt +++ b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/UiState.kt @@ -18,6 +18,7 @@ data class UiState( val activityTypeIsExpanded: Boolean = false, val showBottomSheet: Boolean = false, val showLoadDialog: Boolean = false, + val showShareDialog: Boolean = false, val showSaveDialog: Boolean = false, val showDeleteDialog: Boolean = false, val showPreviewDialog: Boolean = false, diff --git a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/components/BottomSheet.kt b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/components/BottomSheet.kt index f13c8f4a..208984c0 100644 --- a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/components/BottomSheet.kt +++ b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/components/BottomSheet.kt @@ -21,6 +21,7 @@ import androidx.compose.material.icons.outlined.ClearAll import androidx.compose.material.icons.outlined.Delete import androidx.compose.material.icons.outlined.FileOpen import androidx.compose.material.icons.outlined.SaveAs +import androidx.compose.material.icons.outlined.Share import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.rememberModalBottomSheetState @@ -102,6 +103,17 @@ fun BottomSheet(onEvent: (UiEvent.SheetEvent) -> Unit,onDismiss: () -> Unit) { }, icon = Icons.Outlined.ClearAll ) + + SheetItem( + title = stringResource(id = R.string.share_config), + icon = Icons.Outlined.Share, + onClick = { + scope.launch { + state.hide() + onEvent(UiEvent.SheetEvent.TriggerShareDialog) + } + } + ) } } } diff --git a/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/components/sheet/ShareConfigDialog.kt b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/components/sheet/ShareConfigDialog.kt new file mode 100644 index 00000000..aa1d954b --- /dev/null +++ b/feature_custom_rpc/src/main/java/com/my/kizzy/feature_custom_rpc/components/sheet/ShareConfigDialog.kt @@ -0,0 +1,51 @@ +/* + * + * ****************************************************************** + * * * Copyright (C) 2022 + * * * LoadConfigDialog.kt is part of Kizzy + * * * and can not be copied and/or distributed without the express + * * * permission of yzziK(Vaibhav) + * * ***************************************************************** + * + * + */ + +package com.my.kizzy.feature_custom_rpc.components.sheet + +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import com.my.kizzy.data.utils.shareFile +import com.my.kizzy.resources.R +import com.my.kizzy.ui.components.dialog.SingleChoiceItem +import java.io.File + +@Composable +fun ShareConfig( + onDismiss: () -> Unit +) { + val ctx = LocalContext.current + val dir = ctx.dir() + dir.mkdirs() + AlertDialog(onDismissRequest = { onDismiss() }, + confirmButton = {}, + title = { Text(text = stringResource(id = R.string.select_a_config)) }, text = { + LazyColumn { + val files = dir.list(FILE_FILTER)?.asList() + files?.forEach { file -> + item { + SingleChoiceItem( + text = file.dropLast(5), + selected = false + ) { + onDismiss() + ctx.shareFile(File(dir,file)) + } + } + } + } + }) +} \ No newline at end of file