Minor code cleanup

This commit is contained in:
arkon
2020-01-07 19:20:08 -05:00
parent 0d5099f230
commit 5cddb269d6
67 changed files with 184 additions and 184 deletions
@@ -43,6 +43,7 @@ import timber.log.Timber
import uy.kohesive.injekt.injectLazy
import java.io.File
import java.util.concurrent.TimeUnit
import kotlin.math.abs
/**
* Activity containing the reader of Tachiyomi. This activity is mostly a container of the
@@ -692,18 +693,22 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
*/
private fun setCustomBrightnessValue(value: Int) {
// Calculate and set reader brightness.
val readerBrightness = if (value > 0) {
value / 100f
} else if (value < 0) {
0.01f
} else WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
val readerBrightness = when {
value > 0 -> {
value / 100f
}
value < 0 -> {
0.01f
}
else -> WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
}
window.attributes = window.attributes.apply { screenBrightness = readerBrightness }
// Set black overlay visibility.
if (value < 0) {
brightness_overlay.visibility = View.VISIBLE
val alpha = (Math.abs(value) * 2.56).toInt()
val alpha = (abs(value) * 2.56).toInt()
brightness_overlay.setBackgroundColor(Color.argb(alpha, 0, 0, 0))
} else {
brightness_overlay.visibility = View.GONE
@@ -1,12 +1,12 @@
package eu.kanade.tachiyomi.ui.reader
import android.graphics.Color
import androidx.annotation.ColorInt
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import android.view.View
import android.view.ViewGroup
import android.widget.SeekBar
import androidx.annotation.ColorInt
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
@@ -14,12 +14,14 @@ import eu.kanade.tachiyomi.util.plusAssign
import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
import kotlinx.android.synthetic.main.reader_color_filter.*
import kotlinx.android.synthetic.main.reader_color_filter_sheet.*
import kotlinx.android.synthetic.main.reader_color_filter_sheet.brightness_overlay
import kotlinx.android.synthetic.main.reader_color_filter_sheet.color_overlay
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import rx.subscriptions.CompositeSubscription
import uy.kohesive.injekt.injectLazy
import java.util.concurrent.TimeUnit
import kotlin.math.abs
/**
* Color filter sheet to toggle custom filter and brightness overlay.
@@ -221,7 +223,7 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activ
// Set black overlay visibility.
if (value < 0) {
brightness_overlay.visibility = View.VISIBLE
val alpha = (Math.abs(value) * 2.56).toInt()
val alpha = (abs(value) * 2.56).toInt()
brightness_overlay.setBackgroundColor(Color.argb(alpha, 0, 0, 0))
} else {
brightness_overlay.visibility = View.GONE
@@ -13,7 +13,7 @@ class ReaderColorFilterView(
private val colorFilterPaint: Paint = Paint()
fun setFilterColor(color: Int, filterMode: Int) {
colorFilterPaint.setColor(color)
colorFilterPaint.color = color
colorFilterPaint.xfermode = PorterDuffXfermode(when (filterMode) {
1 -> PorterDuff.Mode.MULTIPLY
2 -> PorterDuff.Mode.SCREEN
@@ -90,7 +90,7 @@ class ReaderPresenter(
val chaptersForReader =
if (preferences.skipRead()) {
var list = dbChapters.filter { it -> !it.read }.toMutableList()
val list = dbChapters.filter { !it.read }.toMutableList()
val find = list.find { it.id == chapterId }
if (find == null) {
list.add(selectedChapter)
@@ -57,8 +57,9 @@ class SaveImageNotifier(private val context: Context) {
setStyle(NotificationCompat.BigPictureStyle().bigPicture(image))
setLargeIcon(image)
setAutoCancel(true)
// Clear old actions if they exist
if (!mActions.isEmpty())
if (mActions.isNotEmpty())
mActions.clear()
setContentIntent(NotificationHandler.openImagePendingActivity(context, file))
@@ -70,8 +71,8 @@ class SaveImageNotifier(private val context: Context) {
addAction(R.drawable.ic_delete_grey_24dp,
context.getString(R.string.action_delete),
NotificationReceiver.deleteImagePendingBroadcast(context, file.absolutePath, notificationId))
updateNotification()
updateNotification()
}
}
@@ -87,7 +88,6 @@ class SaveImageNotifier(private val context: Context) {
context.notificationManager.notify(notificationId, notificationBuilder.build())
}
/**
* Called on error while downloading image.
* @param error string containing error information.
@@ -12,20 +12,6 @@ sealed class ChapterTransition {
override val from: ReaderChapter, override val to: ReaderChapter?
) : ChapterTransition()
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is ChapterTransition) return false
if (from == other.from && to == other.to) return true
if (from == other.to && to == other.from) return true
return false
}
override fun hashCode(): Int {
var result = from.hashCode()
result = 31 * result + (to?.hashCode() ?: 0)
return result
}
override fun toString(): String {
return "${javaClass.simpleName}(from=${from.chapter.url}, to=${to?.chapter?.url})"
}
@@ -5,6 +5,7 @@ import android.os.Handler
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.ViewConfiguration
import kotlin.math.abs
/**
* A custom gesture detector that also implements an on long tap confirmed, because the built-in
@@ -45,7 +46,7 @@ open class GestureDetectorWithLongTap(
}
}
MotionEvent.ACTION_MOVE -> {
if (Math.abs(ev.rawX - downX) > slop || Math.abs(ev.rawY - downY) > slop) {
if (abs(ev.rawX - downX) > slop || abs(ev.rawY - downY) > slop) {
handler.removeCallbacks(longTapFn)
}
}
@@ -16,6 +16,7 @@ import android.view.animation.LinearInterpolator
import android.view.animation.RotateAnimation
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.getResourceColor
import kotlin.math.min
/**
* A custom progress bar that always rotates while being determinate. By always rotating we give
@@ -75,7 +76,7 @@ class ReaderProgressBar @JvmOverloads constructor(
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
val diameter = Math.min(width, height)
val diameter = min(width, height)
val thickness = diameter / 10f
val pad = thickness / 2f
ovalRect.set(pad, pad, diameter - pad, diameter - pad)
@@ -12,6 +12,7 @@ import android.view.animation.DecelerateInterpolator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import eu.kanade.tachiyomi.ui.reader.viewer.GestureDetectorWithLongTap
import kotlin.math.abs
/**
* Implementation of a [RecyclerView] used by the webtoon reader.
@@ -267,7 +268,7 @@ open class WebtoonRecyclerView @JvmOverloads constructor(
if (!isZoomDragging && currentScale > 1f) {
var startScroll = false
if (Math.abs(dx) > touchSlop) {
if (abs(dx) > touchSlop) {
if (dx < 0) {
dx += touchSlop
} else {
@@ -275,7 +276,7 @@ open class WebtoonRecyclerView @JvmOverloads constructor(
}
startScroll = true
}
if (Math.abs(dy) > touchSlop) {
if (abs(dy) > touchSlop) {
if (dy < 0) {
dy += touchSlop
} else {