Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mô Dev todo mvp tablet dialogfragment #670

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0a92311
Adds tablet mode, without tablet presenter
JoseAlcerreca Jul 25, 2016
e658d6c
Adds tablet mode, using a tablet presenter
JoseAlcerreca Jul 25, 2016
95794b8
Fixes tablet UI and uses retained fragments to save state.
JoseAlcerreca Jul 28, 2016
88d7afc
Cleaning, refactoring, testing, upgrading versions
JoseAlcerreca Jul 29, 2016
062998f
Resets README
JoseAlcerreca Jul 29, 2016
3da9736
Fixes some comments
JoseAlcerreca Jul 29, 2016
7ace7d3
Bumps versions and typo fix
JoseAlcerreca Aug 22, 2016
d678482
Fixes N7 NPE
JoseAlcerreca Sep 5, 2016
1e8d218
Sets retain instances to false and refactors the whole thing
JoseAlcerreca Nov 3, 2016
e822ec6
Renames the starting methods of presenters and fixes unit tests
JoseAlcerreca Nov 3, 2016
cd4daef
Fixes UI tests in non-EN locales
JoseAlcerreca Nov 4, 2016
edd28bf
Moves isTablet to utils and uses a listSelector for highlighting
JoseAlcerreca Nov 7, 2016
d1ecfd3
Build before pushing, kids
JoseAlcerreca Nov 7, 2016
0b1a71a
Merge pull request #131 from JoseAlcerreca/dev-todo-mvp-tablet-uberpr…
malmstein Nov 7, 2016
cf25f8c
Adds README to mvp-tablet
JoseAlcerreca Nov 8, 2016
626ea26
Shows a dialog instead of a new activity when adding or editing a task
JoseAlcerreca Nov 8, 2016
61760a9
Removes longclick edits task
JoseAlcerreca Nov 9, 2016
c4d17f4
The MVP controller is now only used in tablet mode
JoseAlcerreca Nov 10, 2016
158e5f3
restores scrollview to fix the coordinatorlayout behavior
JoseAlcerreca Nov 10, 2016
8dc13f6
Fixes the empty task case on tablet
JoseAlcerreca Nov 11, 2016
ea03e27
Update README.md
JoseAlcerreca Nov 14, 2016
c487af6
Adds an interface to show that a navigator could be moved out of the …
JoseAlcerreca Nov 15, 2016
3bc6e6f
Merge pull request #232 from googlesamples/JoseAlcerreca-tablet-readme
JoseAlcerreca Nov 22, 2016
0407433
Creates Tablet Navigator
JoseAlcerreca Nov 22, 2016
fd1da06
Merge remote-tracking branch 'origin/dev-todo-mvp-tablet' into dev-to…
JoseAlcerreca Nov 22, 2016
98baaa9
Merge remote-tracking branch 'origin/todo-mvp' into dev-todo-mvp-tablet
JoseAlcerreca Nov 22, 2016
decf037
Fixes merge issue with fab ids
JoseAlcerreca Nov 22, 2016
a502194
Merge branch 'dev-todo-mvp-tablet' into dev-todo-mvp-tablet_dialogfra…
JoseAlcerreca Nov 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds tablet mode, using a tablet presenter
  • Loading branch information
JoseAlcerreca committed Jul 25, 2016
commit e658d6c3e2b0815107c8b8c232c5bbe290fab7fe
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.example.android.architecture.blueprints.todoapp.taskdetail;

import com.example.android.architecture.blueprints.todoapp.BasePresenter;
import com.example.android.architecture.blueprints.todoapp.BaseView;

/**
Expand Down Expand Up @@ -51,7 +50,7 @@ interface View extends BaseView<Presenter> {
boolean isActive();
}

interface Presenter extends BasePresenter {
interface Presenter {

void editTask();

Expand All @@ -60,5 +59,7 @@ interface Presenter extends BasePresenter {
void completeTask();

void activateTask();

void startTaskDetailPresenter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static TaskDetailFragment newInstance(String taskId) {
@Override
public void onResume() {
super.onResume();
mPresenter.start();
mPresenter.startTaskDetailPresenter();
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,30 @@
import com.example.android.architecture.blueprints.todoapp.data.Task;
import com.example.android.architecture.blueprints.todoapp.data.source.TasksDataSource;
import com.example.android.architecture.blueprints.todoapp.data.source.TasksRepository;
import com.example.android.architecture.blueprints.todoapp.tasks.TasksNavigator;
import com.example.android.architecture.blueprints.todoapp.tasks.TasksPresenter;

/**
* Listens to user actions from the UI ({@link TaskDetailFragment}), retrieves the data and updates
* the UI as required.
*/
public class TaskDetailPresenter implements TaskDetailContract.Presenter {

@NonNull private final TasksRepository mTasksRepository;
private final TasksRepository mTasksRepository;

private final TaskDetailContract.View mTaskDetailView;

@NonNull private TasksPresenter mTasksPresenter;

@NonNull private TasksNavigator mTasksNavigator;

@Nullable
private String mTaskId;

public TaskDetailPresenter(@Nullable String taskId,
@NonNull TasksRepository tasksRepository,
@NonNull TaskDetailContract.View taskDetailView,
@NonNull TasksNavigator tasksNavigator) {
@NonNull TaskDetailContract.View taskDetailView) {
this.mTaskId = taskId;
mTasksRepository = checkNotNull(tasksRepository, "tasksRepository cannot be null!");
mTaskDetailView = checkNotNull(taskDetailView, "taskDetailView cannot be null!");
mTasksNavigator = checkNotNull(tasksNavigator);
}

@Override
public void start() {
public void startTaskDetailPresenter() {
if (mTaskDetailView.isActive()) {
openTask();
}
Expand Down Expand Up @@ -107,12 +99,7 @@ public void editTask() {
@Override
public void deleteTask() {
mTasksRepository.deleteTask(mTaskId);
if (isTablet()) {
mTasksPresenter.start();
mTasksNavigator.removeDetailPane();
} else {
mTaskDetailView.showTaskDeleted();
}
mTaskDetailView.showTaskDeleted();
}

@Override
Expand All @@ -123,11 +110,6 @@ public void completeTask() {
}
mTasksRepository.completeTask(mTaskId);
showTaskMarkedComplete();

// In tablet mode, ping the other presenter in case it needs to update
if (mTasksPresenter != null) {
mTasksPresenter.start();
}
}

public void showTaskMarkedComplete() {
Expand All @@ -142,11 +124,6 @@ public void activateTask() {
}
mTasksRepository.activateTask(mTaskId);
mTaskDetailView.showTaskMarkedActive();

// In tablet mode, ping the other presenter in case it needs to update
if (mTasksPresenter != null) {
mTasksPresenter.start();
}
}

private void showTask(Task task) {
Expand All @@ -171,12 +148,4 @@ private void showTask(Task task) {
public String getTaskId() {
return mTaskId;
}

public void setTasksPresenter(TasksPresenter tasksPresenter) {
mTasksPresenter = tasksPresenter;
}

private boolean isTablet() {
return mTasksPresenter != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.example.android.architecture.blueprints.todoapp.BaseView;
import com.example.android.architecture.blueprints.todoapp.data.Task;
import com.example.android.architecture.blueprints.todoapp.BasePresenter;

import java.util.List;

Expand Down Expand Up @@ -66,7 +65,7 @@ interface View extends BaseView<Presenter> {
void showFilteringPopUpMenu();
}

interface Presenter extends BasePresenter {
interface Presenter {

void result(int requestCode, int resultCode);

Expand All @@ -85,5 +84,7 @@ interface Presenter extends BasePresenter {
void setFiltering(TasksFilterType requestType);

TasksFilterType getFiltering();

void startTasksPresenter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
@Override
public void onResume() {
super.onResume();
mPresenter.start();
mPresenter.startTasksPresenter();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class TasksMvpController {

private final FragmentActivity mFragmentActivity;

private TasksTabletPresenter mTasksTabletPresenter;

private TasksPresenter mTasksPresenter;

private TaskDetailPresenter mTaskDetailPresenter;
Expand Down Expand Up @@ -103,33 +105,44 @@ public TaskDetailFragment createDetailViewForTablet(String taskId) {
TaskDetailFragment taskDetailFragment = TaskDetailFragment.newInstance(taskId);

// Create the Presenter
mTaskDetailPresenter = createTaskDetailPresenter(taskId,
TaskDetailPresenter taskDetailPresenter = createTaskDetailPresenter(taskId,
taskDetailFragment);

// Wire presenters
taskDetailFragment.setPresenter(mTaskDetailPresenter);
mTasksPresenter.setTaskDetailPresenter(mTaskDetailPresenter);
mTaskDetailPresenter.setTasksPresenter(mTasksPresenter);

mTasksTabletPresenter.setTaskDetailPresenter(taskDetailPresenter);
taskDetailFragment.setPresenter(mTasksTabletPresenter);
return taskDetailFragment;
}

private void createTabletElements() {
TasksFragment tasksFragment;// Tablet presenter rule all presenters

mTasksTabletPresenter = new TasksTabletPresenter(
Injection.provideTasksRepository(mFragmentActivity),
new TasksNavigator(mFragmentActivity, this));

tasksFragment = findOrCreateTasksFragment();
mTasksPresenter = createListPresenter(tasksFragment);
mTasksTabletPresenter.setTasksPresenter(mTasksPresenter);

tasksFragment.setPresenter(mTasksPresenter);
tasksFragment.setPresenter(mTasksTabletPresenter);

// TaskDetailFragment is retained, so let's reuse its presenter.
TaskDetailFragment taskDetailFragment = getDetailFragment();
if (taskDetailFragment != null && taskDetailFragment.isAdded()) {
mTaskDetailPresenter =
(TaskDetailPresenter) taskDetailFragment.getPresenter();

mTasksPresenter.setTaskDetailPresenter(mTaskDetailPresenter);
mTaskDetailPresenter.setTasksPresenter(mTasksPresenter);
if (taskDetailFragment.getPresenter() instanceof TasksTabletPresenter) {
TasksTabletPresenter retainedPresenter =
(TasksTabletPresenter) taskDetailFragment.getPresenter();

TaskDetailPresenter retainedTaskDetailPresenter =
retainedPresenter.getTaskDetailPresenter();

mTasksTabletPresenter.setTaskDetailPresenter(retainedTaskDetailPresenter);

// Replace retained presenter with new one.
taskDetailFragment.setPresenter(mTasksTabletPresenter);
}
}
}

Expand All @@ -139,15 +152,13 @@ private TaskDetailPresenter createTaskDetailPresenter(
return new TaskDetailPresenter(
taskId,
Injection.provideTasksRepository(mFragmentActivity.getApplicationContext()),
taskDetailFragment,
new TasksNavigator(mFragmentActivity, this));
taskDetailFragment);
}

private TasksPresenter createListPresenter(TasksFragment tasksFragment) {
mTasksPresenter = new TasksPresenter(
Injection.provideTasksRepository(mFragmentActivity.getApplicationContext()),
tasksFragment,
new TasksNavigator(mFragmentActivity, this));
tasksFragment);

return mTasksPresenter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public boolean isTablet() {
return mFragmentActivity.getResources().getBoolean(R.bool.isTablet);
}

public void removeDetailPane() {
private void removeDetailPane() {
Fragment detailFragment = getDetailFragment();
FragmentTransaction transaction = mFragmentActivity.getSupportFragmentManager().beginTransaction();
transaction.remove(detailFragment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.example.android.architecture.blueprints.todoapp.addedittask.AddEditTaskActivity;
import com.example.android.architecture.blueprints.todoapp.data.Task;
import com.example.android.architecture.blueprints.todoapp.data.source.TasksDataSource;
import com.example.android.architecture.blueprints.todoapp.data.source.TasksRepository;
import com.example.android.architecture.blueprints.todoapp.taskdetail.TaskDetailPresenter;
import com.example.android.architecture.blueprints.todoapp.util.EspressoIdlingResource;

import java.util.ArrayList;
Expand All @@ -36,39 +34,28 @@
* Listens to user actions from the UI ({@link TasksFragment}), retrieves the data and updates the
* UI as required.
*/
public class TasksPresenter implements TasksContract.Presenter {
class TasksPresenter implements TasksContract.Presenter {

private final TasksRepository mTasksRepository;

private final TasksContract.View mTasksView;
@NonNull
private final TasksNavigator mTasksNavigator;

private TasksFilterType mCurrentFiltering = TasksFilterType.ALL_TASKS;

private boolean mFirstLoad = true;

@Nullable
private TaskDetailPresenter mTaskDetailPresenter;

TasksPresenter(
@NonNull TasksRepository tasksRepository,
@NonNull TasksContract.View tasksView,
@NonNull TasksNavigator tasksNavigator) {
@NonNull TasksContract.View tasksView) {
mTasksRepository = checkNotNull(tasksRepository, "tasksRepository cannot be null");
mTasksView = checkNotNull(tasksView, "tasksView cannot be null!");
mTasksNavigator = checkNotNull(tasksNavigator);
}

@Override
public void start() {
public void startTasksPresenter() {
loadTasks(false);
}

public void setTaskDetailPresenter(@Nullable TaskDetailPresenter presenter) {
mTaskDetailPresenter = presenter;
}

@Override
public void result(int requestCode, int resultCode) {
// If a task was successfully added, show snackbar
Expand Down Expand Up @@ -203,7 +190,7 @@ public void addNewTask() {
@Override
public void openTaskDetails(@NonNull Task requestedTask) {
checkNotNull(requestedTask, "requestedTask cannot be null!");
mTasksNavigator.startTaskDetail(requestedTask.getId());
mTasksView.showTaskDetailsUi(requestedTask.getId());
}

@Override
Expand All @@ -212,12 +199,6 @@ public void completeTask(@NonNull Task completedTask) {
mTasksRepository.completeTask(completedTask);
mTasksView.showTaskMarkedComplete();
loadTasks(false, false);

// In tablet mode, ping the other presenter in case it needs to update
if (mTaskDetailPresenter != null
&& mTaskDetailPresenter.getTaskId().equals(completedTask.getId())) {
mTaskDetailPresenter.start();
}
}

@Override
Expand All @@ -226,42 +207,13 @@ public void activateTask(@NonNull Task activeTask) {
mTasksRepository.activateTask(activeTask);
mTasksView.showTaskMarkedActive();
loadTasks(false, false);
// In tablet mode, ping the other presenter in case it needs to update
if (mTaskDetailPresenter != null
&& mTaskDetailPresenter.getTaskId().equals(activeTask.getId())) {
mTaskDetailPresenter.start();
}
}

@Override
public void clearCompletedTasks() {
mTasksRepository.clearCompletedTasks();
mTasksView.showCompletedTasksCleared();
loadTasks(false, false);

// In tablet mode, ping the other presenter in case it needs to update
if (mTaskDetailPresenter != null) {

// If task on detail has just been cleared, remove fragment.
String taskId = mTaskDetailPresenter.getTaskId();
if (taskId != null) {
mTasksRepository.getTask(taskId,
new TasksDataSource.GetTaskCallback() {
@Override
public void onTaskLoaded(Task task) {
// No-op
if (task == null) {
mTasksNavigator.onTaskDeleted();
}
}

@Override
public void onDataNotAvailable() {
mTasksNavigator.onTaskDeleted();
}
});
}
}
}

/**
Expand Down
Loading