This file contains hidden or 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 Event<out T>(private val content: T) { | |
var hasBeenUsed = false | |
private set | |
fun getContentIfNotUsed(): T? { | |
return if (hasBeenUsed) { | |
null | |
} else { | |
hasBeenUsed = true |
This file contains hidden or 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
buildScript { | |
ext { | |
def appcompat_version = '1.1.0' | |
def constraint_layout_version = '1.1.3' | |
def coroutines_android_version = '1.3.2' | |
def reflect_android_version = '1.3.61' | |
def lifecycle_version = '2.1.0' | |
def livedata_version = '2.2.0-rc02' | |
def material_version = '1.0.0' | |
def security_version = '1.0.0-alpha02' |
This file contains hidden or 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
import android.content.Context | |
import android.content.SharedPreferences | |
import androidx.security.crypto.EncryptedSharedPreferences | |
import androidx.security.crypto.MasterKeys | |
import com.example.app.BuildConfig | |
class SecurePreferences(context: Context) { | |
private val _encryptedSharedPreferences: SharedPreferences |
This file contains hidden or 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
import android.text.Editable | |
import android.text.TextWatcher | |
abstract class SimpleTextWatcher : TextWatcher { | |
override fun afterTextChanged(s: Editable?) { | |
} | |
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { | |
} |
This file contains hidden or 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
import android.widget.DatePicker | |
import android.widget.Spinner | |
import androidx.databinding.BindingAdapter | |
import androidx.databinding.InverseBindingAdapter | |
import androidx.databinding.InverseBindingListener | |
import java.util.* | |
@BindingAdapter(value = ["selectedDate", "selectedDateAttrChanged"], requireAll = false) | |
fun DatePicker.selectedDate( | |
newSelectedDate: Date?, |
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Covid19 Cases in Countries</title> | |
</head> | |
<body style="padding: 0; margin: 0;"> | |
<!-- Peta --> |
This file contains hidden or 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 Validator { | |
companion object { | |
val EMAIL_REGEX = | |
Regex("(?:[a-z0-9!#\$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#\$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])") | |
val NUMBER_REGEX = Regex("^[0-9]+$") | |
} | |
enum class Field { |
This file contains hidden or 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 APIManager { | |
// client with persistent Cookie | |
public static OkHttpClient getRetrofitClient(final Context context) { | |
OkHttpClient client = new OkHttpClient(); | |
CookieManager cookieManager = new CookieManager(new PersistentCookieStore(context), CookiePolicy.ACCEPT_ALL); | |
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); | |
client.setCookieHandler(cookieManager); | |
return client; | |
} |
This file contains hidden or 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
abstract class AppPagedRecyclerViewAdapter<BIND : ViewDataBinding, M : Any>( | |
diffUtil: DiffUtil.ItemCallback<M> | |
) : PagedListAdapter<M, AppPagedRecyclerViewAdapter.ViewHolder<BIND>>(diffUtil) { | |
abstract fun onCreateViewBindingHolder(inflater: LayoutInflater, parent: ViewGroup): BIND | |
abstract fun onPrepareBindViewHolder(binding: BIND, model: M) | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder<BIND> { | |
val inflater = LayoutInflater.from(parent.context) |
This file contains hidden or 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 CombinedTransformation<T>( | |
vararg liveData: LiveData<*>, | |
private val onAllChanged: (data: List<Any?>) -> T | |
) : MediatorLiveData<T>() { | |
private val mLiveDataList: MutableList<Any?> = MutableList(liveData.size) { null } | |
init { | |
liveData.forEachIndexed { index, liveDatum -> | |
super.addSource(liveDatum) { datum -> |