filter dialog
This commit is contained in:
@@ -0,0 +1,71 @@
|
|||||||
|
package net.headlezz.notificationlogger.notificationlist;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import net.headlezz.notificationlogger.R;
|
||||||
|
|
||||||
|
import butterknife.Bind;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
|
public class NotificationListFilterDialog extends AlertDialog implements DialogInterface.OnClickListener {
|
||||||
|
|
||||||
|
NotificationListFilterDialogCallbacks mCallbacks;
|
||||||
|
|
||||||
|
@Bind(R.id.notification_filter_etTitle)
|
||||||
|
EditText etTitle;
|
||||||
|
|
||||||
|
@Bind(R.id.notification_filter_etMessage)
|
||||||
|
EditText etMessage;
|
||||||
|
|
||||||
|
@Bind(R.id.notification_filter_etAppName)
|
||||||
|
EditText etAppName;
|
||||||
|
|
||||||
|
@Bind(R.id.notification_filter_etPackage)
|
||||||
|
EditText etPackageName;
|
||||||
|
|
||||||
|
interface NotificationListFilterDialogCallbacks {
|
||||||
|
void onFilterNotificationList(
|
||||||
|
String title,
|
||||||
|
String message,
|
||||||
|
String appName,
|
||||||
|
String packageName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotificationListFilterDialog(Context context, NotificationListFilterDialogCallbacks cb) {
|
||||||
|
super(context);
|
||||||
|
mCallbacks = cb;
|
||||||
|
|
||||||
|
setButton(BUTTON_POSITIVE, context.getString(R.string.filter_dialog_ok), this);
|
||||||
|
setButton(BUTTON_NEGATIVE, context.getString(R.string.filter_dialog_cancel), this);
|
||||||
|
|
||||||
|
View view = LayoutInflater.from(getContext()).inflate(R.layout.notification_list_filter_dialog, null);
|
||||||
|
setView(view);
|
||||||
|
|
||||||
|
setTitle(context.getString(R.string.filter_dialog_title));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
ButterKnife.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
if(which == BUTTON_POSITIVE)
|
||||||
|
mCallbacks.onFilterNotificationList(
|
||||||
|
etTitle.getText().toString(),
|
||||||
|
etMessage.getText().toString(),
|
||||||
|
etAppName.getText().toString(),
|
||||||
|
etPackageName.getText().toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ import butterknife.Bind;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class NotificationListFragment extends Fragment implements NotificationListLoaderCallbacks.NotificationListView, NotificationListAdapter.NotificationClickListener {
|
public class NotificationListFragment extends Fragment implements NotificationListLoaderCallbacks.NotificationListView, NotificationListAdapter.NotificationClickListener, NotificationListFilterDialog.NotificationListFilterDialogCallbacks {
|
||||||
|
|
||||||
@Bind(R.id.nList_emptyView)
|
@Bind(R.id.nList_emptyView)
|
||||||
View mEmptyView;
|
View mEmptyView;
|
||||||
@@ -76,8 +76,7 @@ public class NotificationListFragment extends Fragment implements NotificationLi
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menu_filter:
|
case R.id.menu_filter:
|
||||||
mLoaderManager.loadNotificationsUnfiltered();
|
new NotificationListFilterDialog(getContext(), this).show();
|
||||||
setIsFiltered(true);
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_clear_filter:
|
case R.id.menu_clear_filter:
|
||||||
mLoaderManager.loadNotificationsUnfiltered();
|
mLoaderManager.loadNotificationsUnfiltered();
|
||||||
@@ -116,4 +115,11 @@ public class NotificationListFragment extends Fragment implements NotificationLi
|
|||||||
|
|
||||||
new NotificationInfoDialog(getContext(), notification).show();
|
new NotificationInfoDialog(getContext(), notification).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFilterNotificationList(String title, String message, String appName, String packageName) {
|
||||||
|
Timber.d("Selected filter: " + title + "/" + message + "/" + appName + "/" + packageName);
|
||||||
|
setIsFiltered(true);
|
||||||
|
mLoaderManager.loadNotificationsFiltered(title, message, appName, packageName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import android.support.v4.content.Loader;
|
|||||||
|
|
||||||
import net.headlezz.notificationlogger.logger.Logged_notificationTable;
|
import net.headlezz.notificationlogger.logger.Logged_notificationTable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class NotificationListLoaderCallbacks implements LoaderManager.LoaderCallbacks<Cursor> {
|
public class NotificationListLoaderCallbacks implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
@@ -27,13 +30,44 @@ public class NotificationListLoaderCallbacks implements LoaderManager.LoaderCall
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||||
|
// TODO apply filters
|
||||||
Timber.d("Loader created.");
|
Timber.d("Loader created.");
|
||||||
|
String titleFilter = args.containsKey(Logged_notificationTable.FIELD_TITLE) ? args.getString(Logged_notificationTable.FIELD_TITLE) : "";
|
||||||
|
String messageFilter = args.containsKey(Logged_notificationTable.FIELD_MESSAGE) ? args.getString(Logged_notificationTable.FIELD_MESSAGE) : "";
|
||||||
|
String appNameFilter = args.containsKey(Logged_notificationTable.FIELD_APP_NAME) ? args.getString(Logged_notificationTable.FIELD_APP_NAME) : "";
|
||||||
|
String packageFilter = args.containsKey(Logged_notificationTable.FIELD_PACKAGE_NAME) ? args.getString(Logged_notificationTable.FIELD_PACKAGE_NAME) : "";
|
||||||
|
|
||||||
|
StringBuilder selectionClauseBuilder = new StringBuilder();
|
||||||
|
List<String> selectionParams = new ArrayList<>();
|
||||||
|
if(!titleFilter.isEmpty()) {
|
||||||
|
selectionClauseBuilder.append(Logged_notificationTable.FIELD_TITLE + " like ?");
|
||||||
|
selectionParams.add("%" + titleFilter + "%");
|
||||||
|
}
|
||||||
|
if(!messageFilter.isEmpty()) {
|
||||||
|
if(selectionClauseBuilder.length() > 0)
|
||||||
|
selectionClauseBuilder.append(" AND ");
|
||||||
|
selectionClauseBuilder.append(Logged_notificationTable.FIELD_MESSAGE + " like ?");
|
||||||
|
selectionParams.add("%" + messageFilter + "%");
|
||||||
|
}
|
||||||
|
if(!appNameFilter.isEmpty()) {
|
||||||
|
if(selectionClauseBuilder.length() > 0)
|
||||||
|
selectionClauseBuilder.append(" AND ");
|
||||||
|
selectionClauseBuilder.append(Logged_notificationTable.FIELD_APP_NAME + " like ?");
|
||||||
|
selectionParams.add("%" + appNameFilter + "%");
|
||||||
|
}
|
||||||
|
if(!packageFilter.isEmpty()) {
|
||||||
|
if(selectionClauseBuilder.length() > 0)
|
||||||
|
selectionClauseBuilder.append(" AND ");
|
||||||
|
selectionClauseBuilder.append(Logged_notificationTable.FIELD_PACKAGE_NAME + " like ?");
|
||||||
|
selectionParams.add("%" + packageFilter + "%");
|
||||||
|
}
|
||||||
|
|
||||||
return new CursorLoader(
|
return new CursorLoader(
|
||||||
mContext,
|
mContext,
|
||||||
Logged_notificationTable.CONTENT_URI,
|
Logged_notificationTable.CONTENT_URI,
|
||||||
null,
|
null,
|
||||||
null,
|
selectionClauseBuilder.toString(),
|
||||||
null,
|
selectionParams.toArray(new String[selectionParams.size()]),
|
||||||
Logged_notificationTable.FIELD_DATE + " DESC"
|
Logged_notificationTable.FIELD_DATE + " DESC"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ package net.headlezz.notificationlogger.notificationlist;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
|
|
||||||
|
import net.headlezz.notificationlogger.logger.Logged_notificationTable;
|
||||||
|
|
||||||
public class NotificationListLoaderManager {
|
public class NotificationListLoaderManager {
|
||||||
|
|
||||||
final int LOADER_ID = 124;
|
final int LOADER_ID = 124;
|
||||||
@@ -20,4 +23,24 @@ public class NotificationListLoaderManager {
|
|||||||
mLoaderManager.restartLoader(LOADER_ID, Bundle.EMPTY, mLoaderCallbacks);
|
mLoaderManager.restartLoader(LOADER_ID, Bundle.EMPTY, mLoaderCallbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loadNotificationsFiltered(@Nullable String titleFilter, @Nullable String messageFilter, @Nullable String appNameFilter, @Nullable String packageFilter) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
|
||||||
|
if(titleFilter != null && !titleFilter.isEmpty())
|
||||||
|
bundle.putString(Logged_notificationTable.FIELD_TITLE, titleFilter);
|
||||||
|
|
||||||
|
if(messageFilter != null && !messageFilter .isEmpty())
|
||||||
|
bundle.putString(Logged_notificationTable.FIELD_MESSAGE, messageFilter);
|
||||||
|
|
||||||
|
|
||||||
|
if(appNameFilter != null && !appNameFilter.isEmpty())
|
||||||
|
bundle.putString(Logged_notificationTable.FIELD_APP_NAME, appNameFilter);
|
||||||
|
|
||||||
|
|
||||||
|
if(packageFilter != null && !packageFilter.isEmpty())
|
||||||
|
bundle.putString(Logged_notificationTable.FIELD_PACKAGE_NAME, packageFilter);
|
||||||
|
|
||||||
|
mLoaderManager.restartLoader(LOADER_ID, bundle, mLoaderCallbacks);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
33
app/src/main/res/layout/notification_list_filter_dialog.xml
Normal file
33
app/src/main/res/layout/notification_list_filter_dialog.xml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/notification_filter_etTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Title" />
|
||||||
|
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/notification_filter_etMessage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Message" />
|
||||||
|
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/notification_filter_etAppName"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Application name" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/notification_filter_etPackage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Package name" />
|
||||||
|
</LinearLayout>
|
||||||
@@ -57,6 +57,9 @@
|
|||||||
<string name="notification_info_dialog_app_info_error">Failed to display app info.</string>
|
<string name="notification_info_dialog_app_info_error">Failed to display app info.</string>
|
||||||
<string name="menu_item_filter">Filter</string>
|
<string name="menu_item_filter">Filter</string>
|
||||||
<string name="menu_item_clear_filter">Clear filter</string>
|
<string name="menu_item_clear_filter">Clear filter</string>
|
||||||
|
<string name="filter_dialog_ok">OK</string>
|
||||||
|
<string name="filter_dialog_cancel">Cancel</string>
|
||||||
|
<string name="filter_dialog_title">Filter</string>
|
||||||
|
|
||||||
<string-array name="create_categories">
|
<string-array name="create_categories">
|
||||||
<item>Alarm</item>
|
<item>Alarm</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user