notification list context menu
This commit is contained in:
@@ -75,4 +75,11 @@ public class DatabaseUtils {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void deleteNotification(Context context, long id) {
|
||||||
|
context.getContentResolver().delete(
|
||||||
|
Logged_notificationTable.CONTENT_URI,
|
||||||
|
Logged_notificationTable.FIELD__ID + " = ?",
|
||||||
|
new String[] {String.valueOf(id)}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import butterknife.Bind;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
|
|
||||||
public class NotificationListAdapter extends CursorRecyclerViewAdapter<NotificationListAdapter.NotificationViewHolder> implements View.OnClickListener {
|
public class NotificationListAdapter extends CursorRecyclerViewAdapter<NotificationListAdapter.NotificationViewHolder> implements View.OnClickListener, View.OnLongClickListener {
|
||||||
|
|
||||||
class NotificationViewHolder extends RecyclerView.ViewHolder {
|
class NotificationViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
@@ -74,6 +74,7 @@ public class NotificationListAdapter extends CursorRecyclerViewAdapter<Notificat
|
|||||||
|
|
||||||
interface NotificationClickListener {
|
interface NotificationClickListener {
|
||||||
void onNotificationClick(long id);
|
void onNotificationClick(long id);
|
||||||
|
void onNotificationLongClick(long id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private NotificationClickListener mNotificationClickListener;
|
private NotificationClickListener mNotificationClickListener;
|
||||||
@@ -96,6 +97,7 @@ public class NotificationListAdapter extends CursorRecyclerViewAdapter<Notificat
|
|||||||
public NotificationViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public NotificationViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.notification_list_item, parent, false);
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.notification_list_item, parent, false);
|
||||||
v.setOnClickListener(this);
|
v.setOnClickListener(this);
|
||||||
|
v.setOnLongClickListener(this);
|
||||||
return new NotificationViewHolder(v);
|
return new NotificationViewHolder(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,4 +109,15 @@ public class NotificationListAdapter extends CursorRecyclerViewAdapter<Notificat
|
|||||||
mNotificationClickListener.onNotificationClick(id);
|
mNotificationClickListener.onNotificationClick(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
if(mNotificationClickListener != null) {
|
||||||
|
long id = (long) v.getTag();
|
||||||
|
mNotificationClickListener.onNotificationLongClick(id);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ public class NotificationListFilterDialog extends AlertDialog implements DialogI
|
|||||||
@Bind(R.id.notification_filter_etPackage)
|
@Bind(R.id.notification_filter_etPackage)
|
||||||
EditText etPackageName;
|
EditText etPackageName;
|
||||||
|
|
||||||
|
boolean hasPreselection = false;
|
||||||
|
String message, title, appName, packageName;
|
||||||
|
|
||||||
interface NotificationListFilterDialogCallbacks {
|
interface NotificationListFilterDialogCallbacks {
|
||||||
void onFilterNotificationList(
|
void onFilterNotificationList(
|
||||||
String title,
|
String title,
|
||||||
@@ -51,10 +54,29 @@ public class NotificationListFilterDialog extends AlertDialog implements DialogI
|
|||||||
setTitle(context.getString(R.string.filter_dialog_title));
|
setTitle(context.getString(R.string.filter_dialog_title));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NotificationListFilterDialog(Context context, NotificationListFilterDialogCallbacks cb, String title, String message, String appName, String packageName) {
|
||||||
|
this(context, cb);
|
||||||
|
this.title = title;
|
||||||
|
this.message = message;
|
||||||
|
this.appName = appName;
|
||||||
|
this.packageName = packageName;
|
||||||
|
hasPreselection = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
if(hasPreselection) {
|
||||||
|
if(title != null)
|
||||||
|
etTitle.setText(title);
|
||||||
|
if(message != null)
|
||||||
|
etMessage.setText(message);
|
||||||
|
if(packageName != null)
|
||||||
|
etPackageName.setText(packageName);
|
||||||
|
if(appName != null)
|
||||||
|
etAppName.setText(appName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package net.headlezz.notificationlogger.notificationlist;
|
package net.headlezz.notificationlogger.notificationlist;
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -16,6 +20,7 @@ import android.view.ViewGroup;
|
|||||||
import net.headlezz.notificationlogger.DatabaseUtils;
|
import net.headlezz.notificationlogger.DatabaseUtils;
|
||||||
import net.headlezz.notificationlogger.NotificationInfoDialog;
|
import net.headlezz.notificationlogger.NotificationInfoDialog;
|
||||||
import net.headlezz.notificationlogger.R;
|
import net.headlezz.notificationlogger.R;
|
||||||
|
import net.headlezz.notificationlogger.logger.BlacklistItem;
|
||||||
import net.headlezz.notificationlogger.logger.LoggedNotification;
|
import net.headlezz.notificationlogger.logger.LoggedNotification;
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
@@ -107,10 +112,7 @@ public class NotificationListFragment extends Fragment implements NotificationLi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNotificationClick(long id) {
|
public void onNotificationClick(long id) {
|
||||||
LoggedNotification notification = DatabaseUtils.getNotificationById(getContext(), id);
|
showNotificationInfo(id);
|
||||||
Timber.e(notification.title);
|
|
||||||
|
|
||||||
new NotificationInfoDialog(getContext(), notification).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -119,4 +121,85 @@ public class NotificationListFragment extends Fragment implements NotificationLi
|
|||||||
setIsFiltered(true);
|
setIsFiltered(true);
|
||||||
mLoaderManager.loadNotificationsFiltered(title, message, appName, packageName);
|
mLoaderManager.loadNotificationsFiltered(title, message, appName, packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showNotificationInfo(long id) {
|
||||||
|
LoggedNotification notification = DatabaseUtils.getNotificationById(getContext(), id);
|
||||||
|
new NotificationInfoDialog(getContext(), notification).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNotificationLongClick(final long id) {
|
||||||
|
String[] options = getResources().getStringArray(R.array.notification_list_options);
|
||||||
|
new AlertDialog.Builder(getContext())
|
||||||
|
.setItems(options, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
switch (which) {
|
||||||
|
case 0:
|
||||||
|
showNotificationInfo(id);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
DatabaseUtils.deleteNotification(getContext(), id);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
showPreselectedFilter(id);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
blacklistNotificationPackage(id);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
shareMessage(id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create().show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shareMessage(long id) {
|
||||||
|
LoggedNotification notification = DatabaseUtils.getNotificationById(getContext(), id);
|
||||||
|
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||||
|
shareIntent.setType("text/plain");
|
||||||
|
shareIntent.putExtra(Intent.EXTRA_TEXT, notification.message);
|
||||||
|
shareIntent.putExtra(Intent.EXTRA_TITLE, notification.title);
|
||||||
|
shareIntent.putExtra(Intent.EXTRA_SUBJECT, notification.title);
|
||||||
|
startActivity(Intent.createChooser(shareIntent, getContext().getString(R.string.share_title)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showPreselectedFilter(long id) {
|
||||||
|
LoggedNotification notification = DatabaseUtils.getNotificationById(getContext(), id);
|
||||||
|
new NotificationListFilterDialog(
|
||||||
|
getContext(),
|
||||||
|
this,
|
||||||
|
notification.title,
|
||||||
|
notification.message,
|
||||||
|
notification.appName,
|
||||||
|
notification.packageName)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void blacklistNotificationPackage(long id) {
|
||||||
|
final LoggedNotification ln = DatabaseUtils.getNotificationById(getContext(), id);
|
||||||
|
if (!DatabaseUtils.isPackageBlacklisted(getContext(), ln.packageName)) {
|
||||||
|
BlacklistItem item = new BlacklistItem();
|
||||||
|
item.packageName = ln.packageName;
|
||||||
|
DatabaseUtils.insertBlacklistItem(getContext(), item);
|
||||||
|
}
|
||||||
|
if (getActivity() != null) {
|
||||||
|
Snackbar snackbar = Snackbar.make(
|
||||||
|
getActivity().findViewById(android.R.id.content),
|
||||||
|
String.format(getContext().getString(R.string.notification_list_frag_blacklist_snack), ln.packageName),
|
||||||
|
Snackbar.LENGTH_LONG
|
||||||
|
);
|
||||||
|
snackbar.setAction(R.string.notification_list_frag_blacklist_snack_action, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
DatabaseUtils.deleteBlacklistItem(getContext(), ln.packageName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
snackbar.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,17 @@
|
|||||||
<string name="pref_export_progress_message">Exporting ...</string>
|
<string name="pref_export_progress_message">Exporting ...</string>
|
||||||
<string name="pref_export_snack_failed">Failed to export data.</string>
|
<string name="pref_export_snack_failed">Failed to export data.</string>
|
||||||
<string name="pref_export_snack_success">Exported to %s.</string>
|
<string name="pref_export_snack_success">Exported to %s.</string>
|
||||||
|
<string name="share_title">Share Notification</string>
|
||||||
|
<string name="notification_list_frag_blacklist_snack">%s blacklisted.</string>
|
||||||
|
<string name="notification_list_frag_blacklist_snack_action">Undo</string>
|
||||||
|
|
||||||
|
<string-array name="notification_list_options">
|
||||||
|
<item>Show more info</item>
|
||||||
|
<item>Delete notification</item>
|
||||||
|
<item>Create filter</item>
|
||||||
|
<item>Blacklist this app</item>
|
||||||
|
<item>Share message</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="create_categories">
|
<string-array name="create_categories">
|
||||||
<item>Alarm</item>
|
<item>Alarm</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user