From 9a75f49aa1181aa0104f21c9c16c2e4560a6772f Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Mon, 13 Nov 2017 09:31:01 -0800 Subject: [PATCH] Add an empty state for search --- res/layout/conversation_list_fragment.xml | 10 ++++++++++ res/values/strings.xml | 1 + .../securesms/ConversationListActivity.java | 2 ++ .../securesms/ConversationListFragment.java | 12 +++++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/res/layout/conversation_list_fragment.xml b/res/layout/conversation_list_fragment.xml index 3e459b37f1..9c192ab010 100644 --- a/res/layout/conversation_list_fragment.xml +++ b/res/layout/conversation_list_fragment.xml @@ -7,6 +7,16 @@ android:layout_height="fill_parent" android:orientation="vertical"> + + Give your inbox something to write home about. Get started by messaging a friend. Inbox zeeerrro Zip. Zilch. Zero. Nada. You\'re all caught up! + No results found for \'%s\' diff --git a/src/org/thoughtcrime/securesms/ConversationListActivity.java b/src/org/thoughtcrime/securesms/ConversationListActivity.java index bd43f37a2e..8f5c97b5fb 100644 --- a/src/org/thoughtcrime/securesms/ConversationListActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationListActivity.java @@ -16,6 +16,7 @@ */ package org.thoughtcrime.securesms; +import android.annotation.SuppressLint; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; @@ -209,6 +210,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit startActivity(new Intent(this, ImportExportActivity.class)); } + @SuppressLint("StaticFieldLeak") private void handleMarkAllRead() { new AsyncTask() { @Override diff --git a/src/org/thoughtcrime/securesms/ConversationListFragment.java b/src/org/thoughtcrime/securesms/ConversationListFragment.java index e8b2f74f6c..b9d7eeb8de 100644 --- a/src/org/thoughtcrime/securesms/ConversationListFragment.java +++ b/src/org/thoughtcrime/securesms/ConversationListFragment.java @@ -48,6 +48,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import org.thoughtcrime.securesms.ConversationListAdapter.ItemClickListener; import org.thoughtcrime.securesms.components.recyclerview.DeleteItemAnimator; @@ -91,6 +92,7 @@ public class ConversationListFragment extends Fragment private RecyclerView list; private ReminderView reminderView; private View emptyState; + private TextView emptySearch; private PulsingFloatingActionButton fab; private Locale locale; private String queryFilter = ""; @@ -112,6 +114,7 @@ public class ConversationListFragment extends Fragment list = ViewUtil.findById(view, R.id.list); fab = ViewUtil.findById(view, R.id.fab); emptyState = ViewUtil.findById(view, R.id.empty_state); + emptySearch = ViewUtil.findById(view, R.id.empty_search); if (archive) fab.setVisibility(View.GONE); else fab.setVisibility(View.VISIBLE); @@ -318,13 +321,20 @@ public class ConversationListFragment extends Fragment @Override public void onLoadFinished(Loader arg0, Cursor cursor) { - if (cursor == null || cursor.getCount() <= 0) { + if ((cursor == null || cursor.getCount() <= 0) && TextUtils.isEmpty(queryFilter) && !archive) { list.setVisibility(View.INVISIBLE); emptyState.setVisibility(View.VISIBLE); + emptySearch.setVisibility(View.INVISIBLE); fab.startPulse(3 * 1000); + } else if ((cursor == null || cursor.getCount() <= 0) && !TextUtils.isEmpty(queryFilter)) { + list.setVisibility(View.INVISIBLE); + emptyState.setVisibility(View.GONE); + emptySearch.setVisibility(View.VISIBLE); + emptySearch.setText(getString(R.string.ConversationListFragment_no_results_found_for_s_, queryFilter)); } else { list.setVisibility(View.VISIBLE); emptyState.setVisibility(View.GONE); + emptySearch.setVisibility(View.INVISIBLE); fab.stopPulse(); }