Skip to content

Instantly share code, notes, and snippets.

View JohnLeeroy's full-sized avatar

John Li JohnLeeroy

View GitHub Profile
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
class MVPLifecycleObserver<VIEW : BaseView<PRESENTER>, PRESENTER : BasePresenter<VIEW>>(
private val view: VIEW,
private val presenter: PRESENTER,
private val retainedState: RetainedState
) : LifecycleObserver {
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
class RetainedState(private val state: SavedStateHandle) : ViewModel() {
fun <T> get(key: String): T? {
return state.get(key)
}
fun <T> remove(key: String): T? {
interface BaseView<PRESENTER> {
fun getPresenter(): PRESENTER
}
import androidx.annotation.CallSuper
interface PresenterContract<VIEW> {
fun attach(view: VIEW, retainedState: RetainedState)
fun detach()
fun onViewAttached()
fun onViewDetached()
}
abstract class BasePresenter<VIEW>: PresenterContract<VIEW> {
interface AppRepository {
suspend fun getAppById(id: Long): AppDetail
suspend fun getAppsByPublisher(publisherId: Long): List<AppDetail>
}
class AppApiRepository(private val api: AppApi) : AppRepository {
override suspend fun getAppById(id: Long): AppDetail { /*...*/ }
override suspend fun getAppsByPublisher(publisherId: Long): List<AppDetail> { /*...*/ }
}
data class AppDetail(
val id: Long,
val name: String,
val description: String,
val publisher: Publisher
)
interface ResultCallback<T> {
fun onSuccess(result: T)
fun onError(exception: Exception)
class KataTest {
@Test
fun testStringInvokeOverride() {
val arg = "somearg"
val result = "SomeThing"(arg)
assert.true(result, arg)
}
operator fun <T> String.invoke(arg : T) : T{
@JohnLeeroy
JohnLeeroy / README.md
Created August 7, 2019 10:55 — forked from lopspower/README.md
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

All hex value from 100% to 0% alpha:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/video_view"
android:layout_width="0dp"
android:layout_height="0dp"
@JohnLeeroy
JohnLeeroy / Topics.txt
Created July 17, 2017 20:37
Android Speaking Topics
Androind N
- Notification badges
- Wi-Fi Aware
- Instant App
Android
- Wearables
- Android TV
- Android Studio tools & plugins
Debugging Tips
Optimization Tips