Skip to content

Commit d11fbf1

Browse files
committed
Addressing Dan's comments (XML, back stack, unnecessary refreshes in mvp-loaders, themes)
1 parent c373138 commit d11fbf1

File tree

59 files changed

+313
-358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+313
-358
lines changed

todo-mvp-loaders/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
package="com.example.android.architecture.blueprints.todoapp"
2020
xmlns:android="http://schemas.android.com/apk/res/android">
2121

22-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
23-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
2422
<application
2523
android:allowBackup="false"
2624
android:icon="@mipmap/ic_launcher"

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ public void saveTask(@NonNull Task task) {
188188
}
189189
mCachedTasks.put(task.getId(), task);
190190

191-
// Mark the cache as dirty to make sure we are keeping the sync between in memory cache and
192-
// persisted + server data
193-
refreshTasks();
191+
// Update the UI
192+
notifyContentObserver();
194193
}
195194

196195
@Override
@@ -207,9 +206,8 @@ public void completeTask(@NonNull Task task) {
207206
}
208207
mCachedTasks.put(task.getId(), completedTask);
209208

210-
// Mark the cache as dirty to make sure we are keeping the sync between in memory cache and
211-
// persisted + server data
212-
refreshTasks();
209+
// Update the UI
210+
notifyContentObserver();
213211
}
214212

215213
@Override
@@ -232,9 +230,8 @@ public void activateTask(@NonNull Task task) {
232230
}
233231
mCachedTasks.put(task.getId(), activeTask);
234232

235-
// Mark the cache as dirty to make sure we are keeping the sync between in memory cache and
236-
// persisted + server data
237-
refreshTasks();
233+
// Update the UI
234+
notifyContentObserver();
238235
}
239236

240237
@Override
@@ -260,9 +257,8 @@ public void clearCompletedTasks() {
260257
}
261258
}
262259

263-
// Mark the cache as dirty to make sure we are keeping the sync between in memory cache and
264-
// server data
265-
refreshTasks();
260+
// Update the UI
261+
notifyContentObserver();
266262
}
267263

268264
/**
@@ -315,7 +311,8 @@ public void deleteAllTasks() {
315311
}
316312
mCachedTasks.clear();
317313

318-
refreshTasks();
314+
// Update the UI
315+
notifyContentObserver();
319316
}
320317

321318
@Override
@@ -325,7 +322,8 @@ public void deleteTask(@NonNull String taskId) {
325322

326323
mCachedTasks.remove(taskId);
327324

328-
refreshTasks();
325+
// Update the UI
326+
notifyContentObserver();
329327
}
330328

331329
public interface TasksRepositoryObserver {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
9595
case R.id.list_navigation_menu_item:
9696
Intent intent =
9797
new Intent(StatisticsActivity.this, TasksActivity.class);
98+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
99+
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
98100
startActivity(intent);
99101
break;
100102
case R.id.statistics_navigation_menu_item:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
122122
case R.id.statistics_navigation_menu_item:
123123
Intent intent =
124124
new Intent(TasksActivity.this, StatisticsActivity.class);
125+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
126+
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
125127
startActivity(intent);
126128
break;
127129
default:
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<vector android:alpha="0.49" android:height="24dp"
3-
android:viewportHeight="24.0" android:viewportWidth="24.0"
4-
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
5-
<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"/>
2+
<vector android:alpha="0.49"
3+
android:height="24dp"
4+
android:viewportHeight="24.0"
5+
android:viewportWidth="24.0"
6+
android:width="24dp"
7+
xmlns:android="http://schemas.android.com/apk/res/android">
8+
<path
9+
android:fillColor="#FF000000"
10+
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"/>
611
</vector>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:width="24dp"
3-
android:height="24dp"
4-
android:alpha="0.49"
5-
android:viewportHeight="24.0"
6-
android:viewportWidth="24.0">
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:alpha="0.49"
5+
android:viewportHeight="24.0"
6+
android:viewportWidth="24.0">
77
<path
88
android:fillColor="#FF000000"
9-
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" />
9+
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"/>
1010
</vector>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:width="24dp"
3-
android:height="24dp"
4-
android:viewportHeight="24.0"
5-
android:viewportWidth="24.0">
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportHeight="24.0"
5+
android:viewportWidth="24.0">
66
<path
77
android:fillColor="#FFFFFFFF"
8-
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z" />
8+
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
99
</vector>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
-->
1616

1717
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18-
android:width="24dp"
19-
android:height="24dp"
20-
android:viewportWidth="24.0"
21-
android:viewportHeight="24.0">
18+
android:width="24dp"
19+
android:height="24dp"
20+
android:viewportWidth="24.0"
21+
android:viewportHeight="24.0">
2222
<path
2323
android:fillColor="#FFFFFFFF"
2424
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2-
android:width="24dp"
3-
android:height="24dp"
4-
android:viewportWidth="24.0"
5-
android:viewportHeight="24.0">
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
66
<path
77
android:fillColor="#FFFFFFFF"
88
android:pathData="M10,18h4v-2h-4v2zM3,6v2h18V6H3zm3,7h12v-2H6v2z"/>
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<vector android:alpha="0.80" android:height="100dp"
3-
android:viewportHeight="24.0" android:viewportWidth="24.0"
4-
android:width="100dp" xmlns:android="http://schemas.android.com/apk/res/android">
5-
<path android:fillColor="#FF000000" android:pathData="M19,3H5c-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,-2zM9,17H7v-7h2v7zm4,0h-2V7h2v10zm4,0h-2v-4h2v4z"/>
2+
<vector android:alpha="0.80"
3+
android:height="100dp"
4+
android:viewportHeight="24.0"
5+
android:viewportWidth="24.0"
6+
android:width="100dp"
7+
xmlns:android="http://schemas.android.com/apk/res/android">
8+
<path
9+
android:fillColor="#FF000000"
10+
android:pathData="M19,3H5c-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,-2zM9,17H7v-7h2v7zm4,0h-2V7h2v10zm4,0h-2v-4h2v4z"/>
611
</vector>
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<vector android:alpha="0.49" android:height="24dp"
3-
android:viewportHeight="24.0" android:viewportWidth="24.0"
4-
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
5-
<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"/>
2+
<vector android:alpha="0.49"
3+
android:height="24dp"
4+
android:viewportHeight="24.0"
5+
android:viewportWidth="24.0"
6+
android:width="24dp"
7+
xmlns:android="http://schemas.android.com/apk/res/android">
8+
<path
9+
android:fillColor="#FF000000"
10+
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"/>
611
</vector>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
android:layout_height="wrap_content"
3939
android:background="?attr/colorPrimary"
4040
android:minHeight="?attr/actionBarSize"
41-
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
42-
app:theme="@style/Toolbar" />
41+
android:theme="@style/Toolbar"
42+
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
4343
</android.support.design.widget.AppBarLayout>
4444

4545
<android.support.design.widget.CoordinatorLayout
@@ -50,7 +50,7 @@
5050
<FrameLayout
5151
android:id="@+id/contentFrame"
5252
android:layout_width="match_parent"
53-
android:layout_height="match_parent" />
53+
android:layout_height="match_parent"/>
5454

5555
<android.support.design.widget.FloatingActionButton
5656
android:id="@+id/fab_edit_task_done"
@@ -60,7 +60,7 @@
6060
android:src="@drawable/ic_add"
6161
app:fabSize="normal"
6262
app:layout_anchor="@id/coordinatorLayout"
63-
app:layout_anchorGravity="bottom|right|end" />
63+
app:layout_anchorGravity="bottom|right|end"/>
6464
</android.support.design.widget.CoordinatorLayout>
6565

6666
</LinearLayout>

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,32 @@
1515
-->
1616

1717
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
18-
android:layout_width="match_parent"
19-
android:layout_height="match_parent">
18+
android:layout_width="match_parent"
19+
android:layout_height="match_parent">
2020

2121
<LinearLayout
22-
android:layout_width="match_parent"
23-
android:layout_height="wrap_content"
24-
android:orientation="vertical"
25-
android:paddingBottom="@dimen/activity_vertical_margin"
26-
android:paddingLeft="@dimen/activity_horizontal_margin"
27-
android:paddingRight="@dimen/activity_horizontal_margin"
28-
android:paddingTop="@dimen/activity_vertical_margin">
22+
android:layout_width="match_parent"
23+
android:layout_height="wrap_content"
24+
android:orientation="vertical"
25+
android:paddingBottom="@dimen/activity_vertical_margin"
26+
android:paddingLeft="@dimen/activity_horizontal_margin"
27+
android:paddingRight="@dimen/activity_horizontal_margin"
28+
android:paddingTop="@dimen/activity_vertical_margin">
2929

3030
<EditText
31-
android:id="@+id/add_task_title"
32-
android:layout_width="match_parent"
33-
android:layout_height="wrap_content"
34-
android:hint="@string/title_hint"
35-
android:singleLine="true"
36-
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
31+
android:id="@+id/add_task_title"
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:hint="@string/title_hint"
35+
android:singleLine="true"
36+
android:textAppearance="@style/TextAppearance.AppCompat.Title"/>
3737

3838
<EditText
39-
android:id="@+id/add_task_description"
40-
android:layout_width="match_parent"
41-
android:layout_height="350dp"
42-
android:gravity="top"
43-
android:hint="@string/description_hint"/>
39+
android:id="@+id/add_task_description"
40+
android:layout_width="match_parent"
41+
android:layout_height="350dp"
42+
android:gravity="top"
43+
android:hint="@string/description_hint"/>
4444

4545
</LinearLayout>
4646
</ScrollView>

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@
1515
-->
1616

1717
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
18-
android:layout_width="match_parent"
19-
android:layout_height="192dp"
20-
android:background="?attr/colorPrimaryDark"
21-
android:gravity="bottom"
22-
android:orientation="vertical"
23-
android:padding="16dp"
24-
android:theme="@style/ThemeOverlay.AppCompat.Dark">
18+
android:layout_width="match_parent"
19+
android:layout_height="192dp"
20+
android:background="?attr/colorPrimaryDark"
21+
android:gravity="bottom"
22+
android:orientation="vertical"
23+
android:padding="16dp"
24+
android:theme="@style/ThemeOverlay.AppCompat.Dark">
2525

2626
<ImageView
27-
android:layout_width="100dp"
28-
android:layout_height="wrap_content"
29-
android:layout_gravity="center"
30-
android:src="@drawable/logo" />
27+
android:layout_width="100dp"
28+
android:layout_height="wrap_content"
29+
android:layout_gravity="center"
30+
android:src="@drawable/logo"/>
31+
3132
<TextView
3233
android:layout_width="wrap_content"
3334
android:layout_height="wrap_content"
3435
android:layout_gravity="bottom|center_horizontal"
3536
android:text="@string/navigation_view_header_title"
36-
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
37+
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
3738

3839
</FrameLayout>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
android:layout_height="wrap_content"
4040
android:background="?attr/colorPrimary"
4141
android:minHeight="?attr/actionBarSize"
42-
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
43-
app:theme="@style/Toolbar" />
42+
android:theme="@style/Toolbar"
43+
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
4444
</android.support.design.widget.AppBarLayout>
4545

4646
<FrameLayout
4747
android:id="@+id/contentFrame"
4848
android:layout_width="match_parent"
49-
android:layout_height="match_parent" />
49+
android:layout_height="match_parent"/>
5050

5151
</LinearLayout>
5252

@@ -58,7 +58,7 @@
5858
android:layout_gravity="start"
5959
android:fitsSystemWindows="true"
6060
app:headerLayout="@layout/nav_header"
61-
app:menu="@menu/drawer_actions" />
61+
app:menu="@menu/drawer_actions"/>
6262

6363

6464
</android.support.v4.widget.DrawerLayout>

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
-->
1616

1717
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
18-
android:layout_width="match_parent"
19-
android:layout_height="match_parent"
20-
android:orientation="vertical"
21-
android:paddingBottom="@dimen/activity_vertical_margin"
22-
android:paddingLeft="@dimen/activity_horizontal_margin"
23-
android:paddingRight="@dimen/activity_horizontal_margin"
24-
android:paddingTop="@dimen/activity_vertical_margin">
18+
android:layout_width="match_parent"
19+
android:layout_height="match_parent"
20+
android:orientation="vertical"
21+
android:paddingBottom="@dimen/activity_vertical_margin"
22+
android:paddingLeft="@dimen/activity_horizontal_margin"
23+
android:paddingRight="@dimen/activity_horizontal_margin"
24+
android:paddingTop="@dimen/activity_vertical_margin">
2525

2626
<TextView
2727
android:id="@+id/statistics"
2828
android:layout_width="match_parent"
2929
android:layout_height="match_parent"
3030
android:text="Medium Text"
31-
android:textAppearance="?android:attr/textAppearanceMedium" />
31+
android:textAppearance="?android:attr/textAppearanceMedium"/>
3232

3333
</LinearLayout>

0 commit comments

Comments
 (0)