Skip to content

Commit

Permalink
chore(plugin): plugin structure refactored (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
srtvprateek authored Jul 20, 2023
1 parent 275aeb8 commit 0e0294e
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pluto.plugin

import com.pluto.utilities.list.ListItem

class PluginGroup : ListItem()
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.pluto.plugins.datastore.pref

@SuppressWarnings("UnusedPrivateMember")
class PlutoDatastorePreferencesPlugin(identifier: String)
class PlutoDatastorePreferencesPlugin @JvmOverloads constructor(identifier: String = ID) {
companion object {
const val ID = "datastore-preferences"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import com.pluto.plugin.Plugin
import com.pluto.plugin.PluginConfiguration
import com.pluto.plugins.datastore.pref.internal.BaseFragment

class PlutoDatastorePreferencesPlugin(identifier: String) : Plugin(identifier) {
class PlutoDatastorePreferencesPlugin() : Plugin(ID) {

@SuppressWarnings("UnusedPrivateMember")
@Deprecated("Use the default constructor PlutoDatastorePreferencesPlugin() instead.")
constructor(identifier: String) : this()

override fun getConfig() = PluginConfiguration(
name = "DataStore Preferences",
Expand All @@ -29,4 +33,8 @@ class PlutoDatastorePreferencesPlugin(identifier: String) : Plugin(identifier) {
override fun onPluginInstalled() {}

override fun onPluginDataCleared() {}

companion object {
const val ID = "datastore-preferences"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.demo.plugin

@SuppressWarnings("UnusedPrivateMember")
class DemoPlugin(devIdentifier: String)
class DemoPlugin @JvmOverloads constructor(identifier: String = ID) {
companion object {
const val ID = "demo"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import com.pluto.plugin.Plugin
import com.pluto.plugin.PluginConfiguration
import com.pluto.utilities.DebugLog

class DemoPlugin(devIdentifier: String) : Plugin(devIdentifier) {
class DemoPlugin() : Plugin(ID) {

@SuppressWarnings("UnusedPrivateMember")
@Deprecated("Use the default constructor DemoPlugin() instead.")
constructor(identifier: String) : this()

init {
Session.devIdentifier = devIdentifier
Expand Down Expand Up @@ -34,4 +38,8 @@ class DemoPlugin(devIdentifier: String) : Plugin(devIdentifier) {

override fun onPluginDataCleared() {
}

companion object {
const val ID = "demo"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.pluto.plugins.exceptions

@SuppressWarnings("UnusedPrivateMember")
class PlutoExceptionsPlugin(identifier: String)
class PlutoExceptionsPlugin @JvmOverloads constructor(identifier: String = ID) {
companion object {
const val ID = "exceptions"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import com.pluto.plugin.PluginConfiguration
import com.pluto.plugins.exceptions.internal.BaseFragment
import com.pluto.plugins.exceptions.internal.persistence.ExceptionDBHandler

class PlutoExceptionsPlugin(private val identifier: String) : Plugin(identifier) {
class PlutoExceptionsPlugin() : Plugin(ID) {

@SuppressWarnings("UnusedPrivateMember")
@Deprecated("Use the default constructor PlutoExceptionsPlugin() instead.")
constructor(identifier: String) : this()

override fun getConfig() = PluginConfiguration(
name = context.getString(R.string.pluto_excep___plugin_name),
icon = R.drawable.pluto_excep___ic_plugin_logo,
Expand All @@ -30,6 +35,10 @@ class PlutoExceptionsPlugin(private val identifier: String) : Plugin(identifier)

override fun onPluginInstalled() {
ExceptionDBHandler.initialize(context)
PlutoExceptions.initialize(context, identifier)
PlutoExceptions.initialize(context, ID)
}

companion object {
const val ID = "exceptions"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.pluto.plugins.layoutinspector

@SuppressWarnings("UnusedPrivateMember")
class PlutoLayoutInspectorPlugin(identifier: String)
class PlutoLayoutInspectorPlugin @JvmOverloads constructor(identifier: String = ID) {
companion object {
const val ID = "layout-inspector"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import com.pluto.plugin.Plugin
import com.pluto.plugin.PluginConfiguration
import com.pluto.plugins.layoutinspector.internal.ActivityLifecycle

class PlutoLayoutInspectorPlugin(identifier: String) : Plugin(identifier) {
class PlutoLayoutInspectorPlugin() : Plugin(ID) {

@SuppressWarnings("UnusedPrivateMember")
@Deprecated("Use the default constructor PlutoLayoutInspectorPlugin() instead.")
constructor(identifier: String) : this()

override fun getConfig() = PluginConfiguration(
name = context.getString(R.string.pluto_li___plugin_name),
icon = R.drawable.pluto_li___ic_plugin_logo,
Expand All @@ -29,4 +34,8 @@ class PlutoLayoutInspectorPlugin(identifier: String) : Plugin(identifier) {
override fun onPluginInstalled() {
application.registerActivityLifecycleCallbacks(ActivityLifecycle())
}

companion object {
const val ID = "layout-inspector"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.pluto.plugins.logger

@SuppressWarnings("UnusedPrivateMember")
class PlutoLoggerPlugin(identifier: String)
class PlutoLoggerPlugin @JvmOverloads constructor(identifier: String = ID) {
companion object {
const val ID = "logger"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import com.pluto.plugin.PluginConfiguration
import com.pluto.plugins.logger.internal.LogsFragment
import com.pluto.plugins.logger.internal.persistence.LogDBHandler

class PlutoLoggerPlugin(identifier: String) : Plugin(identifier) {
class PlutoLoggerPlugin() : Plugin(ID) {

@SuppressWarnings("UnusedPrivateMember")
@Deprecated("Use the default constructor PlutoLoggerPlugin() instead.")
constructor(identifier: String) : this()

override fun getConfig(): PluginConfiguration = PluginConfiguration(
name = context.getString(R.string.pluto_logger___plugin_name),
Expand All @@ -32,4 +36,8 @@ class PlutoLoggerPlugin(identifier: String) : Plugin(identifier) {
override fun onPluginDataCleared() {
LogDBHandler.flush()
}

companion object {
const val ID = "logger"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.pluto.plugins.network

@SuppressWarnings("UnusedPrivateMember")
class PlutoNetworkPlugin(devIdentifier: String)
class PlutoNetworkPlugin @JvmOverloads constructor(identifier: String = ID) {
companion object {
const val ID = "network"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import com.pluto.plugins.network.internal.NetworkFragment
import com.pluto.plugins.network.internal.interceptor.logic.NetworkCallsRepo
import com.pluto.plugins.network.internal.mock.logic.MockSettingsRepo

class PlutoNetworkPlugin(devIdentifier: String) : Plugin(devIdentifier) {
class PlutoNetworkPlugin() : Plugin(ID) {

@SuppressWarnings("UnusedPrivateMember")
@Deprecated("Use the default constructor PlutoNetworkPlugin() instead.")
constructor(identifier: String) : this()

override fun getConfig(): PluginConfiguration {
return PluginConfiguration(
name = context.getString(R.string.pluto_network___plugin_name),
Expand All @@ -34,4 +39,8 @@ class PlutoNetworkPlugin(devIdentifier: String) : Plugin(devIdentifier) {
PlutoNetwork.initialize(context)
MockSettingsRepo.init(context)
}

companion object {
const val ID = "network"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.pluto.plugins.rooms.db

@SuppressWarnings("UnusedPrivateMember")
class PlutoRoomsDatabasePlugin(identifier: String)
class PlutoRoomsDatabasePlugin @JvmOverloads constructor(identifier: String = ID) {
companion object {
const val ID = "rooms-database"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import com.pluto.plugin.Plugin
import com.pluto.plugin.PluginConfiguration
import com.pluto.plugins.rooms.db.internal.ui.filter.FilterConfig

class PlutoRoomsDatabasePlugin(identifier: String) : Plugin(identifier) {
class PlutoRoomsDatabasePlugin() : Plugin(ID) {

@SuppressWarnings("UnusedPrivateMember")
@Deprecated("Use the default constructor PlutoRoomsDatabasePlugin() instead.")
constructor(identifier: String) : this()

override fun getConfig(): PluginConfiguration = PluginConfiguration(
name = context.getString(R.string.pluto_rooms___plugin_name),
Expand All @@ -30,4 +34,8 @@ class PlutoRoomsDatabasePlugin(identifier: String) : Plugin(identifier) {
override fun onPluginDataCleared() {
FilterConfig.clear()
}

companion object {
const val ID = "rooms-database"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.pluto.plugins.preferences

@SuppressWarnings("UnusedPrivateMember")
class PlutoSharePreferencesPlugin(identifier: String)
class PlutoSharePreferencesPlugin @JvmOverloads constructor(identifier: String = ID) {
companion object {
const val ID = "shared-preferences"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import com.pluto.plugin.DeveloperDetails
import com.pluto.plugin.Plugin
import com.pluto.plugin.PluginConfiguration

class PlutoSharePreferencesPlugin(identifier: String) : Plugin(identifier) {
class PlutoSharePreferencesPlugin() : Plugin(ID) {

@SuppressWarnings("UnusedPrivateMember")
@Deprecated("Use the default constructor PlutoSharePreferencesPlugin() instead.")
constructor(identifier: String) : this()

override fun getConfig(): PluginConfiguration = PluginConfiguration(
name = context.getString(R.string.pluto_pref___plugin_name),
Expand All @@ -29,4 +33,8 @@ class PlutoSharePreferencesPlugin(identifier: String) : Plugin(identifier) {

override fun onPluginDataCleared() {
}

companion object {
const val ID = "shared-preferences"
}
}
3 changes: 2 additions & 1 deletion sample/src/main/java/com/sampleapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.chip.Chip
import com.pluto.Pluto
import com.pluto.plugins.layoutinspector.PlutoLayoutInspectorPlugin
import com.sampleapp.ContainerFragment.Companion.FUNCTION_ID
import com.sampleapp.ContainerFragment.Companion.FUNCTION_LABEL
import com.sampleapp.databinding.ActivityMainBinding
Expand All @@ -26,7 +27,7 @@ class MainActivity : AppCompatActivity() {
textStartPadding = CHIP_PADDING
textEndPadding = CHIP_PADDING
setOnClickListener { _ ->
if (it.id == SupportedPlugins.LAYOUT_INSPECTOR) {
if (it.id == PlutoLayoutInspectorPlugin.ID) {
startActivity(Intent(this@MainActivity, DemoLayoutInspectorActivity::class.java))
} else {
ContainerFragment().apply {
Expand Down
24 changes: 8 additions & 16 deletions sample/src/main/java/com/sampleapp/SampleApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ import com.pluto.plugins.network.PlutoNetworkPlugin
import com.pluto.plugins.preferences.PlutoSharePreferencesPlugin
import com.pluto.plugins.rooms.db.PlutoRoomsDBWatcher
import com.pluto.plugins.rooms.db.PlutoRoomsDatabasePlugin
import com.sampleapp.SupportedPlugins.Companion.DATASTORE_PREF
import com.sampleapp.SupportedPlugins.Companion.DEMO
import com.sampleapp.SupportedPlugins.Companion.EXCEPTIONS
import com.sampleapp.SupportedPlugins.Companion.LAYOUT_INSPECTOR
import com.sampleapp.SupportedPlugins.Companion.LOGGER
import com.sampleapp.SupportedPlugins.Companion.NETWORK
import com.sampleapp.SupportedPlugins.Companion.ROOMS_DATABASE
import com.sampleapp.SupportedPlugins.Companion.SHARED_PREF
import com.sampleapp.functions.datastore.DemoDatastorePrefFragment.Companion.APP_STATE_PREF_NAME
import com.sampleapp.functions.datastore.DemoDatastorePrefFragment.Companion.USER_STATE_PREF_NAME
import com.sampleapp.functions.datastore.appStateDatastore
Expand All @@ -41,14 +33,14 @@ class SampleApp : Application() {
initializeStrictMode()
super.onCreate()
Pluto.Installer(this)
.addPlugin(DemoPlugin(DEMO))
.addPlugin(PlutoExceptionsPlugin(EXCEPTIONS))
.addPlugin(PlutoDatastorePreferencesPlugin(DATASTORE_PREF))
.addPlugin(PlutoNetworkPlugin(NETWORK))
.addPlugin(PlutoLoggerPlugin(LOGGER))
.addPlugin(PlutoSharePreferencesPlugin(SHARED_PREF))
.addPlugin(PlutoRoomsDatabasePlugin(ROOMS_DATABASE))
.addPlugin(PlutoLayoutInspectorPlugin(LAYOUT_INSPECTOR))
.addPlugin(DemoPlugin())
.addPlugin(PlutoExceptionsPlugin())
.addPlugin(PlutoDatastorePreferencesPlugin())
.addPlugin(PlutoNetworkPlugin())
.addPlugin(PlutoLoggerPlugin())
.addPlugin(PlutoSharePreferencesPlugin())
.addPlugin(PlutoRoomsDatabasePlugin())
.addPlugin(PlutoLayoutInspectorPlugin())
.install()
Pluto.showNotch(true)

Expand Down
42 changes: 20 additions & 22 deletions sample/src/main/java/com/sampleapp/SupportedFunctions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ package com.sampleapp

import androidx.annotation.Keep
import androidx.fragment.app.Fragment
import com.pluto.plugins.datastore.pref.PlutoDatastorePreferencesPlugin
import com.pluto.plugins.exceptions.PlutoExceptionsPlugin
import com.pluto.plugins.layoutinspector.PlutoLayoutInspectorPlugin
import com.pluto.plugins.logger.PlutoLoggerPlugin
import com.pluto.plugins.network.PlutoNetworkPlugin
import com.pluto.plugins.preferences.PlutoSharePreferencesPlugin
import com.pluto.plugins.rooms.db.PlutoRoomsDatabasePlugin
import com.sampleapp.functions.datastore.DemoDatastorePrefFragment
import com.sampleapp.functions.exceptions.DemoExceptionFragment
import com.sampleapp.functions.logger.DemoLoggerFragment
Expand All @@ -13,36 +20,27 @@ class SupportedPlugins private constructor() {
companion object {
internal fun get(): ArrayList<FunctionsModel> {
return arrayListOf(
FunctionsModel(NETWORK, "Network & API calls"),
FunctionsModel(EXCEPTIONS, "Crashes & ANRs"),
FunctionsModel(LOGGER, "Logger"),
FunctionsModel(SHARED_PREF, "Shared Preferences"),
FunctionsModel(ROOMS_DATABASE, "Rooms Database"),
FunctionsModel(DATASTORE_PREF, "Datastore Preferences"),
FunctionsModel(LAYOUT_INSPECTOR, "Layout Inspector")
FunctionsModel(PlutoNetworkPlugin.ID, "Network & API calls"),
FunctionsModel(PlutoExceptionsPlugin.ID, "Crashes & ANRs"),
FunctionsModel(PlutoLoggerPlugin.ID, "Logger"),
FunctionsModel(PlutoSharePreferencesPlugin.ID, "Shared Preferences"),
FunctionsModel(PlutoRoomsDatabasePlugin.ID, "Rooms Database"),
FunctionsModel(PlutoDatastorePreferencesPlugin.ID, "Datastore Preferences"),
FunctionsModel(PlutoLayoutInspectorPlugin.ID, "Layout Inspector")
)
}

fun getDemoFragment(id: String): Fragment {
return when (id) {
NETWORK -> DemoNetworkFragment()
EXCEPTIONS -> DemoExceptionFragment()
SHARED_PREF -> DemoSharedPrefFragment()
DATASTORE_PREF -> DemoDatastorePrefFragment()
LOGGER -> DemoLoggerFragment()
ROOMS_DATABASE -> DemoRoomsDatabaseFragment()
PlutoNetworkPlugin.ID -> DemoNetworkFragment()
PlutoExceptionsPlugin.ID -> DemoExceptionFragment()
PlutoSharePreferencesPlugin.ID -> DemoSharedPrefFragment()
PlutoDatastorePreferencesPlugin.ID -> DemoDatastorePrefFragment()
PlutoLoggerPlugin.ID -> DemoLoggerFragment()
PlutoRoomsDatabasePlugin.ID -> DemoRoomsDatabaseFragment()
else -> DemoNetworkFragment()
}
}

const val DEMO: String = "demo"
const val NETWORK: String = "network"
const val EXCEPTIONS: String = "exceptions"
const val SHARED_PREF: String = "shared-preferences"
const val LOGGER: String = "logger"
const val ROOMS_DATABASE: String = "rooms-database"
const val DATASTORE_PREF: String = "datastore-preferences"
const val LAYOUT_INSPECTOR: String = "layout-inspector"
}
}

Expand Down

0 comments on commit 0e0294e

Please sign in to comment.