mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
Added context extensions
This commit is contained in:
parent
e2de6973bc
commit
b9bbd7990c
2
.gitignore
vendored
2
.gitignore
vendored
@ -6,3 +6,5 @@
|
|||||||
/build
|
/build
|
||||||
/captures
|
/captures
|
||||||
.externalNativeBuild
|
.externalNativeBuild
|
||||||
|
/release
|
||||||
|
/tmp
|
@ -1,13 +1,12 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
|
|
||||||
apply plugin: 'kotlin-android-extensions'
|
apply plugin: 'kotlin-android-extensions'
|
||||||
|
apply plugin: 'kotlin-kapt'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 28
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "io.legado.book"
|
applicationId "io.legado.app"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 1
|
versionCode 1
|
||||||
@ -24,12 +23,25 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
|
||||||
implementation 'androidx.core:core-ktx:1.0.2'
|
implementation 'androidx.core:core-ktx:1.0.2'
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation 'com.google.android.material:material:1.0.0'
|
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||||
|
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
||||||
|
implementation 'androidx.cardview:cardview:1.0.0'
|
||||||
|
implementation 'com.google.android.material:material:1.0.0'
|
||||||
|
|
||||||
|
implementation 'androidx.paging:paging-runtime:2.1.0'
|
||||||
|
|
||||||
|
def anko_version = '0.10.8'
|
||||||
|
implementation "org.jetbrains.anko:anko-sdk27:$anko_version"
|
||||||
|
implementation "org.jetbrains.anko:anko-sdk27-listeners:$anko_version"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'androidx.test:runner:1.1.1'
|
androidTestImplementation 'androidx.test:runner:1.1.1'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
|
||||||
|
42
app/src/main/java/io/legado/app/utils/ContextExtensions.kt
Normal file
42
app/src/main/java/io/legado/app/utils/ContextExtensions.kt
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package io.legado.app.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import org.jetbrains.anko.connectivityManager
|
||||||
|
import org.jetbrains.anko.defaultSharedPreferences
|
||||||
|
|
||||||
|
fun Context.isOnline() = connectivityManager.activeNetworkInfo?.isConnected == true
|
||||||
|
|
||||||
|
fun Context.getPrefBoolean(key: String, defValue: Boolean) =
|
||||||
|
defaultSharedPreferences.getBoolean(key, defValue)
|
||||||
|
|
||||||
|
fun Context.putPrefBoolean(key: String, value: Boolean) =
|
||||||
|
defaultSharedPreferences.edit { putBoolean(key, value) }
|
||||||
|
|
||||||
|
|
||||||
|
fun Context.getPrefInt(key: String, defValue: Int) =
|
||||||
|
defaultSharedPreferences.getInt(key, defValue)
|
||||||
|
|
||||||
|
fun Context.putPrefInt(key: String, value: Int) =
|
||||||
|
defaultSharedPreferences.edit { putInt(key, value) }
|
||||||
|
|
||||||
|
fun Context.getPrefLong(key: String, defValue: Long) =
|
||||||
|
defaultSharedPreferences.getLong(key, defValue)
|
||||||
|
|
||||||
|
fun Context.putPrefLong(key: String, value: Long) =
|
||||||
|
defaultSharedPreferences.edit { putLong(key, value) }
|
||||||
|
|
||||||
|
fun Context.getPrefString(key: String, defValue: String) =
|
||||||
|
defaultSharedPreferences.getString(key, defValue)
|
||||||
|
|
||||||
|
fun Context.putPrefString(key: String, value: String) =
|
||||||
|
defaultSharedPreferences.edit { putString(key, value) }
|
||||||
|
|
||||||
|
fun Context.getPrefStringSet(key: String, defValue: MutableSet<String>) =
|
||||||
|
defaultSharedPreferences.getStringSet(key, defValue)
|
||||||
|
|
||||||
|
fun Context.putPrefStringSet(key: String, value: MutableSet<String>) =
|
||||||
|
defaultSharedPreferences.edit { putStringSet(key, value) }
|
||||||
|
|
||||||
|
fun Context.removePref(key: String) =
|
||||||
|
defaultSharedPreferences.edit { remove(key) }
|
Loading…
Reference in New Issue
Block a user