Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
Add debug logs, add throw on reply button click
Browse files Browse the repository at this point in the history
  • Loading branch information
K1rakishou committed Sep 5, 2020
1 parent 4d08c9d commit 83ea210
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Kuroba/app/buildnumber.property
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1008
1020
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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")
}
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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")
}
}
}
Expand Down Expand Up @@ -206,15 +204,15 @@ 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)
}

if (parentView != null) {
if (LOG_STATES) {
Logger.test(javaClass.simpleName + " view attached")
Logger.d(TAG, javaClass.simpleName + " view attached")
}

attachToView(parentView)
Expand Down Expand Up @@ -245,6 +243,7 @@ abstract class Controller(@JvmField var context: Context) {
return true
}
}

return false
}

Expand Down Expand Up @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -181,6 +170,8 @@ public void transition(
to.onShow();
}

printTransitionDebugInfo(from, to, pushing, controllerTransition);

if (controllerTransition != null) {
controllerTransition.from = from;
controllerTransition.to = to;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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() + ")"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ private DrawerController getDrawerController() {
return (DrawerController) doubleNav.parentController;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 83ea210

Please sign in to comment.