This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.library' | |
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-kapt' | |
apply from: "$rootDir/gradle/dependencies.gradle" | |
def ext = rootProject.ext | |
android { | |
compileSdkVersion ext.compileSdkVersion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.berider.app.common.utils | |
import android.app.Activity | |
import android.content.Intent | |
import android.os.Bundle | |
import android.os.Parcelable | |
import android.view.inputmethod.InputMethodManager | |
import androidx.activity.OnBackPressedCallback | |
import androidx.appcompat.app.ActionBar | |
import androidx.appcompat.app.AppCompatActivity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeRepository( | |
private val someManager: SomeManager | |
) : ISomeRepository, BaseRepository() { | |
override val userId: Long? | |
get() = someManager.userId | |
override fun testSet(userId: Long) { | |
someManager.userId = userId | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Generic<T : Any>(val c: Class<T>) { | |
companion object { | |
/** | |
* Returns generic's argument class. | |
*/ | |
inline operator fun <reified T : Any> invoke() = Generic(T::class.java) | |
} | |
/** | |
* Check if value is instance of desired class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* SharedPreferences.Editor extension function for putting [value] as Any into Shared preferences. | |
* @param key - key for the value. | |
* @param value - value as Any. | |
*/ | |
@Suppress("UNCHECKED_CAST") | |
fun SharedPreferences.Editor.putAny(key: String, value: Any) { | |
when { | |
Generic<String>().checkType(value) -> (value as? String)?.let { putString(key, it) } | |
Generic<Boolean>().checkType(value) -> (value as? Boolean)?.let { putBoolean(key, it) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class PreferencesDelegate<T>(private val key: String) { | |
private var variable: Any? = null | |
private var initialized = false | |
/** | |
* Saves given value to SharedPreferences on synchronized thread. | |
* @param thisRef - is the reference to the class that contains the property | |
* @param property - is an instance of the [KProperty] class, which contains metadata. | |
*/ | |
open operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class PreferencesDelegate<T>(private val key: String) { | |
private var variable: Any? = null | |
private var initialized = false | |
/** | |
* Return desired value by a given key. Performing operation on synchronized thread. | |
* @param thisRef - is the reference to the class that contains the property | |
* @param property - is an instance of the [KProperty] class, which contains metadata. | |
* @return T - T or null. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SomeManager.kt | |
interface SomeManager { | |
var userId: Long? | |
var userName: String? | |
/** | |
* Returns true if user valid. | |
*/ | |
fun isUserValid(): Boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class PreferencesDelegate<T>(private val key: String) { | |
private var variable: Any? = null | |
/** | |
* Performing operation on synchronized thread. | |
* @param thisRef - is the reference to the class that contains the property | |
* @param property - is an instance of the [KProperty] class, which contains metadata. | |
* @return T - desired value by a given key or null. | |
*/ | |
open operator fun getValue(thisRef: Any?, property: KProperty<*>): T? { |
NewerOlder