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 CounterActivity : AppCompatActivity() { | |
private val viewModel by viewModels<CounterViewModel>() | |
private lateinit var binding: ActivityCounterBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivityCounterBinding.inflate(layoutInflater) | |
setContentView(binding.root) |
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 CounterViewModel(private val store: Store<CounterState>) : ViewModel() { | |
val actions: Flow<Action> = store.actions | |
val states: Flow<CounterState> = store.states | |
override fun onCleared() { | |
super.onCleared() | |
store.terminate() | |
} |
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 Store<S : State>( | |
initialState: S, | |
reduce: (Action, S) -> S, | |
val scope: CoroutineScope, | |
) { | |
private val inputActionsChannel: Channel<Action> = | |
Channel(capacity = Channel.UNLIMITED) | |
private val outputChannel: Channel<S> = Channel() |
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
fun <S : State> CoroutineScope.stateMachine( | |
initialState: S, | |
inputActionsChannel: ReceiveChannel<Action>, | |
outputChannel: SendChannel<S>, | |
publishActions: MutableSharedFlow<Action>, | |
outputStateFlow: MutableStateFlow<S>, | |
reduce: (Action, S) -> S, | |
) = launch { | |
var state = initialState |
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
import kotlinx.coroutines.CoroutineStart.LAZY | |
import kotlinx.coroutines.Deferred | |
import kotlinx.coroutines.async | |
import kotlinx.coroutines.cancelAndJoin | |
import kotlinx.coroutines.coroutineScope | |
import kotlinx.coroutines.sync.Mutex | |
import kotlinx.coroutines.sync.withLock | |
import kotlinx.coroutines.yield | |
import java.util.concurrent.atomic.AtomicReference | |
import kotlin.DeprecationLevel.ERROR |
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.yourcompany.name | |
import android.graphics.Rect | |
import android.view.View | |
import androidx.recyclerview.widget.GridLayoutManager | |
import androidx.recyclerview.widget.RecyclerView | |
class EqualSpaceItemDecoration(private val padding: Int) : | |
RecyclerView.ItemDecoration() { |
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.yourcompany.name | |
import android.content.Context | |
import android.util.AttributeSet | |
import android.view.View | |
import android.widget.Checkable | |
import androidx.constraintlayout.widget.ConstraintLayout | |
class CheckableConstraintLayout @JvmOverloads constructor( | |
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 |
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
import groovy.json.JsonOutput | |
import groovy.json.JsonSlurper | |
class ActivityPostBody { | |
Activity[] app_content | |
String app_id | |
String app_version | |
} | |
class Activity { |
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
import android.graphics.Rect; | |
import android.support.v7.widget.GridLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.View; | |
public class EqualSpacingGridItemDecorator extends RecyclerView.ItemDecoration { | |
private final int padding; | |
public EqualSpacingGridItemDecorator(int padding) { |
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
public class SquareCardView extends CardView { | |
public SquareCardView(Context context) { | |
super(context); | |
} | |
public SquareCardView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
@Override |