diff --git a/build.gradle.kts b/build.gradle.kts index fa9fae5c..0fea89a4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { subprojects { tasks.withType().configureEach { kotlinOptions.freeCompilerArgs += listOf( - "-opt-in=com.redmadrobot.debug_panel_core.annotation.DebugPanelInternal" + "-opt-in=com.redmadrobot.debug.core.annotation.DebugPanelInternal" ) } } diff --git a/debug-panel-common/.gitignore b/common/.gitignore similarity index 100% rename from debug-panel-common/.gitignore rename to common/.gitignore diff --git a/debug-panel-common/build.gradle.kts b/common/build.gradle.kts similarity index 74% rename from debug-panel-common/build.gradle.kts rename to common/build.gradle.kts index 252e361a..64481878 100644 --- a/debug-panel-common/build.gradle.kts +++ b/common/build.gradle.kts @@ -40,27 +40,39 @@ android { buildFeatures { viewBinding = true } - namespace = "com.redmadrobot.debug_panel_common" + namespace = "com.redmadrobot.debug.panel.common" } dependencies { - api(kotlin("stdlib")) + api(androidx.compose.animation) + api(stack.accompanist.themeadapter.material) + api(androidx.compose.material) + api(androidx.compose.foundation) + api(androidx.compose.ui) + api(androidx.compose.ui.viewbinding) + api(androidx.compose.ui.tooling) + api(androidx.fragment) + api(androidx.constraintlayout.compose) + api(androidx.activity.compose) + api(androidx.compose.ui.tooling.preview) + api(androidx.lifecycle.viewmodel.compose) + api(androidx.room.runtime) + api(androidx.room) + api(androidx.core) api(stack.okhttp) + api(stack.kotlinx.coroutines.android) + api(stack.timber) + api(rmr.itemsadapter.viewbinding) + api(rmr.flipper) + kapt(androidx.room.compiler) + // legacy api(androidx.appcompat) api(stack.material) api(androidx.constraintlayout) - api(stack.kotlinx.coroutines.android) + api(androidx.lifecycle.viewmodel) api(androidx.lifecycle.runtime) api(androidx.lifecycle.livedata) api(androidx.lifecycle.livedata.core) - api(androidx.lifecycle.viewmodel) - api(androidx.room.runtime) - api(androidx.room) - api(androidx.core) - api(rmr.itemsadapter.viewbinding) - api(rmr.flipper) - api(stack.timber) - kapt(androidx.room.compiler) } tasks.register("prepareKotlinBuildScriptModel") {} diff --git a/debug-panel-common/consumer-rules.pro b/common/consumer-rules.pro similarity index 100% rename from debug-panel-common/consumer-rules.pro rename to common/consumer-rules.pro diff --git a/debug-panel-common/library.properties b/common/library.properties similarity index 100% rename from debug-panel-common/library.properties rename to common/library.properties diff --git a/debug-panel-common/proguard-rules.pro b/common/proguard-rules.pro similarity index 100% rename from debug-panel-common/proguard-rules.pro rename to common/proguard-rules.pro diff --git a/debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/base/PluginFragment.kt b/common/src/main/kotlin/com/redmadrobot/debug/common/base/PluginFragment.kt similarity index 76% rename from debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/base/PluginFragment.kt rename to common/src/main/kotlin/com/redmadrobot/debug/common/base/PluginFragment.kt index 4d73a5f0..7c3278a2 100644 --- a/debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/base/PluginFragment.kt +++ b/common/src/main/kotlin/com/redmadrobot/debug/common/base/PluginFragment.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_common.base +package com.redmadrobot.debug.common.base import android.os.Bundle import android.view.LayoutInflater @@ -6,10 +6,14 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.view.ContextThemeWrapper import androidx.fragment.app.Fragment -import com.redmadrobot.debug_panel_common.R +import com.redmadrobot.debug.panel.common.R public open class PluginFragment(private val layoutId: Int) : Fragment() { + protected val isSettingMode: Boolean by lazy { + activity?.javaClass?.simpleName == "DebugActivity" + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, diff --git a/debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/base/PluginViewModel.kt b/common/src/main/kotlin/com/redmadrobot/debug/common/base/PluginViewModel.kt similarity index 64% rename from debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/base/PluginViewModel.kt rename to common/src/main/kotlin/com/redmadrobot/debug/common/base/PluginViewModel.kt index 920da676..b0a8e2a0 100644 --- a/debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/base/PluginViewModel.kt +++ b/common/src/main/kotlin/com/redmadrobot/debug/common/base/PluginViewModel.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_common.base +package com.redmadrobot.debug.common.base import androidx.lifecycle.ViewModel diff --git a/debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/extension/CoroutinesExtension.kt b/common/src/main/kotlin/com/redmadrobot/debug/common/extension/CoroutinesExtension.kt similarity index 94% rename from debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/extension/CoroutinesExtension.kt rename to common/src/main/kotlin/com/redmadrobot/debug/common/extension/CoroutinesExtension.kt index 4205fd0b..a4a4b86f 100644 --- a/debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/extension/CoroutinesExtension.kt +++ b/common/src/main/kotlin/com/redmadrobot/debug/common/extension/CoroutinesExtension.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_common.extension +package com.redmadrobot.debug.common.extension import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope diff --git a/debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/extension/LifecicleExt.kt b/common/src/main/kotlin/com/redmadrobot/debug/common/extension/LifecicleExt.kt similarity index 96% rename from debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/extension/LifecicleExt.kt rename to common/src/main/kotlin/com/redmadrobot/debug/common/extension/LifecicleExt.kt index f9c57c90..843b5390 100644 --- a/debug-panel-common/src/main/kotlin/com/redmadrobot/debug_panel_common/extension/LifecicleExt.kt +++ b/common/src/main/kotlin/com/redmadrobot/debug/common/extension/LifecicleExt.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_common.extension +package com.redmadrobot.debug.common.extension import androidx.annotation.MainThread import androidx.fragment.app.Fragment diff --git a/debug-panel-common/src/main/res/layout/item_section_header.xml b/common/src/main/res/layout/item_section_header.xml similarity index 100% rename from debug-panel-common/src/main/res/layout/item_section_header.xml rename to common/src/main/res/layout/item_section_header.xml diff --git a/debug-panel-common/src/main/res/values/colors.xml b/common/src/main/res/values/colors.xml similarity index 91% rename from debug-panel-common/src/main/res/values/colors.xml rename to common/src/main/res/values/colors.xml index a7e6499e..10c3b0e8 100644 --- a/debug-panel-common/src/main/res/values/colors.xml +++ b/common/src/main/res/values/colors.xml @@ -11,5 +11,5 @@ #000000 #EF0000 #009688 - #E1E5EA + #E1E5EA diff --git a/debug-panel-common/src/main/res/values/dimens.xml b/common/src/main/res/values/dimens.xml similarity index 100% rename from debug-panel-common/src/main/res/values/dimens.xml rename to common/src/main/res/values/dimens.xml diff --git a/debug-panel-common/src/main/res/values/styles.xml b/common/src/main/res/values/styles.xml similarity index 99% rename from debug-panel-common/src/main/res/values/styles.xml rename to common/src/main/res/values/styles.xml index 7b624ca6..0b1cc572 100644 --- a/debug-panel-common/src/main/res/values/styles.xml +++ b/common/src/main/res/values/styles.xml @@ -10,4 +10,3 @@ @color/colorOnSurface - \ No newline at end of file diff --git a/debug-panel-core/.gitignore b/core/.gitignore similarity index 100% rename from debug-panel-core/.gitignore rename to core/.gitignore diff --git a/debug-panel-core/build.gradle.kts b/core/build.gradle.kts similarity index 82% rename from debug-panel-core/build.gradle.kts rename to core/build.gradle.kts index 9709b339..86a908cc 100644 --- a/debug-panel-core/build.gradle.kts +++ b/core/build.gradle.kts @@ -39,8 +39,13 @@ android { buildFeatures { viewBinding = true + compose = true } - namespace = "com.redmadrobot.panel_core" + + composeOptions { + kotlinCompilerExtensionVersion = androidx.versions.compose.compiler.get() + } + namespace = "com.redmadrobot.debug.panel.core" } kotlin { @@ -48,6 +53,6 @@ kotlin { } dependencies { - implementation(project(":debug-panel-common")) + implementation(project(":common")) kapt(androidx.room.compiler) } diff --git a/debug-panel-core/consumer-rules.pro b/core/consumer-rules.pro similarity index 100% rename from debug-panel-core/consumer-rules.pro rename to core/consumer-rules.pro diff --git a/debug-panel-core/library.properties b/core/library.properties similarity index 100% rename from debug-panel-core/library.properties rename to core/library.properties diff --git a/debug-panel-core/proguard-rules.pro b/core/proguard-rules.pro similarity index 100% rename from debug-panel-core/proguard-rules.pro rename to core/proguard-rules.pro diff --git a/debug-panel-core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml similarity index 83% rename from debug-panel-core/src/main/AndroidManifest.xml rename to core/src/main/AndroidManifest.xml index 76a080e4..ed5719c9 100644 --- a/debug-panel-core/src/main/AndroidManifest.xml +++ b/core/src/main/AndroidManifest.xml @@ -4,7 +4,7 @@ @@ -14,7 +14,7 @@ android:enabled="true" android:exported="true" android:label="@string/debug_panel" - android:targetActivity="com.redmadrobot.debug_panel_core.ui.debugpanel.DebugActivity" + android:targetActivity="com.redmadrobot.debug.core.ui.debugpanel.DebugActivity" android:taskAffinity="com.redmadrobot.debug_panel.DebugActivity" android:theme="@style/DebugPanelTheme"> diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/CommonContainer.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/CommonContainer.kt new file mode 100644 index 00000000..3ea89f51 --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/CommonContainer.kt @@ -0,0 +1,8 @@ +package com.redmadrobot.debug.core + +import android.content.Context +import com.redmadrobot.debug.core.annotation.DebugPanelInternal +import com.redmadrobot.debug.core.plugin.PluginDependencyContainer + +@DebugPanelInternal +public class CommonContainer(public val context: Context) : PluginDependencyContainer diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/DebugPanelInstance.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/DebugPanelInstance.kt similarity index 89% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/DebugPanelInstance.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/DebugPanelInstance.kt index 50ac84da..3baf0295 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/DebugPanelInstance.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/DebugPanelInstance.kt @@ -1,12 +1,12 @@ -package com.redmadrobot.debug_panel_core +package com.redmadrobot.debug.core import android.app.Application import android.content.Context import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData -import com.redmadrobot.debug_panel_core.internal.DebugEvent -import com.redmadrobot.debug_panel_core.plugin.Plugin -import com.redmadrobot.debug_panel_core.plugin.PluginManager +import com.redmadrobot.debug.core.internal.DebugEvent +import com.redmadrobot.debug.core.plugin.Plugin +import com.redmadrobot.debug.core.plugin.PluginManager import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/annotation/DebugPanelInternal.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/annotation/DebugPanelInternal.kt similarity index 74% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/annotation/DebugPanelInternal.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/annotation/DebugPanelInternal.kt index 67a05c24..1a34aa25 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/annotation/DebugPanelInternal.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/annotation/DebugPanelInternal.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.annotation +package com.redmadrobot.debug.core.annotation @RequiresOptIn( level = RequiresOptIn.Level.ERROR, @@ -6,4 +6,4 @@ package com.redmadrobot.debug_panel_core.annotation ) @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -public annotation class DebugPanelInternal \ No newline at end of file +public annotation class DebugPanelInternal diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/data/DebugDataProvider.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/data/DebugDataProvider.kt similarity index 62% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/data/DebugDataProvider.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/data/DebugDataProvider.kt index 78cf9910..82b0648a 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/data/DebugDataProvider.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/data/DebugDataProvider.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.data +package com.redmadrobot.debug.core.data public interface DebugDataProvider { public fun provideData(): T diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/extension/ComposeExt.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/extension/ComposeExt.kt new file mode 100644 index 00000000..4a812474 --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/extension/ComposeExt.kt @@ -0,0 +1,46 @@ +package com.redmadrobot.debug.core.extension + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.rememberUpdatedState +import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleEventObserver +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.viewmodel.compose.viewModel +import com.redmadrobot.debug.core.annotation.DebugPanelInternal + +@DebugPanelInternal +@Composable +public inline fun provideViewModel(crossinline block: () -> T): T { + return viewModel( + factory = object : ViewModelProvider.Factory { + override fun create(modelClass: Class): T { + @Suppress("UNCHECKED_CAST") + return block() as T + } + } + ) +} + + +@DebugPanelInternal +@Composable +public fun OnLifecycleEvent(onEvent: (event: Lifecycle.Event) -> Unit) { + val eventHandler by rememberUpdatedState(onEvent) + val lifecycleOwner by rememberUpdatedState(LocalLifecycleOwner.current) + + DisposableEffect(lifecycleOwner) { + val lifecycle = lifecycleOwner.lifecycle + val observer = LifecycleEventObserver { _, event -> + eventHandler(event) + } + + lifecycle.addObserver(observer) + onDispose { + lifecycle.removeObserver(observer) + } + } +} diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/extension/PluginsExt.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/extension/PluginsExt.kt similarity index 67% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/extension/PluginsExt.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/extension/PluginsExt.kt index 21f01b3f..f6573243 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/extension/PluginsExt.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/extension/PluginsExt.kt @@ -1,8 +1,8 @@ -package com.redmadrobot.debug_panel_core.extension +package com.redmadrobot.debug.core.extension -import com.redmadrobot.debug_panel_core.DebugPanelInstance -import com.redmadrobot.debug_panel_core.annotation.DebugPanelInternal -import com.redmadrobot.debug_panel_core.plugin.Plugin +import com.redmadrobot.debug.core.DebugPanelInstance +import com.redmadrobot.debug.core.annotation.DebugPanelInternal +import com.redmadrobot.debug.core.plugin.Plugin @PublishedApi internal fun getPlugin(pluginName: String): Plugin { diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/DebugBottomSheet.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/DebugBottomSheet.kt similarity index 84% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/DebugBottomSheet.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/inapp/DebugBottomSheet.kt index 33529eaa..06fe47b0 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/DebugBottomSheet.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/DebugBottomSheet.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.inapp +package com.redmadrobot.debug.core.inapp import android.app.Dialog import android.os.Bundle @@ -10,9 +10,10 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.tabs.TabLayoutMediator -import com.redmadrobot.debug_panel_core.extension.getAllPlugins -import com.redmadrobot.panel_core.databinding.BottomSheetDebugPanelBinding -import com.redmadrobot.debug_panel_common.R as CommonR +import com.redmadrobot.debug.core.extension.getAllPlugins +import com.redmadrobot.debug.panel.core.databinding.BottomSheetDebugPanelBinding +import com.redmadrobot.debug.panel.common.R as CommonR + internal class DebugBottomSheet : BottomSheetDialogFragment() { @@ -40,7 +41,7 @@ internal class DebugBottomSheet : BottomSheetDialogFragment() { setBottomSheetSize() } dialog.setContentView(binding.root) - setViews(binding) + binding.setViews() return dialog } @@ -49,12 +50,12 @@ internal class DebugBottomSheet : BottomSheetDialogFragment() { _binding = null } - private fun setViews(binding: BottomSheetDebugPanelBinding) { + private fun BottomSheetDebugPanelBinding.setViews() { val plugins = getAllPlugins() /*Only Plugins with Fragment*/ .filter { it.getFragment() != null } - binding.debugSheetViewpager.adapter = DebugSheetViewPagerAdapter( + debugSheetViewpager.adapter = DebugSheetViewPagerAdapter( requireActivity(), plugins ) @@ -64,13 +65,14 @@ internal class DebugBottomSheet : BottomSheetDialogFragment() { } TabLayoutMediator( - binding.debugSheetTabLayout, - binding.debugSheetViewpager, + debugSheetTabLayout, + debugSheetViewpager, tabConfigurationStrategy ).attach() } private fun setBottomSheetSize() { + if (_binding == null) return val dialogContainer = binding.root.parent as? FrameLayout dialogContainer?.apply { layoutParams?.height = ViewGroup.LayoutParams.MATCH_PARENT diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/DebugSheetViewPagerAdapter.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/DebugSheetViewPagerAdapter.kt similarity index 82% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/DebugSheetViewPagerAdapter.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/inapp/DebugSheetViewPagerAdapter.kt index c58d44b9..59736bf7 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/DebugSheetViewPagerAdapter.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/DebugSheetViewPagerAdapter.kt @@ -1,9 +1,9 @@ -package com.redmadrobot.debug_panel_core.inapp +package com.redmadrobot.debug.core.inapp import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity import androidx.viewpager2.adapter.FragmentStateAdapter -import com.redmadrobot.debug_panel_core.plugin.Plugin +import com.redmadrobot.debug.core.plugin.Plugin internal class DebugSheetViewPagerAdapter( fragmentActivity: FragmentActivity, diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/ModalLayout.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/ModalLayout.kt similarity index 89% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/ModalLayout.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/inapp/ModalLayout.kt index d89fe7e2..aaf3b3b3 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/ModalLayout.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/ModalLayout.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.inapp +package com.redmadrobot.debug.core.inapp import android.content.Context import android.graphics.Canvas @@ -7,8 +7,8 @@ import android.graphics.RectF import android.util.AttributeSet import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.content.ContextCompat -import com.redmadrobot.panel_core.R -import com.redmadrobot.debug_panel_common.R as CommonR +import com.redmadrobot.debug.panel.core.R +import com.redmadrobot.debug.panel.common.R as CommonR internal class ModalLayout @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 @@ -18,7 +18,7 @@ internal class ModalLayout @JvmOverloads constructor( * Paint для отрисовки "ручки" модального окна */ private val handlePaint = Paint().apply { - color = ContextCompat.getColor(context, CommonR.color.gray) + color = ContextCompat.getColor(context, CommonR.color.super_light_gray) style = Paint.Style.FILL } diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/compose/DebugBottomSheet.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/compose/DebugBottomSheet.kt new file mode 100644 index 00000000..e3611f94 --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/compose/DebugBottomSheet.kt @@ -0,0 +1,107 @@ +@file:OptIn(ExperimentalFoundationApi::class) + +package com.redmadrobot.debug.core.inapp.compose + +import androidx.appcompat.view.ContextThemeWrapper +import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.pager.HorizontalPager +import androidx.compose.foundation.pager.PagerState +import androidx.compose.foundation.pager.rememberPagerState +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.* +import androidx.compose.material.TabRowDefaults.tabIndicatorOffset +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.unit.dp +import com.google.accompanist.themeadapter.material.MdcTheme +import com.redmadrobot.debug.core.extension.getAllPlugins +import com.redmadrobot.debug.core.plugin.Plugin +import com.redmadrobot.debug.panel.core.R +import kotlinx.coroutines.launch +import com.redmadrobot.debug.panel.common.R as CommonR + +@OptIn(ExperimentalMaterialApi::class) +@Composable +public fun DebugBottomSheet(onClose: () -> Unit) { + val state = rememberModalBottomSheetState( + initialValue = ModalBottomSheetValue.HalfExpanded, + confirmValueChange = { + if (it == ModalBottomSheetValue.Hidden) onClose() + true + } + ) + + MdcTheme(context = ContextThemeWrapper(LocalContext.current, CommonR.style.DebugPanelTheme)) { + ModalBottomSheetLayout( + sheetContent = { BottomSheetContent() }, + sheetState = state, + content = {} + ) + } +} + +@OptIn(ExperimentalFoundationApi::class) +@Composable +private fun BottomSheetContent() { + val plugins = remember { getAllPlugins() } + val pluginsName = remember { plugins.map { it.getName() } } + val pagerState = rememberPagerState(initialPage = 0, pageCount = { plugins.size }) + Column(modifier = Modifier.fillMaxSize()) { + Spacer(modifier = Modifier.height(8.dp)) + // Handle + Box( + modifier = Modifier + .height(4.dp) + .width(50.dp) + .clip(CircleShape) + .background(Color.Gray) + .align(Alignment.CenterHorizontally) + ) + Spacer(modifier = Modifier.height(8.dp)) + PluginsTabLayout(pluginsName, pagerState = pagerState) + PluginsPager(plugins, pagerState = pagerState) + } +} + +@Composable +private fun PluginsTabLayout(pluginsName: List, pagerState: PagerState) { + val scope = rememberCoroutineScope() + ScrollableTabRow( + selectedTabIndex = pagerState.currentPage, + backgroundColor = MaterialTheme.colors.background, + indicator = { tabPositions -> + TabRowDefaults.Indicator( + modifier = Modifier.tabIndicatorOffset(tabPositions[pagerState.currentPage]), + height = 2.dp, + color = MaterialTheme.colors.secondary + ) + } + ) { + pluginsName.forEachIndexed { index, _ -> + Tab( + text = { Text(pluginsName[index]) }, + selected = pagerState.currentPage == index, + onClick = { + scope.launch { pagerState.animateScrollToPage(index) } + } + ) + } + } +} + +@Composable +private fun PluginsPager(plugins: List, pagerState: PagerState) { + plugins[pagerState.currentPage].content() + HorizontalPager(state = pagerState) { + // no impl. Temporary solution + } +} diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/shake/ShakeController.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/shake/ShakeController.kt similarity index 88% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/shake/ShakeController.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/inapp/shake/ShakeController.kt index e83b42d3..95fe40fd 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/shake/ShakeController.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/shake/ShakeController.kt @@ -1,10 +1,10 @@ -package com.redmadrobot.debug_panel_core.inapp.shake +package com.redmadrobot.debug.core.inapp.shake import android.content.Context import android.hardware.Sensor import android.hardware.SensorManager import androidx.fragment.app.FragmentManager -import com.redmadrobot.debug_panel_core.inapp.DebugBottomSheet +import com.redmadrobot.debug.core.inapp.DebugBottomSheet internal class ShakeController(context: Context) { private val sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/shake/ShakeListener.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/shake/ShakeListener.kt similarity index 96% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/shake/ShakeListener.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/inapp/shake/ShakeListener.kt index d3011990..bfb395b0 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/inapp/shake/ShakeListener.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/inapp/shake/ShakeListener.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.inapp.shake +package com.redmadrobot.debug.core.inapp.shake import android.hardware.Sensor import android.hardware.SensorEvent diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/internal/DebugEvent.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/internal/DebugEvent.kt new file mode 100644 index 00000000..f4057a00 --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/internal/DebugEvent.kt @@ -0,0 +1,3 @@ +package com.redmadrobot.debug.core.internal + +public interface DebugEvent diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/internal/DebugPanel.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/internal/DebugPanel.kt similarity index 57% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/internal/DebugPanel.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/internal/DebugPanel.kt index f7a5d3c5..e8d10816 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/internal/DebugPanel.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/internal/DebugPanel.kt @@ -1,13 +1,18 @@ -package com.redmadrobot.debug_panel_core.internal +package com.redmadrobot.debug.core.internal +import android.app.Activity import android.app.Application +import android.view.ViewGroup +import android.widget.FrameLayout +import androidx.compose.ui.platform.ComposeView import androidx.fragment.app.FragmentManager import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.Observer -import com.redmadrobot.debug_panel_core.DebugPanelInstance -import com.redmadrobot.debug_panel_core.inapp.DebugBottomSheet -import com.redmadrobot.debug_panel_core.plugin.Plugin -import com.redmadrobot.debug_panel_core.util.ApplicationLifecycleHandler +import com.redmadrobot.debug.core.DebugPanelInstance +import com.redmadrobot.debug.core.inapp.DebugBottomSheet +import com.redmadrobot.debug.core.inapp.compose.DebugBottomSheet +import com.redmadrobot.debug.core.plugin.Plugin +import com.redmadrobot.debug.core.util.ApplicationLifecycleHandler import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.emptyFlow @@ -40,9 +45,21 @@ public object DebugPanel { } } + public fun showPanel(activity: Activity) { + if (isInitialized) { + val contentView = activity.window.decorView + .findViewById(android.R.id.content) as FrameLayout + + val debugPanelComposeView = ComposeView(contentView.context).apply { + setContent { + DebugBottomSheet(onClose = { contentView.removeView(this) }) + } + } + contentView.addView(debugPanelComposeView) + } + } + private fun createDebugPanelInstance(application: Application, plugins: List) { instance = DebugPanelInstance(application, plugins) } - - } diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/internal/DebugPanelConfig.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/internal/DebugPanelConfig.kt similarity index 78% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/internal/DebugPanelConfig.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/internal/DebugPanelConfig.kt index 9475c342..509de599 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/internal/DebugPanelConfig.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/internal/DebugPanelConfig.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.internal +package com.redmadrobot.debug.core.internal public class DebugPanelConfig( public val shakerMode: Boolean @@ -6,4 +6,4 @@ public class DebugPanelConfig( internal companion object { internal val defaultConfig = DebugPanelConfig(shakerMode = true) } -} \ No newline at end of file +} diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/plugin/Plugin.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/plugin/Plugin.kt new file mode 100644 index 00000000..04d7a7b2 --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/plugin/Plugin.kt @@ -0,0 +1,48 @@ +package com.redmadrobot.debug.core.plugin + +import androidx.compose.runtime.Composable +import androidx.compose.ui.viewinterop.AndroidViewBinding +import androidx.fragment.app.Fragment +import com.redmadrobot.debug.core.CommonContainer +import com.redmadrobot.debug.core.DebugPanelInstance +import com.redmadrobot.debug.core.internal.DebugEvent + +public abstract class Plugin { + + private lateinit var pluginContainer: PluginDependencyContainer + + internal fun start(commonContainer: CommonContainer): Plugin { + pluginContainer = getPluginContainer(commonContainer) + return this + } + + public fun pushEvent(debugEvent: DebugEvent) { + DebugPanelInstance.instance?.pushEvent(debugEvent) + } + + public fun getContainer(): T = pluginContainer as T + + @Deprecated( + "You shouldn't use fragments for you plugins. Please use Jetpack Compose", + ReplaceWith("content()", "com.redmadrobot.debug.core.plugin.Plugin") + ) + public open fun getFragment(): Fragment? = null + + @Deprecated( + "You shouldn't use fragments for you plugins. Please use Jetpack Compose", + ReplaceWith("content()", "com.redmadrobot.debug.core.plugin.Plugin") + ) + public open fun getSettingFragment(): Fragment? = null + + @Composable + public open fun content() { + } + + @Composable + public open fun settingsContent() { + } + + public abstract fun getPluginContainer(commonContainer: CommonContainer): PluginDependencyContainer + + public abstract fun getName(): String +} diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/plugin/PluginDependencyContainer.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/plugin/PluginDependencyContainer.kt new file mode 100644 index 00000000..e32f4a27 --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/plugin/PluginDependencyContainer.kt @@ -0,0 +1,6 @@ +package com.redmadrobot.debug.core.plugin + +import com.redmadrobot.debug.core.annotation.DebugPanelInternal + +@DebugPanelInternal +public interface PluginDependencyContainer diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/plugin/PluginManager.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/plugin/PluginManager.kt similarity index 83% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/plugin/PluginManager.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/plugin/PluginManager.kt index 4dc8ab15..4a2a210e 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/plugin/PluginManager.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/plugin/PluginManager.kt @@ -1,6 +1,6 @@ -package com.redmadrobot.debug_panel_core.plugin +package com.redmadrobot.debug.core.plugin -import com.redmadrobot.debug_panel_core.CommonContainer +import com.redmadrobot.debug.core.CommonContainer internal class PluginManager(val plugins: List) { diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/ui/debugpanel/DebugActivity.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/DebugActivity.kt similarity index 84% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/ui/debugpanel/DebugActivity.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/DebugActivity.kt index a1593627..f8bc5109 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/ui/debugpanel/DebugActivity.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/DebugActivity.kt @@ -1,15 +1,15 @@ -package com.redmadrobot.debug_panel_core.ui.debugpanel +package com.redmadrobot.debug.core.ui.debugpanel import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager -import com.redmadrobot.debug_panel_core.extension.getAllPlugins +import com.redmadrobot.debug.core.extension.getAllPlugins import com.redmadrobot.itemsadapter.bind import com.redmadrobot.itemsadapter.itemsAdapter -import com.redmadrobot.panel_core.R -import com.redmadrobot.panel_core.databinding.ActivityDebugBinding -import com.redmadrobot.panel_core.databinding.ItemPluginSettingBinding +import com.redmadrobot.debug.panel.core.R +import com.redmadrobot.debug.panel.core.databinding.ActivityDebugBinding +import com.redmadrobot.debug.panel.core.databinding.ItemPluginSettingBinding internal class DebugActivity : AppCompatActivity() { diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/ui/debugpanel/PluginsSettingItem.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/PluginsSettingItem.kt similarity index 62% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/ui/debugpanel/PluginsSettingItem.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/PluginsSettingItem.kt index 8c325867..064e86af 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/ui/debugpanel/PluginsSettingItem.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/PluginsSettingItem.kt @@ -1,6 +1,6 @@ -package com.redmadrobot.debug_panel_core.ui.debugpanel +package com.redmadrobot.debug.core.ui.debugpanel internal class PluginsSettingItem( val pluginName: String, val onClicked: () -> Unit -) \ No newline at end of file +) diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/ActivityLifecycleCallbacksAdapter.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/util/ActivityLifecycleCallbacksAdapter.kt similarity index 93% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/ActivityLifecycleCallbacksAdapter.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/util/ActivityLifecycleCallbacksAdapter.kt index fae21241..c86a485e 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/ActivityLifecycleCallbacksAdapter.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/util/ActivityLifecycleCallbacksAdapter.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.util +package com.redmadrobot.debug.core.util import android.app.Activity import android.app.Application diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/ApplicationLifecycleHandler.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/util/ApplicationLifecycleHandler.kt similarity index 96% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/ApplicationLifecycleHandler.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/util/ApplicationLifecycleHandler.kt index ee25b386..e9444742 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/ApplicationLifecycleHandler.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/util/ApplicationLifecycleHandler.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.util +package com.redmadrobot.debug.core.util import android.app.Activity import android.app.Application @@ -6,7 +6,7 @@ import android.content.BroadcastReceiver import android.content.IntentFilter import androidx.core.content.ContextCompat import androidx.fragment.app.FragmentActivity -import com.redmadrobot.debug_panel_core.inapp.shake.ShakeController +import com.redmadrobot.debug.core.inapp.shake.ShakeController import timber.log.Timber internal class ApplicationLifecycleHandler( diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/DebugPanelBroadcastReceiver.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelBroadcastReceiver.kt similarity index 69% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/DebugPanelBroadcastReceiver.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelBroadcastReceiver.kt index 059984bf..509a6cc1 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/DebugPanelBroadcastReceiver.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelBroadcastReceiver.kt @@ -1,18 +1,17 @@ -package com.redmadrobot.debug_panel_core.util +package com.redmadrobot.debug.core.util import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import androidx.fragment.app.FragmentManager -import com.redmadrobot.debug_panel_core.internal.DebugPanel +import com.redmadrobot.debug.core.internal.DebugPanel internal class DebugPanelBroadcastReceiver( private val supportFragmentManager: FragmentManager ) : BroadcastReceiver() { companion object { - const val ACTION_OPEN_DEBUG_PANEL = - "com.redmadrobot.debug_panel_core.ACTION_OPEN_DEBUG_PANEL" + const val ACTION_OPEN_DEBUG_PANEL = "com.redmadrobot.debug.core.ACTION_OPEN_DEBUG_PANEL" } override fun onReceive(context: Context, intent: Intent) { diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/DebugPanelNotification.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelNotification.kt similarity index 95% rename from debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/DebugPanelNotification.kt rename to core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelNotification.kt index 178cc9ed..6a1e8662 100644 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/util/DebugPanelNotification.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelNotification.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.util +package com.redmadrobot.debug.core.util import android.Manifest.permission.POST_NOTIFICATIONS import android.app.NotificationChannel @@ -13,8 +13,8 @@ import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.core.app.TaskStackBuilder import androidx.core.content.ContextCompat -import com.redmadrobot.debug_panel_core.ui.debugpanel.DebugActivity -import com.redmadrobot.panel_core.R +import com.redmadrobot.debug.core.ui.debugpanel.DebugActivity +import com.redmadrobot.debug.panel.core.R internal class DebugPanelNotification(private val context: Context) { diff --git a/debug-panel-core/src/main/res/drawable/ic_debug_notification.xml b/core/src/main/res/drawable/ic_debug_notification.xml similarity index 100% rename from debug-panel-core/src/main/res/drawable/ic_debug_notification.xml rename to core/src/main/res/drawable/ic_debug_notification.xml diff --git a/debug-panel-core/src/main/res/drawable/ic_debug_panel.xml b/core/src/main/res/drawable/ic_debug_panel.xml similarity index 100% rename from debug-panel-core/src/main/res/drawable/ic_debug_panel.xml rename to core/src/main/res/drawable/ic_debug_panel.xml diff --git a/debug-panel-core/src/main/res/drawable/ic_settings_notification_action.xml b/core/src/main/res/drawable/ic_settings_notification_action.xml similarity index 100% rename from debug-panel-core/src/main/res/drawable/ic_settings_notification_action.xml rename to core/src/main/res/drawable/ic_settings_notification_action.xml diff --git a/debug-panel-core/src/main/res/drawable/shape_scrollable_sheet.xml b/core/src/main/res/drawable/shape_scrollable_sheet.xml similarity index 100% rename from debug-panel-core/src/main/res/drawable/shape_scrollable_sheet.xml rename to core/src/main/res/drawable/shape_scrollable_sheet.xml diff --git a/debug-panel-core/src/main/res/layout/activity_debug.xml b/core/src/main/res/layout/activity_debug.xml similarity index 88% rename from debug-panel-core/src/main/res/layout/activity_debug.xml rename to core/src/main/res/layout/activity_debug.xml index 0c598968..c3d012fb 100644 --- a/debug-panel-core/src/main/res/layout/activity_debug.xml +++ b/core/src/main/res/layout/activity_debug.xml @@ -4,7 +4,7 @@ android:id="@+id/debug_activity_root" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.redmadrobot.debug_panel_core.ui.debugpanel.DebugActivity"> + tools:context="com.redmadrobot.debug.core.ui.debugpanel.DebugActivity"> - - + diff --git a/debug-panel-core/src/main/res/layout/fragment_stub.xml b/core/src/main/res/layout/fragment_stub.xml similarity index 100% rename from debug-panel-core/src/main/res/layout/fragment_stub.xml rename to core/src/main/res/layout/fragment_stub.xml diff --git a/debug-panel-core/src/main/res/layout/item_plugin_setting.xml b/core/src/main/res/layout/item_plugin_setting.xml similarity index 100% rename from debug-panel-core/src/main/res/layout/item_plugin_setting.xml rename to core/src/main/res/layout/item_plugin_setting.xml diff --git a/debug-panel-core/src/main/res/values/dimens.xml b/core/src/main/res/values/dimens.xml similarity index 100% rename from debug-panel-core/src/main/res/values/dimens.xml rename to core/src/main/res/values/dimens.xml diff --git a/debug-panel-core/src/main/res/values/public.xml b/core/src/main/res/values/public.xml similarity index 100% rename from debug-panel-core/src/main/res/values/public.xml rename to core/src/main/res/values/public.xml diff --git a/debug-panel-core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml similarity index 100% rename from debug-panel-core/src/main/res/values/strings.xml rename to core/src/main/res/values/strings.xml diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/CommonContainer.kt b/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/CommonContainer.kt deleted file mode 100644 index c1572cbb..00000000 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/CommonContainer.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.redmadrobot.debug_panel_core - -import android.content.Context -import com.redmadrobot.debug_panel_core.annotation.DebugPanelInternal -import com.redmadrobot.debug_panel_core.plugin.PluginDependencyContainer - -@DebugPanelInternal -public class CommonContainer(public val context: Context) : PluginDependencyContainer diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/internal/DebugEvent.kt b/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/internal/DebugEvent.kt deleted file mode 100644 index baac0d25..00000000 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/internal/DebugEvent.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.redmadrobot.debug_panel_core.internal - -public interface DebugEvent diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/plugin/Plugin.kt b/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/plugin/Plugin.kt deleted file mode 100644 index 617bd6f5..00000000 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/plugin/Plugin.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.redmadrobot.debug_panel_core.plugin - -import androidx.fragment.app.Fragment -import com.redmadrobot.debug_panel_core.CommonContainer -import com.redmadrobot.debug_panel_core.DebugPanelInstance -import com.redmadrobot.debug_panel_core.internal.DebugEvent - -public abstract class Plugin { - - private lateinit var pluginContainer: PluginDependencyContainer - - internal fun start(commonContainer: CommonContainer): Plugin { - pluginContainer = getPluginContainer(commonContainer) - return this - } - - public fun pushEvent(debugEvent: DebugEvent) { - DebugPanelInstance.instance?.pushEvent(debugEvent) - } - - public fun getContainer(): T = pluginContainer as T - - public open fun getFragment(): Fragment? = null - - public open fun getSettingFragment(): Fragment? = null - - public abstract fun getPluginContainer(commonContainer: CommonContainer): PluginDependencyContainer - - public abstract fun getName(): String -} diff --git a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/plugin/PluginDependencyContainer.kt b/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/plugin/PluginDependencyContainer.kt deleted file mode 100644 index 3b46687b..00000000 --- a/debug-panel-core/src/main/kotlin/com/redmadrobot/debug_panel_core/plugin/PluginDependencyContainer.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.redmadrobot.debug_panel_core.plugin - -import com.redmadrobot.debug_panel_core.annotation.DebugPanelInternal - -@DebugPanelInternal -public interface PluginDependencyContainer diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/AccountSelectedEvent.kt b/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/AccountSelectedEvent.kt deleted file mode 100644 index c3815205..00000000 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/AccountSelectedEvent.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.redmadrobot.account_plugin.plugin - -import com.redmadrobot.account_plugin.data.model.DebugAccount -import com.redmadrobot.debug_panel_core.internal.DebugEvent - -data class AccountSelectedEvent(val debugAccount: DebugAccount) : DebugEvent diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/DebugAuthenticator.kt b/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/DebugAuthenticator.kt deleted file mode 100644 index 9893d800..00000000 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/DebugAuthenticator.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.redmadrobot.account_plugin.authenticator - -import com.redmadrobot.account_plugin.data.model.DebugAccount - -interface DebugAuthenticator { - fun onAccountSelected(account: DebugAccount) -} diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/core/DebugEvent.kt b/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/core/DebugEvent.kt deleted file mode 100644 index eabf5098..00000000 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/core/DebugEvent.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.redmadrobot.debug_panel_core.internal - -interface DebugEvent diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/DebugServer.kt b/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/DebugServer.kt deleted file mode 100644 index cac2fd98..00000000 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/DebugServer.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.redmadrobot.servers_plugin.data.model - -data class DebugServer( - val id: Int = 0, - val name: String, - val url: String -) diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/ServerSelectedEvent.kt b/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/ServerSelectedEvent.kt deleted file mode 100644 index c179ec4d..00000000 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/ServerSelectedEvent.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.redmadrobot.servers_plugin.plugin - -import com.redmadrobot.debug_panel_core.internal.DebugEvent -import com.redmadrobot.servers_plugin.data.model.DebugServer - -data class ServerSelectedEvent(val debugServer: DebugServer) : DebugEvent diff --git a/docs/changelog.md b/docs/changelog.md index 47f82429..6db8cff0 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,13 @@ # Changelog +## In progress +* Gradle обновлен до 7.5 +* compileSdk и targetSdk повышены до 33 +* Добавлена поддержка Jetpack Compose +* accounts-plugin переведен на Jetpack Compose +* Переименованы модули. +* Breaking changes - Изменены наименования пакетов во всех модулях. Приведены к общему виду. + ## 0.8.1 ### Изменения * Исправлен краш при остановке активити (#13) diff --git a/docs/plugin_development.md b/docs/plugin_development.md index 397350f9..f448f58e 100644 --- a/docs/plugin_development.md +++ b/docs/plugin_development.md @@ -114,7 +114,7 @@ public class YourPlugin( Вместо этого, в библиотеке используется подход с **Service Locator**. Для этого необходимо создать свой класс-контейнер, унаследовать его от **PluginDependencyContainer** и внутри него инициировать необходимые зависимости. Если вам для этого понадобится **Context**, его можно получить из **CommonContainer** который прилетает в качестве аргумента в методе `getPluginContainer()` при инициализации плагина. -Пример реализации можно [посмотреть тут](../plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/plugin/AccountsPluginContainer.kt) +Пример реализации можно [посмотреть тут](../plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account/plugin/AccountsPluginContainer.kt) ## Работа с классом плагина diff --git a/debug-panel-no-op/.gitignore b/no-op/.gitignore similarity index 100% rename from debug-panel-no-op/.gitignore rename to no-op/.gitignore diff --git a/debug-panel-no-op/build.gradle.kts b/no-op/build.gradle.kts similarity index 95% rename from debug-panel-no-op/build.gradle.kts rename to no-op/build.gradle.kts index 5e63b0f2..1759265a 100644 --- a/debug-panel-no-op/build.gradle.kts +++ b/no-op/build.gradle.kts @@ -35,7 +35,7 @@ android { jvmTarget = "1.8" } - namespace = "com.redmadrobot.debug_panel_no_op" + namespace = "com.redmadrobot.debug.noop" } dependencies { diff --git a/debug-panel-no-op/consumer-rules.pro b/no-op/consumer-rules.pro similarity index 100% rename from debug-panel-no-op/consumer-rules.pro rename to no-op/consumer-rules.pro diff --git a/debug-panel-no-op/library.properties b/no-op/library.properties similarity index 100% rename from debug-panel-no-op/library.properties rename to no-op/library.properties diff --git a/debug-panel-no-op/proguard-rules.pro b/no-op/proguard-rules.pro similarity index 100% rename from debug-panel-no-op/proguard-rules.pro rename to no-op/proguard-rules.pro diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/DebugDataProvider.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/DebugDataProvider.kt similarity index 57% rename from debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/DebugDataProvider.kt rename to no-op/src/main/kotlin/com/redmadrobot/debug/noop/DebugDataProvider.kt index 9e970c4d..9d801333 100644 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/DebugDataProvider.kt +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/DebugDataProvider.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.data +package com.redmadrobot.debug.core.data interface DebugDataProvider { fun provideData(): T diff --git a/no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/AccountSelectedEvent.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/AccountSelectedEvent.kt new file mode 100644 index 00000000..907e0d3f --- /dev/null +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/AccountSelectedEvent.kt @@ -0,0 +1,6 @@ +package com.redmadrobot.debug.accounts.plugin + +import com.redmadrobot.debug.accounts.data.model.DebugAccount +import com.redmadrobot.debug.core.internal.DebugEvent + +data class AccountSelectedEvent(val debugAccount: DebugAccount) : DebugEvent diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/AccountsPlugin.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/AccountsPlugin.kt similarity index 71% rename from debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/AccountsPlugin.kt rename to no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/AccountsPlugin.kt index a0c78a46..06e8d1c4 100644 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/AccountsPlugin.kt +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/AccountsPlugin.kt @@ -1,7 +1,7 @@ -package com.redmadrobot.account_plugin.plugin +package com.redmadrobot.debug.accounts.plugin -import com.redmadrobot.account_plugin.data.model.DebugAccount -import com.redmadrobot.debug_panel_core.data.DebugDataProvider +import com.redmadrobot.debug.accounts.data.model.DebugAccount +import com.redmadrobot.debug.core.data.DebugDataProvider import java.util.Collections.emptyList class AccountsPlugin( diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/DebugAccount.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/DebugAccount.kt similarity index 71% rename from debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/DebugAccount.kt rename to no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/DebugAccount.kt index 80e505d5..35d9a6ad 100644 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/accounts/DebugAccount.kt +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/DebugAccount.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.account_plugin.data.model +package com.redmadrobot.debug.accounts.data.model data class DebugAccount( val id: Int = 0, diff --git a/no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/DebugAuthenticator.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/DebugAuthenticator.kt new file mode 100644 index 00000000..6d343a11 --- /dev/null +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/accounts/DebugAuthenticator.kt @@ -0,0 +1,7 @@ +package com.redmadrobot.debug.accounts.authenticator + +import com.redmadrobot.debug.accounts.data.model.DebugAccount + +interface DebugAuthenticator { + fun onAccountSelected(account: DebugAccount) +} diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/app_setting/AppSettingsPlugin.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/app_setting/AppSettingsPlugin.kt similarity index 77% rename from debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/app_setting/AppSettingsPlugin.kt rename to no-op/src/main/kotlin/com/redmadrobot/debug/noop/app_setting/AppSettingsPlugin.kt index c86d2c15..4e39c098 100644 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/app_setting/AppSettingsPlugin.kt +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/app_setting/AppSettingsPlugin.kt @@ -1,5 +1,4 @@ -package com.redmadrobot.app_settings_plugin.plugin - +package com.redmadrobot.debug.appsettings.plugin import android.content.SharedPreferences import java.util.Collections.emptyList diff --git a/no-op/src/main/kotlin/com/redmadrobot/debug/noop/core/DebugEvent.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/core/DebugEvent.kt new file mode 100644 index 00000000..c7651ed9 --- /dev/null +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/core/DebugEvent.kt @@ -0,0 +1,3 @@ +package com.redmadrobot.debug.core.internal + +interface DebugEvent diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/core/DebugPanel.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/core/DebugPanel.kt similarity index 75% rename from debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/core/DebugPanel.kt rename to no-op/src/main/kotlin/com/redmadrobot/debug/noop/core/DebugPanel.kt index 07003b15..5661c167 100644 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/core/DebugPanel.kt +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/core/DebugPanel.kt @@ -1,5 +1,6 @@ -package com.redmadrobot.debug_panel_core.internal +package com.redmadrobot.debug.core.internal +import android.app.Activity import android.app.Application import androidx.fragment.app.FragmentManager import androidx.lifecycle.LifecycleOwner @@ -15,7 +16,9 @@ object DebugPanel { fun subscribeToEvents(lifecycleOwner: LifecycleOwner, onEvent: (DebugEvent) -> Unit) = Unit - fun observeEvents(): Flow? = emptyFlow() + fun observeEvents(): Flow = emptyFlow() fun showPanel(fragmentManager: FragmentManager) = Unit + + fun showPanel(activity: Activity) = Unit } diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/core/DebugPanelConfig.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/core/DebugPanelConfig.kt similarity index 78% rename from debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/core/DebugPanelConfig.kt rename to no-op/src/main/kotlin/com/redmadrobot/debug/noop/core/DebugPanelConfig.kt index 4936beaa..c570b898 100644 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/core/DebugPanelConfig.kt +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/core/DebugPanelConfig.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.debug_panel_core.internal +package com.redmadrobot.debug.core.internal public class DebugPanelConfig( public val shakerMode: Boolean diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/flipper/FlipperPlugin.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/flipper/FlipperPlugin.kt similarity index 94% rename from debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/flipper/FlipperPlugin.kt rename to no-op/src/main/kotlin/com/redmadrobot/debug/noop/flipper/FlipperPlugin.kt index e6e13a6e..069b8b49 100644 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/flipper/FlipperPlugin.kt +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/flipper/FlipperPlugin.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.flipper_plugin.plugin +package com.redmadrobot.debug.flipper.plugin import com.redmadrobot.flipper.config.FlipperValue import kotlinx.coroutines.flow.Flow diff --git a/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugServer.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugServer.kt new file mode 100644 index 00000000..2ed1b16d --- /dev/null +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugServer.kt @@ -0,0 +1,8 @@ +package com.redmadrobot.debug.servers.data.model + +data class DebugServer( + val id: Int = 0, + val name: String, + val url: String, + val isDefault: Boolean = false +) diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/DebugServerInterceptor.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugServerInterceptor.kt similarity index 76% rename from debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/DebugServerInterceptor.kt rename to no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugServerInterceptor.kt index ace38d44..2fc35bc7 100644 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/DebugServerInterceptor.kt +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugServerInterceptor.kt @@ -1,6 +1,6 @@ -package com.redmadrobot.servers_plugin.util +package com.redmadrobot.debug.servers.interceptor -import com.redmadrobot.servers_plugin.data.model.DebugServer +import com.redmadrobot.debug.servers.data.model.DebugServer import okhttp3.Interceptor import okhttp3.Request import okhttp3.Response diff --git a/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugStage.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugStage.kt new file mode 100644 index 00000000..8ebcad11 --- /dev/null +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugStage.kt @@ -0,0 +1,9 @@ +package com.redmadrobot.debug.servers.data.model + + +data class DebugStage( + val id: Int = 0, + val name: String, + val hosts: Map, + val isDefault: Boolean = false +) diff --git a/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugStageInterceptor.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugStageInterceptor.kt new file mode 100644 index 00000000..c2dccf2c --- /dev/null +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/DebugStageInterceptor.kt @@ -0,0 +1,18 @@ +package com.redmadrobot.debug.servers.interceptor + +import com.redmadrobot.debug.servers.data.model.DebugStage +import okhttp3.Interceptor +import okhttp3.Request +import okhttp3.Response + + +public class DebugStageInterceptor(private val tag: String) : Interceptor { + + public fun modifyRequest(block: (Request, DebugStage) -> Request): DebugStageInterceptor { + return this + } + + override fun intercept(chain: Interceptor.Chain): Response { + return chain.proceed(chain.request()) + } +} diff --git a/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/ServerSelectedEvent.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/ServerSelectedEvent.kt new file mode 100644 index 00000000..0fd0f8ed --- /dev/null +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/ServerSelectedEvent.kt @@ -0,0 +1,6 @@ +package com.redmadrobot.debug.servers.plugin + +import com.redmadrobot.debug.core.internal.DebugEvent +import com.redmadrobot.debug.servers.data.model.DebugServer + +data class ServerSelectedEvent(val debugServer: DebugServer) : DebugEvent diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/ServersPlugin.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/ServersPlugin.kt similarity index 61% rename from debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/ServersPlugin.kt rename to no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/ServersPlugin.kt index b772ac12..03ad3a6f 100644 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/servers/ServersPlugin.kt +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/servers/ServersPlugin.kt @@ -1,7 +1,7 @@ -package com.redmadrobot.servers_plugin.plugin +package com.redmadrobot.debug.servers.plugin -import com.redmadrobot.debug_panel_core.data.DebugDataProvider -import com.redmadrobot.servers_plugin.data.model.DebugServer +import com.redmadrobot.debug.servers.data.model.DebugServer +import com.redmadrobot.debug.core.data.DebugDataProvider import java.util.Collections.emptyList class ServersPlugin( diff --git a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/variable/VariablePlugin.kt b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/variable/VariablePlugin.kt similarity index 85% rename from debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/variable/VariablePlugin.kt rename to no-op/src/main/kotlin/com/redmadrobot/debug/noop/variable/VariablePlugin.kt index 505b8cfb..817cad58 100644 --- a/debug-panel-no-op/src/main/kotlin/com/redmadrobot/debug_panel_no_op/variable/VariablePlugin.kt +++ b/no-op/src/main/kotlin/com/redmadrobot/debug/noop/variable/VariablePlugin.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.variable_plugin.plugin +package com.redmadrobot.debug.variable.plugin import kotlin.reflect.KClass diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/authenticator/DebugAuthenticator.kt b/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/authenticator/DebugAuthenticator.kt deleted file mode 100644 index 18a3bd5c..00000000 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/authenticator/DebugAuthenticator.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.redmadrobot.account_plugin.authenticator - -import com.redmadrobot.account_plugin.data.model.DebugAccount - -public interface DebugAuthenticator { - public fun onAccountSelected(account: DebugAccount) -} diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/plugin/AccountSelectedEvent.kt b/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/plugin/AccountSelectedEvent.kt deleted file mode 100644 index 3b355c81..00000000 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/plugin/AccountSelectedEvent.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.redmadrobot.account_plugin.plugin - -import com.redmadrobot.account_plugin.data.model.DebugAccount -import com.redmadrobot.debug_panel_core.internal.DebugEvent - -public data class AccountSelectedEvent(val debugAccount: DebugAccount) : DebugEvent diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/plugin/AccountsPlugin.kt b/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/plugin/AccountsPlugin.kt deleted file mode 100644 index 0ae57c0a..00000000 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/plugin/AccountsPlugin.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.redmadrobot.account_plugin.plugin - -import androidx.core.os.bundleOf -import androidx.fragment.app.Fragment -import com.redmadrobot.account_plugin.authenticator.DebugAuthenticator -import com.redmadrobot.account_plugin.authenticator.DefaultAuthenticator -import com.redmadrobot.account_plugin.data.model.DebugAccount -import com.redmadrobot.account_plugin.ui.AccountsFragment -import com.redmadrobot.debug_panel_core.CommonContainer -import com.redmadrobot.debug_panel_core.data.DebugDataProvider -import com.redmadrobot.debug_panel_core.plugin.Plugin -import com.redmadrobot.debug_panel_core.plugin.PluginDependencyContainer - -public class AccountsPlugin( - private val preInstalledAccounts: List = emptyList(), - public val debugAuthenticator: DebugAuthenticator = DefaultAuthenticator() -) : Plugin() { - - 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) - } - - override fun getFragment(): Fragment { - return AccountsFragment().apply { - arguments = bundleOf(AccountsFragment.IS_EDIT_MODE_KEY to false) - } - } - - override fun getSettingFragment(): Fragment { - return AccountsFragment().apply { - arguments = bundleOf(AccountsFragment.IS_EDIT_MODE_KEY to true) - } - } -} diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/AccountsFragment.kt b/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/AccountsFragment.kt deleted file mode 100644 index fc71b002..00000000 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/AccountsFragment.kt +++ /dev/null @@ -1,132 +0,0 @@ -package com.redmadrobot.account_plugin.ui - -import android.os.Bundle -import android.view.View -import android.widget.Toast -import androidx.core.view.isVisible -import androidx.recyclerview.widget.LinearLayoutManager -import com.redmadrobot.account_plugin.R -import com.redmadrobot.account_plugin.data.model.DebugAccount -import com.redmadrobot.account_plugin.databinding.FragmentAccountsBinding -import com.redmadrobot.account_plugin.databinding.ItemAccountBinding -import com.redmadrobot.account_plugin.plugin.AccountSelectedEvent -import com.redmadrobot.account_plugin.plugin.AccountsPlugin -import com.redmadrobot.account_plugin.plugin.AccountsPluginContainer -import com.redmadrobot.account_plugin.ui.add.AddAccountDialog -import com.redmadrobot.account_plugin.ui.item.DebugAccountItems -import com.redmadrobot.debug_panel_common.base.PluginFragment -import com.redmadrobot.debug_panel_common.databinding.ItemSectionHeaderBinding -import com.redmadrobot.debug_panel_common.extension.observe -import com.redmadrobot.debug_panel_common.extension.obtainShareViewModel -import com.redmadrobot.debug_panel_core.extension.getPlugin -import com.redmadrobot.itemsadapter.ItemsAdapter -import com.redmadrobot.itemsadapter.bind -import com.redmadrobot.itemsadapter.itemsAdapter -import com.redmadrobot.debug_panel_common.R as CommonR - -internal class AccountsFragment : PluginFragment(R.layout.fragment_accounts) { - - companion object { - const val IS_EDIT_MODE_KEY = "IS_EDIT_MODE_KEY" - } - - private var _binding: FragmentAccountsBinding? = null - private val binding get() = checkNotNull(_binding) - - private val isEditMode by lazy { - requireNotNull(arguments).getBoolean(IS_EDIT_MODE_KEY) - } - - private val viewModel by lazy { - obtainShareViewModel { - getPlugin() - .getContainer() - .createAccountsViewModel() - } - } - - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) - observe(viewModel.state, ::render) - viewModel.loadAccounts() - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - _binding = FragmentAccountsBinding.bind(view) - binding.setView() - } - - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - - private fun FragmentAccountsBinding.setView() { - accountList.layoutManager = LinearLayoutManager(requireContext()) - addAccount.setOnClickListener { - AddAccountDialog.show( - requireActivity().supportFragmentManager - ) - } - addAccount.isVisible = isEditMode - } - - private fun render(state: AccountsViewState) { - val adapter = createAdapterByState(state) - binding.accountList.adapter = adapter - } - - private fun createAdapterByState(state: AccountsViewState): ItemsAdapter { - return itemsAdapter(state.preInstalledAccounts.plus(state.addedAccounts)) { item -> - when (item) { - is DebugAccountItems.Header -> { - bind(CommonR.layout.item_section_header) { - itemSectionTitle.text = item.header - } - } - is DebugAccountItems.PreinstalledAccount -> { - bind(R.layout.item_account) { - accountLogin.text = item.account.login - if (!isEditMode) { - root.setOnClickListener { setAccountAsCurrent(item.account) } - } - } - } - is DebugAccountItems.AddedAccount -> { - bind(R.layout.item_account) { - accountLogin.text = item.account.login - accountDelete.isVisible = isEditMode - accountDelete.setOnClickListener { viewModel.removeAccount(item.account) } - root.setOnClickListener { onAddedAccountClicked(item.account) } - } - } - } - } - } - - private fun onAddedAccountClicked(account: DebugAccount) { - if (isEditMode) openAccountDialog(account) else setAccountAsCurrent(account) - } - - private fun openAccountDialog(account: DebugAccount) { - AddAccountDialog.show( - fragmentManager = requireActivity().supportFragmentManager, - account = account - ) - } - - private fun setAccountAsCurrent(account: DebugAccount) { - getPlugin().debugAuthenticator.onAccountSelected(account) - pushEvent(account) - } - - private fun pushEvent(account: DebugAccount) { - Toast.makeText( - requireActivity(), - "Account ${account.login} selected", - Toast.LENGTH_SHORT - ).show() - getPlugin().pushEvent(AccountSelectedEvent(account)) - } -} diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/AccountsViewState.kt b/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/AccountsViewState.kt deleted file mode 100644 index 6a5dd2a4..00000000 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/AccountsViewState.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.redmadrobot.account_plugin.ui - -import com.redmadrobot.account_plugin.ui.item.DebugAccountItems - -internal data class AccountsViewState( - val preInstalledAccounts: List, - val addedAccounts: List -) diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/item/DebugAccountItems.kt b/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/item/DebugAccountItems.kt deleted file mode 100644 index 1ceea176..00000000 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/item/DebugAccountItems.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.redmadrobot.account_plugin.ui.item - -import com.redmadrobot.account_plugin.data.model.DebugAccount - - -internal sealed class DebugAccountItems { - internal data class Header(val header: String) : DebugAccountItems() - internal data class PreinstalledAccount(val account: DebugAccount) : DebugAccountItems() - internal data class AddedAccount(var account: DebugAccount) : DebugAccountItems() -} - diff --git a/plugins/accounts-plugin/src/main/res/layout/fragment_accounts.xml b/plugins/accounts-plugin/src/main/res/layout/fragment_accounts.xml deleted file mode 100644 index 587a7085..00000000 --- a/plugins/accounts-plugin/src/main/res/layout/fragment_accounts.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - diff --git a/plugins/accounts-plugin/.gitignore b/plugins/accounts/.gitignore similarity index 100% rename from plugins/accounts-plugin/.gitignore rename to plugins/accounts/.gitignore diff --git a/plugins/accounts-plugin/build.gradle.kts b/plugins/accounts/build.gradle.kts similarity index 81% rename from plugins/accounts-plugin/build.gradle.kts rename to plugins/accounts/build.gradle.kts index 40c245e0..a74cb71c 100644 --- a/plugins/accounts-plugin/build.gradle.kts +++ b/plugins/accounts/build.gradle.kts @@ -44,8 +44,13 @@ android { buildFeatures { viewBinding = true + compose = true } - namespace = "com.redmadrobot.account_plugin" + + composeOptions { + kotlinCompilerExtensionVersion = androidx.versions.compose.compiler.get() + } + namespace = "com.redmadrobot.debug.accounts" } kotlin { @@ -53,8 +58,8 @@ kotlin { } dependencies { - implementation(project(":debug-panel-core")) - implementation(project(":debug-panel-common")) + implementation(project(":core")) + implementation(project(":common")) implementation(kotlin("stdlib")) kapt(androidx.room.compiler) } diff --git a/plugins/accounts-plugin/consumer-rules.pro b/plugins/accounts/consumer-rules.pro similarity index 100% rename from plugins/accounts-plugin/consumer-rules.pro rename to plugins/accounts/consumer-rules.pro diff --git a/plugins/accounts-plugin/library.properties b/plugins/accounts/library.properties similarity index 100% rename from plugins/accounts-plugin/library.properties rename to plugins/accounts/library.properties diff --git a/plugins/accounts-plugin/proguard-rules.pro b/plugins/accounts/proguard-rules.pro similarity index 100% rename from plugins/accounts-plugin/proguard-rules.pro rename to plugins/accounts/proguard-rules.pro diff --git a/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/authenticator/DebugAuthenticator.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/authenticator/DebugAuthenticator.kt new file mode 100644 index 00000000..0e6d7ef5 --- /dev/null +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/authenticator/DebugAuthenticator.kt @@ -0,0 +1,7 @@ +package com.redmadrobot.debug.accounts.authenticator + +import com.redmadrobot.debug.accounts.data.model.DebugAccount + +public interface DebugAuthenticator { + public fun onAccountSelected(account: DebugAccount) +} diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/authenticator/DefaultAuthenticator.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/authenticator/DefaultAuthenticator.kt similarity index 52% rename from plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/authenticator/DefaultAuthenticator.kt rename to plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/authenticator/DefaultAuthenticator.kt index 8676a95d..c088897e 100644 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/authenticator/DefaultAuthenticator.kt +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/authenticator/DefaultAuthenticator.kt @@ -1,6 +1,6 @@ -package com.redmadrobot.account_plugin.authenticator +package com.redmadrobot.debug.accounts.authenticator -import com.redmadrobot.account_plugin.data.model.DebugAccount +import com.redmadrobot.debug.accounts.data.model.DebugAccount internal class DefaultAuthenticator : DebugAuthenticator { override fun onAccountSelected(account: DebugAccount) = Unit diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/DebugAccountRepository.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/DebugAccountRepository.kt similarity index 74% rename from plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/DebugAccountRepository.kt rename to plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/DebugAccountRepository.kt index 3f41ddc3..bc2cb7e8 100644 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/DebugAccountRepository.kt +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/DebugAccountRepository.kt @@ -1,6 +1,6 @@ -package com.redmadrobot.account_plugin.data +package com.redmadrobot.debug.accounts.data -import com.redmadrobot.account_plugin.data.model.DebugAccount +import com.redmadrobot.debug.accounts.data.model.DebugAccount internal interface DebugAccountRepository { suspend fun addAccount(account: DebugAccount) diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/LocalDebugAccountRepository.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/LocalDebugAccountRepository.kt similarity index 85% rename from plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/LocalDebugAccountRepository.kt rename to plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/LocalDebugAccountRepository.kt index 6519335f..8c4ce610 100644 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/LocalDebugAccountRepository.kt +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/LocalDebugAccountRepository.kt @@ -1,7 +1,7 @@ -package com.redmadrobot.account_plugin.data +package com.redmadrobot.debug.accounts.data -import com.redmadrobot.account_plugin.data.model.DebugAccount -import com.redmadrobot.account_plugin.data.storage.DebugAccountDao +import com.redmadrobot.debug.accounts.data.model.DebugAccount +import com.redmadrobot.debug.accounts.data.storage.DebugAccountDao import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/model/DebugAccount.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/model/DebugAccount.kt similarity index 90% rename from plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/model/DebugAccount.kt rename to plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/model/DebugAccount.kt index 1f661184..22c36c72 100644 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/model/DebugAccount.kt +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/model/DebugAccount.kt @@ -1,4 +1,4 @@ -package com.redmadrobot.account_plugin.data.model +package com.redmadrobot.debug.accounts.data.model import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/storage/AccountsPluginDatabase.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/storage/AccountsPluginDatabase.kt similarity index 85% rename from plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/storage/AccountsPluginDatabase.kt rename to plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/storage/AccountsPluginDatabase.kt index 23f8e16a..aba7c244 100644 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/storage/AccountsPluginDatabase.kt +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/storage/AccountsPluginDatabase.kt @@ -1,10 +1,10 @@ -package com.redmadrobot.account_plugin.data.storage +package com.redmadrobot.debug.accounts.data.storage import android.content.Context import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase -import com.redmadrobot.account_plugin.data.model.DebugAccount +import com.redmadrobot.debug.accounts.data.model.DebugAccount @Database( entities = [DebugAccount::class], diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/storage/DebugAccountDao.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/storage/DebugAccountDao.kt similarity index 77% rename from plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/storage/DebugAccountDao.kt rename to plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/storage/DebugAccountDao.kt index d4b6af97..47ee41dd 100644 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/data/storage/DebugAccountDao.kt +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/data/storage/DebugAccountDao.kt @@ -1,7 +1,7 @@ -package com.redmadrobot.account_plugin.data.storage +package com.redmadrobot.debug.accounts.data.storage import androidx.room.* -import com.redmadrobot.account_plugin.data.model.DebugAccount +import com.redmadrobot.debug.accounts.data.model.DebugAccount @Dao internal interface DebugAccountDao { diff --git a/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/plugin/AccountSelectedEvent.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/plugin/AccountSelectedEvent.kt new file mode 100644 index 00000000..67b3fb37 --- /dev/null +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/plugin/AccountSelectedEvent.kt @@ -0,0 +1,6 @@ +package com.redmadrobot.debug.accounts.plugin + +import com.redmadrobot.debug.accounts.data.model.DebugAccount +import com.redmadrobot.debug.core.internal.DebugEvent + +public data class AccountSelectedEvent(val debugAccount: DebugAccount) : DebugEvent diff --git a/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/plugin/AccountsPlugin.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/plugin/AccountsPlugin.kt new file mode 100644 index 00000000..0007aa1a --- /dev/null +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/plugin/AccountsPlugin.kt @@ -0,0 +1,69 @@ +package com.redmadrobot.debug.accounts.plugin + +import androidx.compose.runtime.Composable +import androidx.compose.ui.viewinterop.AndroidViewBinding +import androidx.core.os.bundleOf +import androidx.fragment.app.Fragment +import com.redmadrobot.debug.accounts.databinding.FragmentContainerAccountBinding +import com.redmadrobot.debug.accounts.authenticator.DebugAuthenticator +import com.redmadrobot.debug.accounts.authenticator.DefaultAuthenticator +import com.redmadrobot.debug.accounts.data.model.DebugAccount +import com.redmadrobot.debug.accounts.ui.AccountsFragment +import com.redmadrobot.debug.core.CommonContainer +import com.redmadrobot.debug.core.data.DebugDataProvider +import com.redmadrobot.debug.core.plugin.Plugin +import com.redmadrobot.debug.core.plugin.PluginDependencyContainer + +public class AccountsPlugin( + private val preInstalledAccounts: List = emptyList(), + public val debugAuthenticator: DebugAuthenticator = DefaultAuthenticator() +) : Plugin() { + + 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) + } + + override fun getFragment(): Fragment { + return AccountsFragment().apply { + arguments = bundleOf(AccountsFragment.IS_EDIT_MODE_KEY to false) + } + } + + @Composable + override fun content() { + AndroidViewBinding(factory = FragmentContainerAccountBinding::inflate) { + fragmentContainer.getFragment().apply { + arguments = bundleOf(AccountsFragment.IS_EDIT_MODE_KEY to false) + } + } + } + + @Composable + override fun settingsContent() { + AndroidViewBinding(factory = FragmentContainerAccountBinding::inflate) { + fragmentContainer.getFragment().apply { + arguments = bundleOf(AccountsFragment.IS_EDIT_MODE_KEY to true) + } + } + } + + override fun getSettingFragment(): Fragment { + return AccountsFragment().apply { + arguments = bundleOf(AccountsFragment.IS_EDIT_MODE_KEY to true) + } + } +} diff --git a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/plugin/AccountsPluginContainer.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/plugin/AccountsPluginContainer.kt similarity index 59% rename from plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/plugin/AccountsPluginContainer.kt rename to plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/plugin/AccountsPluginContainer.kt index ea7b25e2..93638d31 100644 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/plugin/AccountsPluginContainer.kt +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/plugin/AccountsPluginContainer.kt @@ -1,11 +1,11 @@ -package com.redmadrobot.account_plugin.plugin +package com.redmadrobot.debug.accounts.plugin -import com.redmadrobot.account_plugin.data.LocalDebugAccountRepository -import com.redmadrobot.account_plugin.data.model.DebugAccount -import com.redmadrobot.account_plugin.data.storage.AccountsPluginDatabase -import com.redmadrobot.account_plugin.ui.AccountsViewModel -import com.redmadrobot.debug_panel_core.CommonContainer -import com.redmadrobot.debug_panel_core.plugin.PluginDependencyContainer +import com.redmadrobot.debug.accounts.data.LocalDebugAccountRepository +import com.redmadrobot.debug.accounts.data.model.DebugAccount +import com.redmadrobot.debug.accounts.data.storage.AccountsPluginDatabase +import com.redmadrobot.debug.accounts.ui.AccountsViewModel +import com.redmadrobot.debug.core.CommonContainer +import com.redmadrobot.debug.core.plugin.PluginDependencyContainer internal class AccountsPluginContainer( private val preInstalledAccounts: List, diff --git a/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsFragment.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsFragment.kt new file mode 100644 index 00000000..d735b387 --- /dev/null +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsFragment.kt @@ -0,0 +1,40 @@ +package com.redmadrobot.debug.accounts.ui + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.compose.ui.platform.ComposeView +import androidx.fragment.app.Fragment +import com.redmadrobot.debug.accounts.plugin.AccountsPlugin +import com.redmadrobot.debug.accounts.plugin.AccountsPluginContainer +import com.redmadrobot.debug.common.extension.obtainShareViewModel +import com.redmadrobot.debug.core.extension.getPlugin + +internal class AccountsFragment : Fragment() { + + private val isSettingMode: Boolean by lazy { + activity?.javaClass?.simpleName == "DebugActivity" + } + + companion object { + const val IS_EDIT_MODE_KEY = "IS_EDIT_MODE_KEY" + } + + private val viewModel by lazy { + obtainShareViewModel { + getPlugin() + .getContainer() + .createAccountsViewModel() + } + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ) = ComposeView(inflater.context).apply { + setContent { + AccountsScreen(viewModel, isSettingMode) + } + } +} diff --git a/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsScreen.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsScreen.kt new file mode 100644 index 00000000..2c38c532 --- /dev/null +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsScreen.kt @@ -0,0 +1,240 @@ +package com.redmadrobot.debug.accounts.ui + +import android.annotation.SuppressLint +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.* +import androidx.compose.runtime.* +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 androidx.lifecycle.asFlow +import com.redmadrobot.debug.accounts.R +import com.redmadrobot.debug.accounts.data.model.DebugAccount + +@SuppressLint("UnusedMaterialScaffoldPaddingParameter") +@Composable +internal fun AccountsScreen( + viewModel: AccountsViewModel, + isEditMode: Boolean +) { + val state by viewModel.state.asFlow().collectAsState(AccountsViewState()) + 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 account = DebugAccount( + id = account?.id ?: 0, + login = login, + password = password, + pin = pin + ) + onSaveClick(account) + 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/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/AccountsViewModel.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsViewModel.kt similarity index 64% rename from plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/AccountsViewModel.kt rename to plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsViewModel.kt index 2fc34a0f..fcab1052 100644 --- a/plugins/accounts-plugin/src/main/kotlin/com/redmadrobot/account_plugin/ui/AccountsViewModel.kt +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsViewModel.kt @@ -1,14 +1,16 @@ -package com.redmadrobot.account_plugin.ui +package com.redmadrobot.debug.accounts.ui import android.content.Context import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope -import com.redmadrobot.account_plugin.R -import com.redmadrobot.account_plugin.data.DebugAccountRepository -import com.redmadrobot.account_plugin.data.model.DebugAccount -import com.redmadrobot.account_plugin.ui.item.DebugAccountItems -import com.redmadrobot.debug_panel_common.base.PluginViewModel -import com.redmadrobot.debug_panel_common.extension.safeLaunch +import com.redmadrobot.debug.accounts.R +import com.redmadrobot.debug.accounts.data.DebugAccountRepository +import com.redmadrobot.debug.accounts.data.model.DebugAccount +import com.redmadrobot.debug.accounts.plugin.AccountSelectedEvent +import com.redmadrobot.debug.accounts.plugin.AccountsPlugin +import com.redmadrobot.debug.common.base.PluginViewModel +import com.redmadrobot.debug.common.extension.safeLaunch +import com.redmadrobot.debug.core.extension.getPlugin internal class AccountsViewModel( private val context: Context, @@ -30,14 +32,13 @@ internal class AccountsViewModel( } } - fun saveAccount(login: String, password: String, pin: String) { - val account = DebugAccount( - login = login, - password = password, - pin = pin - ) + fun saveAccount(debugAccount: DebugAccount) { viewModelScope.safeLaunch { - debugAccountsRepository.addAccount(account) + if (debugAccount.id != 0) { + debugAccountsRepository.updateAccount(debugAccount) + } else { + debugAccountsRepository.addAccount(debugAccount) + } loadAddedAccounts() } } @@ -68,14 +69,21 @@ internal class AccountsViewModel( } } + 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 -> - DebugAccountItems.PreinstalledAccount(account) + DebugAccountItem.PreinstalledAccount(account) } val header = context.getString(R.string.pre_installed_accounts) - listOf(/*Header item*/DebugAccountItems.Header(header)).plus(items) + listOf(/*Header item*/DebugAccountItem.Header(header)).plus(items) } else { emptyList() } @@ -86,10 +94,10 @@ internal class AccountsViewModel( val accounts = debugAccountsRepository.getAccounts() val addedAccountItems = if (accounts.isNotEmpty()) { val items = accounts.map { account -> - DebugAccountItems.AddedAccount(account) + DebugAccountItem.AddedAccount(account) } val header = context.getString(R.string.added_accounts) - listOf(/*Header item*/DebugAccountItems.Header(header)).plus(items) + listOf(/*Header item*/DebugAccountItem.Header(header)).plus(items) } else { emptyList() } diff --git a/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsViewState.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsViewState.kt new file mode 100644 index 00000000..2c64b3b2 --- /dev/null +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/accounts/ui/AccountsViewState.kt @@ -0,0 +1,11 @@ +package com.redmadrobot.debug.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/accounts-plugin/src/main/res/drawable/icon_account.xml b/plugins/accounts/src/main/res/drawable/icon_account.xml similarity index 94% rename from plugins/accounts-plugin/src/main/res/drawable/icon_account.xml rename to plugins/accounts/src/main/res/drawable/icon_account.xml index 7fe80c7b..4649894e 100644 --- a/plugins/accounts-plugin/src/main/res/drawable/icon_account.xml +++ b/plugins/accounts/src/main/res/drawable/icon_account.xml @@ -1,7 +1,7 @@ + + diff --git a/plugins/accounts-plugin/src/main/res/layout/item_account.xml b/plugins/accounts/src/main/res/layout/item_account.xml similarity index 100% rename from plugins/accounts-plugin/src/main/res/layout/item_account.xml rename to plugins/accounts/src/main/res/layout/item_account.xml diff --git a/plugins/accounts-plugin/src/main/res/values/color.xml b/plugins/accounts/src/main/res/values/color.xml similarity index 100% rename from plugins/accounts-plugin/src/main/res/values/color.xml rename to plugins/accounts/src/main/res/values/color.xml diff --git a/plugins/accounts-plugin/src/main/res/values/public.xml b/plugins/accounts/src/main/res/values/public.xml similarity index 100% rename from plugins/accounts-plugin/src/main/res/values/public.xml rename to plugins/accounts/src/main/res/values/public.xml diff --git a/plugins/accounts-plugin/src/main/res/values/strings.xml b/plugins/accounts/src/main/res/values/strings.xml similarity index 100% rename from plugins/accounts-plugin/src/main/res/values/strings.xml rename to plugins/accounts/src/main/res/values/strings.xml diff --git a/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/plugin/AppSettingsPlugin.kt b/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/plugin/AppSettingsPlugin.kt deleted file mode 100644 index f97c59e1..00000000 --- a/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/plugin/AppSettingsPlugin.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.redmadrobot.app_settings_plugin.plugin - -import android.content.SharedPreferences -import androidx.fragment.app.Fragment -import com.redmadrobot.app_settings_plugin.data.DefaultSharedPreferences -import com.redmadrobot.app_settings_plugin.ui.ApplicationSettingsFragment -import com.redmadrobot.debug_panel_core.CommonContainer -import com.redmadrobot.debug_panel_core.plugin.Plugin -import com.redmadrobot.debug_panel_core.plugin.PluginDependencyContainer - -public class AppSettingsPlugin( - private val sharedPreferences: List = listOf(DefaultSharedPreferences()) -) : Plugin() { - - internal companion object { - const val NAME = "APP SETTINGS" - } - - override fun getName(): String = NAME - - override fun getPluginContainer(commonContainer: CommonContainer): PluginDependencyContainer { - return AppSettingsPluginContainer(sharedPreferences) - } - - override fun getFragment(): Fragment? { - return ApplicationSettingsFragment() - } -} diff --git a/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/ui/ApplicationSettingsFragment.kt b/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/ui/ApplicationSettingsFragment.kt deleted file mode 100644 index 497967ef..00000000 --- a/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/ui/ApplicationSettingsFragment.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.redmadrobot.app_settings_plugin.ui - -import android.os.Bundle -import android.view.View -import androidx.recyclerview.widget.LinearLayoutManager -import com.redmadrobot.app_settings_plugin.R -import com.redmadrobot.app_settings_plugin.databinding.FragmentAppSettingsBinding -import com.redmadrobot.app_settings_plugin.plugin.AppSettingsPlugin -import com.redmadrobot.app_settings_plugin.plugin.AppSettingsPluginContainer -import com.redmadrobot.app_settings_plugin.ui.item.AppSettingItems -import com.redmadrobot.debug_panel_common.base.PluginFragment -import com.redmadrobot.debug_panel_common.extension.observe -import com.redmadrobot.debug_panel_common.extension.obtainViewModel -import com.redmadrobot.debug_panel_core.extension.getPlugin -import com.redmadrobot.itemsadapter.itemsAdapter - -internal class ApplicationSettingsFragment : PluginFragment(R.layout.fragment_app_settings) { - - private var binding: FragmentAppSettingsBinding? = null - - private val settingsViewModel by lazy { - obtainViewModel { - getPlugin() - .getContainer() - .createApplicationSettingsViewModel() - } - } - - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) - observe(settingsViewModel.settingsLiveData, ::setSettingList) - settingsViewModel.loadSettings() - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - binding = FragmentAppSettingsBinding.bind(view).also { - it.setViews() - } - } - - private fun FragmentAppSettingsBinding.setViews() { - appSettings.layoutManager = LinearLayoutManager(context) - } - - private fun setSettingList(settings: List) { - val binding = binding ?: return - binding.appSettings.adapter = itemsAdapter(settings) { item -> - item.getItem(this) - } - } -} diff --git a/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/ui/ApplicationSettingsViewModel.kt b/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/ui/ApplicationSettingsViewModel.kt deleted file mode 100644 index 70006072..00000000 --- a/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/ui/ApplicationSettingsViewModel.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.redmadrobot.app_settings_plugin.ui - -import android.content.SharedPreferences -import androidx.lifecycle.MutableLiveData -import com.redmadrobot.app_settings_plugin.data.AppSettingsRepository -import com.redmadrobot.app_settings_plugin.ui.item.AppSettingItems -import com.redmadrobot.debug_panel_common.base.PluginViewModel - -internal class ApplicationSettingsViewModel( - private val appSettingsRepository: AppSettingsRepository -) : PluginViewModel() { - - val settingsLiveData = MutableLiveData>() - - fun loadSettings() { - val settings = appSettingsRepository.getSettings() - val settingItems = mapToItems(settings) - settingsLiveData.value = settingItems - } - - @Suppress("NewApi") - private fun mapToItems(settings: List): List { - val items = mutableListOf() - settings.forEach { sharedPreferences -> - /*Settings header*/ - items.add( - AppSettingItems.Header(sharedPreferences.toString()) - ) - - /*Map SharedPreferences to Items*/ - sharedPreferences.all.forEach { (key, value) -> - val item = if (value is Boolean) { - AppSettingItems.BooleanValueItem(key, value) { settingKey, newValue -> - updateSetting(settingKey, newValue) - } - } else { - AppSettingItems.ValueItem(key, value) { settingKey, newValue -> - updateSetting(settingKey, newValue) - } - } - items.add(item) - } - } - return items - } - - private fun updateSetting(settingKey: String, newValue: Any) { - appSettingsRepository.updateSetting(settingKey, newValue) - } -} diff --git a/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/ui/item/AppSettingItems.kt b/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/ui/item/AppSettingItems.kt deleted file mode 100644 index 5861b2f1..00000000 --- a/plugins/app-settings-plugin/src/main/kotlin/com/redmadrobot/app_settings_plugin/ui/item/AppSettingItems.kt +++ /dev/null @@ -1,97 +0,0 @@ -package com.redmadrobot.app_settings_plugin.ui.item - -import androidx.core.view.isVisible -import com.redmadrobot.app_settings_plugin.R -import com.redmadrobot.app_settings_plugin.databinding.ItemHeaderBinding -import com.redmadrobot.app_settings_plugin.databinding.ItemPreferenceBooleanBinding -import com.redmadrobot.app_settings_plugin.databinding.ItemPreferenceValueBinding -import com.redmadrobot.itemsadapter.ItemsAdapter -import com.redmadrobot.itemsadapter.bind -import timber.log.Timber - -internal sealed class AppSettingItems { - - abstract fun getItem(bindingContext: ItemsAdapter.BindingContext): ItemsAdapter.Item - - internal class Header(private val header: String) : AppSettingItems() { - override fun getItem(bindingContext: ItemsAdapter.BindingContext): ItemsAdapter.Item { - return bindingContext.bind(R.layout.item_header) { - itemHeaderText.text = header - } - } - } - - class ValueItem( - private val key: String, - var value: Any?, - private val onChanged: (key: String, newValue: Any) -> Unit - ) : AppSettingItems() { - override fun getItem(bindingContext: ItemsAdapter.BindingContext): ItemsAdapter.Item { - return bindingContext.bind(R.layout.item_preference_value) { - settingLabel.text = key - settingType.text = value?.let { it::class.java.simpleName } - settingType.isVisible = value != null - - setSettingValue() - saveValue.setOnClickListener { saveNewValue() } - } - } - - private fun ItemPreferenceValueBinding.setSettingValue() = with(settingValue) { - setText(value.toString()) - clearFocus() - settingValueContainer.error = null - - setOnFocusChangeListener { _, hasFocus -> - saveValue.isVisible = hasFocus && value != null - } - } - - private fun ItemPreferenceValueBinding.saveNewValue() { - val fieldValue = settingValue.text.toString() - try { - val newValue = castToNeededType(fieldValue) - onChanged.invoke(key, newValue) - - value = newValue - setSettingValue() - } catch (e: Exception) { - Timber.e(e) - settingValueContainer.error = root.context.getString(R.string.wrong_type) - } - } - - private fun castToNeededType(newValue: String): Any { - return when (value) { - is Long -> newValue.toLong() - is String -> newValue - is Float -> newValue.toFloat() - is Int -> newValue.toInt() - else -> throw Throwable("Unexpected type") - } - } - } - - class BooleanValueItem( - private val key: String, - var value: Boolean, - private val onChanged: (key: String, newValue: Any) -> Unit - ) : AppSettingItems() { - - override fun getItem(bindingContext: ItemsAdapter.BindingContext): ItemsAdapter.Item { - return bindingContext.bind(R.layout.item_preference_boolean) { - settingLabel.text = key - settingType.text = value::class.java.simpleName - - with(settingSwitch) { - setOnCheckedChangeListener(null) - isChecked = value - setOnCheckedChangeListener { _, isChecked -> - onChanged.invoke(key, isChecked) - value = isChecked - } - } - } - } - } -} diff --git a/plugins/app-settings-plugin/src/main/res/layout/fragment_app_settings.xml b/plugins/app-settings-plugin/src/main/res/layout/fragment_app_settings.xml deleted file mode 100644 index 7dc0e7a7..00000000 --- a/plugins/app-settings-plugin/src/main/res/layout/fragment_app_settings.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - diff --git a/plugins/app-settings-plugin/src/main/res/layout/item_header.xml b/plugins/app-settings-plugin/src/main/res/layout/item_header.xml deleted file mode 100644 index 0c14cf96..00000000 --- a/plugins/app-settings-plugin/src/main/res/layout/item_header.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - diff --git a/plugins/app-settings-plugin/src/main/res/layout/item_preference_boolean.xml b/plugins/app-settings-plugin/src/main/res/layout/item_preference_boolean.xml deleted file mode 100644 index def246fc..00000000 --- a/plugins/app-settings-plugin/src/main/res/layout/item_preference_boolean.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - diff --git a/plugins/app-settings-plugin/src/main/res/layout/item_preference_unsupported.xml b/plugins/app-settings-plugin/src/main/res/layout/item_preference_unsupported.xml deleted file mode 100644 index 74ed1890..00000000 --- a/plugins/app-settings-plugin/src/main/res/layout/item_preference_unsupported.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - diff --git a/plugins/app-settings-plugin/src/main/res/layout/item_preference_value.xml b/plugins/app-settings-plugin/src/main/res/layout/item_preference_value.xml deleted file mode 100644 index a85965a4..00000000 --- a/plugins/app-settings-plugin/src/main/res/layout/item_preference_value.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - -