From 197b5cf6a463aa9eccfc0923d7b9073a1f3eb791 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 28 Oct 2019 02:27:01 -0700 Subject: [PATCH] Still more insets work Fixed insets for landscape manga info controller + using snackbars for adding and removing mangas --- .../data/updater/github/GithubService.kt | 2 +- .../browse/BrowseCatalogueController.kt | 3 - .../ui/manga/chapter/ChaptersController.kt | 3 - .../ui/manga/info/MangaInfoController.kt | 76 ++++++++++++++----- .../ui/setting/SettingsAboutController.kt | 2 +- .../kanade/tachiyomi/util/ViewExtensions.kt | 11 ++- .../res/layout-land/manga_info_controller.xml | 40 ++++++---- .../main/res/layout/manga_info_controller.xml | 13 ++-- app/src/main/res/values/styles.xml | 9 +++ 9 files changed, 108 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubService.kt index e19e3528d5..b32a9ff8e6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/github/GithubService.kt @@ -27,7 +27,7 @@ interface GithubService { } } - @GET("/repos/inorichi/tachiyomi/releases/latest") + @GET("/repos/Jays2Kings/tachiyomi/releases/latest") fun getLatestVersion(): Observable } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt index 53d36cb70a..3ccd7b044d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt @@ -375,9 +375,6 @@ open class BrowseCatalogueController(bundle: Bundle) : presenter.requestNext() } } - snack?.view?.doOnApplyWindowInsets { v, _, padding -> - v.setPadding(padding.left,0,padding.right,0) - } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 3c1701e6de..caf00088c0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -379,9 +379,6 @@ class ChaptersController : NucleusController(), presenter.addToLibrary() } } - snack.view.doOnApplyWindowInsets { v, _, padding -> - v.setPadding(padding.left,0,padding.right,0) - } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index 02d44b6a4a..1f5be44e5d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -6,12 +6,12 @@ import android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.content.Intent +import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.drawable.Drawable -import android.net.Uri import android.os.Build import android.os.Bundle -import android.support.customtabs.CustomTabsIntent +import android.support.design.widget.Snackbar import android.support.v4.content.pm.ShortcutInfoCompat import android.support.v4.content.pm.ShortcutManagerCompat import android.support.v4.graphics.drawable.IconCompat @@ -49,6 +49,7 @@ import uy.kohesive.injekt.injectLazy import java.text.DateFormat import java.text.DecimalFormat import java.util.Date +import kotlin.math.max /** * Fragment that shows manga information. @@ -63,6 +64,13 @@ class MangaInfoController : NucleusController(), */ private val preferences: PreferencesHelper by injectLazy() + /** + * Snackbar containing an error message when a request fails. + */ + private var snack: Snackbar? = null + + private var container:View? = null + init { setHasOptionsMenu(true) setOptionsMenuHidden(true) @@ -85,7 +93,7 @@ class MangaInfoController : NucleusController(), fab_favorite.clicks().subscribeUntilDestroy { onFabClick() } // Set onLongClickListener to manage categories when FAB is clicked. - fab_favorite.longClicks().subscribeUntilDestroy{ onFabLongClick() } + fab_favorite.longClicks().subscribeUntilDestroy { onFabLongClick() } // Set SwipeRefresh to refresh manga data. swipe_refresh.refreshes().subscribeUntilDestroy { fetchMangaFromSource() } @@ -123,10 +131,24 @@ class MangaInfoController : NucleusController(), manga_cover.longClicks().subscribeUntilDestroy { copyToClipboard(view.context.getString(R.string.title), presenter.manga.title) } - - view.doOnApplyWindowInsets { v, insets, padding -> + container = (view as ViewGroup).findViewById(R.id.manga_info_layout) as? View + val bottomM = manga_genres_tags.marginBottom + val fabBaseMarginBottom = fab_favorite.marginBottom + container?.doOnApplyWindowInsets { v, insets, padding -> + if (resources?.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) { + fab_favorite?.updateLayoutParams { + bottomMargin = fabBaseMarginBottom + insets.systemWindowInsetBottom + } + } + else { + manga_genres_tags?.updateLayoutParams { + bottomMargin = bottomM + +insets.systemWindowInsetBottom + } + } + } + info_scrollview.doOnApplyWindowInsets { v, insets, padding -> v.updatePaddingRelative( - bottom = padding.bottom + insets.systemWindowInsetBottom + bottom = max(padding.bottom, insets.systemWindowInsetBottom) ) } } @@ -245,6 +267,7 @@ class MangaInfoController : NucleusController(), override fun onDestroyView(view: View) { manga_genres_tags.setOnTagClickListener(null) + snack?.dismiss() super.onDestroyView(view) } @@ -273,16 +296,7 @@ class MangaInfoController : NucleusController(), * Toggles the favorite status and asks for confirmation to delete downloaded chapters. */ private fun toggleFavorite() { - val view = view - - val isNowFavorite = presenter.toggleFavorite() - if (view != null && !isNowFavorite && presenter.hasDownloads()) { - view.snack(view.context.getString(R.string.delete_downloads_for_manga)) { - setAction(R.string.action_delete) { - presenter.deleteDownloads() - } - } - } + presenter.toggleFavorite() } /** @@ -398,9 +412,33 @@ class MangaInfoController : NucleusController(), .showDialog(router) } } - activity?.toast(activity?.getString(R.string.manga_added_library)) + showAddedSnack() } else { - activity?.toast(activity?.getString(R.string.manga_removed_library)) + showRemovedSnack() + } + } + + private fun showAddedSnack() { + val view = container + snack?.dismiss() + snack = view?.snack(view.context.getString(R.string.manga_added_library), Snackbar + .LENGTH_SHORT) + } + + private fun showRemovedSnack() { + val view = container + val hasDownloads = presenter.hasDownloads() + snack?.dismiss() + if (view != null) { + val message = view.context.getString(R.string.manga_removed_library) + + (if (hasDownloads) "\n" + view.context.getString(R.string + .delete_downloads_for_manga) else "") + snack = view.snack(message, (if (hasDownloads) Snackbar.LENGTH_INDEFINITE + else Snackbar.LENGTH_SHORT)) { + if (hasDownloads) setAction(R.string.action_delete) { + presenter.deleteDownloads() + } + } } } @@ -411,7 +449,7 @@ class MangaInfoController : NucleusController(), val manga = presenter.manga if (!manga.favorite) { toggleFavorite() - activity?.toast(activity?.getString(R.string.manga_added_library)) + showAddedSnack() } val categories = presenter.getCategories() if (categories.size <= 1) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt index b6ff16dcae..dced1cd006 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAboutController.kt @@ -80,7 +80,7 @@ class SettingsAboutController : SettingsController() { } preference { title = "Github" - val url = "https://github.com/inorichi/tachiyomi" + val url = "https://github.com/Jays2Kings/tachiyomi" summary = url onClick { val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt index c8dd10466d..48d8bc3226 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt @@ -36,7 +36,8 @@ fun View.getCoordinates() = Point((left + right) / 2, (top + bottom) / 2) * @param length the duration of the snack. * @param f a function to execute in the snack, allowing for example to define a custom action. */ -inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit): Snackbar { +fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: (Snackbar.() -> +Unit)? = null): Snackbar { val snack = Snackbar.make(this, message, length) val textView: TextView = snack.view.findViewById(android.support.design.R.id.snackbar_text) textView.setTextColor(Color.WHITE) @@ -44,7 +45,12 @@ inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Sn Build.VERSION.SDK_INT >= 23 -> snack.config(context, rootWindowInsets.systemWindowInsetBottom) else -> snack.config(context) } - snack.f() + if (f != null) { + snack.f() + } + snack.view.doOnApplyWindowInsets { v, _, padding -> + v.setPadding(padding.left,0,padding.right,0) + } snack.show() return snack } @@ -53,7 +59,6 @@ fun Snackbar.config(context: Context, bottomMargin: Int = 0) { val params = this.view.layoutParams as ViewGroup.MarginLayoutParams params.setMargins(12, 12, 12, 12 + bottomMargin) this.view.layoutParams = params - this.view.background = context.getDrawable(R.drawable.bg_snackbar) ViewCompat.setElevation(this.view, 6f) diff --git a/app/src/main/res/layout-land/manga_info_controller.xml b/app/src/main/res/layout-land/manga_info_controller.xml index bba645590f..0d0d778109 100644 --- a/app/src/main/res/layout-land/manga_info_controller.xml +++ b/app/src/main/res/layout-land/manga_info_controller.xml @@ -8,12 +8,25 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:orientation="vertical" + android:id="@+id/manga_info_layout"> + + + + - - + android:layout_marginEnd="16dp" + android:clipToPadding="false"> + diff --git a/app/src/main/res/layout/manga_info_controller.xml b/app/src/main/res/layout/manga_info_controller.xml index fe78d31821..8b70b06159 100644 --- a/app/src/main/res/layout/manga_info_controller.xml +++ b/app/src/main/res/layout/manga_info_controller.xml @@ -7,13 +7,15 @@ android:id="@id/swipe_refresh" android:layout_width="match_parent" android:layout_height="match_parent"> - - + android:orientation="vertical" + android:id="@+id/manga_info_layout"> + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 6d29eb4692..50e68de444 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -146,6 +146,15 @@ eu.kanade.tachiyomi.widget.FABAnimationUpDown + +