pull/78/head
parent
7b080b9f16
commit
ecaac00432
@ -1,12 +1,13 @@ |
||||
package io.legado.app.help |
||||
|
||||
import android.content.Context |
||||
import io.legado.app.constant.PreferKey |
||||
import io.legado.app.utils.getPrefBoolean |
||||
import io.legado.app.utils.getPrefInt |
||||
|
||||
|
||||
val Context.isShowRSS: Boolean |
||||
get() = getPrefBoolean("showRss", true) |
||||
get() = getPrefBoolean(PreferKey.showRss, true) |
||||
|
||||
val Context.threadCount: Int |
||||
get() = getPrefInt("threadCount", 16) |
||||
get() = getPrefInt(PreferKey.threadCount, 16) |
@ -0,0 +1,66 @@ |
||||
package io.legado.app.ui.widget.number |
||||
|
||||
import android.content.Context |
||||
import android.widget.NumberPicker |
||||
import androidx.appcompat.app.AlertDialog |
||||
import io.legado.app.R |
||||
import io.legado.app.utils.applyTint |
||||
import io.legado.app.utils.hideSoftInput |
||||
import kotlinx.android.synthetic.main.dialog_number_picker.* |
||||
|
||||
|
||||
class NumberPickerDialog(context: Context) { |
||||
private val builder = AlertDialog.Builder(context) |
||||
private var numberPicker: NumberPicker? = null |
||||
private var maxValue: Int? = null |
||||
private var minValue: Int? = null |
||||
private var value: Int? = null |
||||
|
||||
init { |
||||
builder.setView(R.layout.dialog_number_picker) |
||||
} |
||||
|
||||
fun setTitle(title: String): NumberPickerDialog { |
||||
builder.setTitle(title) |
||||
return this |
||||
} |
||||
|
||||
fun setMaxValue(value: Int): NumberPickerDialog { |
||||
maxValue = value |
||||
return this |
||||
} |
||||
|
||||
fun setMinValue(value: Int): NumberPickerDialog { |
||||
minValue = value |
||||
return this |
||||
} |
||||
|
||||
fun setValue(value: Int): NumberPickerDialog { |
||||
this.value = value |
||||
return this |
||||
} |
||||
|
||||
fun show(callBack: ((value: Int) -> Unit)?) { |
||||
builder.setPositiveButton(R.string.ok) { _, _ -> |
||||
numberPicker?.let { |
||||
it.clearFocus() |
||||
it.hideSoftInput() |
||||
callBack?.invoke(it.value) |
||||
} |
||||
} |
||||
builder.setNegativeButton(R.string.cancel, null) |
||||
val dialog = builder.show().applyTint() |
||||
numberPicker = dialog.number_picker |
||||
numberPicker?.let { np -> |
||||
minValue?.let { |
||||
np.minValue = it |
||||
} |
||||
maxValue?.let { |
||||
np.maxValue = it |
||||
} |
||||
value?.let { |
||||
np.value = it |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:background="@color/background"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:gravity="center" |
||||
tools:ignore="UselessParent"> |
||||
|
||||
<NumberPicker |
||||
android:id="@+id/number_picker" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content"> |
||||
|
||||
</NumberPicker> |
||||
|
||||
</LinearLayout> |
||||
|
||||
</LinearLayout> |
Loading…
Reference in new issue