File tree Expand file tree Collapse file tree
panel-core/src/main/kotlin/com/redmadrobot/debug/core
sample/src/main/kotlin/com/redmadrobot/debug_sample Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import kotlinx.coroutines.channels.BufferOverflow
1111import kotlinx.coroutines.flow.Flow
1212import kotlinx.coroutines.flow.MutableSharedFlow
1313
14- internal class DebugPanelInstance constructor (
14+ internal class DebugPanelInstance (
1515 application : Application ,
1616 plugins : List <Plugin > = emptyList()
1717) {
Original file line number Diff line number Diff line change @@ -5,18 +5,18 @@ import android.content.BroadcastReceiver
55import android.content.Context
66import android.content.Intent
77import com.redmadrobot.debug.core.DebugPanel
8+ import java.lang.ref.WeakReference
89
9- internal class DebugPanelBroadcastReceiver (
10- private val activity : Activity
11- ) : BroadcastReceiver() {
10+ internal class DebugPanelBroadcastReceiver (activity : Activity ) : BroadcastReceiver() {
11+ private val activityReference = WeakReference (activity)
1212
1313 companion object {
1414 const val ACTION_OPEN_DEBUG_PANEL = " com.redmadrobot.debug.core.ACTION_OPEN_DEBUG_PANEL"
1515 }
1616
1717 override fun onReceive (context : Context , intent : Intent ) {
1818 if (intent.action == ACTION_OPEN_DEBUG_PANEL ) {
19- DebugPanel .showPanel(activity)
19+ activityReference.get()?. let { DebugPanel .showPanel(it) }
2020 }
2121 }
2222}
Original file line number Diff line number Diff line change @@ -14,9 +14,6 @@ import com.redmadrobot.debug_sample.network.ApiFactory
1414import com.redmadrobot.debugpanel.databinding.ActivityMainBinding
1515import com.redmadrobot.flipper.config.FlipperValue
1616import kotlinx.coroutines.DelicateCoroutinesApi
17- import kotlinx.coroutines.Dispatchers
18- import kotlinx.coroutines.GlobalScope
19- import kotlinx.coroutines.flow.flowOn
2017import kotlinx.coroutines.flow.launchIn
2118import kotlinx.coroutines.flow.onEach
2219import okhttp3.ResponseBody
@@ -146,8 +143,7 @@ class MainActivity : AppCompatActivity() {
146143 .onEach { changedToggles ->
147144 onFlipperTogglesChanged(changedToggles)
148145 }
149- .flowOn(Dispatchers .Main )
150- .launchIn(GlobalScope )
146+ .launchIn(lifecycleScope)
151147 }
152148
153149 private fun onFlipperTogglesChanged (changedToggles : Map <String , FlipperValue >) {
You can’t perform that action at this time.
0 commit comments