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
private boolean notFirstTime; | |
@Override | |
public void setUserVisibleHint(boolean isVisibleToUser) { | |
super.setUserVisibleHint(isVisibleToUser); | |
if (isVisibleToUser && notFirstTime) { | |
//TODO: Call function to be executed every time. | |
requestData(); | |
} | |
} |
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.app.Service | |
import android.content.Intent | |
import android.os.IBinder | |
import android.support.annotation.Nullable | |
import android.support.annotation.WorkerThread | |
import kotlinx.coroutines.* | |
import kotlinx.coroutines.channels.Channel | |
import kotlinx.coroutines.channels.SendChannel | |
import kotlinx.coroutines.channels.actor | |
import kotlin.coroutines.CoroutineContext |
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
[ | |
{ | |
"eventType": "VIEW_CLICKED", | |
"timestamp": 1570986000016, | |
"replacementText": "", | |
"actionCode": -1, | |
"delayTime": 0, | |
"canScrollTo": false, | |
"elementDescriptors": [ | |
{ |
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
data class MainViewState(val fetchStatus: FetchStatus, val newsList: List<NewsItem>) | |
sealed class MainViewEffect { | |
data class ShowSnackbar(val message: String) : MainViewEffect() | |
data class ShowToast(val message: String) : MainViewEffect() | |
} | |
sealed class MainViewEvent { | |
data class NewsItemClicked(val newsItem: NewsItem) : MainViewEvent() | |
object FabClicked : MainViewEvent() |
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
abstract class AacMviActivity<STATE, EFFECT, EVENT, ViewModel : AacMviViewModel<STATE, EFFECT, EVENT>> : | |
AppCompatActivity() { | |
abstract val viewModel: ViewModel | |
private val viewStateObserver = Observer<STATE> { | |
Log.d(TAG, "observed viewState : $it") | |
renderViewState(it) | |
} |
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
open class AacMviViewModel<STATE, EFFECT, EVENT>(application: Application) : | |
AndroidViewModel(application), ViewModelContract<EVENT> { | |
private val _viewStates: MutableLiveData<STATE> = MutableLiveData() | |
fun viewStates(): LiveData<STATE> = _viewStates | |
private var _viewState: STATE? = null | |
protected var viewState: STATE | |
get() = _viewState | |
?: throw UninitializedPropertyAccessException("\"viewState\" was queried before being initialized") |
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 MainActVM(application: Application) : | |
AacMviViewModel<MainViewState, MainViewEffect, MainViewEvent>(application) { | |
init { | |
viewState = MainViewState(fetchStatus = FetchStatus.NotFetched, newsList = emptyList()) | |
} | |
override fun process(viewEvent: MainViewEvent) { | |
super.process(viewEvent) | |
} |
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 MainActivity : AacMviActivity<MainViewState, MainViewEffect, MainViewEvent, MainActVM>() { | |
override val viewModel: MainActVM by viewModels() | |
override fun renderViewState(viewState: MainViewState) { | |
//Handle new viewState | |
} | |
override fun renderViewEffect(viewEffect: MainViewEffect) { | |
//Show effects | |
} |
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
data class MainViewState(val fetchStatus: FetchStatus, val newsList: List<NewsItem>) | |
sealed class FetchStatus { | |
object Fetching : FetchStatus() | |
object Fetched : FetchStatus() | |
object NotFetched : FetchStatus() | |
} |
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
sealed class MainViewEffect { | |
data class ShowSnackbar(val message: String) : MainViewEffect() | |
data class ShowToast(val message: String) : MainViewEffect() | |
} |
OlderNewer