diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.java b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.java deleted file mode 100644 index fa4b62846f..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.java +++ /dev/null @@ -1,139 +0,0 @@ -package eu.kanade.tachiyomi.ui.base.controller; - -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.bluelinelabs.conductor.RestoreViewOnCreateController; -import com.bluelinelabs.conductor.Router; -import com.bluelinelabs.conductor.RouterTransaction; -import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler; - -/** - * A controller that displays a dialog window, floating on top of its activity's window. - * This is a wrapper over {@link Dialog} object like {@link android.app.DialogFragment}. - * - *
Implementations should override this class and implement {@link #onCreateDialog(Bundle)} to create a custom dialog, such as an {@link android.app.AlertDialog} - */ -public abstract class DialogController extends RestoreViewOnCreateController { - - private static final String SAVED_DIALOG_STATE_TAG = "android:savedDialogState"; - - private Dialog dialog; - private boolean dismissed; - - /** - * Convenience constructor for use when no arguments are needed. - */ - protected DialogController() { - super(null); - } - - /** - * Constructor that takes arguments that need to be retained across restarts. - * - * @param args Any arguments that need to be retained. - */ - protected DialogController(@Nullable Bundle args) { - super(args); - } - - @NonNull - @Override - final protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container, @Nullable Bundle savedViewState) { - dialog = onCreateDialog(savedViewState); - //noinspection ConstantConditions - dialog.setOwnerActivity(getActivity()); - dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - dismissDialog(); - } - }); - if (savedViewState != null) { - Bundle dialogState = savedViewState.getBundle(SAVED_DIALOG_STATE_TAG); - if (dialogState != null) { - dialog.onRestoreInstanceState(dialogState); - } - } - return new View(getActivity());//stub view - } - - @Override - protected void onSaveViewState(@NonNull View view, @NonNull Bundle outState) { - super.onSaveViewState(view, outState); - Bundle dialogState = dialog.onSaveInstanceState(); - outState.putBundle(SAVED_DIALOG_STATE_TAG, dialogState); - } - - @Override - protected void onAttach(@NonNull View view) { - super.onAttach(view); - dialog.show(); - } - - @Override - protected void onDetach(@NonNull View view) { - super.onDetach(view); - dialog.hide(); - } - - @Override - protected void onDestroyView(@NonNull View view) { - super.onDestroyView(view); - dialog.setOnDismissListener(null); - dialog.dismiss(); - dialog = null; - } - - /** - * Display the dialog, create a transaction and pushing the controller. - * @param router The router on which the transaction will be applied - */ - public void showDialog(@NonNull Router router) { - showDialog(router, null); - } - - /** - * Display the dialog, create a transaction and pushing the controller. - * @param router The router on which the transaction will be applied - * @param tag The tag for this controller - */ - public void showDialog(@NonNull Router router, @Nullable String tag) { - dismissed = false; - router.pushController(RouterTransaction.with(this) - .pushChangeHandler(new SimpleSwapChangeHandler(false)) - .popChangeHandler(new SimpleSwapChangeHandler(false)) - .tag(tag)); - } - - /** - * Dismiss the dialog and pop this controller - */ - public void dismissDialog() { - if (dismissed) { - return; - } - getRouter().popController(this); - dismissed = true; - } - - @Nullable - protected Dialog getDialog() { - return dialog; - } - - /** - * Build your own custom Dialog container such as an {@link android.app.AlertDialog} - * - * @param savedViewState A bundle for the view's state, which would have been created in {@link #onSaveViewState(View, Bundle)} or {@code null} if no saved state exists. - * @return Return a new Dialog instance to be displayed by the Controller - */ - @NonNull - protected abstract Dialog onCreateDialog(@Nullable Bundle savedViewState); -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt new file mode 100644 index 0000000000..7d59b864c9 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt @@ -0,0 +1,118 @@ +package eu.kanade.tachiyomi.ui.base.controller + +import android.app.Dialog +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.bluelinelabs.conductor.RestoreViewOnCreateController +import com.bluelinelabs.conductor.Router +import com.bluelinelabs.conductor.RouterTransaction +import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler + +/** + * A controller that displays a dialog window, floating on top of its activity's window. + * This is a wrapper over [Dialog] object like [android.app.DialogFragment]. + * + * + * Implementations should override this class and implement [.onCreateDialog] to create a custom dialog, such as an [android.app.AlertDialog] + */ +abstract class DialogController : RestoreViewOnCreateController { + + protected var dialog: Dialog? = null + private set + + private var dismissed = false + + /** + * Convenience constructor for use when no arguments are needed. + */ + protected constructor() : super(null) + + /** + * Constructor that takes arguments that need to be retained across restarts. + * + * @param args Any arguments that need to be retained. + */ + protected constructor(args: Bundle?) : super(args) + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View { + dialog = onCreateDialog(savedViewState) + dialog!!.ownerActivity = activity + dialog!!.setOnDismissListener { dismissDialog() } + if (savedViewState != null) { + val dialogState = savedViewState.getBundle(SAVED_DIALOG_STATE_TAG) + if (dialogState != null) { + dialog!!.onRestoreInstanceState(dialogState) + } + } + return View(activity) //stub view + } + + override fun onSaveViewState(view: View, outState: Bundle) { + super.onSaveViewState(view, outState) + val dialogState = dialog!!.onSaveInstanceState() + outState.putBundle(SAVED_DIALOG_STATE_TAG, dialogState) + } + + override fun onAttach(view: View) { + super.onAttach(view) + dialog!!.show() + } + + override fun onDetach(view: View) { + super.onDetach(view) + dialog!!.hide() + } + + override fun onDestroyView(view: View) { + super.onDestroyView(view) + dialog!!.setOnDismissListener(null) + dialog!!.dismiss() + dialog = null + } + + /** + * Display the dialog, create a transaction and pushing the controller. + * @param router The router on which the transaction will be applied + */ + open fun showDialog(router: Router) { + showDialog(router, null) + } + + /** + * Display the dialog, create a transaction and pushing the controller. + * @param router The router on which the transaction will be applied + * @param tag The tag for this controller + */ + fun showDialog(router: Router, tag: String?) { + dismissed = false + router.pushController(RouterTransaction.with(this) + .pushChangeHandler(SimpleSwapChangeHandler(false)) + .popChangeHandler(SimpleSwapChangeHandler(false)) + .tag(tag)) + } + + /** + * Dismiss the dialog and pop this controller + */ + fun dismissDialog() { + if (dismissed) { + return + } + router.popController(this) + dismissed = true + } + + /** + * Build your own custom Dialog container such as an [android.app.AlertDialog] + * + * @param savedViewState A bundle for the view's state, which would have been created in [.onSaveViewState] or `null` if no saved state exists. + * @return Return a new Dialog instance to be displayed by the Controller + */ + protected abstract fun onCreateDialog(savedViewState: Bundle?): Dialog + + companion object { + private const val SAVED_DIALOG_STATE_TAG = "android:savedDialogState" + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/NucleusController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/NucleusController.kt index 4df8dbd3fb..5a9250d87c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/NucleusController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/NucleusController.kt @@ -13,7 +13,7 @@ abstract class NucleusController
>(val bundle: Bundle? = null) : private val delegate = NucleusConductorDelegate(this) val presenter: P - get() = delegate.presenter + get() = delegate.presenter!! init { addLifecycleListener(NucleusConductorLifecycleListener(delegate)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorDelegate.java b/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorDelegate.java deleted file mode 100644 index 46034fbf87..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorDelegate.java +++ /dev/null @@ -1,61 +0,0 @@ -package eu.kanade.tachiyomi.ui.base.presenter; - -import android.os.Bundle; -import androidx.annotation.Nullable; - -import nucleus.factory.PresenterFactory; -import nucleus.presenter.Presenter; - -public class NucleusConductorDelegate
{ - - @Nullable private P presenter; - @Nullable private Bundle bundle; - - private PresenterFactory
factory; - - public NucleusConductorDelegate(PresenterFactory
creator) { - this.factory = creator; - } - - public P getPresenter() { - if (presenter == null) { - presenter = factory.createPresenter(); - presenter.create(bundle); - bundle = null; - } - return presenter; - } - - Bundle onSaveInstanceState() { - Bundle bundle = new Bundle(); -// getPresenter(); // Workaround a crash related to saving instance state with child routers - if (presenter != null) { - presenter.save(bundle); - } - return bundle; - } - - void onRestoreInstanceState(Bundle presenterState) { - bundle = presenterState; - } - - void onTakeView(Object view) { - getPresenter(); - if (presenter != null) { - //noinspection unchecked - presenter.takeView(view); - } - } - - void onDropView() { - if (presenter != null) { - presenter.dropView(); - } - } - - void onDestroy() { - if (presenter != null) { - presenter.destroy(); - } - } -} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorDelegate.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorDelegate.kt new file mode 100644 index 0000000000..02ad4f966d --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorDelegate.kt @@ -0,0 +1,45 @@ +package eu.kanade.tachiyomi.ui.base.presenter + +import android.os.Bundle +import nucleus.factory.PresenterFactory +import nucleus.presenter.Presenter + +class NucleusConductorDelegate
>(private val factory: PresenterFactory
) {
+
+ var presenter: P? = null
+ get() {
+ if (field == null) {
+ field = factory.createPresenter()
+ field!!.create(bundle)
+ bundle = null
+ }
+ return field
+ }
+
+ private var bundle: Bundle? = null
+
+ fun onSaveInstanceState(): Bundle {
+ val bundle = Bundle()
+ // getPresenter(); // Workaround a crash related to saving instance state with child routers
+ presenter?.save(bundle)
+ return bundle
+ }
+
+ fun onRestoreInstanceState(presenterState: Bundle?) {
+ bundle = presenterState
+ }
+
+ @Suppress("TYPE_MISMATCH")
+ fun onTakeView(view: Any) {
+ presenter?.takeView(view)
+ }
+
+ fun onDropView() {
+ presenter?.dropView()
+ }
+
+ fun onDestroy() {
+ presenter?.destroy()
+ }
+
+}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorLifecycleListener.java b/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorLifecycleListener.java
deleted file mode 100644
index 90d94e5d45..0000000000
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorLifecycleListener.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package eu.kanade.tachiyomi.ui.base.presenter;
-
-import android.os.Bundle;
-import androidx.annotation.NonNull;
-import android.view.View;
-
-import com.bluelinelabs.conductor.Controller;
-
-public class NucleusConductorLifecycleListener extends Controller.LifecycleListener {
-
- private static final String PRESENTER_STATE_KEY = "presenter_state";
-
- private NucleusConductorDelegate delegate;
-
- public NucleusConductorLifecycleListener(NucleusConductorDelegate delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public void postCreateView(@NonNull Controller controller, @NonNull View view) {
- delegate.onTakeView(controller);
- }
-
- @Override
- public void preDestroyView(@NonNull Controller controller, @NonNull View view) {
- delegate.onDropView();
- }
-
- @Override
- public void preDestroy(@NonNull Controller controller) {
- delegate.onDestroy();
- }
-
- @Override
- public void onSaveInstanceState(@NonNull Controller controller, @NonNull Bundle outState) {
- outState.putBundle(PRESENTER_STATE_KEY, delegate.onSaveInstanceState());
- }
-
- @Override
- public void onRestoreInstanceState(@NonNull Controller controller, @NonNull Bundle savedInstanceState) {
- delegate.onRestoreInstanceState(savedInstanceState.getBundle(PRESENTER_STATE_KEY));
- }
-
-}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorLifecycleListener.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorLifecycleListener.kt
new file mode 100644
index 0000000000..0e25020337
--- /dev/null
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/NucleusConductorLifecycleListener.kt
@@ -0,0 +1,33 @@
+package eu.kanade.tachiyomi.ui.base.presenter
+
+import android.os.Bundle
+import android.view.View
+import com.bluelinelabs.conductor.Controller
+
+class NucleusConductorLifecycleListener(private val delegate: NucleusConductorDelegate<*>) : Controller.LifecycleListener() {
+
+ override fun postCreateView(controller: Controller, view: View) {
+ delegate.onTakeView(controller)
+ }
+
+ override fun preDestroyView(controller: Controller, view: View) {
+ delegate.onDropView()
+ }
+
+ override fun preDestroy(controller: Controller) {
+ delegate.onDestroy()
+ }
+
+ override fun onSaveInstanceState(controller: Controller, outState: Bundle) {
+ outState.putBundle(PRESENTER_STATE_KEY, delegate.onSaveInstanceState())
+ }
+
+ override fun onRestoreInstanceState(controller: Controller, savedInstanceState: Bundle) {
+ delegate.onRestoreInstanceState(savedInstanceState.getBundle(PRESENTER_STATE_KEY))
+ }
+
+ companion object {
+ private const val PRESENTER_STATE_KEY = "presenter_state"
+ }
+
+}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
index 56f128d56e..df055837ab 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
@@ -85,7 +85,7 @@ class ReaderActivity : BaseRxActivity