use of com.orgzly.android.db.entity.SavedSearch in project orgzly-android by orgzly.
the class SavedSearchFragment method sameNameFilterExists.
/**
* Checks if filter with the same name (ignoring case) already exists.
*/
private boolean sameNameFilterExists(String name) {
List<SavedSearch> savedSearches = dataRepository.getSavedSearchesByNameIgnoreCase(name);
if (isEditingExistingFilter()) {
long id = getArguments().getLong(ARG_ID);
for (SavedSearch savedSearch : savedSearches) {
long savedSearchId = savedSearch.getId();
String savedSearchName = savedSearch.getName();
// Ignore currently edited filter
if (name.equalsIgnoreCase(savedSearchName) && id != savedSearchId) {
return true;
}
}
return false;
} else {
// New filter
return savedSearches.size() > 0;
}
}
use of com.orgzly.android.db.entity.SavedSearch in project orgzly-android by orgzly.
the class ListWidgetProvider method getSavedSearch.
private SavedSearch getSavedSearch(Context context, int appWidgetId) {
long filterId = context.getSharedPreferences(PREFERENCES_ID, Context.MODE_PRIVATE).getLong(getFilterPreferenceKey(appWidgetId), -1);
SavedSearch savedSearch = null;
if (filterId != -1) {
savedSearch = dataRepository.getSavedSearch(filterId);
}
if (savedSearch == null) {
savedSearch = new SavedSearch(0, context.getString(R.string.list_widget_select_search), "", 0);
}
return savedSearch;
}
use of com.orgzly.android.db.entity.SavedSearch in project orgzly-android by orgzly.
the class ListWidgetProvider method updateAppWidgetLayout.
private void updateAppWidgetLayout(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG);
App.EXECUTORS.diskIO().execute(() -> {
SavedSearch savedSearch = getSavedSearch(context, appWidgetId);
App.EXECUTORS.mainThread().execute(() -> {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.list_widget);
WidgetStyle.updateWidget(remoteViews, context);
Intent serviceIntent = new Intent(context, ListWidgetService.class);
serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
serviceIntent.putExtra(AppIntent.EXTRA_QUERY_STRING, savedSearch.getQuery());
serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
// Tell ListView where to get the data from
remoteViews.setRemoteAdapter(R.id.list_widget_list_view, serviceIntent);
remoteViews.setEmptyView(R.id.list_widget_list_view, R.id.list_widget_empty_view);
remoteViews.setTextViewText(R.id.list_widget_empty_view, context.getString(R.string.no_notes_found_after_search));
// Rows - open note
final Intent onClickIntent = new Intent(context, ListWidgetProvider.class);
onClickIntent.setAction(AppIntent.ACTION_CLICK_LIST_WIDGET);
onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(context, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setPendingIntentTemplate(R.id.list_widget_list_view, onClickPendingIntent);
// Plus icon - new note
remoteViews.setOnClickPendingIntent(R.id.list_widget_header_add, ShareActivity.createNewNoteIntent(context, savedSearch));
// Logo - open query
Intent openIntent = Intent.makeRestartActivityTask(new ComponentName(context, MainActivity.class));
openIntent.putExtra(AppIntent.EXTRA_QUERY_STRING, savedSearch.getQuery());
openIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
remoteViews.setOnClickPendingIntent(R.id.list_widget_header_icon, PendingIntent.getActivity(context, 0, openIntent, PendingIntent.FLAG_UPDATE_CURRENT));
Intent selectionIntent = new Intent(context, ListWidgetSelectionActivity.class);
selectionIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
selectionIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
remoteViews.setOnClickPendingIntent(R.id.list_widget_header_bar, PendingIntent.getActivity(context, 0, selectionIntent, PendingIntent.FLAG_UPDATE_CURRENT));
remoteViews.setTextViewText(R.id.list_widget_header_selection, savedSearch.getName());
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
});
});
}
Aggregations