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
object CountryFlags { | |
private val A = getEmojiByUnicode(0x1F1E6) | |
private val B = getEmojiByUnicode(0x1F1E7) | |
private val C = getEmojiByUnicode(0x1F1E8) | |
private val D = getEmojiByUnicode(0x1F1E9) | |
private val E = getEmojiByUnicode(0x1F1EA) | |
private val F = getEmojiByUnicode(0x1F1EB) | |
private val G = getEmojiByUnicode(0x1F1EC) | |
private val H = getEmojiByUnicode(0x1F1ED) | |
private val I = getEmojiByUnicode(0x1F1EE) |
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 LifecycleRecyclerView @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0 | |
) : RecyclerView(context, attrs, defStyleAttr), LifecycleObserver { | |
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) | |
private fun onDestroy() { | |
adapter = null | |
} |
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 ViewModelFactory constructor( | |
private val baseRepository: BaseRepository, // your repository class to handle database, network, shared preferences, etc. | |
owner: SavedStateRegistryOwner, | |
defaultArgs: Bundle? = null | |
) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { | |
// usage in activity: | |
// val sharedVM by viewModels<MySharedViewModel> { ViewModelFactory(App.getRep(), this) } | |
// App.getRep() returns instance of BaseRepository, replace with your actual logic | |
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.security.keystore.KeyGenParameterSpec | |
import android.security.keystore.KeyProperties | |
import java.security.* | |
import javax.crypto.* | |
import javax.crypto.spec.GCMParameterSpec | |
import android.util.Base64 | |
import androidx.annotation.VisibleForTesting | |
class EncryptionAES { |
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
inline fun <reified T> SharedPreferences.observeKey(key: String, default: T): Flow<T> = channelFlow { | |
send(getItem(key, default)) | |
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, k -> | |
if (key == k) { | |
trySend(getItem(key, default)) | |
} | |
} | |
registerOnSharedPreferenceChangeListener(listener) |
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
<ScrollView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layoutAnimation="@anim/layout_animation" | |
android:orientation="vertical"> | |
</ScrollView> |
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
// Generate a minor version code from git commit count (for prod builds) | |
static def generateVersionCode() { | |
def result = "git rev-list HEAD --count".execute().text.trim() //unix | |
if(result.empty) result = "PowerShell -Command git rev-list HEAD --count".execute().text.trim() //windows | |
if(result.empty) throw new RuntimeException("Could not generate versioncode on this platform? Cmd output: ${result.text}") | |
return result.toInteger() | |
} | |
def majorVersion = 1 |
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
launch(UI) { | |
editText.onTextChanged() | |
.debounce(1, TimeUnit.SECONDS) | |
.consumeEach { | |
Log.d("DebounceTest", "value: $it") | |
} | |
} | |
} | |
fun EditText.onTextChanged(): ReceiveChannel<String> = |
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
package com.gabrielfv.android.engine; | |
import android.app.Service; | |
import android.content.Intent; | |
import android.os.Handler; | |
import android.os.HandlerThread; | |
import android.os.IBinder; | |
import android.os.Looper; | |
import android.os.Message; | |
import android.os.PowerManager; |
NewerOlder