don't add tablet interface's jay the 7 users who use them complain (#324)

* don't add tablet interface's jay the 7 users who use them complain

* fix formatting
This commit is contained in:
Carlos 2020-05-04 19:43:01 -04:00 committed by GitHub
parent 31800027a1
commit f890f5cfff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 137 deletions

View File

@ -11,7 +11,6 @@ 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.Color
import android.graphics.Rect
@ -19,7 +18,6 @@ import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
@ -30,12 +28,10 @@ import android.view.ViewPropertyAnimator
import android.view.WindowInsets
import android.view.animation.DecelerateInterpolator
import android.view.inputmethod.InputMethodManager
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.view.ActionMode
import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import androidx.palette.graphics.Palette
import androidx.recyclerview.widget.ItemTouchHelper
@ -102,9 +98,7 @@ import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.isInNightMode
import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.system.pxToDp
import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
import eu.kanade.tachiyomi.util.view.getText
import eu.kanade.tachiyomi.util.view.hide
import eu.kanade.tachiyomi.util.view.requestPermissionsSafe
@ -157,7 +151,8 @@ class MangaDetailsController : BaseController,
}
constructor(mangaId: Long) : this(
Injekt.get<DatabaseHelper>().getManga(mangaId).executeAsBlocking())
Injekt.get<DatabaseHelper>().getManga(mangaId).executeAsBlocking()
)
constructor(bundle: Bundle) : this(bundle.getLong(MANGA_EXTRA)) {
val notificationId = bundle.getInt("notificationId", -1)
@ -184,11 +179,6 @@ class MangaDetailsController : BaseController,
private var scrollAnim: ViewPropertyAnimator? = null
var chapterPopupMenu: Pair<Int, PopupMenu>? = null
// Tablet Layout
var isTablet = false
var tabletRecycler: RecyclerView? = null
private var tabletAdapter: MangaDetailsAdapter? = null
private var query = ""
private var adapter: MangaDetailsAdapter? = null
@ -212,7 +202,6 @@ class MangaDetailsController : BaseController,
super.onViewCreated(view)
coverColor = null
setTabletMode(view)
setRecycler(view)
setPaletteColor()
setFastScroller()
@ -231,31 +220,6 @@ class MangaDetailsController : BaseController,
super.onDestroyView(view)
}
/** Check if device is tablet, and create a second recycler to hold the details header if so */
private fun setTabletMode(view: View) {
isTablet = isTabletSize()
if (isTablet) {
tabletRecycler = RecyclerView(view.context)
linear_recycler_layout.addView(tabletRecycler, 0)
tabletRecycler?.updateLayoutParams<LinearLayout.LayoutParams> {
weight = 0.4f
height = ViewGroup.LayoutParams.MATCH_PARENT
width = ViewGroup.LayoutParams.MATCH_PARENT
}
tabletRecycler?.clipToPadding = false
tabletAdapter = MangaDetailsAdapter(this)
tabletRecycler?.adapter = tabletAdapter
tabletRecycler?.layoutManager = LinearLayoutManager(view.context)
val divider = View(view.context)
divider.setBackgroundColor(ContextCompat.getColor(view.context, R.color.divider))
linear_recycler_layout.addView(divider, 1)
divider.updateLayoutParams<LinearLayout.LayoutParams> {
height = ViewGroup.LayoutParams.MATCH_PARENT
width = 1.dpToPx
}
}
}
/** Set adapter, insets, and scroll listener for recycler view */
private fun setRecycler(view: View) {
adapter = MangaDetailsAdapter(this)
@ -276,27 +240,19 @@ class MangaDetailsController : BaseController,
swipe_refresh.setDistanceToTriggerSync(70.dpToPx)
activity!!.appbar.elevation = 0f
if (isTablet) {
recycler.doOnApplyWindowInsets { _, insets, _ ->
setInsets(insets, appbarHeight, offset)
}
} else {
scrollViewWith(recycler, padBottom = true, customPadding = true, afterInsets = { insets ->
setInsets(insets, appbarHeight, offset)
}, liftOnScroll = {
colorToolbar(it)
})
}
scrollViewWith(recycler, padBottom = true, customPadding = true, afterInsets = { insets ->
setInsets(insets, appbarHeight, offset)
}, liftOnScroll = {
colorToolbar(it)
})
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (!isTablet) {
val atTop = !recycler.canScrollVertically(-1)
val tY = getHeader()?.backdrop?.translationY ?: 0f
getHeader()?.backdrop?.translationY = max(0f, tY + dy * 0.25f)
if (atTop) getHeader()?.backdrop?.translationY = 0f
}
val atTop = !recycler.canScrollVertically(-1)
val tY = getHeader()?.backdrop?.translationY ?: 0f
getHeader()?.backdrop?.translationY = max(0f, tY + dy * 0.25f)
if (atTop) getHeader()?.backdrop?.translationY = 0f
}
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
@ -319,11 +275,9 @@ class MangaDetailsController : BaseController,
private fun setInsets(insets: WindowInsets, appbarHeight: Int, offset: Int) {
recycler?.updatePaddingRelative(bottom = insets.systemWindowInsetBottom)
tabletRecycler?.updatePaddingRelative(bottom = insets.systemWindowInsetBottom)
headerHeight = appbarHeight + insets.systemWindowInsetTop
swipe_refresh.setProgressViewOffset(false, (-40).dpToPx, headerHeight + offset)
// 1dp extra to line up chapter header and manga header
if (isTablet) recycler.updatePaddingRelative(top = headerHeight + 1.dpToPx)
getHeader()?.setTopHeight(headerHeight)
fast_scroll_layout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = headerHeight
@ -365,9 +319,7 @@ class MangaDetailsController : BaseController,
(recycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(
itemPosition, headerHeight
)
if (!isTablet) {
colorToolbar(itemPosition > 0, false)
}
colorToolbar(itemPosition > 0, false)
}
}
}
@ -396,15 +348,15 @@ class MangaDetailsController : BaseController,
)
colorAnimator?.cancel()
if (animate) {
colorAnimator = ValueAnimator.ofObject(
android.animation.ArgbEvaluator(), colorFrom, colorTo
)
colorAnimator?.duration = 250 // milliseconds
colorAnimator?.addUpdateListener { animator ->
(activity as MainActivity).toolbar.setBackgroundColor(animator.animatedValue as Int)
activity?.window?.statusBarColor = (animator.animatedValue as Int)
}
colorAnimator?.start()
colorAnimator = ValueAnimator.ofObject(
android.animation.ArgbEvaluator(), colorFrom, colorTo
)
colorAnimator?.duration = 250 // milliseconds
colorAnimator?.addUpdateListener { animator ->
(activity as MainActivity).toolbar.setBackgroundColor(animator.animatedValue as Int)
activity?.window?.statusBarColor = (animator.animatedValue as Int)
}
colorAnimator?.start()
} else {
(activity as MainActivity).toolbar.setBackgroundColor(colorTo)
activity?.window?.statusBarColor = colorTo
@ -444,7 +396,7 @@ class MangaDetailsController : BaseController,
}
}
override fun onLoadCleared(placeholder: Drawable?) { }
override fun onLoadCleared(placeholder: Drawable?) {}
})
}
@ -488,28 +440,12 @@ class MangaDetailsController : BaseController,
translucentColor
} else Color.TRANSPARENT
(activity as MainActivity).appbar.setBackgroundColor(Color.TRANSPARENT)
(activity as MainActivity).toolbar.setBackgroundColor(activity?.window?.statusBarColor
?: Color.TRANSPARENT)
(activity as MainActivity).toolbar.setBackgroundColor(
activity?.window?.statusBarColor
?: Color.TRANSPARENT
)
}
private fun isTabletSize(): Boolean {
val activity = activity ?: return false
if ((activity.resources.configuration.screenLayout and Configuration
.SCREENLAYOUT_SIZE_MASK) < Configuration.SCREENLAYOUT_SIZE_LARGE)
return false
val displayMetrics = DisplayMetrics()
activity.windowManager?.defaultDisplay?.getMetrics(displayMetrics)
return displayMetrics.widthPixels.pxToDp >= 720
}
fun hasTabletHeight(): Boolean {
val activity = activity ?: return false
if ((activity.resources.configuration.screenLayout and Configuration
.SCREENLAYOUT_SIZE_MASK) < Configuration.SCREENLAYOUT_SIZE_LARGE) return false
val displayMetrics = DisplayMetrics()
activity.windowManager?.defaultDisplay?.getMetrics(displayMetrics)
return displayMetrics.heightPixels.pxToDp >= 720
}
//endregion
//region Lifecycle methods
@ -548,7 +484,8 @@ class MangaDetailsController : BaseController,
R.attr.colorSecondary
) ?: Color.BLACK
if (router.backstackSize > 0 &&
router.backstack.last().controller() !is MangaDetailsController) {
router.backstack.last().controller() !is MangaDetailsController
) {
(activity as? MainActivity)?.appbar?.setBackgroundColor(colorSecondary)
(activity as? MainActivity)?.toolbar?.setBackgroundColor(colorSecondary)
@ -614,8 +551,10 @@ class MangaDetailsController : BaseController,
//region Recycler methods
fun updateChapterDownload(download: Download) {
getHolder(download.chapter)?.notifyStatus(download.status, presenter.isLockedFromSearch,
download.progress)
getHolder(download.chapter)?.notifyStatus(
download.status, presenter.isLockedFromSearch,
download.progress
)
}
private fun getHolder(chapter: Chapter): ChapterHolder? {
@ -623,8 +562,7 @@ class MangaDetailsController : BaseController,
}
private fun getHeader(): MangaHeaderHolder? {
return if (isTablet) tabletRecycler?.findViewHolderForAdapterPosition(0) as? MangaHeaderHolder
else recycler.findViewHolderForAdapterPosition(0) as? MangaHeaderHolder
return recycler.findViewHolderForAdapterPosition(0) as? MangaHeaderHolder
}
fun updateHeader() {
@ -652,12 +590,7 @@ class MangaDetailsController : BaseController,
}
private fun addMangaHeader() {
if (tabletAdapter?.scrollableHeaders?.isEmpty() == true) {
tabletAdapter?.removeAllScrollableHeaders()
tabletAdapter?.addScrollableHeader(presenter.headerItem)
adapter?.removeAllScrollableHeaders()
adapter?.addScrollableHeader(presenter.tabletChapterHeaderItem!!)
} else if (!isTablet && adapter?.scrollableHeaders?.isEmpty() == true) {
if (adapter?.scrollableHeaders?.isEmpty() == true) {
adapter?.removeAllScrollableHeaders()
adapter?.addScrollableHeader(presenter.headerItem)
}
@ -818,8 +751,10 @@ class MangaDetailsController : BaseController,
inflater.inflate(R.menu.manga_details, menu)
val editItem = menu.findItem(R.id.action_edit)
editItem.isVisible = presenter.manga.favorite && !presenter.isLockedFromSearch
editItem.title = view?.context?.getString(if (manga?.source == LocalSource.ID)
R.string.edit else R.string.edit_cover)
editItem.title = view?.context?.getString(
if (manga?.source == LocalSource.ID)
R.string.edit else R.string.edit_cover
)
menu.findItem(R.id.action_download).isVisible = !presenter.isLockedFromSearch &&
manga?.source != LocalSource.ID
menu.findItem(R.id.action_mark_all_as_read).isVisible =
@ -833,8 +768,10 @@ class MangaDetailsController : BaseController,
presenter.hasBookmark() && !presenter.isLockedFromSearch
menu.findItem(R.id.action_migrate).isVisible = !presenter.isLockedFromSearch &&
manga?.source != LocalSource.ID && presenter.manga.favorite
menu.findItem(R.id.action_migrate).title = view?.context?.getString(R.string.migrate_,
presenter.manga.mangaType(view!!.context))
menu.findItem(R.id.action_migrate).title = view?.context?.getString(
R.string.migrate_,
presenter.manga.mangaType(view!!.context)
)
val iconPrimary = view?.context?.getResourceColor(android.R.attr.textColorPrimary)
?: Color.BLACK
menu.findItem(R.id.action_download).icon?.mutate()?.setTint(iconPrimary)
@ -853,10 +790,8 @@ class MangaDetailsController : BaseController,
setOnQueryTextChangeListener(searchView) {
query = it ?: ""
if (!isTablet) {
if (query.isNotEmpty()) getHeader()?.collapse()
else getHeader()?.expand()
}
if (query.isNotEmpty()) getHeader()?.collapse()
else getHeader()?.expand()
adapter?.setFilter(query)
adapter?.performFilter()
@ -898,7 +833,8 @@ class MangaDetailsController : BaseController,
PreMigrationController.navigateToMigration(
presenter.preferences.skipPreMigration().getOrDefault(),
router,
listOf(manga!!.id!!))
listOf(manga!!.id!!)
)
R.id.action_mark_all_as_read -> {
MaterialDialog(view!!.context).message(R.string.mark_all_chapters_as_read)
.positiveButton(R.string.mark_as_read) {
@ -923,6 +859,7 @@ class MangaDetailsController : BaseController,
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
presenter.shareManga(resource)
}
override fun onLoadCleared(placeholder: Drawable?) {}
override fun onLoadFailed(errorDrawable: Drawable?) {
@ -964,8 +901,10 @@ class MangaDetailsController : BaseController,
}
val activity = activity ?: return
val intent = WebViewActivity.newIntent(activity.applicationContext, source.id, url, presenter.manga
.title)
val intent = WebViewActivity.newIntent(
activity.applicationContext, source.id, url, presenter.manga
.title
)
startActivity(intent)
}
@ -988,8 +927,8 @@ class MangaDetailsController : BaseController,
R.plurals.remove_n_chapters, chapters.size, chapters.size
)
).positiveButton(R.string.remove) {
presenter.deleteChapters(chapters)
}.negativeButton(android.R.string.cancel).show()
presenter.deleteChapters(chapters)
}.negativeButton(android.R.string.cancel).show()
}
private fun downloadChapters(choice: Int) {
@ -1038,10 +977,13 @@ class MangaDetailsController : BaseController,
private fun downloadChapters(chapters: List<ChapterItem>) {
val view = view ?: return
presenter.downloadChapters(chapters)
val text = view.context.getString(R.string.add_x_to_library, presenter.manga.mangaType
(view.context).toLowerCase(Locale.ROOT))
val text = view.context.getString(
R.string.add_x_to_library, presenter.manga.mangaType
(view.context).toLowerCase(Locale.ROOT)
)
if (!presenter.manga.favorite && (snack == null ||
snack?.getText() != text)) {
snack?.getText() != text)
) {
snack = view.snack(text, Snackbar.LENGTH_INDEFINITE) {
setAction(R.string.add) {
presenter.setFavorite(true)
@ -1069,9 +1011,11 @@ class MangaDetailsController : BaseController,
}
val item = presenter.getNextUnreadChapter()
if (item != null) {
openChapter(item.chapter)
openChapter(item.chapter)
} else if (snack == null || snack?.getText() != view?.context?.getString(
R.string.next_chapter_not_found)) {
R.string.next_chapter_not_found
)
) {
snack = view?.snack(R.string.next_chapter_not_found, Snackbar.LENGTH_LONG) {
addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
@ -1131,8 +1075,8 @@ class MangaDetailsController : BaseController,
}.toTypedArray()
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected).showDialog(
router
)
router
)
} else {
if (!manga.favorite) {
toggleMangaFavorite()
@ -1307,8 +1251,10 @@ class MangaDetailsController : BaseController,
}
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean {
mode?.title = view?.context?.getString(if (startingDLChapterPos == null)
R.string.select_starting_chapter else R.string.select_ending_chapter)
mode?.title = view?.context?.getString(
if (startingDLChapterPos == null)
R.string.select_starting_chapter else R.string.select_ending_chapter
)
return false
}
@ -1333,8 +1279,10 @@ class MangaDetailsController : BaseController,
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.type = "image/*"
startActivityForResult(
Intent.createChooser(intent,
resources?.getString(R.string.select_cover_image)),
Intent.createChooser(
intent,
resources?.getString(R.string.select_cover_image)
),
101
)
} else {

View File

@ -75,15 +75,9 @@ class MangaDetailsPresenter(
private set
var headerItem = MangaHeaderItem(manga, controller.fromCatalogue)
var tabletChapterHeaderItem: MangaHeaderItem? = null
fun onCreate() {
headerItem.startExpanded = controller.hasTabletHeight() || headerItem.startExpanded
headerItem.isTablet = controller.isTablet
if (controller.isTablet) {
tabletChapterHeaderItem = MangaHeaderItem(manga, false)
tabletChapterHeaderItem?.isChapterHeader = true
}
isLockedFromSearch = SecureActivityDelegate.shouldBeLocked()
headerItem.isLocked = isLockedFromSearch
downloadManager.addListener(this)
@ -313,6 +307,7 @@ class MangaDetailsPresenter(
private fun hasTensOfChapters(chapters: List<ChapterItem>): Boolean {
return chapters.size in 21..300
}
/**
* Returns the next unread chapter or null if everything is read.
*/

View File

@ -36,8 +36,7 @@ import kotlinx.android.synthetic.main.manga_header_item.*
class MangaHeaderHolder(
private val view: View,
private val adapter: MangaDetailsAdapter,
startExpanded: Boolean,
isTablet: Boolean = false
startExpanded: Boolean
) : BaseFlexibleViewHolder(view, adapter) {
private var showReadingButton = true
@ -97,7 +96,6 @@ class MangaHeaderHolder(
track_button.setOnClickListener { adapter.delegate.showTrackingSheet() }
if (startExpanded) expandDesc()
else collapseDesc()
if (isTablet) chapter_layout.gone()
} else {
filter_button.updateLayoutParams<ViewGroup.MarginLayoutParams> {
marginEnd = 12.dpToPx

View File

@ -12,7 +12,6 @@ import eu.kanade.tachiyomi.util.system.HashCode
class MangaHeaderItem(val manga: Manga, var startExpanded: Boolean) :
AbstractFlexibleItem<MangaHeaderHolder>() {
var isTablet = false
var isChapterHeader = false
var isLocked = false
@ -29,7 +28,7 @@ class MangaHeaderItem(val manga: Manga, var startExpanded: Boolean) :
}
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): MangaHeaderHolder {
return MangaHeaderHolder(view, adapter as MangaDetailsAdapter, startExpanded, isTablet)
return MangaHeaderHolder(view, adapter as MangaDetailsAdapter, startExpanded)
}
override fun bindViewHolder(