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
interface MyGeneralObserver<T> { | |
void notifyUpdate(T value); | |
} | |
interface ObservableViewState { | |
void observeTitle(LifecycleOwner lifecycleOwner, MyGeneralObserver<String> observer); | |
} | |
interface IScreenPresenter extends ObservableViewState { | |
void loadData(); |
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 val backgroundColorLiveData = MutableLiveData<Int>() | |
override fun observeTitleBackgroundColorWithDefaultValue(lifecycle: Lifecycle, observer: (Int) -> Unit) { | |
observer(R.color.colorAccent) | |
backgroundColorLiveData.observe({lifecycle}) { | |
it?.let(observer) | |
} | |
} |
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
@RunWith(AndroidJUnit4::class) | |
class ScreenViewTests { | |
@get:Rule val testRule = createTestRuleWithFakeScreenViewInjector { | |
presenter = mockPresenter | |
} | |
private val mockPresenter = mock(IScreenPresenter::class.java) | |
@Test | |
fun someTest() { | |
val captor = lambdaArgumentCaptor<(String) -> Unit>() |
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
interface ObservableViewState { | |
fun observeTitle(lifecycle: Lifecycle, observer: (String) -> Unit) | |
} | |
interface IScreenPresenter : ObservableViewState { | |
fun loadData() | |
} | |
class ScreenPresentationState : ObservableViewState { | |
private val titleLiveData = MutableLiveData<String>() |
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 JobCanceler : LifecycleObserver { | |
var job: Job? = null | |
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | |
fun cancelJob() { | |
job?.cancel() | |
} | |
} |
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 ProgressBarState | |
object ProgressBarShowState : ProgressBarState() | |
object ProgressBarHideState : ProgressBarState() | |
interface SomeScreenViewObservers { | |
fun observeProgressBarState(lifecycle: Lifecycle, observer: (ProgressBarState) -> Unit) | |
} | |
interface IPresenter { |
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 SomeScreenContract { | |
public interface View { | |
void showProgressBar(); | |
void hideProgressBar(); | |
} | |
public interface IPresenter { | |
void startSomethingButtonClicked(); | |
} | |
} |
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 SharedUiData | |
class FragmentInteractionViewModel : ViewModel() { | |
val interactionLiveData = MutableLiveData<SharedUiData>() | |
} | |
class FragmentA : Fragment() { | |
fun publishNextUiDataToNextScreen(sharedUiData: SharedUiData) { | |
val viewModel = ViewModelProviders.of(activity) | |
.get(FragmentInteractionViewModel::class.java) |
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
@RunWith(AndroidJUnit4::class) | |
class MainViewTests { | |
val mockUserAction = mock(MainContract.UserAction::class.java) | |
@get:Rule | |
val activityTestRule = object : ActivityTestRule<MainActivity>(MainActivity::class.java, true, true) { | |
override fun beforeActivityLaunched() { | |
super.beforeActivityLaunched() | |
val myApp = InstrumentationRegistry.getTargetContext().applicationContext as MyApp | |
myApp.dispatchingActivityInjector = createFakeFragmentInjector<MainFragment> { |
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.shop.app | |
import android.app.Activity | |
import android.support.test.InstrumentationRegistry | |
import android.support.v4.app.Fragment | |
import com.shop.app.common.BaseActivity | |
import dagger.android.AndroidInjector | |
import dagger.android.DispatchingAndroidInjector | |
import dagger.android.DispatchingAndroidInjector_Factory | |
import dagger.android.dispatchingActivityInjector |
NewerOlder