pull/32/head
parent
3328980791
commit
27133a11c8
@ -1,63 +0,0 @@ |
||||
package io.legado.app.utils |
||||
|
||||
import android.content.res.ColorStateList |
||||
import android.graphics.drawable.Drawable |
||||
import android.view.View |
||||
import androidx.annotation.ColorRes |
||||
import androidx.annotation.DrawableRes |
||||
import androidx.annotation.StringRes |
||||
import androidx.fragment.app.Fragment |
||||
import com.google.android.material.snackbar.Snackbar |
||||
import org.jetbrains.anko.dip |
||||
import org.jetbrains.anko.longToast |
||||
import org.jetbrains.anko.toast |
||||
|
||||
|
||||
/** |
||||
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@JvmName("snackbar2") |
||||
fun View.snackbar(@StringRes message: Int) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_SHORT) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@JvmName("longSnackbar2") |
||||
fun View.longSnackbar(@StringRes message: Int) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_LONG) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@JvmName("longSnackbar2") |
||||
fun View.longSnackbar(@StringRes message: Int, @StringRes actionText: Int, action: (View) -> Unit) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_LONG) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
fun Fragment.toast(textResource: Int) = requireActivity().toast(textResource) |
||||
|
||||
fun Fragment.toast(text: CharSequence) = requireActivity().toast(text) |
||||
|
||||
fun Fragment.longToast(textResource: Int) = requireActivity().longToast(textResource) |
||||
|
||||
fun Fragment.longToast(text: CharSequence) = requireActivity().longToast(text) |
||||
|
||||
fun Fragment.dip(value: Int): Int = requireActivity().dip(value) |
||||
|
||||
fun Fragment.dip(value: Float): Int = requireActivity().dip(value) |
||||
|
||||
fun Fragment.getCompatColor(@ColorRes id: Int): Int = requireContext().getCompatColor(id) |
||||
|
||||
fun Fragment.getCompatDrawable(@DrawableRes id: Int): Drawable? = requireContext().getCompatDrawable(id) |
||||
|
||||
fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = requireContext().getCompatColorStateList(id) |
@ -0,0 +1,57 @@ |
||||
package io.legado.app.utils |
||||
|
||||
import android.content.res.ColorStateList |
||||
import android.graphics.drawable.Drawable |
||||
import androidx.annotation.ColorRes |
||||
import androidx.annotation.DrawableRes |
||||
import androidx.core.content.edit |
||||
import androidx.fragment.app.Fragment |
||||
import org.jetbrains.anko.connectivityManager |
||||
import org.jetbrains.anko.defaultSharedPreferences |
||||
|
||||
fun Fragment.isOnline() = requireContext().connectivityManager.activeNetworkInfo?.isConnected == true |
||||
|
||||
fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) = |
||||
requireContext().defaultSharedPreferences.getBoolean(key, defValue) |
||||
|
||||
fun Fragment.putPrefBoolean(key: String, value: Boolean = false) = |
||||
requireContext().defaultSharedPreferences.edit { putBoolean(key, value) } |
||||
|
||||
fun Fragment.getPrefInt(key: String, defValue: Int = 0) = |
||||
requireContext().defaultSharedPreferences.getInt(key, defValue) |
||||
|
||||
fun Fragment.putPrefInt(key: String, value: Int) = |
||||
requireContext().defaultSharedPreferences.edit { putInt(key, value) } |
||||
|
||||
fun Fragment.getPrefLong(key: String, defValue: Long = 0L) = |
||||
requireContext().defaultSharedPreferences.getLong(key, defValue) |
||||
|
||||
fun Fragment.putPrefLong(key: String, value: Long) = |
||||
requireContext().defaultSharedPreferences.edit { putLong(key, value) } |
||||
|
||||
fun Fragment.getPrefString(key: String, defValue: String? = null) = |
||||
requireContext().defaultSharedPreferences.getString(key, defValue) |
||||
|
||||
fun Fragment.putPrefString(key: String, value: String) = |
||||
requireContext().defaultSharedPreferences.edit { putString(key, value) } |
||||
|
||||
fun Fragment.getPrefStringSet(key: String, defValue: MutableSet<String>? = null) = |
||||
requireContext().defaultSharedPreferences.getStringSet(key, defValue) |
||||
|
||||
fun Fragment.putPrefStringSet(key: String, value: MutableSet<String>) = |
||||
requireContext().defaultSharedPreferences.edit { putStringSet(key, value) } |
||||
|
||||
fun Fragment.removePref(key: String) = |
||||
requireContext().defaultSharedPreferences.edit { remove(key) } |
||||
|
||||
fun Fragment.getCompatColor(@ColorRes id: Int): Int = requireContext().getCompatColor(id) |
||||
|
||||
fun Fragment.getCompatDrawable(@DrawableRes id: Int): Drawable? = requireContext().getCompatDrawable(id) |
||||
|
||||
fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = requireContext().getCompatColorStateList(id) |
||||
|
||||
val Fragment.isNightTheme: Boolean |
||||
get() = getPrefBoolean("isNightTheme") |
||||
|
||||
val Fragment.isTransparentStatusBar: Boolean |
||||
get() = getPrefBoolean("transparentStatusBar") |
@ -0,0 +1,257 @@ |
||||
package io.legado.app.utils |
||||
|
||||
import android.view.View |
||||
import androidx.annotation.StringRes |
||||
import com.google.android.material.snackbar.Snackbar |
||||
|
||||
/** |
||||
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@Deprecated("Use 'View.snackbar(Int)' instead.", ReplaceWith("view.snackbar(message)")) |
||||
inline fun snackbar(view: View, message: Int) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_SHORT) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@Deprecated("Use 'View.longSnackbar(Int)' instead.", ReplaceWith("view.longSnackbar(message)")) |
||||
inline fun longSnackbar(view: View, message: Int) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_LONG) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@Deprecated("Use 'View.indefiniteSnackbar(Int)' instead.", ReplaceWith("view.indefiniteSnackbar(message)")) |
||||
inline fun indefiniteSnackbar(view: View, message: Int) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_INDEFINITE) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@Deprecated("Use 'View.snackbar(CharSequence)' instead.", ReplaceWith("view.snackbar(message)")) |
||||
inline fun snackbar(view: View, message: CharSequence) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_SHORT) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@Deprecated("Use 'View.longSnackbar(CharSequence)' instead.", ReplaceWith("view.longSnackbar(message)")) |
||||
inline fun longSnackbar(view: View, message: CharSequence) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_LONG) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@Deprecated("Use 'View.indefiniteSnackbar(CharSequence)' instead.", ReplaceWith("view.indefiniteSnackbar(message)")) |
||||
inline fun indefiniteSnackbar(view: View, message: CharSequence) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_INDEFINITE) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@Deprecated("Use 'View.snackbar(Int, Int, (View) -> Unit)' instead.", ReplaceWith("view.snackbar(message, actionText, action)")) |
||||
inline fun snackbar(view: View, message: Int, actionText: Int, noinline action: (View) -> Unit) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_SHORT) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@Deprecated("Use 'View.longSnackbar(Int, Int, (View) -> Unit)' instead.", ReplaceWith("view.longSnackbar(message, actionText, action)")) |
||||
inline fun longSnackbar(view: View, message: Int, actionText: Int, noinline action: (View) -> Unit) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_LONG) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@Deprecated("Use 'View.indefiniteSnackbar(Int, Int, (View) -> Unit)' instead.", ReplaceWith("view.indefiniteSnackbar(message, actionText, action)")) |
||||
inline fun indefiniteSnackbar(view: View, message: Int, actionText: Int, noinline action: (View) -> Unit) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_INDEFINITE) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@Deprecated("Use 'View.snackbar(CharSequence, CharSequence, (View) -> Unit)' instead.", ReplaceWith("view.snackbar(message, actionText, action)")) |
||||
inline fun snackbar(view: View, message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_SHORT) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@Deprecated("Use 'View.longSnackbar(CharSequence, CharSequence, (View) -> Unit)' instead.", ReplaceWith("view.longSnackbar(message, actionText, action)")) |
||||
inline fun longSnackbar(view: View, message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_LONG) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@Deprecated("Use 'View.indefiniteSnackbar(CharSequence, CharSequence, (View) -> Unit)' instead.", ReplaceWith("view.indefiniteSnackbar(message, actionText, action)")) |
||||
inline fun indefiniteSnackbar(view: View, message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar |
||||
.make(view, message, Snackbar.LENGTH_INDEFINITE) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@JvmName("snackbar2") |
||||
inline fun View.snackbar(@StringRes message: Int) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_SHORT) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@JvmName("longSnackbar2") |
||||
inline fun View.longSnackbar(@StringRes message: Int) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_LONG) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@JvmName("indefiniteSnackbar2") |
||||
inline fun View.indefiniteSnackbar(@StringRes message: Int) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_INDEFINITE) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@JvmName("snackbar2") |
||||
inline fun View.snackbar(message: CharSequence) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_SHORT) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@JvmName("longSnackbar2") |
||||
inline fun View.longSnackbar(message: CharSequence) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_LONG) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@JvmName("indefiniteSnackbar2") |
||||
inline fun View.indefiniteSnackbar(message: CharSequence) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_INDEFINITE) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@JvmName("snackbar2") |
||||
inline fun View.snackbar(message: Int, @StringRes actionText: Int, noinline action: (View) -> Unit) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_SHORT) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@JvmName("longSnackbar2") |
||||
inline fun View.longSnackbar(@StringRes message: Int, @StringRes actionText: Int, noinline action: (View) -> Unit) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_LONG) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
@JvmName("indefiniteSnackbar2") |
||||
inline fun View.indefiniteSnackbar(@StringRes message: Int, @StringRes actionText: Int, noinline action: (View) -> Unit) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_INDEFINITE) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@JvmName("snackbar2") |
||||
inline fun View.snackbar(message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_SHORT) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@JvmName("longSnackbar2") |
||||
inline fun View.longSnackbar(message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_LONG) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
||||
|
||||
/** |
||||
* Display Snackbar with the [Snackbar.LENGTH_INDEFINITE] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
@JvmName("indefiniteSnackbar2") |
||||
inline fun View.indefiniteSnackbar(message: CharSequence, actionText: CharSequence, noinline action: (View) -> Unit) = Snackbar |
||||
.make(this, message, Snackbar.LENGTH_INDEFINITE) |
||||
.setAction(actionText, action) |
||||
.apply { show() } |
@ -0,0 +1,80 @@ |
||||
package io.legado.app.utils |
||||
|
||||
import android.content.Context |
||||
import android.widget.Toast |
||||
import androidx.fragment.app.Fragment |
||||
import org.jetbrains.anko.longToast |
||||
import org.jetbrains.anko.toast |
||||
|
||||
|
||||
/** |
||||
* Display the simple Toast message with the [Toast.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
inline fun Fragment.toast(message: Int) = requireActivity().toast(message) |
||||
|
||||
/** |
||||
* Display the simple Toast message with the [Toast.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
inline fun Context.toast(message: Int): Toast = Toast |
||||
.makeText(this, message, Toast.LENGTH_SHORT) |
||||
.apply { |
||||
show() |
||||
} |
||||
|
||||
/** |
||||
* Display the simple Toast message with the [Toast.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
inline fun Fragment.toast(message: CharSequence) = requireActivity().toast(message) |
||||
|
||||
/** |
||||
* Display the simple Toast message with the [Toast.LENGTH_SHORT] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
inline fun Context.toast(message: CharSequence): Toast = Toast |
||||
.makeText(this, message, Toast.LENGTH_SHORT) |
||||
.apply { |
||||
show() |
||||
} |
||||
|
||||
/** |
||||
* Display the simple Toast message with the [Toast.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
inline fun Fragment.longToast(message: Int) = requireActivity().longToast(message) |
||||
|
||||
/** |
||||
* Display the simple Toast message with the [Toast.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text resource. |
||||
*/ |
||||
inline fun Context.longToast(message: Int): Toast = Toast |
||||
.makeText(this, message, Toast.LENGTH_LONG) |
||||
.apply { |
||||
show() |
||||
} |
||||
|
||||
/** |
||||
* Display the simple Toast message with the [Toast.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
inline fun Fragment.longToast(message: CharSequence) = requireActivity().longToast(message) |
||||
|
||||
/** |
||||
* Display the simple Toast message with the [Toast.LENGTH_LONG] duration. |
||||
* |
||||
* @param message the message text. |
||||
*/ |
||||
inline fun Context.longToast(message: CharSequence): Toast = Toast |
||||
.makeText(this, message, Toast.LENGTH_LONG) |
||||
.apply { |
||||
show() |
||||
} |
Loading…
Reference in new issue