Fixed no alert text shown when there is alert

Fixed by hiding the text when there is alert, and
then unhide it when there is no alerts at beginning
or after history cleared.

Test: Manual
Bug: 131642555
Merged-In: Ieca1bc28a6aee52a699ee408888087e30edf1d54
Change-Id: Ieca1bc28a6aee52a699ee408888087e30edf1d54
(cherry picked from commit 468b75b68ca0642cd3c4203760790f99072b373a)
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java b/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java
index 1c1bf21..dde4042 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java
@@ -44,6 +44,7 @@
 import android.view.ViewGroup;
 import android.widget.CursorAdapter;
 import android.widget.ListView;
+import android.widget.TextView;
 
 import java.util.ArrayList;
 
@@ -166,6 +167,7 @@
             // old cursor once we return.)
             mAdapter.swapCursor(data);
             getActivity().invalidateOptionsMenu();
+            updateNoAlertTextVisibility();
         }
 
         @Override
@@ -206,6 +208,21 @@
                     }
                 };
 
+        private void updateNoAlertTextVisibility() {
+            TextView noAlertsTextView = getActivity().findViewById(R.id.empty);
+            if (noAlertsTextView != null) {
+                noAlertsTextView.setVisibility(!hasAlertsInHistory()
+                        ? View.VISIBLE : View.INVISIBLE);
+            }
+        }
+
+        /**
+         * @return {@code true} if the alert history database has any item
+         */
+        private boolean hasAlertsInHistory() {
+            return mAdapter.getCursor().getCount() > 0;
+        }
+
         @Override
         public boolean onContextItemSelected(MenuItem item) {
             Cursor cursor = mAdapter.getCursor();