Skip to content

Commit 7238d5e

Browse files
authored
Merge pull request #877 from Automattic/update-empty-views
Update Empty Views
2 parents 322083f + f0a8b09 commit 7238d5e

File tree

14 files changed

+116
-78
lines changed

14 files changed

+116
-78
lines changed

Simplenote/src/main/java/com/automattic/simplenote/NoteListFragment.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import android.widget.TextView;
4040
import android.widget.Toast;
4141

42+
import androidx.annotation.DrawableRes;
4243
import androidx.annotation.NonNull;
4344
import androidx.appcompat.widget.PopupMenu;
4445
import androidx.fragment.app.ListFragment;
@@ -54,7 +55,6 @@
5455
import com.automattic.simplenote.utils.DateTimeUtils;
5556
import com.automattic.simplenote.utils.DisplayUtils;
5657
import com.automattic.simplenote.utils.DrawableUtils;
57-
import com.automattic.simplenote.utils.HtmlCompat;
5858
import com.automattic.simplenote.utils.PrefUtils;
5959
import com.automattic.simplenote.utils.SearchSnippetFormatter;
6060
import com.automattic.simplenote.utils.SearchTokenizer;
@@ -125,7 +125,8 @@ public void onNoteSelected(String noteID, int position, String matchOffsets, boo
125125
private Bucket<Tag> mBucket;
126126
private ActionMode mActionMode;
127127
private View mRootView;
128-
private TextView mEmptyListTextView;
128+
private ImageView mEmptyViewImage;
129+
private TextView mEmptyViewText;
129130
private View mDividerLine;
130131
private FloatingActionButton mFloatingActionButton;
131132
private boolean mIsCondensedNoteList;
@@ -162,12 +163,6 @@ public void onNoteSelected(String noteID, int position, String matchOffsets, boo
162163
public NoteListFragment() {
163164
}
164165

165-
public void setEmptyListViewClickable(boolean isClickable) {
166-
if (mEmptyListTextView != null) {
167-
mEmptyListTextView.setClickable(isClickable);
168-
}
169-
}
170-
171166
@Override
172167
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int position, long l) {
173168
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
@@ -277,14 +272,10 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
277272

278273
LinearLayout emptyView = view.findViewById(android.R.id.empty);
279274
emptyView.setVisibility(View.GONE);
280-
mEmptyListTextView = view.findViewById(R.id.empty_message);
281-
mEmptyListTextView.setOnClickListener(new View.OnClickListener() {
282-
@Override
283-
public void onClick(View v) {
284-
addNote();
285-
}
286-
});
287-
setEmptyListMessage("<strong>" + getString(R.string.no_notes_here) + "</strong><br />" + String.format(getString(R.string.why_not_create_one), "<u>", "</u>"));
275+
mEmptyViewImage = emptyView.findViewById(R.id.image);
276+
mEmptyViewText = emptyView.findViewById(R.id.text);
277+
setEmptyListImage(R.drawable.ic_notes_24dp);
278+
setEmptyListMessage(getString(R.string.empty_notes_all));
288279
mDividerLine = view.findViewById(R.id.divider_line);
289280

290281
if (DisplayUtils.isLargeScreenLandscape(notesActivity)) {
@@ -468,9 +459,21 @@ public void onDetach() {
468459
mCallbacks = sCallbacks;
469460
}
470461

462+
public void setEmptyListImage(@DrawableRes int image) {
463+
if (mEmptyViewImage != null) {
464+
if (image != -1) {
465+
mEmptyViewImage.setVisibility(View.VISIBLE);
466+
mEmptyViewImage.setImageResource(image);
467+
} else {
468+
mEmptyViewImage.setVisibility(View.GONE);
469+
}
470+
}
471+
}
472+
471473
public void setEmptyListMessage(String message) {
472-
if (mEmptyListTextView != null && message != null)
473-
mEmptyListTextView.setText(HtmlCompat.fromHtml(message));
474+
if (mEmptyViewText != null && message != null) {
475+
mEmptyViewText.setText(message);
476+
}
474477
}
475478

476479
@Override

Simplenote/src/main/java/com/automattic/simplenote/NotesActivity.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ private void filterListBySelectedTag() {
407407
mSelectedTag = mTagsAdapter.getDefaultItem();
408408
}
409409

410-
checkEmptyListText(false);
410+
checkEmptyListText(mSearchMenuItem != null && mSearchMenuItem.isActionViewExpanded());
411411

412412
if (mNoteListFragment.isHidden()) {
413413
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
@@ -669,6 +669,7 @@ public boolean onQueryTextChange(String newText) {
669669
@Override
670670
public boolean onQueryTextSubmit(String queryText) {
671671
getNoteListFragment().searchNotes(queryText, true);
672+
checkEmptyListText(true);
672673
return true;
673674
}
674675
});
@@ -1213,19 +1214,35 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
12131214

12141215
public void checkEmptyListText(boolean isSearch) {
12151216
if (isSearch) {
1216-
getNoteListFragment().setEmptyListMessage("<strong>" + getString(R.string.no_notes_found) + "</strong>");
1217-
getNoteListFragment().setEmptyListViewClickable(false);
1218-
} else if (mSelectedTag != null && mSelectedTag.id == TRASH_ID) {
1219-
getNoteListFragment().setEmptyListMessage("<strong>" + getString(R.string.trash_is_empty) + "</strong>");
1220-
AnalyticsTracker.track(
1221-
AnalyticsTracker.Stat.LIST_TRASH_VIEWED,
1222-
AnalyticsTracker.CATEGORY_NOTE,
1223-
"trash_filter_selected"
1224-
);
1225-
getNoteListFragment().setEmptyListViewClickable(false);
1217+
if (DisplayUtils.isLandscape(this) && !DisplayUtils.isLargeScreen(this)) {
1218+
getNoteListFragment().setEmptyListImage(-1);
1219+
} else {
1220+
getNoteListFragment().setEmptyListImage(R.drawable.ic_search_24dp);
1221+
}
1222+
1223+
getNoteListFragment().setEmptyListMessage(getString(R.string.empty_notes_search));
1224+
} else if (mSelectedTag != null) {
1225+
if (mSelectedTag.id == ALL_NOTES_ID) {
1226+
getNoteListFragment().setEmptyListImage(R.drawable.ic_notes_24dp);
1227+
getNoteListFragment().setEmptyListMessage(getString(R.string.empty_notes_all));
1228+
} else if (mSelectedTag.id == TRASH_ID) {
1229+
getNoteListFragment().setEmptyListImage(R.drawable.ic_trash_24dp);
1230+
getNoteListFragment().setEmptyListMessage(getString(R.string.empty_notes_trash));
1231+
AnalyticsTracker.track(
1232+
AnalyticsTracker.Stat.LIST_TRASH_VIEWED,
1233+
AnalyticsTracker.CATEGORY_NOTE,
1234+
"trash_filter_selected"
1235+
);
1236+
} else if (mSelectedTag.id == UNTAGGED_NOTES_ID) {
1237+
getNoteListFragment().setEmptyListImage(R.drawable.ic_untagged_24dp);
1238+
getNoteListFragment().setEmptyListMessage(getString(R.string.empty_notes_untagged));
1239+
} else {
1240+
getNoteListFragment().setEmptyListImage(R.drawable.ic_tag_24dp);
1241+
getNoteListFragment().setEmptyListMessage(getString(R.string.empty_notes_tag, mSelectedTag.name));
1242+
}
12261243
} else {
1227-
getNoteListFragment().setEmptyListMessage("<strong>" + getString(R.string.no_notes_here) + "</strong><br />" + String.format(getString(R.string.why_not_create_one), "<u>", "</u>"));
1228-
getNoteListFragment().setEmptyListViewClickable(true);
1244+
getNoteListFragment().setEmptyListImage(R.drawable.ic_notes_24dp);
1245+
getNoteListFragment().setEmptyListMessage(getString(R.string.empty_notes_all));
12291246
}
12301247
}
12311248

Simplenote/src/main/java/com/automattic/simplenote/TagsListFragment.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import android.view.ViewGroup;
1717
import android.widget.EditText;
1818
import android.widget.ImageButton;
19+
import android.widget.ImageView;
1920
import android.widget.LinearLayout;
2021
import android.widget.TextView;
2122
import android.widget.Toast;
@@ -30,7 +31,6 @@
3031
import com.automattic.simplenote.models.Note;
3132
import com.automattic.simplenote.models.Tag;
3233
import com.automattic.simplenote.utils.BaseCursorAdapter;
33-
import com.automattic.simplenote.utils.HtmlCompat;
3434
import com.automattic.simplenote.widgets.EmptyViewRecyclerView;
3535
import com.simperium.client.Bucket;
3636
import com.simperium.client.BucketObjectNameInvalid;
@@ -71,8 +71,11 @@ public void onActivityCreated(Bundle savedInstanceState) {
7171
mTagsAdapter = new TagsAdapter();
7272
recyclerView.setAdapter(mTagsAdapter);
7373
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
74-
TextView emptyView = getActivity().findViewById(R.id.empty);
75-
emptyView.setText(HtmlCompat.fromHtml("<strong>" + getString(R.string.no_tags_found) + "</strong>"));
74+
View emptyView = getActivity().findViewById(R.id.empty);
75+
ImageView emptyViewImage = emptyView.findViewById(R.id.image);
76+
emptyViewImage.setImageResource(R.drawable.ic_tag_24dp);
77+
TextView emptyViewText = emptyView.findViewById(R.id.text);
78+
emptyViewText.setText(R.string.empty_tags);
7679
recyclerView.setEmptyView(emptyView);
7780

7881
refreshTags();

Simplenote/src/main/res/layout-large-land/fragment_note_editor.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@
115115

116116
<ImageView
117117
android:contentDescription="@string/logo"
118-
android:layout_height="110dp"
119-
android:layout_width="110dp"
118+
android:layout_height="@dimen/logo_empty"
119+
android:layout_width="@dimen/logo_empty"
120120
android:src="@drawable/ic_simplenote_24dp"
121-
android:tint="?attr/placeholderLogoColor">
121+
android:tint="?attr/emptyImageColor">
122122
</ImageView>
123123

124124
</LinearLayout>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<LinearLayout
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:gravity="center"
6+
android:layout_height="match_parent"
7+
android:layout_width="match_parent"
8+
android:orientation="vertical">
9+
10+
<ImageView
11+
android:id="@+id/image"
12+
android:adjustViewBounds="true"
13+
android:importantForAccessibility="no"
14+
android:layout_height="@dimen/icon_empty"
15+
android:layout_marginBottom="@dimen/padding_large"
16+
android:layout_marginTop="@dimen/padding_large"
17+
android:layout_width="@dimen/icon_empty"
18+
android:src="@drawable/ic_notes_24dp"
19+
android:tint="?attr/emptyImageColor">
20+
</ImageView>
21+
22+
<com.automattic.simplenote.widgets.RobotoRegularTextView
23+
android:id="@+id/text"
24+
android:layout_height="wrap_content"
25+
android:layout_width="wrap_content"
26+
android:textColor="?attr/notePreviewColor"
27+
android:text="@string/empty_notes_all"
28+
android:textSize="@dimen/text_empty">
29+
</com.automattic.simplenote.widgets.RobotoRegularTextView>
30+
31+
</LinearLayout>

Simplenote/src/main/res/layout/fragment_note_editor.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@
114114

115115
<ImageView
116116
android:contentDescription="@string/logo"
117-
android:layout_height="110dp"
118-
android:layout_width="110dp"
117+
android:layout_height="@dimen/logo_empty"
118+
android:layout_width="@dimen/logo_empty"
119119
android:src="@drawable/logo_login"
120-
android:tint="?attr/placeholderLogoColor">
120+
android:tint="?attr/emptyImageColor">
121121
</ImageView>
122122

123123
</LinearLayout>

Simplenote/src/main/res/layout/fragment_notes_list.xml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,11 @@
2222
tools:listitem="@layout/note_list_row">
2323
</ListView>
2424

25-
<LinearLayout
25+
<include
2626
android:id="@android:id/empty"
27-
android:layout_height="match_parent"
28-
android:layout_width="match_parent"
29-
android:gravity="center">
30-
31-
<com.automattic.simplenote.widgets.RobotoRegularTextView
32-
android:id="@+id/empty_message"
33-
android:background="?attr/selectableItemBackground"
34-
android:gravity="center"
35-
android:layout_gravity="center"
36-
android:layout_height="wrap_content"
37-
android:layout_width="wrap_content"
38-
android:padding="8dp"
39-
android:textColor="?attr/notePreviewColor"
40-
android:textSize="@dimen/text_empty">
41-
</com.automattic.simplenote.widgets.RobotoRegularTextView>
42-
43-
</LinearLayout>
27+
android:visibility="gone"
28+
layout="@layout/empty_view">
29+
</include>
4430

4531
<RelativeLayout
4632
android:id="@+id/suggestion_layout"

Simplenote/src/main/res/layout/fragment_tags_list.xml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@
1515
android:layout_width="match_parent">
1616
</com.automattic.simplenote.widgets.EmptyViewRecyclerView>
1717

18-
<com.automattic.simplenote.widgets.RobotoRegularTextView
18+
<include
1919
android:id="@+id/empty"
20-
android:gravity="center"
21-
android:layout_height="match_parent"
22-
android:layout_width="match_parent"
23-
android:padding="@dimen/padding_large"
24-
android:text="@string/no_tags_found"
25-
android:textColor="?attr/placeholderLogoColor"
26-
android:textSize="@dimen/text_empty">
27-
</com.automattic.simplenote.widgets.RobotoRegularTextView>
20+
layout="@layout/empty_view">
21+
</include>
2822

2923
</RelativeLayout>

Simplenote/src/main/res/values-night/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<item name="drawerBackgroundSelector">@color/bg_drawer_selector_dark</item>
2929
<item name="editorSearchHighlightBackgroundColor">@color/blue_60</item>
3030
<item name="editorSearchHighlightForegroundColor">@color/blue_5</item>
31+
<item name="emptyImageColor">@color/empty_dark</item>
3132
<item name="fabColor">@color/item_blue_dark</item>
3233
<item name="fabIconColor">@color/gray_100</item>
3334
<item name="hintTextColor">@color/text_title_disabled</item>
@@ -44,7 +45,6 @@
4445
<item name="noteTitleColor">@android:color/white</item>
4546
<item name="tagChipShadowColor">@color/background_dark</item>
4647
<item name="pinIconSelector">@drawable/bg_pin_selector_dark</item>
47-
<item name="placeholderLogoColor">@color/empty_dark</item>
4848
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
4949
<item name="settingsTextColor">@android:color/white</item>
5050
<item name="toolbarColor">@color/background_dark_4</item>

Simplenote/src/main/res/values/attrs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<attr name="listSearchHighlightBackgroundColor" format="reference|color"/>
1919
<attr name="editorSearchHighlightForegroundColor" format="reference|color"/>
2020
<attr name="editorSearchHighlightBackgroundColor" format="reference|color"/>
21-
<attr name="placeholderLogoColor" format="reference|color"/>
21+
<attr name="emptyImageColor" format="reference|color"/>
2222
<attr name="chipCheckedOffBackgroundColor" format="reference"/>
2323
<attr name="chipCheckedOnBackgroundColor" format="reference"/>
2424
<attr name="chipTextColor" format="reference"/>

0 commit comments

Comments
 (0)