Skip to content

Commit

Permalink
Moved to refactored commons POJOs library version 1.3.0-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Apr 17, 2019
1 parent be46614 commit b296aad
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 68 deletions.
4 changes: 3 additions & 1 deletion omniNotes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ dependencies {
exclude group: 'com.android.support'
}
implementation 'com.github.federicoiosue:Springpad-Importer:1.0.1'
implementation 'com.github.federicoiosue:Omni-Notes-Commons:1.2.0'
implementation ('com.github.federicoiosue:Omni-Notes-Commons:1.3.0-SNAPSHOT') {
exclude group: 'org.projectlombok'
}
implementation ('com.github.federicoiosue:checklistview:3.2.1') {
transitive=false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1243,21 +1243,15 @@ private void categorizeNote() {
.positiveColorRes(R.color.colorPrimary)
.negativeText(R.string.remove_category)
.negativeColorRes(R.color.colorAccent)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Intent intent = new Intent(mainActivity, CategoryActivity.class);
intent.putExtra("noHome", true);
startActivityForResult(intent, CATEGORY);
}
})
.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
noteTmp.setCategory(null);
setTagMarkerColor(null);
}
}).build();
.onPositive((dialog1, which) -> {
Intent intent = new Intent(mainActivity, CategoryActivity.class);
intent.putExtra("noHome", true);
startActivityForResult(intent, CATEGORY);
})
.onNegative((dialog12, which) -> {
noteTmp.setCategory(null);
setTagMarkerColor(null);
}).build();

dialog.getListView().setOnItemClickListener((parent, view, position, id) -> {
noteTmp.setCategory(categories.get(position));
Expand Down Expand Up @@ -1609,7 +1603,7 @@ public void onNoteSaved(Note noteSaved) {
EventBus.getDefault().post(new NotesUpdatedEvent(Collections.singletonList(noteSaved)));
deleteMergedNotes(mergedNotesIds);
if (noteTmp.getAlarm() != null && !noteTmp.getAlarm().equals(note.getAlarm())) {
ReminderHelper.showReminderMessage(noteTmp.getAlarm());
ReminderHelper.showReminderMessage(String.valueOf(noteTmp.getAlarm()));
}
}
note = new Note(noteSaved);
Expand Down Expand Up @@ -1718,7 +1712,7 @@ private String initReminder(Note note) {
if (noteTmp.getAlarm() == null) {
return "";
}
long reminder = parseLong(note.getAlarm());
long reminder = note.getAlarm();
String rrule = note.getRecurrenceRule();
if (!TextUtils.isEmpty(rrule)) {
return DateHelper.getNoteRecurrentReminderText(reminder, rrule);
Expand Down Expand Up @@ -1995,8 +1989,7 @@ public void onRecurrenceReminderPicked(String recurrenceRule) {
noteTmp.setRecurrenceRule(recurrenceRule);
if (!TextUtils.isEmpty(recurrenceRule)) {
Log.d(Constants.TAG, "Recurrent reminder set: " + recurrenceRule);
datetime.setText(DateHelper.getNoteRecurrentReminderText(parseLong(noteTmp
.getAlarm()), recurrenceRule));
datetime.setText(DateHelper.getNoteRecurrentReminderText(noteTmp.getAlarm(), recurrenceRule));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.StrictMode;
import android.support.annotation.NonNull;
import android.support.multidex.MultiDexApplication;

import com.squareup.leakcanary.LeakCanary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void manageNotification(SharedPreferences prefs) {
updateNoteReminder(newReminder, note);
finish();
} else if (Constants.ACTION_POSTPONE.equals(getIntent().getAction())) {
postpone(prefs, Long.parseLong(note.getAlarm()), note.getRecurrenceRule());
postpone(prefs, note.getAlarm(), note.getRecurrenceRule());
} else {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(Constants.INTENT_KEY, note.get_id());
Expand Down Expand Up @@ -132,7 +132,7 @@ public void onRecurrenceReminderPicked(String recurrenceRule) {

public static void setNextRecurrentReminder(Note note) {
if (!TextUtils.isEmpty(note.getRecurrenceRule())) {
long nextReminder = DateHelper.nextReminderFromRecurrenceRule(Long.parseLong(note.getAlarm()), note
long nextReminder = DateHelper.nextReminderFromRecurrenceRule(note.getAlarm(), note
.getRecurrenceRule());
if (nextReminder > 0) {
updateNoteReminder(nextReminder, note, true);
Expand All @@ -154,7 +154,7 @@ private static void updateNoteReminder(long reminder, Note noteToUpdate, boolean
new SaveNoteTask(false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, noteToUpdate);
} else {
ReminderHelper.addReminder(OmniNotes.getAppContext(), noteToUpdate, reminder);
ReminderHelper.showReminderMessage(noteToUpdate.getAlarm());
ReminderHelper.showReminderMessage(String.valueOf(noteToUpdate.getAlarm()));
}
}

Expand Down
29 changes: 13 additions & 16 deletions omniNotes/src/main/java/it/feio/android/omninotes/db/DbHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,25 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}


// Inserting or updating single note
public Note updateNote(Note note, boolean updateLastModification) {
SQLiteDatabase db = getDatabase(true);

String content = note.isLocked()
? Security.encrypt(note.getContent(), prefs.getString(Constants.PREF_PASSWORD, ""))
: note.getContent();

// To ensure note and attachments insertions are atomical and boost performances transaction are used
// To ensure note and attachments insertions are atomic and boost performances transaction are used
db.beginTransaction();

ContentValues values = new ContentValues();
values.put(KEY_TITLE, note.getTitle());
values.put(KEY_CONTENT, content);
values.put(KEY_CREATION, note.getCreation() != null ? note.getCreation() : Calendar.getInstance()
values.put(KEY_CREATION, note.getCreation() > 0 ? note.getCreation() : Calendar.getInstance()
.getTimeInMillis());
values.put(KEY_LAST_MODIFICATION, updateLastModification ? Calendar
.getInstance().getTimeInMillis() : (note.getLastModification() != null ? note.getLastModification() :
Calendar
.getInstance().getTimeInMillis()));
long lastModification = note.getLastModification() > 0 && !updateLastModification
? note.getLastModification()
: Calendar.getInstance().getTimeInMillis();
values.put(KEY_LAST_MODIFICATION, lastModification);
values.put(KEY_ARCHIVED, note.isArchived());
values.put(KEY_TRASHED, note.isTrashed());
values.put(KEY_REMINDER, note.getAlarm());
Expand All @@ -227,10 +226,8 @@ public Note updateNote(Note note, boolean updateLastModification) {
values.put(KEY_LONGITUDE, note.getLongitude());
values.put(KEY_ADDRESS, note.getAddress());
values.put(KEY_CATEGORY, note.getCategory() != null ? note.getCategory().getId() : null);
boolean locked = note.isLocked() != null ? note.isLocked() : false;
values.put(KEY_LOCKED, locked);
boolean checklist = note.isChecklist() != null ? note.isChecklist() : false;
values.put(KEY_CHECKLIST, checklist);
values.put(KEY_LOCKED, note.isLocked());
values.put(KEY_CHECKLIST, note.isChecklist());

db.insertWithOnConflict(TABLE_NOTES, KEY_ID, values, SQLiteDatabase.CONFLICT_REPLACE);
Log.d(Constants.TAG, "Updated note titled '" + note.getTitle() + "'");
Expand All @@ -252,7 +249,7 @@ public Note updateNote(Note note, boolean updateLastModification) {
db.close();

// Fill the note with correct data before returning it
note.setCreation(note.getCreation() != null ? note.getCreation() : values.getAsLong(KEY_CREATION));
note.setCreation(note.getCreation() > 0 ? note.getCreation() : values.getAsLong(KEY_CREATION));
note.setLastModification(values.getAsLong(KEY_LAST_MODIFICATION));

return note;
Expand Down Expand Up @@ -451,8 +448,8 @@ public List<Note> getNotes(String whereCondition, boolean order) {
note.setContent(cursor.getString(i++));
note.setArchived("1".equals(cursor.getString(i++)));
note.setTrashed("1".equals(cursor.getString(i++)));
note.setAlarm(cursor.getString(i++));
note.setReminderFired(cursor.getInt(i++));
note.setAlarm(cursor.getLong(i++));
note.setReminderFired(cursor.getInt(i++) != 0);
note.setRecurrenceRule(cursor.getString(i++));
note.setLatitude(cursor.getString(i++));
note.setLongitude(cursor.getString(i++));
Expand Down Expand Up @@ -982,8 +979,8 @@ public Stats getStats() {
} else {
notesActive++;
}
if (note.getAlarm() != null && Long.parseLong(note.getAlarm()) > 0) {
if (Long.parseLong(note.getAlarm()) > Calendar.getInstance().getTimeInMillis()) {
if (note.getAlarm() != null && note.getAlarm() > 0) {
if (note.getAlarm() > Calendar.getInstance().getTimeInMillis()) {
remindersFuture++;
} else {
reminders++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static void addAttachments(boolean keepMergedNotes, Note note, ArrayList<
public static Note mergeNotes(List<Note> notes, boolean keepMergedNotes) {
boolean locked = false;
ArrayList<Attachment> attachments = new ArrayList<>();
String reminder = null;
Long reminder = null;
String reminderRecurrenceRule = null;
Double latitude = null;
Double longitude = null;
Expand All @@ -91,8 +91,8 @@ public static Note mergeNotes(List<Note> notes, boolean keepMergedNotes) {
for (Note note : notes) {
appendContent(note, content, includeTitle);
locked = locked || note.isLocked();
String currentReminder = note.getAlarm();
if (!StringUtils.isEmpty(currentReminder) && reminder == null) {
Long currentReminder = note.getAlarm();
if (reminder == null && currentReminder != null) {
reminder = currentReminder;
reminderRecurrenceRule = note.getRecurrenceRule();
}
Expand Down
24 changes: 12 additions & 12 deletions omniNotes/src/main/java/it/feio/android/omninotes/models/Note.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public Note() {
}


public Note(Long creation, Long lastModification, String title, String content, Integer archived,
Integer trashed, String alarm, String recurrenceRule, Integer reminderFired, String latitude, String longitude, Category
category, Integer locked, Integer checklist) {
public Note(Long creation, Long lastModification, String title, String content, boolean archived,
boolean trashed, long alarm, String recurrenceRule, boolean reminderFired, String latitude, String longitude, Category
category, boolean locked, boolean checklist) {
super(creation, lastModification, title, content, archived, trashed, alarm, reminderFired, recurrenceRule,
latitude,
longitude, category, locked, checklist);
Expand All @@ -69,21 +69,21 @@ public Note(Note note) {


private Note(Parcel in) {
setCreation(in.readString());
setLastModification(in.readString());
setCreation(in.readLong());
setLastModification(in.readLong());
setTitle(in.readString());
setContent(in.readString());
setArchived(in.readInt());
setTrashed(in.readInt());
setAlarm(in.readString());
setReminderFired(in.readInt());
setArchived(in.readInt() != 0);
setTrashed(in.readInt() != 0);
setAlarm(in.readLong());
setReminderFired(in.readInt() != 0);
setRecurrenceRule(in.readString());
setLatitude(in.readString());
setLongitude(in.readString());
setAddress(in.readString());
super.setCategory(in.readParcelable(Category.class.getClassLoader()));
setLocked(in.readInt());
setChecklist(in.readInt());
setLocked(in.readInt() != 0);
setChecklist(in.readInt() != 0);
in.readList(getAttachmentsList(), Attachment.class.getClassLoader());
}

Expand Down Expand Up @@ -172,7 +172,7 @@ public void writeToParcel(Parcel parcel, int flags) {
parcel.writeString(getContent());
parcel.writeInt(isArchived() ? 1 : 0);
parcel.writeInt(isTrashed() ? 1 : 0);
parcel.writeString(getAlarm());
parcel.writeLong(getAlarm());
parcel.writeInt(isReminderFired() ? 1 : 0);
parcel.writeString(getRecurrenceRule());
parcel.writeString(String.valueOf(getLatitude()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private void manageCloserNote(List<Note> notes, int navigation) {
if (navigation == Navigation.REMINDERS) {
for (int i = 0; i < notes.size(); i++) {
long now = Calendar.getInstance().getTimeInMillis();
long reminder = Long.parseLong(notes.get(i).getAlarm());
long reminder = notes.get(i).getAlarm();
if (now < reminder && reminder < closestNoteReminder) {
closestNotePosition = i;
closestNoteReminder = reminder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ReminderHelper {

public static void addReminder(Context context, Note note) {
if (note.getAlarm() != null) {
addReminder(context, note, Long.parseLong(note.getAlarm()));
addReminder(context, note, note.getAlarm());
}
}

Expand Down Expand Up @@ -70,13 +70,13 @@ public static boolean checkReminder(Context context, Note note) {


static int getRequestCode(Note note) {
Long longCode = note.getCreation() != null ? note.getCreation() : Calendar.getInstance().getTimeInMillis() / 1000L;
Long longCode = note.getCreation() > 0 ? note.getCreation() : Calendar.getInstance().getTimeInMillis() / 1000L;
return longCode.intValue();
}


public static void removeReminder(Context context, Note note) {
if (!TextUtils.isEmpty(note.getAlarm())) {
if (note.getAlarm() != null) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent p = PendingIntent.getBroadcast(context, getRequestCode(note), intent, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ public static String getDateText(Context mContext, Note note, int navigation) {
(), prefs.getBoolean(Constants.PREF_PRETTIFIED_DATES, true));
break;
case DbHelper.KEY_REMINDER:
String noteReminder = note.getAlarm();
if (TextUtils.isEmpty(noteReminder)) {
if (note.getAlarm() == null) {
dateText = mContext.getString(R.string.no_reminder_set);
} else {
dateText = mContext.getString(R.string.alarm_set_on) + " " + DateHelper.getDateTimeShort(mContext,
Long.parseLong(noteReminder));
note.getAlarm());
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,8 @@ public static boolean isFuture(String timestamp) {
/**
* Checks if a epoch-date timestamp is in the future
*/
public static boolean isFuture(long timestamp) {
try {
return timestamp > Calendar.getInstance().getTimeInMillis();
} catch (Exception e) {
return false;
}
public static boolean isFuture(Long timestamp) {
return timestamp != null && timestamp > Calendar.getInstance().getTimeInMillis();
}

public static String prettyTime(String timeInMillisec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public void isFuture() {
assertFalse(DateUtils.isFuture(previousMinute));
}

@Test
public void isFutureManagesNullValues() {
Long longValue = null;
assertFalse(DateUtils.isFuture(longValue));
}

@Test
public void isSameDay() {
long today = Calendar.getInstance().getTimeInMillis();
Expand Down

0 comments on commit b296aad

Please sign in to comment.