Skip to content

Commit

Permalink
Do spotless apply
Browse files Browse the repository at this point in the history
  • Loading branch information
xb2016 committed Oct 28, 2024
1 parent 5cba34e commit 4255936
Show file tree
Hide file tree
Showing 118 changed files with 1,293 additions and 1,970 deletions.
14 changes: 6 additions & 8 deletions app/src/main/java/com/hippo/app/EditTextCheckBoxDialogBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,12 @@ class EditTextCheckBoxDialogBuilder(
return mDialog as AlertDialog
}

override fun onEditorAction(v: TextView?, p1: Int, event: KeyEvent?): Boolean {
return if (mDialog != null) {
val button = mDialog!!.getButton(DialogInterface.BUTTON_POSITIVE)
button?.performClick()
true
} else {
false
}
override fun onEditorAction(v: TextView?, p1: Int, event: KeyEvent?): Boolean = if (mDialog != null) {
val button = mDialog!!.getButton(DialogInterface.BUTTON_POSITIVE)
button?.performClick()
true
} else {
false
}

init {
Expand Down
14 changes: 6 additions & 8 deletions app/src/main/java/com/hippo/app/EditTextDialogBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ class EditTextDialogBuilder(
return mDialog as AlertDialog
}

override fun onEditorAction(v: TextView?, p1: Int, event: KeyEvent?): Boolean {
return if (mDialog != null) {
val button = mDialog!!.getButton(DialogInterface.BUTTON_POSITIVE)
button?.performClick()
true
} else {
false
}
override fun onEditorAction(v: TextView?, p1: Int, event: KeyEvent?): Boolean = if (mDialog != null) {
val button = mDialog!!.getButton(DialogInterface.BUTTON_POSITIVE)
button?.performClick()
true
} else {
false
}

init {
Expand Down
30 changes: 10 additions & 20 deletions app/src/main/java/com/hippo/database/MSQLiteBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ class MSQLiteBuilder {
companion object {
const val COLUMN_ID = "_id"
private val JAVA_TYPE_TO_SQLITE_TYPE: MutableMap<Class<*>?, String> = HashMap()
private fun javaTypeToSQLiteType(clazz: Class<*>?): String {
return JAVA_TYPE_TO_SQLITE_TYPE[clazz]
?: throw IllegalStateException("Unknown type: $clazz")
}
private fun javaTypeToSQLiteType(clazz: Class<*>?): String = JAVA_TYPE_TO_SQLITE_TYPE[clazz]
?: throw IllegalStateException("Unknown type: $clazz")

init {
JAVA_TYPE_TO_SQLITE_TYPE[Boolean::class.javaPrimitiveType] =
Expand Down Expand Up @@ -73,27 +71,21 @@ class MSQLiteBuilder {
table: String,
column: String = COLUMN_ID,
clazz: Class<*>? = Int::class.javaPrimitiveType,
): MSQLiteBuilder {
return statement("CREATE TABLE " + table + " (" + column + " " + javaTypeToSQLiteType(clazz) + " PRIMARY KEY);")
}
): MSQLiteBuilder = statement("CREATE TABLE " + table + " (" + column + " " + javaTypeToSQLiteType(clazz) + " PRIMARY KEY);")

/**
* Drops a table.
*/
fun dropTable(table: String): MSQLiteBuilder {
return statement("DROP TABLE $table;")
}
fun dropTable(table: String): MSQLiteBuilder = statement("DROP TABLE $table;")

/**
* Inserts a column to the table.
*/
fun insertColumn(table: String, column: String, clazz: Class<*>?): MSQLiteBuilder {
return statement(
"ALTER TABLE $table ADD COLUMN $column " + javaTypeToSQLiteType(
clazz,
) + ";",
)
}
fun insertColumn(table: String, column: String, clazz: Class<*>?): MSQLiteBuilder = statement(
"ALTER TABLE $table ADD COLUMN $column " + javaTypeToSQLiteType(
clazz,
) + ";",
)

/**
* Add a statement.
Expand All @@ -107,9 +99,7 @@ class MSQLiteBuilder {
/**
* Build a SQLiteOpenHelper from it.
*/
fun build(context: Context?, name: String?, version: Int): SQLiteOpenHelper {
return MSQLiteOpenHelper(context, name, version, this)
}
fun build(context: Context?, name: String?, version: Int): SQLiteOpenHelper = MSQLiteOpenHelper(context, name, version, this)

fun getStatements(oldVersion: Int, newVersion: Int): List<String> {
val result: MutableList<String> = ArrayList()
Expand Down
12 changes: 3 additions & 9 deletions app/src/main/java/com/hippo/drawable/AddDeleteDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,9 @@ class AddDeleteDrawable(context: Context, color: Int) : Drawable() {
mPaint.setColorFilter(cf)
}

override fun getIntrinsicHeight(): Int {
return mSize * 6 / 5
}
override fun getIntrinsicHeight(): Int = mSize * 6 / 5

override fun getIntrinsicWidth(): Int {
return mSize * 6 / 5
}
override fun getIntrinsicWidth(): Int = mSize * 6 / 5

/**
* If set, canvas is flipped when progress reached to end and going back to start.
Expand Down Expand Up @@ -139,7 +135,5 @@ class AddDeleteDrawable(context: Context, color: Int) : Drawable() {
"Deprecated in Java",
ReplaceWith("PixelFormat.TRANSLUCENT", "android.graphics.PixelFormat"),
)
override fun getOpacity(): Int {
return PixelFormat.TRANSLUCENT
}
override fun getOpacity(): Int = PixelFormat.TRANSLUCENT
}
4 changes: 1 addition & 3 deletions app/src/main/java/com/hippo/drawable/BatteryDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ class BatteryDrawable : Drawable() {
"Deprecated in Java",
ReplaceWith("PixelFormat.TRANSLUCENT", "android.graphics.PixelFormat"),
)
override fun getOpacity(): Int {
return PixelFormat.TRANSLUCENT
}
override fun getOpacity(): Int = PixelFormat.TRANSLUCENT

companion object {
const val WARN_LIMIT = 15
Expand Down
12 changes: 3 additions & 9 deletions app/src/main/java/com/hippo/drawable/DrawerArrowDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,15 @@ class DrawerArrowDrawable(context: Context, color: Int) : Drawable() {
mPaint.setColorFilter(colorFilter)
}

override fun getIntrinsicHeight(): Int {
return mSize
}
override fun getIntrinsicHeight(): Int = mSize

override fun getIntrinsicWidth(): Int {
return mSize
}
override fun getIntrinsicWidth(): Int = mSize

@Deprecated(
"Deprecated in Java",
ReplaceWith("PixelFormat.TRANSLUCENT", "android.graphics.PixelFormat"),
)
override fun getOpacity(): Int {
return PixelFormat.TRANSLUCENT
}
override fun getOpacity(): Int = PixelFormat.TRANSLUCENT

@get:Keep
@set:Keep
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/java/com/hippo/drawable/PreciselyClipDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ class PreciselyClipDrawable(
super.onBoundsChange(mTemp)
}

override fun getIntrinsicWidth(): Int {
return (super.intrinsicWidth * mScale.width()).toInt()
}
override fun getIntrinsicWidth(): Int = (super.intrinsicWidth * mScale.width()).toInt()

override fun getIntrinsicHeight(): Int {
return (super.intrinsicHeight * mScale.height()).toInt()
}
override fun getIntrinsicHeight(): Int = (super.intrinsicHeight * mScale.height()).toInt()

override fun draw(canvas: Canvas) {
canvas.withClip(bounds) { super.draw(canvas) }
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/hippo/drawable/TriangleDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,5 @@ class TriangleDrawable(color: Int) : Drawable() {
"Deprecated in Java",
ReplaceWith("PixelFormat.OPAQUE", "android.graphics.PixelFormat"),
)
override fun getOpacity(): Int {
return PixelFormat.OPAQUE
}
override fun getOpacity(): Int = PixelFormat.OPAQUE
}
16 changes: 4 additions & 12 deletions app/src/main/java/com/hippo/drawable/WrapDrawable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ open class WrapDrawable : Drawable() {
drawable?.bounds = bounds
}

override fun getChangingConfigurations(): Int {
return drawable?.changingConfigurations ?: super.changingConfigurations
}
override fun getChangingConfigurations(): Int = drawable?.changingConfigurations ?: super.changingConfigurations

override fun setChangingConfigurations(configs: Int) {
super.changingConfigurations = configs
Expand All @@ -68,15 +66,9 @@ open class WrapDrawable : Drawable() {
"Deprecated in Java",
ReplaceWith("PixelFormat.TRANSLUCENT", "android.graphics.PixelFormat"),
)
override fun getOpacity(): Int {
return PixelFormat.TRANSLUCENT
}
override fun getOpacity(): Int = PixelFormat.TRANSLUCENT

override fun getIntrinsicWidth(): Int {
return drawable?.intrinsicWidth ?: super.intrinsicWidth
}
override fun getIntrinsicWidth(): Int = drawable?.intrinsicWidth ?: super.intrinsicWidth

override fun getIntrinsicHeight(): Int {
return drawable?.intrinsicHeight ?: super.intrinsicHeight
}
override fun getIntrinsicHeight(): Int = drawable?.intrinsicHeight ?: super.intrinsicHeight
}
34 changes: 10 additions & 24 deletions app/src/main/java/com/hippo/easyrecyclerview/EasyRecyclerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,10 @@ open class EasyRecyclerView @JvmOverloads constructor(
* is invalid
* @see .setChoiceMode
*/
private fun isItemChecked(position: Int): Boolean {
return if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
mCheckStates!![position]
} else {
false
}
private fun isItemChecked(position: Int): Boolean = if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
mCheckStates!![position]
} else {
false
}

val checkedItemPositions: SparseBooleanArray?
Expand Down Expand Up @@ -508,9 +506,7 @@ open class EasyRecyclerView @JvmOverloads constructor(
}
}

override fun describeContents(): Int {
return 0
}
override fun describeContents(): Int = 0

override fun writeToParcel(out: Parcel, flags: Int) {
out.writeParcelable(superState, flags)
Expand All @@ -527,21 +523,15 @@ open class EasyRecyclerView @JvmOverloads constructor(
}

companion object CREATOR : Parcelable.Creator<SavedState> {
override fun createFromParcel(`in`: Parcel): SavedState {
return SavedState(`in`)
}
override fun createFromParcel(`in`: Parcel): SavedState = SavedState(`in`)

override fun newArray(size: Int): Array<SavedState?> {
return arrayOfNulls(size)
}
override fun newArray(size: Int): Array<SavedState?> = arrayOfNulls(size)
}
}

inner class MultiChoiceModeWrapper : MultiChoiceModeListener {
private val mWrapped: MultiChoiceModeListener? = null
fun hasWrappedCallback(): Boolean {
return mWrapped != null
}
fun hasWrappedCallback(): Boolean = mWrapped != null

override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
if (mWrapped!!.onCreateActionMode(mode, menu)) {
Expand All @@ -552,13 +542,9 @@ open class EasyRecyclerView @JvmOverloads constructor(
return false
}

override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
return mWrapped!!.onPrepareActionMode(mode, menu)
}
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean = mWrapped!!.onPrepareActionMode(mode, menu)

override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
return mWrapped!!.onActionItemClicked(mode, item)
}
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean = mWrapped!!.onActionItemClicked(mode, item)

override fun onDestroyActionMode(mode: ActionMode) {
mWrapped!!.onDestroyActionMode(mode)
Expand Down
64 changes: 29 additions & 35 deletions app/src/main/java/com/hippo/easyrecyclerview/LayoutManagerUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ object LayoutManagerUtils {
is LinearLayoutManager -> {
smoothScroller =
object : SimpleSmoothScroller(context!!, millisecondsPerInch.toFloat()) {
override fun computeScrollVectorForPosition(targetPosition: Int): PointF? {
return layoutManager.computeScrollVectorForPosition(targetPosition)
}
override fun computeScrollVectorForPosition(targetPosition: Int): PointF? = layoutManager.computeScrollVectorForPosition(targetPosition)
}
}

Expand Down Expand Up @@ -143,45 +141,41 @@ object LayoutManagerUtils {
}, 200)
}

fun getFirstVisibleItemPosition(layoutManager: RecyclerView.LayoutManager): Int {
return when (layoutManager) {
is LinearLayoutManager -> {
layoutManager.findFirstVisibleItemPosition()
}
fun getFirstVisibleItemPosition(layoutManager: RecyclerView.LayoutManager): Int = when (layoutManager) {
is LinearLayoutManager -> {
layoutManager.findFirstVisibleItemPosition()
}

is StaggeredGridLayoutManager -> {
val positions =
layoutManager.findFirstVisibleItemPositions(null)
MathUtils.min(*positions)
}
is StaggeredGridLayoutManager -> {
val positions =
layoutManager.findFirstVisibleItemPositions(null)
MathUtils.min(*positions)
}

else -> {
throw IllegalStateException(
"Can't do getFirstVisibleItemPosition for " +
layoutManager.javaClass.getName(),
)
}
else -> {
throw IllegalStateException(
"Can't do getFirstVisibleItemPosition for " +
layoutManager.javaClass.getName(),
)
}
}

fun getLastVisibleItemPosition(layoutManager: RecyclerView.LayoutManager): Int {
return when (layoutManager) {
is LinearLayoutManager -> {
layoutManager.findLastVisibleItemPosition()
}
fun getLastVisibleItemPosition(layoutManager: RecyclerView.LayoutManager): Int = when (layoutManager) {
is LinearLayoutManager -> {
layoutManager.findLastVisibleItemPosition()
}

is StaggeredGridLayoutManager -> {
val positions =
layoutManager.findLastVisibleItemPositions(null)
MathUtils.max(*positions)
}
is StaggeredGridLayoutManager -> {
val positions =
layoutManager.findLastVisibleItemPositions(null)
MathUtils.max(*positions)
}

else -> {
throw IllegalStateException(
"Can't do getLastVisibleItemPosition for " +
layoutManager.javaClass.getName(),
)
}
else -> {
throw IllegalStateException(
"Can't do getLastVisibleItemPosition for " +
layoutManager.javaClass.getName(),
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ import androidx.recyclerview.widget.LinearSmoothScroller
import kotlin.math.abs
import kotlin.math.ceil

abstract class SimpleSmoothScroller(context: Context, millisecondsPerInch: Float) :
LinearSmoothScroller(context) {
abstract class SimpleSmoothScroller(context: Context, millisecondsPerInch: Float) : LinearSmoothScroller(context) {
private val mMillisecondsPerPx: Float = millisecondsPerInch / context.resources.displayMetrics.densityDpi

override fun calculateTimeForScrolling(dx: Int): Int {
return if (mMillisecondsPerPx <= 0) {
super.calculateTimeForScrolling(dx)
} else {
ceil(abs(dx.toDouble()) * mMillisecondsPerPx).toInt()
}
override fun calculateTimeForScrolling(dx: Int): Int = if (mMillisecondsPerPx <= 0) {
super.calculateTimeForScrolling(dx)
} else {
ceil(abs(dx.toDouble()) * mMillisecondsPerPx).toInt()
}
}
Loading

0 comments on commit 4255936

Please sign in to comment.