Still more insets work

Fixed insets for landscape manga info controller + using snackbars for adding and removing mangas
This commit is contained in:
Jay 2019-10-28 02:27:01 -07:00
parent fee8ccab86
commit 197b5cf6a4
9 changed files with 108 additions and 51 deletions

View File

@ -27,7 +27,7 @@ interface GithubService {
}
}
@GET("/repos/inorichi/tachiyomi/releases/latest")
@GET("/repos/Jays2Kings/tachiyomi/releases/latest")
fun getLatestVersion(): Observable<GithubRelease>
}

View File

@ -375,9 +375,6 @@ open class BrowseCatalogueController(bundle: Bundle) :
presenter.requestNext()
}
}
snack?.view?.doOnApplyWindowInsets { v, _, padding ->
v.setPadding(padding.left,0,padding.right,0)
}
}
/**

View File

@ -379,9 +379,6 @@ class ChaptersController : NucleusController<ChaptersPresenter>(),
presenter.addToLibrary()
}
}
snack.view.doOnApplyWindowInsets { v, _, padding ->
v.setPadding(padding.left,0,padding.right,0)
}
}
}

View File

@ -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<MangaInfoPresenter>(),
*/
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)
@ -123,10 +131,24 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
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<ViewGroup.MarginLayoutParams> {
bottomMargin = fabBaseMarginBottom + insets.systemWindowInsetBottom
}
}
else {
manga_genres_tags?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
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<MangaInfoPresenter>(),
override fun onDestroyView(view: View) {
manga_genres_tags.setOnTagClickListener(null)
snack?.dismiss()
super.onDestroyView(view)
}
@ -273,16 +296,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
* 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<MangaInfoPresenter>(),
.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<MangaInfoPresenter>(),
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) {

View File

@ -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))

View File

@ -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)
}
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)

View File

@ -8,12 +8,25 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
android:orientation="vertical"
android:id="@+id/manga_info_layout">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_favorite"
style="@style/Theme.Widget.FABFixed"
app:srcCompat="@drawable/ic_bookmark_border_white_24dp"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_anchorGravity=""/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/manga_cover"
@ -31,29 +44,23 @@
app:layout_constraintVertical_bias="0.0"
android:layout_marginStart="16dp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_favorite"
style="@style/Theme.Widget.FAB"
app:srcCompat="@drawable/ic_bookmark_border_white_24dp"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/info_scrollview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:paddingTop="9dp"
android:paddingBottom="16dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/manga_cover"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp">
android:layout_marginEnd="16dp"
android:clipToPadding="false">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
@ -261,4 +268,5 @@
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>

View File

@ -7,13 +7,15 @@
android:id="@id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
android:orientation="vertical"
android:id="@+id/manga_info_layout">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/guideline"
@ -302,4 +304,5 @@
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>

View File

@ -146,6 +146,15 @@
<item name="layout_behavior">eu.kanade.tachiyomi.widget.FABAnimationUpDown</item>
</style>
<style name="Theme.Widget.FABFixed">
<item name="android:layout_height">@dimen/fab_size</item>
<item name="android:layout_width">@dimen/fab_size</item>
<item name="android:layout_gravity">bottom|end</item>
<item name="android:layout_margin">@dimen/fab_margin</item>
<item name="android:scaleType">fitCenter</item>
<item name="android:tint">@color/md_white_1000</item>
</style>
<style name="Theme.Widget.CardView" parent="CardView">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>