More consistent usage of visibility extensions

This commit is contained in:
arkon 2020-03-09 18:42:41 -04:00
parent e195257d2a
commit d5ff5fd6f8
13 changed files with 57 additions and 41 deletions

View File

@ -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<ProgressItem.Holder>() {
@ -23,17 +25,17 @@ class ProgressItem : AbstractFlexibleItem<ProgressItem.Holder>() {
}
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>, holder: Holder, position: Int, payloads: List<Any?>) {
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()
}
}

View File

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

View File

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

View File

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

View File

@ -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<TrackSearch>) {
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())
}

View File

@ -312,7 +312,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
} 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<ReaderPresenter>() {
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<ReaderPresenter>() {
subscriptions.add(customFilterColorSubscription)
} else {
customFilterColorSubscription?.let { subscriptions.remove(it) }
color_overlay.visibility = View.GONE
color_overlay.gone()
}
}
@ -767,11 +767,11 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
// 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<ReaderPresenter>() {
* 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())
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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