Scale mode option for reader
parent
bdebd0578e
commit
28a9659410
@ -0,0 +1,6 @@
|
|||||||
|
package org.koitharu.kotatsu.core.model
|
||||||
|
|
||||||
|
enum class ZoomMode {
|
||||||
|
|
||||||
|
FIT_CENTER, FIT_HEIGHT, FIT_WIDTH, KEEP_START
|
||||||
|
}
|
||||||
@ -1,5 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.ui.reader
|
|
||||||
|
|
||||||
enum class ReaderAction {
|
|
||||||
REPLACE, PREPEND, APPEND
|
|
||||||
}
|
|
||||||
@ -0,0 +1,48 @@
|
|||||||
|
package org.koitharu.kotatsu.ui.reader.reversed
|
||||||
|
|
||||||
|
import android.graphics.PointF
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
|
import kotlinx.android.synthetic.main.item_page.*
|
||||||
|
import org.koitharu.kotatsu.core.model.ZoomMode
|
||||||
|
import org.koitharu.kotatsu.ui.reader.PageLoader
|
||||||
|
import org.koitharu.kotatsu.ui.reader.standard.PageHolder
|
||||||
|
|
||||||
|
class ReversedPageHolder(parent: ViewGroup, loader: PageLoader) : PageHolder(parent, loader) {
|
||||||
|
|
||||||
|
override fun onImageShowing(zoom: ZoomMode) {
|
||||||
|
ssiv.maxScale = 2f * maxOf(
|
||||||
|
ssiv.width / ssiv.sWidth.toFloat(),
|
||||||
|
ssiv.height / ssiv.sHeight.toFloat()
|
||||||
|
)
|
||||||
|
when (zoom) {
|
||||||
|
ZoomMode.FIT_CENTER -> {
|
||||||
|
ssiv.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE)
|
||||||
|
ssiv.resetScaleAndCenter()
|
||||||
|
}
|
||||||
|
ZoomMode.FIT_HEIGHT -> {
|
||||||
|
ssiv.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM)
|
||||||
|
ssiv.minScale = ssiv.height / ssiv.sHeight.toFloat()
|
||||||
|
ssiv.setScaleAndCenter(
|
||||||
|
ssiv.minScale,
|
||||||
|
PointF(ssiv.sWidth.toFloat(), ssiv.sHeight / 2f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ZoomMode.FIT_WIDTH -> {
|
||||||
|
ssiv.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CUSTOM)
|
||||||
|
ssiv.minScale = ssiv.width / ssiv.sWidth.toFloat()
|
||||||
|
ssiv.setScaleAndCenter(
|
||||||
|
ssiv.minScale,
|
||||||
|
PointF(ssiv.sWidth / 2f, 0f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ZoomMode.KEEP_START -> {
|
||||||
|
ssiv.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE)
|
||||||
|
ssiv.setScaleAndCenter(
|
||||||
|
ssiv.maxScale,
|
||||||
|
PointF(ssiv.sWidth.toFloat(), 0f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package org.koitharu.kotatsu.utils.delegates.prefs
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
|
class IntEnumPreferenceDelegate<E : Enum<*>>(
|
||||||
|
private val cls: Class<E>,
|
||||||
|
private val key: String,
|
||||||
|
private val defValue: E
|
||||||
|
) : ReadWriteProperty<SharedPreferences, E> {
|
||||||
|
|
||||||
|
override fun getValue(thisRef: SharedPreferences, property: KProperty<*>): E {
|
||||||
|
val ord = thisRef.getInt(key, -1)
|
||||||
|
if (ord == -1) {
|
||||||
|
return defValue
|
||||||
|
}
|
||||||
|
return cls.enumConstants?.getOrNull(ord) ?: defValue
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setValue(thisRef: SharedPreferences, property: KProperty<*>, value: E) {
|
||||||
|
thisRef.edit {
|
||||||
|
putInt(key, value.ordinal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue