From d5ff5fd6f878176107139c30f55042ee984d7415 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 9 Mar 2020 18:42:41 -0400 Subject: [PATCH] More consistent usage of visibility extensions --- .../tachiyomi/ui/catalogue/browse/ProgressItem.kt | 10 ++++++---- .../ui/extension/ExtensionDetailsController.kt | 3 ++- .../tachiyomi/ui/library/LibraryGridHolder.kt | 7 ++++--- .../tachiyomi/ui/library/LibraryListHolder.kt | 7 ++++--- .../tachiyomi/ui/manga/track/TrackSearchDialog.kt | 14 ++++++++------ .../kanade/tachiyomi/ui/reader/ReaderActivity.kt | 12 ++++++------ .../tachiyomi/ui/reader/ReaderColorFilterSheet.kt | 10 ++++++---- .../tachiyomi/ui/reader/ReaderSettingsSheet.kt | 3 +-- .../ui/reader/viewer/ReaderProgressBar.kt | 5 +++-- .../ui/reader/viewer/pager/PagerViewer.kt | 6 ++++-- .../ui/reader/viewer/webtoon/WebtoonViewer.kt | 6 ++++-- .../eu/kanade/tachiyomi/widget/ActionToolbar.kt | 7 ++++--- .../kanade/tachiyomi/widget/RevealAnimationView.kt | 8 +++++--- 13 files changed, 57 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/ProgressItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/ProgressItem.kt index 545cff952..7b4aa0329 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/ProgressItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/ProgressItem.kt @@ -9,6 +9,8 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.IFlexible import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.visible class ProgressItem : AbstractFlexibleItem() { @@ -23,17 +25,17 @@ class ProgressItem : AbstractFlexibleItem() { } override fun bindViewHolder(adapter: FlexibleAdapter>, holder: Holder, position: Int, payloads: List) { - holder.progressBar.visibility = View.GONE - holder.progressMessage.visibility = View.GONE + holder.progressBar.gone() + holder.progressMessage.gone() if (!adapter.isEndlessScrollEnabled) { loadMore = false } if (loadMore) { - holder.progressBar.visibility = View.VISIBLE + holder.progressBar.visible() } else { - holder.progressMessage.visibility = View.VISIBLE + holder.progressMessage.visible() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt index da84d5b0e..78aa6ae83 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt @@ -31,6 +31,7 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.system.LocaleHelper +import eu.kanade.tachiyomi.util.view.visible import kotlinx.android.synthetic.main.extension_detail_controller.extension_icon import kotlinx.android.synthetic.main.extension_detail_controller.extension_lang import kotlinx.android.synthetic.main.extension_detail_controller.extension_obsolete @@ -86,7 +87,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : } if (extension.isObsolete) { - extension_obsolete.visibility = View.VISIBLE + extension_obsolete.visible() } val themedContext by lazy { getPreferenceThemeContext() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index 131aebc84..5fe8327aa 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -5,6 +5,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.source.LocalSource +import eu.kanade.tachiyomi.util.view.visibleIf import kotlinx.android.synthetic.main.catalogue_grid_item.download_text import kotlinx.android.synthetic.main.catalogue_grid_item.local_text import kotlinx.android.synthetic.main.catalogue_grid_item.thumbnail @@ -37,16 +38,16 @@ class LibraryGridHolder( // Update the unread count and its visibility. with(unread_text) { - visibility = if (item.manga.unread > 0) View.VISIBLE else View.GONE + visibleIf { item.manga.unread > 0 } text = item.manga.unread.toString() } // Update the download count and its visibility. with(download_text) { - visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE + visibleIf { item.downloadCount > 0 } text = item.downloadCount.toString() } // set local visibility if its local manga - local_text.visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE + local_text.visibleIf { item.manga.source == LocalSource.ID } // Update the cover. GlideApp.with(view.context).clear(thumbnail) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 82e51b4dd..f8f871745 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -5,6 +5,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.source.LocalSource +import eu.kanade.tachiyomi.util.view.visibleIf import kotlinx.android.synthetic.main.catalogue_list_item.download_text import kotlinx.android.synthetic.main.catalogue_list_item.local_text import kotlinx.android.synthetic.main.catalogue_list_item.thumbnail @@ -38,16 +39,16 @@ class LibraryListHolder( // Update the unread count and its visibility. with(unread_text) { - visibility = if (item.manga.unread > 0) View.VISIBLE else View.GONE + visibleIf { item.manga.unread > 0 } text = item.manga.unread.toString() } // Update the download count and its visibility. with(download_text) { - visibility = if (item.downloadCount > 0) View.VISIBLE else View.GONE + visibleIf { item.downloadCount > 0 } text = "${item.downloadCount}" } // show local text badge if local manga - local_text.visibility = if (item.manga.source == LocalSource.ID) View.VISIBLE else View.GONE + local_text.visibleIf { item.manga.source == LocalSource.ID } // Create thumbnail onclick to simulate long click thumbnail.setOnClickListener { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt index 33df2f822..62879ea0c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt @@ -13,6 +13,8 @@ import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.util.lang.plusAssign +import eu.kanade.tachiyomi.util.view.invisible +import eu.kanade.tachiyomi.util.view.visible import java.util.concurrent.TimeUnit import kotlinx.android.synthetic.main.track_search_dialog.view.progress import kotlinx.android.synthetic.main.track_search_dialog.view.track_search @@ -117,23 +119,23 @@ class TrackSearchDialog : DialogController { private fun search(query: String) { val view = dialogView ?: return - view.progress.visibility = View.VISIBLE - view.track_search_list.visibility = View.INVISIBLE + view.progress.visible() + view.track_search_list.invisible() trackController.presenter.search(query, service) } fun onSearchResults(results: List) { selectedItem = null val view = dialogView ?: return - view.progress.visibility = View.INVISIBLE - view.track_search_list.visibility = View.VISIBLE + view.progress.invisible() + view.track_search_list.visible() adapter?.setItems(results) } fun onSearchResultsError() { val view = dialogView ?: return - view.progress.visibility = View.VISIBLE - view.track_search_list.visibility = View.INVISIBLE + view.progress.visible() + view.track_search_list.invisible() adapter?.setItems(emptyList()) } 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 6046132c1..a63b9a51a 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 @@ -312,7 +312,7 @@ class ReaderActivity : BaseRxActivity() { } else { resetDefaultMenuAndBar() } - reader_menu.visibility = View.VISIBLE + reader_menu.visible() if (animate) { val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.enter_from_top) @@ -342,7 +342,7 @@ class ReaderActivity : BaseRxActivity() { val toolbarAnimation = AnimationUtils.loadAnimation(this, R.anim.exit_to_top) toolbarAnimation.setAnimationListener(object : SimpleAnimationListener() { override fun onAnimationEnd(animation: Animation) { - reader_menu.visibility = View.GONE + reader_menu.gone() } }) toolbar.startAnimation(toolbarAnimation) @@ -741,7 +741,7 @@ class ReaderActivity : BaseRxActivity() { subscriptions.add(customFilterColorSubscription) } else { customFilterColorSubscription?.let { subscriptions.remove(it) } - color_overlay.visibility = View.GONE + color_overlay.gone() } } @@ -767,11 +767,11 @@ class ReaderActivity : BaseRxActivity() { // Set black overlay visibility. if (value < 0) { - brightness_overlay.visibility = View.VISIBLE + brightness_overlay.visible() val alpha = (abs(value) * 2.56).toInt() brightness_overlay.setBackgroundColor(Color.argb(alpha, 0, 0, 0)) } else { - brightness_overlay.visibility = View.GONE + brightness_overlay.gone() } } @@ -779,7 +779,7 @@ class ReaderActivity : BaseRxActivity() { * Sets the color filter [value]. */ private fun setColorFilterValue(value: Int) { - color_overlay.visibility = View.VISIBLE + color_overlay.visible() color_overlay.setFilterColor(value, preferences.colorFilterMode().getOrDefault()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt index 42c252849..8b5096967 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt @@ -11,6 +11,8 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.lang.plusAssign +import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import java.util.concurrent.TimeUnit @@ -234,11 +236,11 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activ private fun setCustomBrightnessValue(value: Int, view: View, isDisabled: Boolean = false) = with(view) { // Set black overlay visibility. if (value < 0) { - brightness_overlay.visibility = View.VISIBLE + brightness_overlay.visible() val alpha = (abs(value) * 2.56).toInt() brightness_overlay.setBackgroundColor(Color.argb(alpha, 0, 0, 0)) } else { - brightness_overlay.visibility = View.GONE + brightness_overlay.gone() } if (!isDisabled) @@ -259,7 +261,7 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activ subscriptions.add(customFilterColorSubscription) } else { customFilterColorSubscription?.let { subscriptions.remove(it) } - color_overlay.visibility = View.GONE + color_overlay.gone() } setColorFilterSeekBar(enabled, view) } @@ -270,7 +272,7 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activ * @param view view of the dialog */ private fun setColorFilterValue(@ColorInt color: Int, view: View) = with(view) { - color_overlay.visibility = View.VISIBLE + color_overlay.visible() color_overlay.setFilterColor(color, preferences.colorFilterMode().getOrDefault()) setValues(color, view) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt index d0fc2b1af..e32f6d6cd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.reader import android.os.Build import android.os.Bundle -import android.view.View import android.widget.CompoundButton import android.widget.Spinner import androidx.core.widget.NestedScrollView @@ -87,7 +86,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia show_page_number.bindToPreference(preferences.showPageNumber()) fullscreen.bindToPreference(preferences.fullscreen()) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - cutout_short.visibility = View.VISIBLE + cutout_short.visible() cutout_short.bindToPreference(preferences.cutoutShort()) } keepscreen.bindToPreference(preferences.keepScreenOn()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressBar.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressBar.kt index ed215bf81..30c1aced6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressBar.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/ReaderProgressBar.kt @@ -16,6 +16,7 @@ import android.view.animation.LinearInterpolator import android.view.animation.RotateAnimation import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.util.view.gone import kotlin.math.min /** @@ -155,14 +156,14 @@ class ReaderProgressBar @JvmOverloads constructor( if (visibility == View.GONE) return if (!animate) { - visibility = View.GONE + gone() } else { ObjectAnimator.ofFloat(this, "alpha", 1f, 0f).apply { interpolator = DecelerateInterpolator() duration = 1000 addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator?) { - visibility = View.GONE + gone() alpha = 1f } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt index 57c48b6ce..dc8ce052b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerViewer.kt @@ -12,6 +12,8 @@ import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer +import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.visible import timber.log.Timber /** @@ -63,7 +65,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { } init { - pager.visibility = View.GONE // Don't layout the pager yet + pager.gone() // Don't layout the pager yet pager.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT) pager.offscreenPageLimit = 1 pager.id = R.id.reader_pager @@ -195,7 +197,7 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer { Timber.d("Pager first layout") val pages = chapters.currChapter.pages ?: return moveToPage(pages[chapters.currChapter.requestedPage]) - pager.visibility = View.VISIBLE + pager.visible() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt index 7805300ff..ac509a856 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonViewer.kt @@ -12,6 +12,8 @@ import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer +import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.visible import kotlin.math.max import kotlin.math.min import rx.subscriptions.CompositeSubscription @@ -63,7 +65,7 @@ class WebtoonViewer(val activity: ReaderActivity) : BaseViewer { val subscriptions = CompositeSubscription() init { - recycler.visibility = View.GONE // Don't let the recycler layout yet + recycler.gone() // Don't let the recycler layout yet recycler.layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT) recycler.itemAnimator = null recycler.layoutManager = layoutManager @@ -184,7 +186,7 @@ class WebtoonViewer(val activity: ReaderActivity) : BaseViewer { Timber.d("Recycler first layout") val pages = chapters.currChapter.pages ?: return moveToPage(pages[chapters.currChapter.requestedPage]) - recycler.visibility = View.VISIBLE + recycler.visible() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/ActionToolbar.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/ActionToolbar.kt index 9761c7a76..ef88459ab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/ActionToolbar.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/ActionToolbar.kt @@ -3,12 +3,13 @@ package eu.kanade.tachiyomi.widget import android.content.Context import android.util.AttributeSet import android.view.MenuItem -import android.view.View import android.widget.FrameLayout import androidx.annotation.IdRes import androidx.annotation.MenuRes import androidx.appcompat.view.ActionMode import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.visible import kotlinx.android.synthetic.main.common_action_toolbar.view.common_action_menu import kotlinx.android.synthetic.main.common_action_toolbar.view.common_action_toolbar @@ -47,13 +48,13 @@ class ActionToolbar @JvmOverloads constructor(context: Context, attrs: Attribute common_action_menu.setOnMenuItemClickListener { listener(it) } } - common_action_toolbar.visibility = View.VISIBLE + common_action_toolbar.visible() } /** * Hide the menu toolbar. */ fun hide() { - common_action_toolbar.visibility = View.GONE + common_action_toolbar.gone() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/RevealAnimationView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/RevealAnimationView.kt index 9a79b0c68..94594dc21 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/RevealAnimationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/RevealAnimationView.kt @@ -6,6 +6,8 @@ import android.content.Context import android.util.AttributeSet import android.view.View import android.view.ViewAnimationUtils +import eu.kanade.tachiyomi.util.view.invisible +import eu.kanade.tachiyomi.util.view.visible class RevealAnimationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : View(context, attrs) { @@ -19,7 +21,7 @@ class RevealAnimationView @JvmOverloads constructor(context: Context, attrs: Att */ fun hideRevealEffect(centerX: Int, centerY: Int, initialRadius: Int) { // Make the view visible. - this.visibility = View.VISIBLE + this.visible() // Create the animation (the final radius is zero). val anim = ViewAnimationUtils.createCircularReveal( @@ -32,7 +34,7 @@ class RevealAnimationView @JvmOverloads constructor(context: Context, attrs: Att anim.addListener(object : AnimatorListenerAdapter() { override fun onAnimationEnd(animation: Animator) { super.onAnimationEnd(animation) - this@RevealAnimationView.visibility = View.INVISIBLE + this@RevealAnimationView.invisible() } }) @@ -49,7 +51,7 @@ class RevealAnimationView @JvmOverloads constructor(context: Context, attrs: Att * @return sdk version lower then 21 */ fun showRevealEffect(centerX: Int, centerY: Int, listener: Animator.AnimatorListener): Boolean { - this.visibility = View.VISIBLE + this.visible() val height = this.height