1. added swipe to delete
2. added delete all button 3. adjusted UI to fix navigation bar overlapping app UI
This commit is contained in:
@@ -79,6 +79,14 @@ public class PreferencesManager {
|
||||
prefs.edit().remove(KEY_LOG).apply();
|
||||
}
|
||||
|
||||
public void removeNotificationEntry(int position) {
|
||||
List<NotificationEntry> entries = getNotificationLog();
|
||||
if (position >= 0 && position < entries.size()) {
|
||||
entries.remove(position);
|
||||
saveLog(entries);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveLog(List<NotificationEntry> entries) {
|
||||
JSONArray arr = new JSONArray();
|
||||
for (NotificationEntry e : entries) {
|
||||
|
||||
@@ -9,10 +9,13 @@ import android.provider.Settings;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.notificationmonitor.R;
|
||||
import com.notificationmonitor.data.NotificationEntry;
|
||||
@@ -59,6 +62,22 @@ public class MainActivity extends AppCompatActivity {
|
||||
binding.recyclerNotifications.setLayoutManager(new LinearLayoutManager(this));
|
||||
binding.recyclerNotifications.setAdapter(adapter);
|
||||
|
||||
// Add Swipe to Delete
|
||||
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
|
||||
@Override
|
||||
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
int position = viewHolder.getAdapterPosition();
|
||||
prefsManager.removeNotificationEntry(position);
|
||||
adapter.removeEntry(position);
|
||||
updateEmptyState();
|
||||
}
|
||||
}).attachToRecyclerView(binding.recyclerNotifications);
|
||||
|
||||
// Load persisted log
|
||||
List<NotificationEntry> log = prefsManager.getNotificationLog();
|
||||
adapter.setEntries(log);
|
||||
@@ -72,6 +91,20 @@ public class MainActivity extends AppCompatActivity {
|
||||
// Select apps FAB
|
||||
binding.fabSelectApps.setOnClickListener(v ->
|
||||
startActivity(new Intent(this, AppSelectorActivity.class)));
|
||||
|
||||
// Clear all FAB
|
||||
binding.fabClearAll.setOnClickListener(v -> {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Clear Log")
|
||||
.setMessage("Are you sure you want to delete all notification entries?")
|
||||
.setPositiveButton("Clear All", (d, w) -> {
|
||||
prefsManager.clearLog();
|
||||
adapter.clearEntries();
|
||||
updateEmptyState();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,6 +40,13 @@ public class NotificationLogAdapter
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void removeEntry(int position) {
|
||||
if (position >= 0 && position < entries.size()) {
|
||||
entries.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/background"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="@color/background">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
@@ -97,10 +98,23 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="@string/select_apps"
|
||||
app:icon="@android:drawable/ic_menu_manage"
|
||||
app:backgroundTint="@color/primary"
|
||||
app:iconTint="@color/on_primary" />
|
||||
|
||||
<!-- FAB to clear log -->
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_clear_all"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|start"
|
||||
android:layout_margin="16dp"
|
||||
android:contentDescription="Clear All"
|
||||
app:srcCompat="@android:drawable/ic_menu_delete"
|
||||
app:backgroundTint="@color/error"
|
||||
app:tint="@color/on_error" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
<color name="warning">#FFF3CD</color>
|
||||
<color name="on_warning">#856404</color>
|
||||
|
||||
<!-- Error -->
|
||||
<color name="error">#B00020</color>
|
||||
<color name="on_error">#FFFFFF</color>
|
||||
|
||||
<!-- Material defaults -->
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
|
||||
Reference in New Issue
Block a user