From 83ea210b60fc603d543de318a6cf149f7e5a7c75 Mon Sep 17 00:00:00 2001 From: k1rakishou Date: Sat, 5 Sep 2020 18:08:26 +0300 Subject: [PATCH] Add debug logs, add throw on reply button click --- Kuroba/app/buildnumber.property | 2 +- .../chan/controller/Controller.kt | 28 +++++----- .../transition/ControllerTransition.kt | 6 +- .../chan/core/image/ImageLoaderV2.kt | 7 +-- .../chan/features/drawer/DrawerController.kt | 27 +++++++-- .../navigation/NavigationController.java | 56 ++++++++++++++----- .../NavigationControllerDebugHelper.kt | 23 ++++++++ .../StyledToolbarNavigationController.java | 1 + .../chan/ui/layout/ThreadLayout.kt | 6 ++ 9 files changed, 113 insertions(+), 43 deletions(-) create mode 100644 Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/NavigationControllerDebugHelper.kt diff --git a/Kuroba/app/buildnumber.property b/Kuroba/app/buildnumber.property index 0b9e0ab9d3..391a637173 100644 --- a/Kuroba/app/buildnumber.property +++ b/Kuroba/app/buildnumber.property @@ -1 +1 @@ -1008 \ No newline at end of file +1020 \ No newline at end of file diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/controller/Controller.kt b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/controller/Controller.kt index 9e4824f007..f1eb285084 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/controller/Controller.kt +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/controller/Controller.kt @@ -38,10 +38,7 @@ import com.github.adamantcheese.chan.ui.widget.CancellableToast import com.github.adamantcheese.chan.utils.AndroidUtils import com.github.adamantcheese.chan.utils.Logger import io.reactivex.disposables.CompositeDisposable -import kotlinx.coroutines.CoroutineName -import kotlinx.coroutines.MainScope -import kotlinx.coroutines.cancel -import kotlinx.coroutines.plus +import kotlinx.coroutines.* import java.util.* import javax.inject.Inject @@ -97,7 +94,8 @@ abstract class Controller(@JvmField var context: Context) { get private set - protected var mainScope = MainScope() + CoroutineName("Controller_${this::class.java.simpleName}") + private val job = SupervisorJob() + protected var mainScope = CoroutineScope(job + Dispatchers.Main + CoroutineName("Controller_${this::class.java.simpleName}")) var shown = false @JvmName("shown") get @@ -124,7 +122,7 @@ abstract class Controller(@JvmField var context: Context) { alive = true if (LOG_STATES) { - Logger.test(javaClass.simpleName + " onCreate") + Logger.d(TAG, javaClass.simpleName + " onCreate") } } @@ -133,7 +131,7 @@ abstract class Controller(@JvmField var context: Context) { shown = true if (LOG_STATES) { - Logger.test(javaClass.simpleName + " onShow") + Logger.d(TAG, javaClass.simpleName + " onShow") } view.visibility = View.VISIBLE @@ -150,7 +148,7 @@ abstract class Controller(@JvmField var context: Context) { shown = false if (LOG_STATES) { - Logger.test(javaClass.simpleName + " onHide") + Logger.d(TAG, javaClass.simpleName + " onHide") } view.visibility = View.GONE @@ -166,10 +164,10 @@ abstract class Controller(@JvmField var context: Context) { open fun onDestroy() { alive = false compositeDisposable.clear() - mainScope.cancel() + job.cancelChildren() if (LOG_STATES) { - Logger.test(javaClass.simpleName + " onDestroy") + Logger.d(TAG, javaClass.simpleName + " onDestroy") } while (childControllers.size > 0) { @@ -178,7 +176,7 @@ abstract class Controller(@JvmField var context: Context) { if (AndroidUtils.removeFromParentView(view)) { if (LOG_STATES) { - Logger.test(javaClass.simpleName + " view removed onDestroy") + Logger.d(TAG, javaClass.simpleName + " view removed onDestroy") } } } @@ -206,7 +204,7 @@ abstract class Controller(@JvmField var context: Context) { fun attachToParentView(parentView: ViewGroup?) { if (view.parent != null) { if (LOG_STATES) { - Logger.test(javaClass.simpleName + " view removed") + Logger.d(TAG, javaClass.simpleName + " view removed") } AndroidUtils.removeFromParentView(view) @@ -214,7 +212,7 @@ abstract class Controller(@JvmField var context: Context) { if (parentView != null) { if (LOG_STATES) { - Logger.test(javaClass.simpleName + " view attached") + Logger.d(TAG, javaClass.simpleName + " view attached") } attachToView(parentView) @@ -245,6 +243,7 @@ abstract class Controller(@JvmField var context: Context) { return true } } + return false } @@ -329,7 +328,8 @@ abstract class Controller(@JvmField var context: Context) { } companion object { - private const val LOG_STATES = false + private const val TAG = "Controller" + private const val LOG_STATES = true } } \ No newline at end of file diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/controller/transition/ControllerTransition.kt b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/controller/transition/ControllerTransition.kt index 949811767e..6d235f240e 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/controller/transition/ControllerTransition.kt +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/controller/transition/ControllerTransition.kt @@ -44,9 +44,9 @@ abstract class ControllerTransition { fun debugInfo(): String { return String.format( Locale.ENGLISH, - "callback=" + callback!!.javaClass.simpleName + ", " + - "from=" + from!!.javaClass.simpleName + ", " + - "to=" + to!!.javaClass.simpleName + "callback=" + callback?.javaClass?.simpleName + ", " + + "from=" + from?.javaClass?.simpleName + ", " + + "to=" + to?.javaClass?.simpleName ) } diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/image/ImageLoaderV2.kt b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/image/ImageLoaderV2.kt index 4b0119e37c..05e322117e 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/image/ImageLoaderV2.kt +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/core/image/ImageLoaderV2.kt @@ -14,7 +14,6 @@ import com.github.adamantcheese.chan.R import com.github.adamantcheese.chan.core.model.PostImage import com.github.adamantcheese.chan.ui.theme.ThemeHelper import com.github.adamantcheese.chan.utils.BackgroundUtils -import com.github.adamantcheese.chan.utils.Logger import com.github.adamantcheese.chan.utils.getLifecycleFromContext import java.util.concurrent.atomic.AtomicReference @@ -50,7 +49,7 @@ class ImageLoaderV2( val lifecycle = context.getLifecycleFromContext() if (verboseLogsEnabled) { - Logger.d(TAG, "loadFromNetwork(url=$url, width=$width, height=$height)") +// Logger.d(TAG, "loadFromNetwork(url=$url, width=$width, height=$height)") } val request = with(LoadRequest.Builder(context)) { @@ -131,7 +130,7 @@ class ImageLoaderV2( val lifecycle = context.getLifecycleFromContext() if (verboseLogsEnabled) { - Logger.d(TAG, "loadFromResources(drawableId=$drawableId, width=$width, height=$height)") +// Logger.d(TAG, "loadFromResources(drawableId=$drawableId, width=$width, height=$height)") } val request = with(LoadRequest.Builder(context)) { @@ -185,7 +184,7 @@ class ImageLoaderV2( val lifecycle = context.getLifecycleFromContext() if (verboseLogsEnabled) { - Logger.d(TAG, "loadFromNetwork(url=$url, width=$width, height=$height)") +// Logger.d(TAG, "loadFromNetwork(url=$url, width=$width, height=$height)") } val request = with(LoadRequest.Builder(context)) { diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/features/drawer/DrawerController.kt b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/features/drawer/DrawerController.kt index 478798cfa6..560ac78850 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/features/drawer/DrawerController.kt +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/features/drawer/DrawerController.kt @@ -60,6 +60,7 @@ import com.github.adamantcheese.chan.utils.addOneshotModelBuildListener import com.github.adamantcheese.chan.utils.plusAssign import com.github.adamantcheese.common.updatePaddings import com.github.adamantcheese.model.data.descriptor.ChanDescriptor +import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import java.util.* import javax.inject.Inject @@ -319,7 +320,14 @@ class DrawerController( descriptor: ChanDescriptor.ThreadDescriptor, closeAllNonMainControllers: Boolean = false ) { + if (!mainScope.isActive) { + Logger.d(TAG, "loadThread() mainScope is not active!") + } + mainScope.launch { + Logger.d(TAG, "loadThread() inside coroutine, " + + "topThreadController: ${topThreadController?.javaClass?.simpleName}") + if (closeAllNonMainControllers) { closeAllNonMainControllers() } @@ -331,12 +339,8 @@ class DrawerController( private fun onNavigationItemSelectedListener(menuItem: MenuItem) { when (menuItem.itemId) { R.id.action_browse -> closeAllNonMainControllers() - R.id.action_bookmarks -> { - openBookmarksController(emptyList()) - } - R.id.action_settings -> { - openSettingsController() - } + R.id.action_bookmarks -> openBookmarksController(emptyList()) + R.id.action_settings -> openSettingsController() } } @@ -352,8 +356,13 @@ class DrawerController( } private fun closeAllNonMainControllers() { + Logger.d(TAG, "closeAllNonMainControllers") + var currentNavController = top ?: return + + Logger.d(TAG, "currentNavController=${currentNavController.javaClass.simpleName}") + val isPhoneMode = ChanSettings.getCurrentLayoutMode() == ChanSettings.LayoutMode.PHONE while (true) { @@ -522,7 +531,13 @@ class DrawerController( } private fun onHistoryEntryViewClicked(navHistoryEntry: NavigationHistoryEntry) { + if (!mainScope.isActive) { + Logger.d(TAG, "onHistoryEntryViewClicked() mainScope is not active!") + } + mainScope.launch { + Logger.d(TAG, "onHistoryEntryViewClicked() inside coroutine, topThreadController: ${topThreadController?.javaClass?.simpleName}") + val currentTopThreadController = topThreadController ?: return@launch diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/NavigationController.java b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/NavigationController.java index ec6a5662ff..4eb87bc5d6 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/NavigationController.java +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/NavigationController.java @@ -28,10 +28,12 @@ import com.github.adamantcheese.chan.core.manager.ControllerNavigationManager; import com.github.adamantcheese.chan.core.navigation.HasNavigation; import com.github.adamantcheese.chan.utils.AndroidUtils; +import com.github.adamantcheese.chan.utils.Logger; import javax.inject.Inject; public abstract class NavigationController extends Controller implements HasNavigation { + private static final String TAG = "NavigationController"; @Inject ControllerNavigationManager controllerNavigationManager; @@ -59,7 +61,7 @@ public boolean pushController(final Controller to, ControllerTransition controll if (blockingInput) { // Crash on beta and dev builds if (!AndroidUtils.isStableBuild()) { - throwDebugInfo("pushController", to, from, controllerTransition); + throwDebugInfo("pushController", to, from, true, controllerTransition); return false; } @@ -92,7 +94,7 @@ public boolean popController(ControllerTransition controllerTransition) { if (blockingInput) { // Crash on beta and dev builds if (!AndroidUtils.isStableBuild()) { - throwDebugInfo("popController", to, from, controllerTransition); + throwDebugInfo("popController", to, from, false, controllerTransition); return false; } @@ -103,19 +105,6 @@ public boolean popController(ControllerTransition controllerTransition) { return true; } - private void throwDebugInfo( - String tag, - Controller to, - Controller from, - ControllerTransition controllerTransition - ) { - String debugInfo = tag + ": to=" + to.getClass().getSimpleName() + ", " + - "from=" + from.getClass().getSimpleName() + ", " + - "transition=" + controllerTransition.debugInfo(); - - throw new IllegalStateException(debugInfo); - } - public boolean isBlockingInput() { return blockingInput; } @@ -181,6 +170,8 @@ public void transition( to.onShow(); } + printTransitionDebugInfo(from, to, pushing, controllerTransition); + if (controllerTransition != null) { controllerTransition.from = from; controllerTransition.to = to; @@ -197,6 +188,41 @@ public void transition( finishTransition(from, to, pushing); } + private void throwDebugInfo( + String methodName, + Controller to, + Controller from, + boolean pushing, + ControllerTransition controllerTransition + ) { + String log = NavigationControllerDebugHelper.getTransitionDebugInfo( + methodName, + from, + to, + pushing, + controllerTransition + ); + + throw new IllegalStateException(log); + } + + private void printTransitionDebugInfo( + Controller from, + Controller to, + boolean pushing, + ControllerTransition controllerTransition + ) { + String log = NavigationControllerDebugHelper.getTransitionDebugInfo( + "transition", + from, + to, + pushing, + controllerTransition + ); + + Logger.d(TAG, log); + } + private void finishTransition(Controller from, Controller to, boolean pushing) { if (from != null) { from.onHide(); diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/NavigationControllerDebugHelper.kt b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/NavigationControllerDebugHelper.kt new file mode 100644 index 0000000000..1d4d65c4fd --- /dev/null +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/NavigationControllerDebugHelper.kt @@ -0,0 +1,23 @@ +package com.github.adamantcheese.chan.ui.controller.navigation + +import com.github.adamantcheese.chan.controller.Controller +import com.github.adamantcheese.chan.controller.transition.ControllerTransition + +object NavigationControllerDebugHelper { + + @JvmStatic + fun getTransitionDebugInfo( + calledFromMethod: String, + from: Controller?, + to: Controller?, + pushing: Boolean, + controllerTransition: ControllerTransition? + ): String { + return "$calledFromMethod() " + + "from=" + from?.javaClass?.simpleName + ", " + + "to=" + to?.javaClass?.simpleName + ", " + + "pushing=" + pushing + ", " + + "controllerTransition=(" + controllerTransition?.debugInfo() + ")" + } + +} \ No newline at end of file diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/StyledToolbarNavigationController.java b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/StyledToolbarNavigationController.java index dfafca5fd0..96c450b39f 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/StyledToolbarNavigationController.java +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/controller/navigation/StyledToolbarNavigationController.java @@ -135,6 +135,7 @@ private DrawerController getDrawerController() { return (DrawerController) doubleNav.parentController; } } + return null; } } diff --git a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/layout/ThreadLayout.kt b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/layout/ThreadLayout.kt index 70c08affbc..85405a373c 100644 --- a/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/layout/ThreadLayout.kt +++ b/Kuroba/app/src/main/java/com/github/adamantcheese/chan/ui/layout/ThreadLayout.kt @@ -211,6 +211,12 @@ class ThreadLayout @JvmOverloads constructor( if (v === errorRetryButton) { presenter.requestData() } else if (v === replyButton) { + // TODO(KurobaEx): Remove me!!!!!!!!!!!! + + if (true) { + throw RuntimeException("Test exception") + } + threadListLayout.openReply(true) } }