Fix #577. Fix language not applied in reader activity.

This commit is contained in:
len 2016-12-14 22:33:24 +01:00
parent 97e3b5d2ab
commit 816cc17ed3
8 changed files with 37 additions and 74 deletions

View file

@ -3,10 +3,15 @@ package eu.kanade.tachiyomi.ui.base.activity
import android.os.Bundle import android.os.Bundle
import eu.kanade.tachiyomi.App import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.util.LocaleHelper
import nucleus.view.NucleusAppCompatActivity import nucleus.view.NucleusAppCompatActivity
abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P>(), ActivityMixin { abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P>(), ActivityMixin {
init {
LocaleHelper.updateCfg(this)
}
override fun onCreate(savedState: Bundle?) { override fun onCreate(savedState: Bundle?) {
val superFactory = presenterFactory val superFactory = presenterFactory
setPresenterFactory { setPresenterFactory {

View file

@ -227,7 +227,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
toast(error.message) toast(error.message)
} }
fun onLongPress(page: Page) { fun onLongClick(page: Page) {
MaterialDialog.Builder(this) MaterialDialog.Builder(this)
.title(getString(R.string.options)) .title(getString(R.string.options))
.items(R.array.reader_image_options) .items(R.array.reader_image_options)

View file

@ -212,6 +212,16 @@ abstract class BaseReader : BaseFragment() {
moveLeft() moveLeft()
} }
/**
* Method the implementations can call to show a menu with options for the given page.
*/
fun onLongClick(page: Page?): Boolean {
if (isAdded && page != null) {
readerActivity.onLongClick(page)
}
return true
}
/** /**
* Sets the active decoder class. * Sets the active decoder class.
* *

View file

@ -71,6 +71,7 @@ class PageView @JvmOverloads constructor(context: Context, attrs: AttributeSet?
setBitmapDecoderClass(reader.bitmapDecoderClass) setBitmapDecoderClass(reader.bitmapDecoderClass)
setVerticalScrollingParent(reader is VerticalReader) setVerticalScrollingParent(reader is VerticalReader)
setOnTouchListener { v, motionEvent -> reader.gestureDetector.onTouchEvent(motionEvent) } setOnTouchListener { v, motionEvent -> reader.gestureDetector.onTouchEvent(motionEvent) }
setOnLongClickListener { reader.onLongClick(page) }
setOnImageEventListener(object : SubsamplingScaleImageView.DefaultOnImageEventListener() { setOnImageEventListener(object : SubsamplingScaleImageView.DefaultOnImageEventListener() {
override fun onReady() { override fun onReady() {
onImageDecoded(reader) onImageDecoded(reader)

View file

@ -66,7 +66,7 @@ abstract class PagerReader : BaseReader() {
/** /**
* Gesture detector for touch events. * Gesture detector for touch events.
*/ */
val gestureDetector by lazy { createGestureDetector() } val gestureDetector by lazy { GestureDetector(context, ImageGestureListener()) }
/** /**
* Subscriptions for reader settings. * Subscriptions for reader settings.
@ -166,37 +166,24 @@ abstract class PagerReader : BaseReader() {
} }
/** /**
* Creates the gesture detector for the pager. * Gesture detector for Subsampling Scale Image View.
*
* @return a gesture detector.
*/ */
protected fun createGestureDetector(): GestureDetector { inner class ImageGestureListener : GestureDetector.SimpleOnGestureListener() {
return GestureDetector(activity, object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
if (isAdded) {
val positionX = e.x
if (positionX < pager.width * LEFT_REGION) { override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
if (tappingEnabled) moveLeft() if (isAdded) {
} else if (positionX > pager.width * RIGHT_REGION) { val positionX = e.x
if (tappingEnabled) moveRight()
} else {
readerActivity.toggleMenu()
}
}
return true
}
override fun onLongPress(e: MotionEvent?) { if (positionX < pager.width * LEFT_REGION) {
if (isAdded) { if (tappingEnabled) moveLeft()
val page = adapter.pages.getOrNull(pager.currentItem) } else if (positionX > pager.width * RIGHT_REGION) {
if (page != null) if (tappingEnabled) moveRight()
readerActivity.onLongPress(page) } else {
else readerActivity.toggleMenu()
context.toast(getString(R.string.unknown_error))
} }
} }
}) return true
}
} }
/** /**

View file

@ -22,12 +22,7 @@ class WebtoonAdapter(val fragment: WebtoonReader) : RecyclerView.Adapter<Webtoon
/** /**
* Touch listener for images in holders. * Touch listener for images in holders.
*/ */
val imageTouchListener = View.OnTouchListener { v, ev -> fragment.imageGestureDetector.onTouchEvent(ev) } val touchListener = View.OnTouchListener { v, ev -> fragment.imageGestureDetector.onTouchEvent(ev) }
/**
* Touch listener for the other views.
*/
val viewTouchListener = View.OnTouchListener { v, ev -> fragment.viewGestureDetector.onTouchEvent(ev) }
/** /**
* Returns the number of pages. * Returns the number of pages.

View file

@ -63,7 +63,8 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter)
setRegionDecoderClass(webtoonReader.regionDecoderClass) setRegionDecoderClass(webtoonReader.regionDecoderClass)
setBitmapDecoderClass(webtoonReader.bitmapDecoderClass) setBitmapDecoderClass(webtoonReader.bitmapDecoderClass)
setVerticalScrollingParent(true) setVerticalScrollingParent(true)
setOnTouchListener(adapter.imageTouchListener) setOnTouchListener(adapter.touchListener)
setOnLongClickListener { webtoonReader.onLongClick(page) }
setOnImageEventListener(object : SubsamplingScaleImageView.DefaultOnImageEventListener() { setOnImageEventListener(object : SubsamplingScaleImageView.DefaultOnImageEventListener() {
override fun onReady() { override fun onReady() {
onImageDecoded() onImageDecoded()
@ -77,7 +78,7 @@ class WebtoonHolder(private val view: View, private val adapter: WebtoonAdapter)
view.progress_container.minimumHeight = view.resources.displayMetrics.heightPixels * 2 view.progress_container.minimumHeight = view.resources.displayMetrics.heightPixels * 2
view.setOnTouchListener(adapter.viewTouchListener) view.setOnTouchListener(adapter.touchListener)
view.retry_button.setOnTouchListener { v, event -> view.retry_button.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_UP) { if (event.action == MotionEvent.ACTION_UP) {
readerActivity.presenter.retryPage(page) readerActivity.presenter.retryPage(page)

View file

@ -3,14 +3,11 @@ package eu.kanade.tachiyomi.ui.reader.viewer.webtoon
import android.os.Bundle import android.os.Bundle
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.view.* import android.view.*
import android.view.GestureDetector.SimpleOnGestureListener
import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.source.model.Page import eu.kanade.tachiyomi.data.source.model.Page
import eu.kanade.tachiyomi.ui.reader.ReaderChapter import eu.kanade.tachiyomi.ui.reader.ReaderChapter
import eu.kanade.tachiyomi.ui.reader.viewer.base.BaseReader import eu.kanade.tachiyomi.ui.reader.viewer.base.BaseReader
import eu.kanade.tachiyomi.util.toast
import eu.kanade.tachiyomi.widget.PreCachingLayoutManager import eu.kanade.tachiyomi.widget.PreCachingLayoutManager
import rx.subscriptions.CompositeSubscription import rx.subscriptions.CompositeSubscription
@ -59,11 +56,6 @@ class WebtoonReader : BaseReader() {
*/ */
val imageGestureDetector by lazy { GestureDetector(context, ImageGestureListener()) } val imageGestureDetector by lazy { GestureDetector(context, ImageGestureListener()) }
/**
* Gesture detector for other views touch events.
*/
val viewGestureDetector by lazy { GestureDetector(context, ViewGestureListener()) }
/** /**
* Subscriptions used while the view exists. * Subscriptions used while the view exists.
*/ */
@ -127,14 +119,9 @@ class WebtoonReader : BaseReader() {
} }
/** /**
* Gesture detector for Subsampling Scale Image View. [onDown] needs to be false or else * Gesture detector for Subsampling Scale Image View.
* double tap to zoom doesn't work.
*/ */
inner open class ImageGestureListener : SimpleOnGestureListener() { inner class ImageGestureListener : GestureDetector.SimpleOnGestureListener() {
override fun onDown(e: MotionEvent): Boolean {
return false
}
override fun onSingleTapConfirmed(e: MotionEvent): Boolean { override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
if (isAdded) { if (isAdded) {
@ -150,29 +137,6 @@ class WebtoonReader : BaseReader() {
} }
return true return true
} }
override fun onLongPress(e: MotionEvent) {
if (isAdded) {
val child = recycler.findChildViewUnder(e.rawX, e.rawY)
val position = recycler.getChildAdapterPosition(child)
val page = adapter.pages?.getOrNull(position)
if (page != null)
readerActivity.onLongPress(page)
else
context.toast(getString(R.string.unknown_error))
}
}
}
/**
* Gesture detector for other views. [onDown] needs to be true here or it will incorrectly
* detect events.
*/
inner class ViewGestureListener : ImageGestureListener() {
override fun onDown(e: MotionEvent): Boolean {
return true
}
} }
/** /**