Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to show/hide timestamps on the 3x2 widget #373

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Moving option to the prompt displayed when widged is added
  • Loading branch information
Marcel de Sena Dall'Agnol committed Jun 16, 2017
commit aa8fbda46d39b7a88d2bf5f7cd7cf5e5a63f5c76
1 change: 1 addition & 0 deletions etc/translations/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<string name="widget_list_description">Scrolling list widget with buttons</string>
<string name="notes">notes</string>
<string name="show_thumbnails">Show attachment\'s thumbnails</string>
<string name="show_timestamps">Show \"Last updated\" timestamps</string>
<string name="choose_action">Choose action</string>
<string name="edit">Edit</string>
<string name="reminders">reminders</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Note> notes;
private boolean show_last_modified;
private int navigation;


Expand All @@ -67,25 +66,24 @@ 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);
}


@Override
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);
}


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@
android:checked="true"
android:text="@string/show_thumbnails" />

<CheckBox
android:id="@+id/show_timestamps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:checked="true"
android:text="@string/show_timestamps" />

<Button
android:id="@+id/widget_config_confirm"
style="@style/Button.Dialog"
Expand Down
4 changes: 1 addition & 3 deletions omniNotes/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
<string name="widget_list_description">Scrolling list widget with buttons</string>
<string name="notes">notes</string>
<string name="show_thumbnails">Show attachment\'s thumbnails</string>
<string name="show_timestamps">Show \"Last updated\" timestamps</string>
<string name="choose_action">Choose action</string>
<string name="edit">Edit</string>
<string name="reminders">reminders</string>
Expand Down Expand Up @@ -336,9 +337,6 @@
<string name="settings_prettified_dates">Prettified dates</string>
<string name="settings_prettified_dates_summary_on">Dates are shown in a simplier format</string>
<string name="settings_prettified_dates_summary_off">Dates are shown in a more detailed format</string>
<string name="settings_display_last_modified">Last modification on widget</string>
<string name="settings_display_last_modified_summary_on">Last modified timestamp shown on notes</string>
<string name="settings_display_last_modified_summary_off">Last modified timestamp hidden</string>
<string name="settings_screen_privacy">Privacy</string>
<string name="settings_error_reporting">Error reporting</string>
<string name="settings_error_reporting_summary_on">When app crashes developer will be informed to help you</string>
Expand Down
7 changes: 0 additions & 7 deletions omniNotes/src/main/res/xml/settings_interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,4 @@
android:title="@string/settings_prettified_dates"
android:defaultValue="true"/>

<SwitchPreference
android:key="settings_display_last_modified"
android:summaryOn="@string/settings_display_last_modified_summary_on"
android:summaryOff="@string/settings_display_last_modified_summary_off"
android:title="@string/settings_display_last_modified"
android:defaultValue="true"/>

</PreferenceScreen>