Skip to content

Instantly share code, notes, and snippets.

View addeeandra's full-sized avatar
🧭
I am, therefore I am.

Aditya Chandra addeeandra

🧭
I am, therefore I am.
View GitHub Profile
@addeeandra
addeeandra / SimpleTextWatcher.kt
Created February 18, 2020 07:18
A simple TextWatcher, cause you don't need all of its functions
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) {
}
@addeeandra
addeeandra / SecurePreferences.kt
Created January 13, 2020 08:48
SharedPreferences wrapper in secure way with encryption
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
@addeeandra
addeeandra / build.gradle
Last active January 13, 2020 08:32
Default libs
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'
@addeeandra
addeeandra / Event.kt
Last active January 31, 2021 15:43
ViewModel SingleLiveEvent - Wraps the MutableLiveData<ActionEvent<T>>
class Event<out T>(private val content: T) {
var hasBeenUsed = false
private set
fun getContentIfNotUsed(): T? {
return if (hasBeenUsed) {
null
} else {
hasBeenUsed = true
@addeeandra
addeeandra / AnyViewModelHolder.kt
Last active December 27, 2019 11:58
ViewModel Utility Classes
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
open class BindingViewHolder<T, V : ViewDataBinding, L : BindingListener<T>>(
private val binding: V,
private val listener: L?
) : RecyclerView.ViewHolder(binding.root) {
fun bind(data: T) {
binding.setVariable(BR.viewmodel, data)
@addeeandra
addeeandra / koman.sh
Last active April 11, 2020 11:13
Common PHP & Mysql Setup Command in Ubuntu
# in case u need it (common)
sudo apt-get install curl wget unzip
# install mysql
sudo apt-get install mysql-server
# setup mysql
sudo mysql_secure_installation
# Optional step - if mysql can't login using other users
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Region
import android.os.Build
import android.util.AttributeSet
import android.view.View
class ClipBoxView(ctx: Context, attrs: AttributeSet) : View(ctx, attrs) {
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
open class AnyFragmentPagerAdapter(
fm: FragmentManager,
private val mPages: List<AnyPagerableFragment>
) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
@addeeandra
addeeandra / btn_rounded_primary.xml
Created April 26, 2019 20:39
Button Rounded Primary - with selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/btn_rounded_primary_disabled"/>
<item android:state_pressed="true" android:drawable="@drawable/btn_rounded_primary_pressed"/>
<item android:drawable="@drawable/btn_rounded_primary_normal"/>
</selector>
@addeeandra
addeeandra / FieldConverters.kt
Last active October 31, 2019 03:09
Example of @TypeConverters in Room Persistence Database
import androidx.room.TypeConverters
import java.util.*
class FieldConverters {
@TypeConverters
fun fromTimestamp(value: Long?): Date? {
return value?.let { Date(it) }
}