Skip to content

Commit 57103ec

Browse files
committed
Merging changes from mvp to loaders and viceversa to minimize diff
1 parent 13765ab commit 57103ec

File tree

36 files changed

+245
-132
lines changed

36 files changed

+245
-132
lines changed

todo-mvp-loaders/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskFragment.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public class AddEditTaskFragment extends Fragment implements AddEditTaskContract
3939

4040
public static final String ARGUMENT_EDIT_TASK_ID = "EDIT_TASK_ID";
4141

42+
private AddEditTaskPresenter mTasksPresenter;
43+
4244
private TextView mTitle;
4345

4446
private TextView mDescription;
4547

4648
private String mEditedTaskId;
4749

48-
private AddEditTaskPresenter mTasksPresenter;
49-
5050
public static AddEditTaskFragment newInstance() {
5151
return new AddEditTaskFragment();
5252
}
@@ -55,6 +55,12 @@ public AddEditTaskFragment() {
5555
// Required empty public constructor
5656
}
5757

58+
@Override
59+
public void onResume() {
60+
super.onResume();
61+
mTasksPresenter.startLoader(this);
62+
}
63+
5864
public void setPresenter(@NonNull AddEditTaskPresenter presenter) {
5965
mTasksPresenter = checkNotNull(presenter);
6066
}
@@ -99,12 +105,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
99105
return root;
100106
}
101107

102-
@Override
103-
public void onResume() {
104-
super.onResume();
105-
mTasksPresenter.startLoader(this);
106-
}
107-
108108
@Override
109109
public void showEmptyTaskError() {
110110
Snackbar.make(mTitle, getString(R.string.empty_task_message), Snackbar.LENGTH_LONG).show();

todo-mvp-loaders/app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/source/TasksRepository.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
/**
3333
* Concrete implementation to load tasks from the data sources into a cache.
34-
* <p/>
34+
* <p>
3535
* For simplicity, this implements a dumb synchronisation between locally persisted data and data
3636
* obtained from the server, by using the remote data source only if the local database doesn't
3737
* exist or is empty.
@@ -52,7 +52,8 @@ public class TasksRepository implements TasksDataSource {
5252
Map<String, Task> mCachedTasks;
5353

5454
/**
55-
* This variable has package local visibility so it can be accessed from tests.
55+
* Marks the cache as invalid, to force an update the next time data is requested. This variable
56+
* has package local visibility so it can be accessed from tests.
5657
*/
5758
boolean mCacheIsDirty;
5859

@@ -72,8 +73,8 @@ public static TasksRepository getInstance(TasksDataSource tasksRemoteDataSource,
7273
}
7374

7475
/**
75-
* Used to force {@link #getInstance(TasksDataSource, TasksDataSource)} to create a new
76-
* instance next time it's called.
76+
* Used to force {@link #getInstance(TasksDataSource, TasksDataSource)} to create a new instance
77+
* next time it's called.
7778
*/
7879
public static void destroyInstance() {
7980
INSTANCE = null;

todo-mvp-loaders/app/src/main/java/com/example/android/architecture/blueprints/todoapp/statistics/StatisticsActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ protected void onCreate(Bundle savedInstanceState) {
7272
TasksLoader tasksLoader = new TasksLoader(getApplicationContext(),
7373
Injection.provideTasksRepository(getApplicationContext()));
7474

75-
StatisticsPresenter mStatisticsPresenter = new StatisticsPresenter(statisticsFragment,
75+
StatisticsPresenter statisticsPresenter = new StatisticsPresenter(statisticsFragment,
7676
tasksLoader);
7777

78-
statisticsFragment.setPresenter(mStatisticsPresenter);
78+
statisticsFragment.setPresenter(statisticsPresenter);
7979
}
8080

8181
@Override

todo-mvp-loaders/app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailFragment.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import com.example.android.architecture.blueprints.todoapp.addedittask.AddEditTaskActivity;
3838
import com.example.android.architecture.blueprints.todoapp.addedittask.AddEditTaskFragment;
3939

40+
import static com.google.common.base.Preconditions.checkNotNull;
41+
4042
/**
4143
* Main UI for the task detail screen.
4244
*/
@@ -64,10 +66,6 @@ public static TaskDetailFragment newInstance(String taskId) {
6466
return fragment;
6567
}
6668

67-
public void setPresenter(@NonNull TaskDetailPresenter presenter) {
68-
mTaskDetailPresenter = presenter;
69-
}
70-
7169
@Override
7270
public void onActivityCreated(Bundle savedInstanceState) {
7371
super.onActivityCreated(savedInstanceState);
@@ -104,6 +102,10 @@ public void onResume() {
104102
mTaskDetailPresenter.startLoader(this);
105103
}
106104

105+
public void setPresenter(@NonNull TaskDetailPresenter presenter) {
106+
mTaskDetailPresenter = checkNotNull(presenter);
107+
}
108+
107109
@Override
108110
public boolean onOptionsItemSelected(MenuItem item) {
109111
switch (item.getItemId()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2016, The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.architecture.blueprints.todoapp.tasks;
18+
19+
import android.content.Context;
20+
import android.support.v4.view.ViewCompat;
21+
import android.support.v4.widget.SwipeRefreshLayout;
22+
import android.util.AttributeSet;
23+
import android.view.View;
24+
25+
/**
26+
* Extends {@link SwipeRefreshLayout} to support non-direct descendant scrolling views.
27+
* <p>
28+
* {@link SwipeRefreshLayout} works as expected when a scroll view is a direct child: it triggers
29+
* the refresh only when the view is on top. This class adds a way (@link #setScrollUpChild} to
30+
* define which view controls this behavior.
31+
*/
32+
public class ScrollChildSwipeRefreshLayout extends SwipeRefreshLayout {
33+
34+
private View mScrollUpChild;
35+
36+
public ScrollChildSwipeRefreshLayout(Context context) {
37+
super(context);
38+
}
39+
40+
public ScrollChildSwipeRefreshLayout(Context context, AttributeSet attrs) {
41+
super(context, attrs);
42+
}
43+
44+
@Override
45+
public boolean canChildScrollUp() {
46+
if (mScrollUpChild != null) {
47+
return ViewCompat.canScrollVertically(mScrollUpChild, -1);
48+
}
49+
return super.canChildScrollUp();
50+
}
51+
52+
public void setScrollUpChild(View view) {
53+
mScrollUpChild = view;
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2016, The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.android.architecture.blueprints.todoapp.tasks;
18+
19+
/**
20+
* Used with the filter spinner in the tasks list.
21+
*/
22+
public enum TasksFilterType {
23+
/**
24+
* Do not filter tasks.
25+
*/
26+
ALL_TASKS,
27+
28+
/**
29+
* Filters only the active (not completed yet) tasks.
30+
*/
31+
ACTIVE_TASKS,
32+
33+
/**
34+
* Filters only the completed tasks.
35+
*/
36+
COMPLETED_TASKS
37+
}

todo-mvp-loaders/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksFragment.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ public static TasksFragment newInstance() {
8181
return new TasksFragment();
8282
}
8383

84-
public void setPresenter(@NonNull TasksPresenter presenter) {
85-
mTasksPresenter = checkNotNull(presenter);
86-
}
87-
8884
@Override
8985
public void onCreate(@Nullable Bundle savedInstanceState) {
9086
super.onCreate(savedInstanceState);
@@ -97,9 +93,8 @@ public void onResume() {
9793
mTasksPresenter.startLoader(this);
9894
}
9995

100-
@Override
101-
public void onActivityCreated(Bundle savedInstanceState) {
102-
super.onActivityCreated(savedInstanceState);
96+
public void setPresenter(@NonNull TasksPresenter presenter) {
97+
mTasksPresenter = checkNotNull(presenter);
10398
}
10499

105100
@Override
@@ -118,8 +113,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
118113
View root = inflater.inflate(R.layout.tasks_frag, container, false);
119114

120115
// Set up tasks view
121-
ListView mListView = (ListView) root.findViewById(R.id.tasks_list);
122-
mListView.setAdapter(mListAdapter);
116+
ListView listView = (ListView) root.findViewById(R.id.tasks_list);
117+
listView.setAdapter(mListAdapter);
123118
mFilteringLabelView = (TextView) root.findViewById(R.id.filteringLabel);
124119
mTasksView = (LinearLayout) root.findViewById(R.id.tasksLL);
125120

@@ -155,7 +150,7 @@ public void onClick(View v) {
155150
ContextCompat.getColor(getActivity(), R.color.colorAccent),
156151
ContextCompat.getColor(getActivity(), R.color.colorPrimaryDark));
157152
// Set the scrolling view in the custom SwipeRefreshLayout.
158-
swipeRefreshLayout.setScrollUpChild(mListView);
153+
swipeRefreshLayout.setScrollUpChild(listView);
159154

160155
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
161156
@Override

todo-mvp-loaders/app/src/main/res/drawable/ic_assignment_turned_in_24dp.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
android:viewportHeight="24.0" android:viewportWidth="24.0"
44
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
55
<path android:fillColor="#FF000000" android:pathData="M19,3h-4.18C14.4,1.84 13.3,1 12,1c-1.3,0 -2.4,0.84 -2.82,2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2zm-7,0c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zm-2,14l-4,-4 1.41,-1.41L10,14.17l6.59,-6.59L18,9l-8,8z"/>
6-
</vector>
6+
</vector>

todo-mvp-loaders/app/src/main/res/drawable/ic_check_circle_24dp.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
<path
88
android:fillColor="#FF000000"
99
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zm-2,15l-5,-5 1.41,-1.41L10,14.17l7.59,-7.59L19,8l-9,9z" />
10-
</vector>
10+
</vector>

todo-mvp-loaders/app/src/main/res/drawable/ic_filter_list.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
<path
77
android:fillColor="#FFFFFFFF"
88
android:pathData="M10,18h4v-2h-4v2zM3,6v2h18V6H3zm3,7h12v-2H6v2z"/>
9-
</vector>
9+
</vector>

todo-mvp-loaders/app/src/main/res/drawable/ic_verified_user_24dp.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
android:viewportHeight="24.0" android:viewportWidth="24.0"
44
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
55
<path android:fillColor="#FF000000" android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12V5l-9,-4zm-2,16l-4,-4 1.41,-1.41L10,14.17l6.59,-6.59L18,9l-8,8z"/>
6-
</vector>
6+
</vector>

todo-mvp-loaders/app/src/main/res/layout/addtask_act.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
android:id="@+id/drawer_layout"
2222
android:layout_width="match_parent"
2323
android:layout_height="match_parent"
24-
tools:context=".AddTaskActivity">
24+
tools:context=".addedittask.AddEditTaskActivity">
2525

2626
<LinearLayout
2727
android:layout_width="match_parent"

todo-mvp-loaders/app/src/main/res/layout/tasks_frag.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,3 @@
8787
</RelativeLayout>
8888
</com.example.android.architecture.blueprints.todoapp.tasks.ScrollChildSwipeRefreshLayout>
8989

90-

todo-mvp-loaders/app/src/main/res/menu/tasks_fragment_menu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
-->
1717

1818
<menu xmlns:android="http://schemas.android.com/apk/res/android"
19-
xmlns:app="http://schemas.android.com/apk/res-auto">
19+
xmlns:app="http://schemas.android.com/apk/res-auto">
2020
<item
2121
android:id="@+id/menu_filter"
2222
android:title="@string/menu_filter"

todo-mvp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskActivity.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
*/
3434
public class AddEditTaskActivity extends AppCompatActivity {
3535

36-
private AddEditTaskPresenter mAddEditTaskPresenter;
37-
3836
@Override
3937
protected void onCreate(Bundle savedInstanceState) {
4038
super.onCreate(savedInstanceState);
@@ -69,7 +67,7 @@ protected void onCreate(Bundle savedInstanceState) {
6967
}
7068

7169
// Create the presenter
72-
mAddEditTaskPresenter = new AddEditTaskPresenter(
70+
new AddEditTaskPresenter(
7371
Injection.provideTasksRepository(getApplicationContext()), addEditTaskFragment);
7472
}
7573

todo-mvp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskContract.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ interface View {
2727

2828
void showTasksList();
2929

30-
void setUserActionListener(UserActionsListener listener);
31-
3230
void setTitle(String title);
3331

3432
void setDescription(String description);
33+
34+
void setActionListener(UserActionsListener listener);
35+
36+
boolean isActive();
3537
}
3638

3739
interface UserActionsListener {

0 commit comments

Comments
 (0)