pull/32/head
parent
3082db966a
commit
e2a2bbd2b8
@ -0,0 +1,10 @@ |
||||
package io.legado.app.base |
||||
|
||||
import androidx.lifecycle.ViewModel |
||||
|
||||
abstract class VMBaseActivity<VM : ViewModel>(layoutID: Int, fullScreen: Boolean = true) : |
||||
BaseActivity(layoutID, fullScreen) { |
||||
|
||||
protected abstract val viewModel: VM |
||||
|
||||
} |
@ -0,0 +1,9 @@ |
||||
package io.legado.app.base |
||||
|
||||
import androidx.lifecycle.ViewModel |
||||
|
||||
abstract class VMBaseFragment<VM : ViewModel>(layoutID: Int) : BaseFragment(layoutID) { |
||||
|
||||
protected abstract val viewModel: VM |
||||
|
||||
} |
@ -0,0 +1,103 @@ |
||||
/* |
||||
* Copyright 2016 JetBrains s.r.o. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
@file:Suppress("NOTHING_TO_INLINE", "unused") |
||||
package io.legado.app.lib.dialogs |
||||
|
||||
import android.annotation.SuppressLint |
||||
import android.content.Context |
||||
import android.content.DialogInterface |
||||
import android.graphics.drawable.Drawable |
||||
import android.view.KeyEvent |
||||
import android.view.View |
||||
import android.view.ViewManager |
||||
import androidx.annotation.DrawableRes |
||||
import androidx.annotation.StringRes |
||||
import org.jetbrains.anko.UI |
||||
import org.jetbrains.anko.internals.AnkoInternals.NO_GETTER |
||||
import kotlin.DeprecationLevel.ERROR |
||||
|
||||
@SuppressLint("SupportAnnotationUsage") |
||||
interface AlertBuilder<out D : DialogInterface> { |
||||
val ctx: Context |
||||
|
||||
var title: CharSequence |
||||
@Deprecated(NO_GETTER, level = ERROR) get |
||||
|
||||
var titleResource: Int |
||||
@Deprecated(NO_GETTER, level = ERROR) get |
||||
|
||||
var message: CharSequence |
||||
@Deprecated(NO_GETTER, level = ERROR) get |
||||
|
||||
var messageResource: Int |
||||
@Deprecated(NO_GETTER, level = ERROR) get |
||||
|
||||
var icon: Drawable |
||||
@Deprecated(NO_GETTER, level = ERROR) get |
||||
|
||||
@setparam:DrawableRes |
||||
var iconResource: Int |
||||
@Deprecated(NO_GETTER, level = ERROR) get |
||||
|
||||
var customTitle: View |
||||
@Deprecated(NO_GETTER, level = ERROR) get |
||||
|
||||
var customView: View |
||||
@Deprecated(NO_GETTER, level = ERROR) get |
||||
|
||||
var isCancelable: Boolean |
||||
@Deprecated(NO_GETTER, level = ERROR) get |
||||
|
||||
fun onCancelled(handler: (dialog: DialogInterface) -> Unit) |
||||
|
||||
fun onKeyPressed(handler: (dialog: DialogInterface, keyCode: Int, e: KeyEvent) -> Boolean) |
||||
|
||||
fun positiveButton(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) |
||||
fun positiveButton(@StringRes buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) |
||||
|
||||
fun negativeButton(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) |
||||
fun negativeButton(@StringRes buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) |
||||
|
||||
fun neutralPressed(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) |
||||
fun neutralPressed(@StringRes buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) |
||||
|
||||
fun items(items: List<CharSequence>, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit) |
||||
fun <T> items(items: List<T>, onItemSelected: (dialog: DialogInterface, item: T, index: Int) -> Unit) |
||||
|
||||
fun build(): D |
||||
fun show(): D |
||||
} |
||||
|
||||
fun AlertBuilder<*>.customTitle(view: () -> View) { |
||||
customTitle = view() |
||||
} |
||||
|
||||
fun AlertBuilder<*>.customView(view: () -> View) { |
||||
customView = view() |
||||
} |
||||
|
||||
inline fun AlertBuilder<*>.okButton(noinline handler: (dialog: DialogInterface) -> Unit) = |
||||
positiveButton(android.R.string.ok, handler) |
||||
|
||||
inline fun AlertBuilder<*>.cancelButton(noinline handler: (dialog: DialogInterface) -> Unit) = |
||||
negativeButton(android.R.string.cancel, handler) |
||||
|
||||
inline fun AlertBuilder<*>.yesButton(noinline handler: (dialog: DialogInterface) -> Unit) = |
||||
positiveButton(android.R.string.yes, handler) |
||||
|
||||
inline fun AlertBuilder<*>.noButton(noinline handler: (dialog: DialogInterface) -> Unit) = |
||||
negativeButton(android.R.string.no, handler) |
@ -0,0 +1,117 @@ |
||||
/* |
||||
* Copyright 2016 JetBrains s.r.o. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package io.legado.app.lib.dialogs |
||||
|
||||
import android.content.Context |
||||
import android.content.DialogInterface |
||||
import android.graphics.drawable.Drawable |
||||
import android.view.KeyEvent |
||||
import android.view.View |
||||
import androidx.appcompat.app.AlertDialog |
||||
import org.jetbrains.anko.internals.AnkoInternals |
||||
import org.jetbrains.anko.internals.AnkoInternals.NO_GETTER |
||||
import kotlin.DeprecationLevel.ERROR |
||||
|
||||
val Android: AlertBuilderFactory<AlertDialog> = ::AndroidAlertBuilder |
||||
|
||||
internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<AlertDialog> { |
||||
private val builder = AlertDialog.Builder(ctx) |
||||
|
||||
override var title: CharSequence |
||||
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() |
||||
set(value) { builder.setTitle(value) } |
||||
|
||||
override var titleResource: Int |
||||
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() |
||||
set(value) { builder.setTitle(value) } |
||||
|
||||
override var message: CharSequence |
||||
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() |
||||
set(value) { builder.setMessage(value) } |
||||
|
||||
override var messageResource: Int |
||||
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() |
||||
set(value) { builder.setMessage(value) } |
||||
|
||||
override var icon: Drawable |
||||
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() |
||||
set(value) { builder.setIcon(value) } |
||||
|
||||
override var iconResource: Int |
||||
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() |
||||
set(value) { builder.setIcon(value) } |
||||
|
||||
override var customTitle: View |
||||
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() |
||||
set(value) { builder.setCustomTitle(value) } |
||||
|
||||
override var customView: View |
||||
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() |
||||
set(value) { builder.setView(value) } |
||||
|
||||
override var isCancelable: Boolean |
||||
@Deprecated(NO_GETTER, level = ERROR) get() = AnkoInternals.noGetter() |
||||
set(value) { builder.setCancelable(value) } |
||||
|
||||
override fun onCancelled(handler: (DialogInterface) -> Unit) { |
||||
builder.setOnCancelListener(handler) |
||||
} |
||||
|
||||
override fun onKeyPressed(handler: (dialog: DialogInterface, keyCode: Int, e: KeyEvent) -> Boolean) { |
||||
builder.setOnKeyListener(handler) |
||||
} |
||||
|
||||
override fun positiveButton(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) { |
||||
builder.setPositiveButton(buttonText) { dialog, _ -> onClicked(dialog) } |
||||
} |
||||
|
||||
override fun positiveButton(buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) { |
||||
builder.setPositiveButton(buttonTextResource) { dialog, _ -> onClicked(dialog) } |
||||
} |
||||
|
||||
override fun negativeButton(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) { |
||||
builder.setNegativeButton(buttonText) { dialog, _ -> onClicked(dialog) } |
||||
} |
||||
|
||||
override fun negativeButton(buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) { |
||||
builder.setNegativeButton(buttonTextResource) { dialog, _ -> onClicked(dialog) } |
||||
} |
||||
|
||||
override fun neutralPressed(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) { |
||||
builder.setNeutralButton(buttonText) { dialog, _ -> onClicked(dialog) } |
||||
} |
||||
|
||||
override fun neutralPressed(buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) { |
||||
builder.setNeutralButton(buttonTextResource) { dialog, _ -> onClicked(dialog) } |
||||
} |
||||
|
||||
override fun items(items: List<CharSequence>, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit) { |
||||
builder.setItems(Array(items.size) { i -> items[i].toString() }) { dialog, which -> |
||||
onItemSelected(dialog, which) |
||||
} |
||||
} |
||||
|
||||
override fun <T> items(items: List<T>, onItemSelected: (dialog: DialogInterface, item: T, index: Int) -> Unit) { |
||||
builder.setItems(Array(items.size) { i -> items[i].toString() }) { dialog, which -> |
||||
onItemSelected(dialog, items[which], which) |
||||
} |
||||
} |
||||
|
||||
override fun build(): AlertDialog = builder.create() |
||||
|
||||
override fun show(): AlertDialog = builder.show() |
||||
} |
@ -0,0 +1,179 @@ |
||||
/* |
||||
* Copyright 2016 JetBrains s.r.o. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
@file:Suppress("NOTHING_TO_INLINE", "unused") |
||||
|
||||
package io.legado.app.lib.dialogs |
||||
|
||||
import android.app.ProgressDialog |
||||
import android.content.Context |
||||
import android.content.DialogInterface |
||||
import androidx.appcompat.app.AlertDialog |
||||
import androidx.fragment.app.Fragment |
||||
import org.jetbrains.anko.AnkoContext |
||||
|
||||
inline fun AnkoContext<*>.alert( |
||||
title: CharSequence? = null, |
||||
message: CharSequence? = null, |
||||
noinline init: (AlertBuilder<DialogInterface>.() -> Unit)? = null |
||||
) = ctx.alert(title, message, init) |
||||
|
||||
inline fun Fragment.alert( |
||||
title: CharSequence? = null, |
||||
message: CharSequence? = null, |
||||
noinline init: (AlertBuilder<DialogInterface>.() -> Unit)? = null |
||||
) = requireActivity().alert(title, message, init) |
||||
|
||||
fun Context.alert( |
||||
title: CharSequence? = null, |
||||
message: CharSequence? = null, |
||||
init: (AlertBuilder<DialogInterface>.() -> Unit)? = null |
||||
): AlertBuilder<AlertDialog> { |
||||
return AndroidAlertBuilder(this).apply { |
||||
if (title != null) { |
||||
this.title = title |
||||
} |
||||
if (message != null) { |
||||
this.message = message |
||||
} |
||||
if (init != null) init() |
||||
} |
||||
} |
||||
|
||||
inline fun AnkoContext<*>.alert( |
||||
titleResource: Int? = null, |
||||
messageResource: Int? = null, |
||||
noinline init: (AlertBuilder<DialogInterface>.() -> Unit)? = null |
||||
) = ctx.alert(titleResource, messageResource, init) |
||||
|
||||
inline fun Fragment.alert( |
||||
title: Int? = null, |
||||
message: Int? = null, |
||||
noinline init: (AlertBuilder<DialogInterface>.() -> Unit)? = null |
||||
) = requireActivity().alert(title, message, init) |
||||
|
||||
fun Context.alert( |
||||
titleResource: Int? = null, |
||||
messageResource: Int? = null, |
||||
init: (AlertBuilder<DialogInterface>.() -> Unit)? = null |
||||
): AlertBuilder<DialogInterface> { |
||||
return AndroidAlertBuilder(this).apply { |
||||
if (titleResource != null) { |
||||
this.titleResource = titleResource |
||||
} |
||||
if (messageResource != null) { |
||||
this.messageResource = messageResource |
||||
} |
||||
if (init != null) init() |
||||
} |
||||
} |
||||
|
||||
|
||||
inline fun AnkoContext<*>.alert(noinline init: AlertBuilder<DialogInterface>.() -> Unit) = ctx.alert(init) |
||||
inline fun Fragment.alert(noinline init: AlertBuilder<DialogInterface>.() -> Unit) = activity?.alert(init) |
||||
|
||||
fun Context.alert(init: AlertBuilder<DialogInterface>.() -> Unit): AlertBuilder<DialogInterface> = |
||||
AndroidAlertBuilder(this).apply { init() } |
||||
|
||||
inline fun AnkoContext<*>.progressDialog( |
||||
title: Int? = null, |
||||
message: Int? = null, |
||||
noinline init: (ProgressDialog.() -> Unit)? = null |
||||
) = ctx.progressDialog(title, message, init) |
||||
|
||||
inline fun Fragment.progressDialog( |
||||
title: Int? = null, |
||||
message: Int? = null, |
||||
noinline init: (ProgressDialog.() -> Unit)? = null |
||||
) = requireActivity().progressDialog(title, message, init) |
||||
|
||||
fun Context.progressDialog( |
||||
title: Int? = null, |
||||
message: Int? = null, |
||||
init: (ProgressDialog.() -> Unit)? = null |
||||
) = progressDialog(title?.let { getString(it) }, message?.let { getString(it) }, false, init) |
||||
|
||||
|
||||
inline fun AnkoContext<*>.indeterminateProgressDialog( |
||||
title: Int? = null, |
||||
message: Int? = null, |
||||
noinline init: (ProgressDialog.() -> Unit)? = null |
||||
) = ctx.indeterminateProgressDialog(title, message, init) |
||||
|
||||
inline fun Fragment.indeterminateProgressDialog( |
||||
title: Int? = null, |
||||
message: Int? = null, |
||||
noinline init: (ProgressDialog.() -> Unit)? = null |
||||
) = requireActivity().indeterminateProgressDialog(title, message, init) |
||||
|
||||
fun Context.indeterminateProgressDialog( |
||||
title: Int? = null, |
||||
message: Int? = null, |
||||
init: (ProgressDialog.() -> Unit)? = null |
||||
) = progressDialog(title?.let { getString(it) }, message?.let { getString(it) }, true, init) |
||||
|
||||
|
||||
inline fun AnkoContext<*>.progressDialog( |
||||
title: CharSequence? = null, |
||||
message: CharSequence? = null, |
||||
noinline init: (ProgressDialog.() -> Unit)? = null |
||||
) = ctx.progressDialog(title, message, init) |
||||
|
||||
inline fun Fragment.progressDialog( |
||||
title: CharSequence? = null, |
||||
message: CharSequence? = null, |
||||
noinline init: (ProgressDialog.() -> Unit)? = null |
||||
) = requireActivity().progressDialog(title, message, init) |
||||
|
||||
fun Context.progressDialog( |
||||
title: CharSequence? = null, |
||||
message: CharSequence? = null, |
||||
init: (ProgressDialog.() -> Unit)? = null |
||||
) = progressDialog(title, message, false, init) |
||||
|
||||
|
||||
inline fun AnkoContext<*>.indeterminateProgressDialog( |
||||
title: CharSequence? = null, |
||||
message: CharSequence? = null, |
||||
noinline init: (ProgressDialog.() -> Unit)? = null |
||||
) = ctx.indeterminateProgressDialog(title, message, init) |
||||
|
||||
inline fun Fragment.indeterminateProgressDialog( |
||||
title: CharSequence? = null, |
||||
message: CharSequence? = null, |
||||
noinline init: (ProgressDialog.() -> Unit)? = null |
||||
) = requireActivity().indeterminateProgressDialog(title, message, init) |
||||
|
||||
fun Context.indeterminateProgressDialog( |
||||
title: CharSequence? = null, |
||||
message: CharSequence? = null, |
||||
init: (ProgressDialog.() -> Unit)? = null |
||||
) = progressDialog(title, message, true, init) |
||||
|
||||
|
||||
private fun Context.progressDialog( |
||||
title: CharSequence? = null, |
||||
message: CharSequence? = null, |
||||
indeterminate: Boolean, |
||||
init: (ProgressDialog.() -> Unit)? = null |
||||
) = ProgressDialog(this).apply { |
||||
isIndeterminate = indeterminate |
||||
if (!indeterminate) setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) |
||||
if (message != null) setMessage(message) |
||||
if (title != null) setTitle(title) |
||||
if (init != null) init() |
||||
show() |
||||
} |
@ -0,0 +1,50 @@ |
||||
/* |
||||
* Copyright 2016 JetBrains s.r.o. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
@file:Suppress("NOTHING_TO_INLINE", "unused") |
||||
|
||||
package io.legado.app.lib.dialogs |
||||
|
||||
import android.content.Context |
||||
import android.content.DialogInterface |
||||
import androidx.fragment.app.Fragment |
||||
import org.jetbrains.anko.AnkoContext |
||||
|
||||
inline fun AnkoContext<*>.selector( |
||||
title: CharSequence? = null, |
||||
items: List<CharSequence>, |
||||
noinline onClick: (DialogInterface, Int) -> Unit |
||||
) = ctx.selector(title, items, onClick) |
||||
|
||||
inline fun Fragment.selector( |
||||
title: CharSequence? = null, |
||||
items: List<CharSequence>, |
||||
noinline onClick: (DialogInterface, Int) -> Unit |
||||
) = activity?.selector(title, items, onClick) |
||||
|
||||
fun Context.selector( |
||||
title: CharSequence? = null, |
||||
items: List<CharSequence>, |
||||
onClick: (DialogInterface, Int) -> Unit |
||||
) { |
||||
with(AndroidAlertBuilder(this)) { |
||||
if (title != null) { |
||||
this.title = title |
||||
} |
||||
items(items, onClick) |
||||
show() |
||||
} |
||||
} |
@ -0,0 +1,103 @@ |
||||
/* |
||||
* Copyright 2016 JetBrains s.r.o. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
@file:Suppress("NOTHING_TO_INLINE", "unused") |
||||
|
||||
package io.legado.app.lib.dialogs |
||||
|
||||
import android.content.Context |
||||
import android.content.DialogInterface |
||||
import androidx.fragment.app.Fragment |
||||
import org.jetbrains.anko.AnkoContext |
||||
|
||||
typealias AlertBuilderFactory<D> = (Context) -> AlertBuilder<D> |
||||
|
||||
inline fun <D : DialogInterface> AnkoContext<*>.alert( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
title: String? = null, |
||||
message: String? = null, |
||||
noinline init: (AlertBuilder<D>.() -> Unit)? = null |
||||
) = ctx.alert(factory, title, message, init) |
||||
|
||||
inline fun <D : DialogInterface> Fragment.alert( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
title: String? = null, |
||||
message: String? = null, |
||||
noinline init: (AlertBuilder<D>.() -> Unit)? = null |
||||
) = activity?.alert(factory, title, message, init) |
||||
|
||||
fun <D : DialogInterface> Context.alert( |
||||
factory: AlertBuilderFactory<D>, |
||||
title: String? = null, |
||||
message: String? = null, |
||||
init: (AlertBuilder<D>.() -> Unit)? = null |
||||
): AlertBuilder<D> { |
||||
return factory(this).apply { |
||||
if (title != null) { |
||||
this.title = title |
||||
} |
||||
if (message != null) { |
||||
this.message = message |
||||
} |
||||
if (init != null) init() |
||||
} |
||||
} |
||||
|
||||
inline fun <D : DialogInterface> AnkoContext<*>.alert( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
titleResource: Int? = null, |
||||
messageResource: Int? = null, |
||||
noinline init: (AlertBuilder<D>.() -> Unit)? = null |
||||
) = ctx.alert(factory, titleResource, messageResource, init) |
||||
|
||||
inline fun <D : DialogInterface> Fragment.alert( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
titleResource: Int? = null, |
||||
messageResource: Int? = null, |
||||
noinline init: (AlertBuilder<D>.() -> Unit)? = null |
||||
) = requireActivity().alert(factory, titleResource, messageResource, init) |
||||
|
||||
fun <D : DialogInterface> Context.alert( |
||||
factory: AlertBuilderFactory<D>, |
||||
titleResource: Int? = null, |
||||
messageResource: Int? = null, |
||||
init: (AlertBuilder<D>.() -> Unit)? = null |
||||
): AlertBuilder<D> { |
||||
return factory(this).apply { |
||||
if (titleResource != null) { |
||||
this.titleResource = titleResource |
||||
} |
||||
if (messageResource != null) { |
||||
this.messageResource = messageResource |
||||
} |
||||
if (init != null) init() |
||||
} |
||||
} |
||||
|
||||
inline fun <D : DialogInterface> AnkoContext<*>.alert( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
noinline init: AlertBuilder<D>.() -> Unit |
||||
) = ctx.alert(factory, init) |
||||
|
||||
inline fun <D : DialogInterface> Fragment.alert( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
noinline init: AlertBuilder<D>.() -> Unit |
||||
) = requireActivity().alert(factory, init) |
||||
|
||||
fun <D : DialogInterface> Context.alert( |
||||
factory: AlertBuilderFactory<D>, |
||||
init: AlertBuilder<D>.() -> Unit |
||||
): AlertBuilder<D> = factory(this).apply { init() } |
@ -0,0 +1,52 @@ |
||||
/* |
||||
* Copyright 2016 JetBrains s.r.o. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
@file:Suppress("NOTHING_TO_INLINE", "unused") |
||||
package io.legado.app.lib.dialogs |
||||
|
||||
import android.content.Context |
||||
import android.content.DialogInterface |
||||
import androidx.fragment.app.Fragment |
||||
import org.jetbrains.anko.AnkoContext |
||||
|
||||
inline fun <D : DialogInterface> AnkoContext<*>.selector( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
title: CharSequence? = null, |
||||
items: List<CharSequence>, |
||||
noinline onClick: (DialogInterface, CharSequence, Int) -> Unit |
||||
) = ctx.selector(factory, title, items, onClick) |
||||
|
||||
inline fun <D : DialogInterface> Fragment.selector( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
title: CharSequence? = null, |
||||
items: List<CharSequence>, |
||||
noinline onClick: (DialogInterface, CharSequence, Int) -> Unit |
||||
) = requireActivity().selector(factory, title, items, onClick) |
||||
|
||||
fun <D : DialogInterface> Context.selector( |
||||
factory: AlertBuilderFactory<D>, |
||||
title: CharSequence? = null, |
||||
items: List<CharSequence>, |
||||
onClick: (DialogInterface, CharSequence, Int) -> Unit |
||||
) { |
||||
with(factory(this)) { |
||||
if (title != null) { |
||||
this.title = title |
||||
} |
||||
items(items, onClick) |
||||
show() |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
package io.legado.app.ui.main.bookshelf |
||||
|
||||
import android.app.Application |
||||
import io.legado.app.App |
||||
import io.legado.app.base.BaseViewModel |
||||
import io.legado.app.data.entities.BookGroup |
||||
|
||||
class BookshelfViewModel(application: Application) : BaseViewModel(application) { |
||||
|
||||
|
||||
fun saveBookGroup(group: String?) { |
||||
if (!group.isNullOrBlank()) { |
||||
execute { |
||||
App.db.bookGroupDao().insert( |
||||
BookGroup( |
||||
App.db.bookGroupDao().maxId + 1, |
||||
group |
||||
) |
||||
) |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,8 +1,13 @@ |
||||
package io.legado.app.utils |
||||
|
||||
import android.view.WindowManager |
||||
import androidx.appcompat.app.AlertDialog |
||||
import io.legado.app.lib.theme.ATH |
||||
|
||||
fun AlertDialog.upTint(): AlertDialog { |
||||
fun AlertDialog.applyTint(): AlertDialog { |
||||
return ATH.setAlertDialogTint(this) |
||||
} |
||||
|
||||
fun AlertDialog.requestInputMethod(){ |
||||
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) |
||||
} |
||||
|
@ -0,0 +1,18 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<ScrollView |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:layout_marginTop="48dp" |
||||
android:layout_marginBottom="48dp" |
||||
android:overScrollMode="ifContentScrolls"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText |
||||
android:id="@+id/edit_view" |
||||
android:layout_marginLeft="20dp" |
||||
android:layout_marginRight="20dp" |
||||
android:layout_marginStart="20dp" |
||||
android:layout_marginEnd="20dp" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content"/> |
||||
</ScrollView> |
Loading…
Reference in new issue