diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 1430970b..8e16cb48 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -54,6 +54,7 @@ dependencies { api(androidx.compose.ui.tooling.preview) api(androidx.compose.ui.viewbinding) api(androidx.constraintlayout.compose) + api(androidx.navigation.compose) api(androidx.core) api(androidx.fragment) api(androidx.lifecycle.viewmodel.compose) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 8d8d51e7..94507062 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -38,7 +38,6 @@ android { } buildFeatures { - viewBinding = true compose = true } diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml index eb87ba58..8d5d63ee 100644 --- a/core/src/main/AndroidManifest.xml +++ b/core/src/main/AndroidManifest.xml @@ -4,7 +4,7 @@ @@ -21,7 +21,7 @@ android:enabled="true" android:exported="true" android:label="@string/debug_panel" - android:targetActivity=".ui.debugpanel.DebugActivity" + android:targetActivity=".ui.settings.DebugSettingsActivity" android:taskAffinity="com.redmadrobot.debug_panel.DebugActivity" android:theme="@style/DebugPanelTheme"> diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/extension/PluginsExt.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/extension/PluginsExt.kt index 10e7a398..4fa74427 100644 --- a/core/src/main/kotlin/com/redmadrobot/debug/core/extension/PluginsExt.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/extension/PluginsExt.kt @@ -1,10 +1,8 @@ package com.redmadrobot.debug.core.extension -import androidx.fragment.app.Fragment import com.redmadrobot.debug.core.DebugPanelInstance import com.redmadrobot.debug.core.annotation.DebugPanelInternal import com.redmadrobot.debug.core.plugin.Plugin -import com.redmadrobot.debug.core.ui.debugpanel.DebugActivity @PublishedApi internal fun getPlugin(pluginName: String): Plugin { @@ -20,9 +18,4 @@ internal fun getAllPlugins(): List { public inline fun getPlugin(): T { val plugin = getPlugin(T::class.java.name) return plugin as T -} - -@DebugPanelInternal -public fun Fragment.isSettingMode(): Boolean { - return activity?.javaClass == DebugActivity::class.java } \ No newline at end of file diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/internal/EditablePlugin.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/internal/EditablePlugin.kt new file mode 100644 index 00000000..8ff5731c --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/internal/EditablePlugin.kt @@ -0,0 +1,14 @@ +package com.redmadrobot.debug.core.internal + +import androidx.compose.runtime.Composable +import com.redmadrobot.debug.core.annotation.DebugPanelInternal + +/** + * Plugin that will be displayed when opening the settings + */ +@DebugPanelInternal +public interface EditablePlugin { + @Composable + public fun settingsContent() { + } +} \ 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 index 9e1c4eba..9b744701 100644 --- a/core/src/main/kotlin/com/redmadrobot/debug/core/plugin/Plugin.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/plugin/Plugin.kt @@ -1,7 +1,6 @@ package com.redmadrobot.debug.core.plugin import androidx.compose.runtime.Composable -import androidx.fragment.app.Fragment import com.redmadrobot.debug.core.DebugEvent import com.redmadrobot.debug.core.DebugPanelInstance import com.redmadrobot.debug.core.internal.CommonContainer @@ -22,21 +21,10 @@ public abstract class Plugin { public fun getContainer(): T = pluginContainer as T - @Deprecated( - message = "You shouldn't use fragments for you plugins. Please use Jetpack Compose", - replaceWith = ReplaceWith("content()", "com.redmadrobot.debug.core.plugin.Plugin"), - level = DeprecationLevel.WARNING, - ) - 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/ui/debugpanel/DebugActivity.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/DebugActivity.kt deleted file mode 100644 index ab4ef4a4..00000000 --- a/core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/DebugActivity.kt +++ /dev/null @@ -1,50 +0,0 @@ -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.core.R -import com.redmadrobot.debug.core.databinding.ActivityDebugBinding -import com.redmadrobot.debug.core.databinding.ItemPluginSettingBinding -import com.redmadrobot.debug.core.extension.getAllPlugins -import com.redmadrobot.itemsadapter.bind -import com.redmadrobot.itemsadapter.itemsAdapter - -internal class DebugActivity : AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - val binding = ActivityDebugBinding.inflate(layoutInflater) - setContentView(binding.root) - binding.setViews() - } - - private fun ActivityDebugBinding.setViews() { - debugFeatureList.layoutManager = LinearLayoutManager(root.context) - debugFeatureList.adapter = itemsAdapter(getSettingItems()) { item -> - bind(R.layout.item_plugin_setting) { - itemDebugFeatureLabel.text = item.pluginName - root.setOnClickListener { item.onClicked.invoke() } - } - } - } - - private fun openSetting(settingFragment: Fragment) { - supportFragmentManager.beginTransaction() - .replace(R.id.debug_activity_root, settingFragment) - .addToBackStack(settingFragment.javaClass.simpleName) - .commit() - } - - private fun getSettingItems(): List { - return getAllPlugins() - /*Only Plugins with SettingFragment*/ - .filter { it.getSettingFragment() != null } - .map { plugin -> - PluginsSettingItem(plugin.getName()) { - openSetting(requireNotNull(plugin.getSettingFragment())) - } - } - } -} diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/PluginsSettingItem.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/PluginsSettingItem.kt deleted file mode 100644 index 064e86af..00000000 --- a/core/src/main/kotlin/com/redmadrobot/debug/core/ui/debugpanel/PluginsSettingItem.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.redmadrobot.debug.core.ui.debugpanel - -internal class PluginsSettingItem( - val pluginName: String, - val onClicked: () -> Unit -) diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/DebugSettingsActivity.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/DebugSettingsActivity.kt new file mode 100644 index 00000000..a552d51e --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/DebugSettingsActivity.kt @@ -0,0 +1,37 @@ +package com.redmadrobot.debug.core.ui.settings + +import android.os.Bundle +import androidx.activity.compose.setContent +import androidx.appcompat.app.AppCompatActivity +import androidx.compose.material.MaterialTheme +import androidx.compose.runtime.remember +import androidx.navigation.compose.rememberNavController +import com.redmadrobot.debug.core.extension.getAllPlugins +import com.redmadrobot.debug.core.internal.EditablePlugin + + +internal class DebugSettingsActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContent { + MaterialTheme { + val navController = rememberNavController() + val pluginItems = remember { getSettingItems() } + DebugSettingsNavHost(navController = navController, pluginItems = pluginItems) + } + } + } + + private fun getSettingItems(): List { + return getAllPlugins() + .filter { it is EditablePlugin } + .map { plugin -> + PluginSettingsItem( + pluginClassName = plugin::class.java.name, + pluginName = plugin.getName(), + ) + } + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/DebugSettingsNavHost.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/DebugSettingsNavHost.kt new file mode 100644 index 00000000..487dbae5 --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/DebugSettingsNavHost.kt @@ -0,0 +1,28 @@ +package com.redmadrobot.debug.core.ui.settings + +import androidx.compose.runtime.Composable +import androidx.navigation.NavHostController +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import com.redmadrobot.debug.core.extension.getPlugin +import com.redmadrobot.debug.core.internal.EditablePlugin + +private const val MAIN_SCREEN_ROUTE = "main" + +@Composable +internal fun DebugSettingsNavHost( + navController: NavHostController, + pluginItems: List, +) { + NavHost(navController = navController, startDestination = MAIN_SCREEN_ROUTE) { + composable(MAIN_SCREEN_ROUTE) { + DebugSettingsScreen(pluginItems = pluginItems, navController = navController) + } + + pluginItems.forEach { plugin -> + composable(plugin.pluginClassName) { + (getPlugin(plugin.pluginClassName) as? EditablePlugin)?.settingsContent() + } + } + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/DebugSettingsScreen.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/DebugSettingsScreen.kt new file mode 100644 index 00000000..b8ff6d9e --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/DebugSettingsScreen.kt @@ -0,0 +1,42 @@ +package com.redmadrobot.debug.core.ui.settings + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.navigation.NavController + +@Composable +internal fun DebugSettingsScreen( + navController: NavController, + pluginItems: List, +) { + LazyColumn( + modifier = Modifier.fillMaxSize(), + ) { + items(pluginItems) { item -> + PluginItem( + pluginName = item.pluginName, + onClick = { navController.navigate(item.pluginClassName) }, + ) + } + } +} + +@Composable +private fun PluginItem(pluginName: String, onClick: () -> Unit) { + Text( + modifier = Modifier + .fillMaxSize() + .clickable { onClick.invoke() } + .padding(horizontal = 16.dp, vertical = 16.dp), + text = pluginName, + fontSize = 18.sp, + ) +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/PluginSettingsItem.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/PluginSettingsItem.kt new file mode 100644 index 00000000..28510984 --- /dev/null +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/ui/settings/PluginSettingsItem.kt @@ -0,0 +1,6 @@ +package com.redmadrobot.debug.core.ui.settings + +internal class PluginSettingsItem( + val pluginName: String, + val pluginClassName: String, +) diff --git a/core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelNotification.kt b/core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelNotification.kt index 7c60a3d7..bcc00e4a 100644 --- a/core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelNotification.kt +++ b/core/src/main/kotlin/com/redmadrobot/debug/core/util/DebugPanelNotification.kt @@ -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.core.ui.debugpanel.DebugActivity import com.redmadrobot.debug.core.R +import com.redmadrobot.debug.core.ui.settings.DebugSettingsActivity internal class DebugPanelNotification(private val context: Context) { @@ -74,7 +74,7 @@ internal class DebugPanelNotification(private val context: Context) { } private fun getSettingActivityPendingIntent(context: Context): PendingIntent? { - val settingActivityIntent = Intent(context, DebugActivity::class.java) + val settingActivityIntent = Intent(context, DebugSettingsActivity::class.java) return TaskStackBuilder.create(context) .addNextIntentWithParentStack(settingActivityIntent) diff --git a/core/src/main/res/layout/activity_debug.xml b/core/src/main/res/layout/activity_debug.xml deleted file mode 100644 index c3d012fb..00000000 --- a/core/src/main/res/layout/activity_debug.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/core/src/main/res/layout/item_plugin_setting.xml b/core/src/main/res/layout/item_plugin_setting.xml deleted file mode 100644 index 1ade722a..00000000 --- a/core/src/main/res/layout/item_plugin_setting.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - diff --git a/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountsPlugin.kt b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountsPlugin.kt index d3d4e9ff..e5f8627b 100644 --- a/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountsPlugin.kt +++ b/plugins/accounts/src/main/kotlin/com/redmadrobot/debug/plugin/accounts/AccountsPlugin.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable import com.redmadrobot.debug.core.data.DebugDataProvider import com.redmadrobot.debug.core.internal.CommonContainer import com.redmadrobot.debug.core.internal.PluginDependencyContainer +import com.redmadrobot.debug.core.internal.EditablePlugin import com.redmadrobot.debug.core.plugin.Plugin import com.redmadrobot.debug.plugin.accounts.authenticator.DebugAuthenticator import com.redmadrobot.debug.plugin.accounts.authenticator.DefaultAuthenticator @@ -13,7 +14,7 @@ import com.redmadrobot.debug.plugin.accounts.ui.AccountsScreen public class AccountsPlugin( private val preInstalledAccounts: List = emptyList(), public val debugAuthenticator: DebugAuthenticator = DefaultAuthenticator() -) : Plugin() { +) : Plugin(), EditablePlugin { internal companion object { const val NAME = "ACCOUNTS" diff --git a/plugins/servers/src/main/kotlin/com/redmadrobot/debug/plugin/servers/ServersPlugin.kt b/plugins/servers/src/main/kotlin/com/redmadrobot/debug/plugin/servers/ServersPlugin.kt index d60bc0d2..0db018d7 100644 --- a/plugins/servers/src/main/kotlin/com/redmadrobot/debug/plugin/servers/ServersPlugin.kt +++ b/plugins/servers/src/main/kotlin/com/redmadrobot/debug/plugin/servers/ServersPlugin.kt @@ -6,6 +6,7 @@ import com.redmadrobot.debug.core.data.DebugDataProvider import com.redmadrobot.debug.core.extension.getPlugin import com.redmadrobot.debug.core.internal.CommonContainer import com.redmadrobot.debug.core.internal.PluginDependencyContainer +import com.redmadrobot.debug.core.internal.EditablePlugin import com.redmadrobot.debug.core.plugin.Plugin import com.redmadrobot.debug.plugin.servers.data.model.DebugServer import com.redmadrobot.debug.plugin.servers.data.model.DebugServerData @@ -16,7 +17,7 @@ import kotlinx.coroutines.runBlocking @OptIn(DebugPanelInternal::class) public class ServersPlugin( private val preInstalledServers: List = emptyList(), -) : Plugin() { +) : Plugin(), EditablePlugin { init { preInstalledServers.find { it.isDefault }