From 0f825f657bd36f692074177aee6af91fc209fdeb Mon Sep 17 00:00:00 2001 From: Marcel de Sena Dall'Agnol Date: Thu, 1 Jun 2017 01:32:14 -0300 Subject: [PATCH 1/3] Added option to display/hide timestamps on widget --- .../android/omninotes/DetailFragment.java | 1 + .../android/omninotes/SettingsFragment.java | 10 +++++++ .../omninotes/utils/ConstantsBase.java | 1 + .../widget/ListRemoteViewsFactory.java | 29 +++++++++++-------- omniNotes/src/main/res/values/strings.xml | 3 ++ .../src/main/res/xml/settings_interface.xml | 7 +++++ 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java b/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java index bfa3c169d5..03fc403cde 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java @@ -587,6 +587,7 @@ private void initViewFooter() { .PREF_PRETTIFIED_DATES, true)); lastModificationTextView.append(lastModification.length() > 0 ? getString(R.string.last_update) + " " + lastModification : ""); + lastModificationTextView.append("blablabla"); if (lastModificationTextView.getText().length() == 0) lastModificationTextView.setVisibility(View.GONE); } diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java b/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java index d37a3d31ec..3b432ffd4c 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java @@ -369,6 +369,16 @@ public void onResume() { }); } + // Update widget when last modification display for widget is toggled + final SwitchPreference widgetLastModification = (SwitchPreference) findPreference("settings_display_last_modified"); + if (widgetLastModification != null) { + widgetLastModification.setOnPreferenceChangeListener((preference, newValue) -> { + widgetLastModification.setChecked((Boolean) newValue); + MainActivity.notifyAppWidgets(OmniNotes.getAppContext()); + return false; + }); + } + // Notification snooze delay final EditTextPreference snoozeDelay = (EditTextPreference) findPreference diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java b/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java index 34012250e4..bec01e2645 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java @@ -96,6 +96,7 @@ public interface ConstantsBase { String PREF_ENABLE_SWIPE = "settings_enable_swipe"; String PREF_SEND_ANALYTICS = "settings_send_analytics"; String PREF_PRETTIFIED_DATES = "settings_prettified_dates"; + String PREF_DISPLAY_LAST_MODIFICATION = "settings_display_last_modified"; String MIME_TYPE_IMAGE = "image/jpeg"; String MIME_TYPE_AUDIO = "audio/amr"; diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java b/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java index 3316d84049..cb93e81564 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java @@ -21,6 +21,7 @@ import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Color; import android.os.Bundle; @@ -53,6 +54,7 @@ public class ListRemoteViewsFactory implements RemoteViewsFactory { private OmniNotes app; private int appWidgetId; private List notes; + private boolean show_last_modified; private int navigation; @@ -65,11 +67,12 @@ public ListRemoteViewsFactory(Application app, Intent intent) { @Override public void onCreate() { Log.d(Constants.TAG, "Created widget " + appWidgetId); - String condition = app.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS) - .getString( - Constants.PREF_WIDGET_PREFIX - + String.valueOf(appWidgetId), ""); - notes = DbHelper.getInstance().getNotes(condition, true); + + SharedPreferences prefs = app.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS); + notes = DbHelper.getInstance().getNotes( + prefs.getString(Constants.PREF_WIDGET_PREFIX + + String.valueOf(appWidgetId), ""), true); + show_last_modified = prefs.getBoolean(Constants.PREF_DISPLAY_LAST_MODIFICATION, true); } @@ -78,11 +81,11 @@ public void onDataSetChanged() { Log.d(Constants.TAG, "onDataSetChanged widget " + appWidgetId); navigation = Navigation.getNavigation(); - String condition = app.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS) - .getString( - Constants.PREF_WIDGET_PREFIX - + String.valueOf(appWidgetId), ""); - notes = DbHelper.getInstance().getNotes(condition, true); + SharedPreferences prefs = app.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS); + notes = DbHelper.getInstance().getNotes( + prefs.getString(Constants.PREF_WIDGET_PREFIX + + String.valueOf(appWidgetId), ""), true); + show_last_modified = prefs.getBoolean(Constants.PREF_DISPLAY_LAST_MODIFICATION, true); } @@ -122,8 +125,10 @@ public RemoteViews getViewAt(int position) { } else { row.setInt(R.id.attachmentThumbnail, "setVisibility", View.GONE); } - - row.setTextViewText(R.id.note_date, TextHelper.getDateText(app, note, navigation)); + if(show_last_modified) + row.setTextViewText(R.id.note_date, TextHelper.getDateText(app, note, navigation)); + else + row.setTextViewText(R.id.note_date, ""); // Next, set a fill-intent, which will be used to fill in the pending intent template // that is set on the collection view in StackWidgetProvider. diff --git a/omniNotes/src/main/res/values/strings.xml b/omniNotes/src/main/res/values/strings.xml index e4f9d0d2d4..f304037764 100644 --- a/omniNotes/src/main/res/values/strings.xml +++ b/omniNotes/src/main/res/values/strings.xml @@ -336,6 +336,9 @@ Prettified dates Dates are shown in a simplier format Dates are shown in a more detailed format + Last modification on widget + Last modified timestamp shown on notes + Last modified timestamp hidden Privacy Error reporting When app crashes developer will be informed to help you diff --git a/omniNotes/src/main/res/xml/settings_interface.xml b/omniNotes/src/main/res/xml/settings_interface.xml index 12d0f6aa30..a6b74c2ee3 100644 --- a/omniNotes/src/main/res/xml/settings_interface.xml +++ b/omniNotes/src/main/res/xml/settings_interface.xml @@ -65,4 +65,11 @@ android:title="@string/settings_prettified_dates" android:defaultValue="true"/> + + From bd53b838ebd61e5c44a9c315642cd959f7c7f549 Mon Sep 17 00:00:00 2001 From: Marcel de Sena Dall'Agnol Date: Thu, 1 Jun 2017 01:41:32 -0300 Subject: [PATCH 2/3] Oops, fiddled around and forgot to clean up.. --- .../src/main/java/it/feio/android/omninotes/DetailFragment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java b/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java index 03fc403cde..bfa3c169d5 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/DetailFragment.java @@ -587,7 +587,6 @@ private void initViewFooter() { .PREF_PRETTIFIED_DATES, true)); lastModificationTextView.append(lastModification.length() > 0 ? getString(R.string.last_update) + " " + lastModification : ""); - lastModificationTextView.append("blablabla"); if (lastModificationTextView.getText().length() == 0) lastModificationTextView.setVisibility(View.GONE); } From aa8fbda46d39b7a88d2bf5f7cd7cf5e5a63f5c76 Mon Sep 17 00:00:00 2001 From: Marcel de Sena Dall'Agnol Date: Fri, 16 Jun 2017 18:56:48 -0300 Subject: [PATCH 3/3] Moving option to the prompt displayed when widged is added --- etc/translations/strings.xml | 1 + .../android/omninotes/SettingsFragment.java | 11 ----- .../omninotes/utils/ConstantsBase.java | 1 - .../widget/ListRemoteViewsFactory.java | 46 +++++++++---------- .../widget/WidgetConfigurationActivity.java | 3 +- .../layout/activity_widget_configuration.xml | 8 ++++ omniNotes/src/main/res/values/strings.xml | 4 +- .../src/main/res/xml/settings_interface.xml | 7 --- 8 files changed, 35 insertions(+), 46 deletions(-) diff --git a/etc/translations/strings.xml b/etc/translations/strings.xml index 862754c06d..e22214d19a 100644 --- a/etc/translations/strings.xml +++ b/etc/translations/strings.xml @@ -158,6 +158,7 @@ Scrolling list widget with buttons notes Show attachment\'s thumbnails + Show \"Last updated\" timestamps Choose action Edit reminders diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java b/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java index 3b432ffd4c..0f0dd102e7 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/SettingsFragment.java @@ -369,17 +369,6 @@ public void onResume() { }); } - // Update widget when last modification display for widget is toggled - final SwitchPreference widgetLastModification = (SwitchPreference) findPreference("settings_display_last_modified"); - if (widgetLastModification != null) { - widgetLastModification.setOnPreferenceChangeListener((preference, newValue) -> { - widgetLastModification.setChecked((Boolean) newValue); - MainActivity.notifyAppWidgets(OmniNotes.getAppContext()); - return false; - }); - } - - // Notification snooze delay final EditTextPreference snoozeDelay = (EditTextPreference) findPreference ("settings_notification_snooze_delay"); diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java b/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java index bec01e2645..34012250e4 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/utils/ConstantsBase.java @@ -96,7 +96,6 @@ public interface ConstantsBase { String PREF_ENABLE_SWIPE = "settings_enable_swipe"; String PREF_SEND_ANALYTICS = "settings_send_analytics"; String PREF_PRETTIFIED_DATES = "settings_prettified_dates"; - String PREF_DISPLAY_LAST_MODIFICATION = "settings_display_last_modified"; String MIME_TYPE_IMAGE = "image/jpeg"; String MIME_TYPE_AUDIO = "audio/amr"; diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java b/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java index cb93e81564..b6de33860c 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/widget/ListRemoteViewsFactory.java @@ -21,7 +21,6 @@ import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.Color; import android.os.Bundle; @@ -50,11 +49,11 @@ public class ListRemoteViewsFactory implements RemoteViewsFactory { private final int HEIGHT = 80; private static boolean showThumbnails = true; + private static boolean showTimestamps = true; private OmniNotes app; private int appWidgetId; private List notes; - private boolean show_last_modified; private int navigation; @@ -67,12 +66,11 @@ public ListRemoteViewsFactory(Application app, Intent intent) { @Override public void onCreate() { Log.d(Constants.TAG, "Created widget " + appWidgetId); - - SharedPreferences prefs = app.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS); - notes = DbHelper.getInstance().getNotes( - prefs.getString(Constants.PREF_WIDGET_PREFIX - + String.valueOf(appWidgetId), ""), true); - show_last_modified = prefs.getBoolean(Constants.PREF_DISPLAY_LAST_MODIFICATION, true); + String condition = app.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS) + .getString( + Constants.PREF_WIDGET_PREFIX + + String.valueOf(appWidgetId), ""); + notes = DbHelper.getInstance().getNotes(condition, true); } @@ -80,12 +78,12 @@ public void onCreate() { public void onDataSetChanged() { Log.d(Constants.TAG, "onDataSetChanged widget " + appWidgetId); navigation = Navigation.getNavigation(); - - SharedPreferences prefs = app.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS); - notes = DbHelper.getInstance().getNotes( - prefs.getString(Constants.PREF_WIDGET_PREFIX - + String.valueOf(appWidgetId), ""), true); - show_last_modified = prefs.getBoolean(Constants.PREF_DISPLAY_LAST_MODIFICATION, true); + + String condition = app.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS) + .getString( + Constants.PREF_WIDGET_PREFIX + + String.valueOf(appWidgetId), ""); + notes = DbHelper.getInstance().getNotes(condition, true); } @@ -118,17 +116,18 @@ public RemoteViews getViewAt(int position) { color(note, row); if (!note.isLocked() && showThumbnails && note.getAttachmentsList().size() > 0) { - Attachment mAttachment = note.getAttachmentsList().get(0); - Bitmap bmp = BitmapHelper.getBitmapFromAttachment(app, mAttachment, WIDTH, HEIGHT); - row.setBitmap(R.id.attachmentThumbnail, "setImageBitmap", bmp); + Attachment mAttachment = note.getAttachmentsList().get(0); + Bitmap bmp = BitmapHelper.getBitmapFromAttachment(app, mAttachment, WIDTH, HEIGHT); + row.setBitmap(R.id.attachmentThumbnail, "setImageBitmap", bmp); row.setInt(R.id.attachmentThumbnail, "setVisibility", View.VISIBLE); } else { row.setInt(R.id.attachmentThumbnail, "setVisibility", View.GONE); } - if(show_last_modified) - row.setTextViewText(R.id.note_date, TextHelper.getDateText(app, note, navigation)); - else - row.setTextViewText(R.id.note_date, ""); + if(showTimestamps) { + row.setTextViewText(R.id.note_date, TextHelper.getDateText(app, note, navigation)); + } else { + row.setTextViewText(R.id.note_date, ""); + } // Next, set a fill-intent, which will be used to fill in the pending intent template // that is set on the collection view in StackWidgetProvider. @@ -168,12 +167,13 @@ public boolean hasStableIds() { } - public static void updateConfiguration(Context mContext, int mAppWidgetId, String sqlCondition, - boolean thumbnails) { + public static void updateConfiguration(Context mContext, int mAppWidgetId, String sqlCondition, + boolean thumbnails, boolean timestamps) { Log.d(Constants.TAG, "Widget configuration updated"); mContext.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_MULTI_PROCESS).edit() .putString(Constants.PREF_WIDGET_PREFIX + String.valueOf(mAppWidgetId), sqlCondition).commit(); showThumbnails = thumbnails; + showTimestamps = timestamps; } diff --git a/omniNotes/src/main/java/it/feio/android/omninotes/widget/WidgetConfigurationActivity.java b/omniNotes/src/main/java/it/feio/android/omninotes/widget/WidgetConfigurationActivity.java index f8204db4c7..08e82bea4c 100644 --- a/omniNotes/src/main/java/it/feio/android/omninotes/widget/WidgetConfigurationActivity.java +++ b/omniNotes/src/main/java/it/feio/android/omninotes/widget/WidgetConfigurationActivity.java @@ -91,11 +91,12 @@ protected void onCreate(Bundle savedInstanceState) { } CheckBox showThumbnailsCheckBox = (CheckBox) findViewById(R.id.show_thumbnails); + CheckBox showTimestampsCheckBox = (CheckBox) findViewById(R.id.show_timestamps); // Updating the ListRemoteViewsFactory parameter to get the list // of notes ListRemoteViewsFactory.updateConfiguration(getApplicationContext(), mAppWidgetId, - sqlCondition, showThumbnailsCheckBox.isChecked()); + sqlCondition, showThumbnailsCheckBox.isChecked(), showTimestampsCheckBox.isChecked()); Intent resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, diff --git a/omniNotes/src/main/res/layout/activity_widget_configuration.xml b/omniNotes/src/main/res/layout/activity_widget_configuration.xml index dcb4692b38..aa6c35ab66 100644 --- a/omniNotes/src/main/res/layout/activity_widget_configuration.xml +++ b/omniNotes/src/main/res/layout/activity_widget_configuration.xml @@ -62,6 +62,14 @@ android:checked="true" android:text="@string/show_thumbnails" /> + +