Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Building Coinverse's Android app

AdamHurwitz AdamSHurwitz

🚀
Building Coinverse's Android app
View GitHub Profile
@AdamSHurwitz
AdamSHurwitz / ClickListener.java
Created Jul 22, 2020
ODG - Android Touch Feedback: Click listener abbreviation
View ClickListener.java
// Pass method
layoutName.setOnClickListener(onItemClicked);
private View.OnClickListener onItemClicked = view → // Do something;
// Or
private View.OnClickListener onItemClicked =
view → {
// Do something;
};
@AdamSHurwitz
AdamSHurwitz / FeedFragment.kt
Last active Jul 20, 2020
Android Model-View-Intent with Kotlin Flow - LiveData FeedViewState.kt
View FeedFragment.kt
// The view observes the immutable LiveData value emissions
private fun initViewStates() {
feedViewModel.state.feedList.observe(viewLifecycleOwner) { pagedList ->
adapter.submitList(pagedList)
}
}
@AdamSHurwitz
AdamSHurwitz / FeedView.kt
Last active Jul 20, 2020
Android Model-View-Intent with Kotlin Flow - FeedAdapter.kt
View FeedView.kt
import app.coinverse.utils.Event
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
@ExperimentalCoroutinesApi
interface FeedView {
/**
* Intent to load the current feed state
*
* @return A flow that inits the current feed state
@AdamSHurwitz
AdamSHurwitz / FeedAdapter.kt
Last active Aug 11, 2020
Android Model-View-Intent with Kotlin Flow - FeedAdapter.kt
View FeedAdapter.kt
@ExperimentalCoroutinesApi
class FeedAdapter(private val intent: FeedViewIntent) : PagedListAdapter<Content, FeedAdapter.ViewHolder>(DIFF_CALLBACK) {
private fun createOnClickListener(content: Content, position: Int) = OnClickListener { view ->
when (view.id) {
preview -> intent.selectContent.value = Event(SelectContent(...))
}
}
}
@AdamSHurwitz
AdamSHurwitz / FeedViewIntent.kt
Last active Aug 11, 2020
Android Model-View-Intent with Kotlin Flow - FeedViewIntent.kt
View FeedViewIntent.kt
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
@ExperimentalCoroutinesApi
class FeedViewIntent(
val loadFromNetwork: MutableStateFlow<Boolean?> = MutableStateFlow(null),
val selectContent: MutableStateFlow<Event<SelectContent?>> = MutableStateFlow(Event(null)),
) {
data class FeedLoad(
val feedType: FeedType,
@AdamSHurwitz
AdamSHurwitz / FeedFragment.kt
Last active Jul 20, 2020
Android Model-View-Intent with Kotlin Flow - FeedFragment.kt
View FeedFragment.kt
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.filterNotNull
@ExperimentalCoroutinesApi
class FeedFragment : Fragment(), FeedView {
private val intent = FeedViewIntent()
private lateinit var feedViewModel: FeedViewModel
override fun onCreateView(...): View? {
@AdamSHurwitz
AdamSHurwitz / FeedViewState.kt
Last active Jul 20, 2020
Android Model-View-Intent with Kotlin Flow - FeedViewState.kt
View FeedViewState.kt
sealed class FeedViewState {
data class Feed(
val toolbarState: ToolbarState = ToolbarState(),
val feed: PagedList<Content>,
val error: String? = null
) : FeedViewState()
data class OpenContent(
val isLoading: Boolean = false,
val position: Int,
@AdamSHurwitz
AdamSHurwitz / FeedViewModel.kt
Last active Jul 21, 2020
Android Model-View-Intent with Kotlin Flow - FeedViewModel.kt
View FeedViewModel.kt
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ExperimentalCoroutinesApi
class FeedViewModel @AssistedInject constructor(
@AdamSHurwitz
AdamSHurwitz / ApplicationComponent.kt
Last active Jul 19, 2020 — forked from Zhuinden/ApplicationComponent.kt
Dagger + ViewModel + SavedStateHandle
View ApplicationComponent.kt
@Singleton
@Component(modules = [AssistedInjectionModule::class])
interface ApplicationComponent {
fun mySavedStateViewModelFactory(): MySavedStateViewModel.Factory
}
@AdamSHurwitz
AdamSHurwitz / PrintAssert.kt
Created Jul 1, 2020
Test util for print Assertions
View PrintAssert.kt
fun <T> printAssert(actual: T, expect: T) {
println("Actual: ${actual}")
println("Expect: ${expect}")
println()
}
You can’t perform that action at this time.