Skip to content

Instantly share code, notes, and snippets.

View joecks's full-sized avatar

joecks

  • Flutter & Android Freelancer
  • Berlin
View GitHub Profile
@joecks
joecks / showFlags(Intent intent)
Created January 17, 2013 20:16
Prints all flags of an Android Intent, which is very useful for debugging Intents!
Field[] declaredFields = Intent.class.getDeclaredFields();
for (Field field : declaredFields) {
if (field.getName().startsWith("FLAG_")) {
try {
int flag = field.getInt(null);
if ((intent.getFlags() & flag) != 0) {
log.d(field.getName());
}
data class TasksViewData(val dataLoading : Boolean,
val empty: Boolean,
@StringRes val currentFilteringLabel : Int,
@DrawableRes val noTaskIconRes: Int,
@StringRes val noTasksLabel : Int,
val tasksAddViewVisible : Boolean,
val items: List<Task>,
val message: ViewMessage = InvalidMessage)
public class TasksViewModel extends AndroidViewModel {
// These observable fields will update Views automatically
public final ObservableList<Task> items = new ObservableArrayList<>();
public final ObservableBoolean dataLoading = new ObservableBoolean(false);
public final ObservableField<String> currentFilteringLabel = new ObservableField<>();
public final ObservableField<String> noTasksLabel = new ObservableField<>();
public final ObservableField<Drawable> noTaskIconRes = new ObservableField<>();
public final ObservableBoolean empty = new ObservableBoolean(false);
public final ObservableBoolean tasksAddViewVisible = new ObservableBoolean();
// Listen to Single Event live-data object that will only report a snackbar message once
mTasksViewModel.getSnackbarMessage().observe(this, new SnackbarMessage.SnackbarObserver() {
@Override
public void onNewMessage(@StringRes int snackbarMessageResourceId) {
SnackbarUtils.showSnackbar(getView(), getString(snackbarMessageResourceId));
}
});
...
// Bind onItemClick onItemSelect to the view-model
// BaseReacteFragment method which auto listenes to viewData updates
override fun applyViewData(viewData: TasksViewData) {
mTasksFragBinding.viewmodel = viewData
mListAdapter.tasks = viewData.items
SnackbarUtils.showMessage(view, viewData.message)
}
...
// Bind the TasksViewItemActions to the adapter (onItemClick, onItemCheck)
mListAdapter = TasksAdapter(
interface TasksActions {
fun onTaskDetails(taskId: String)
fun onNewTask()
}
class TasksViewModel(private val tasksRepository: TasksRepository,
// The injected callbacks for highlevel actions like onNewTask, onTaskDetails
private val tasksActions: TasksActions) : BaseReactViewModel<TasksViewData>(),
// The taks item Actions
TasksViewItemActions,
// Definition of the provided dependencies of the MainActivity
class MainActivityDependencies(private val activity: FragmentActivity) : Dependencies {
override fun taskRepository(): TasksRepository {
return TasksRepository.getInstance(TasksRemoteDataSource.instance, TasksLocalDataSource.getInstance(activity))
}
fun mainViewModel(): MainViewModel = ViewModelProviders.of(activity).get(MainViewModel::class.java)
fun tasksActions(): TasksActions = mainViewModel()
class MainViewModel : BaseReactViewModel<Data>(), TasksActions, AddEditActions {
override val initialViewData = TasksData
override fun onSaveTask() {
updateViewData(TasksData)
}
override fun onTaskDetails(taskId: String) {
updateViewData(EditTaskData(taskId))
class OpenRideMapTest : BaseRobotTest(
mockDependencyTestRule = mock(locationFound()),
testCase =
{
inLanding {
inLandingList {
inItem(2) { click() }
}
}
inDetails {
class RideDetails : ScopedActions(idMatcher(R.id.ride_details_container)) {
fun inRideEditButton(action: UiActions.() -> Actions) =
UiActions(idMatcher(R.id.rideBookedDetailEdit)).action()
fun inRideMapButton(action: UiActions.() -> Actions) =
UiActions(idMatcher(R.id.map_item)).action()
fun inRideStopList(action: List.() -> Actions) =
List(R.id.ridesStopsRecycler).action()