diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java index c1d24d966..e04959e88 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/EditNoteActivity.java @@ -16,6 +16,7 @@ import java.util.concurrent.TimeUnit; import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.Note; import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper; import it.niedermann.owncloud.notes.util.ICallback; @@ -24,7 +25,7 @@ public class EditNoteActivity extends AppCompatActivity { private final long DELAY = 1000; // in ms private EditText content = null; - private Note note = null; + private DBNote note = null; private Timer timer = new Timer(); private ActionBar actionBar; @@ -32,7 +33,7 @@ public class EditNoteActivity extends AppCompatActivity { protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit); - note = (Note) getIntent().getSerializableExtra( + note = (DBNote) getIntent().getSerializableExtra( NoteActivity.EDIT_NOTE); content = (EditText) findViewById(R.id.editContent); content.setEnabled(false); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java index 022b180c5..44c9a2228 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/NotesListViewActivity.java @@ -21,6 +21,7 @@ import java.util.List; import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.Item; import it.niedermann.owncloud.notes.model.ItemAdapter; import it.niedermann.owncloud.notes.model.Note; @@ -128,7 +129,7 @@ public void onClick(View v) { * @param noteList List<Note> */ @SuppressWarnings("WeakerAccess") - public void setListView(List noteList) { + public void setListView(List noteList) { List itemList = new ArrayList<>(); // #12 Create Sections depending on Time // TODO Move to ItemAdapter? @@ -288,7 +289,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { //not need because of db.synchronisation in createActivity - Note createdNote = (Note) data.getExtras().getSerializable( + DBNote createdNote = (DBNote) data.getExtras().getSerializable( CREATED_NOTE); adapter.add(createdNote); //setListView(db.getNotes()); @@ -299,7 +300,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { SELECTED_NOTE_POSITION); adapter.remove(adapter.getItem(notePosition)); if (resultCode == RESULT_OK) { - Note editedNote = (Note) data.getExtras().getSerializable( + DBNote editedNote = (DBNote) data.getExtras().getSerializable( NoteActivity.EDIT_NOTE); adapter.add(editedNote); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SelectSingleNoteActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SelectSingleNoteActivity.java index 7bcf60cac..b9bb6d7b0 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SelectSingleNoteActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SelectSingleNoteActivity.java @@ -15,6 +15,7 @@ import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.android.widget.SingleNoteWidget; +import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.Item; import it.niedermann.owncloud.notes.model.ItemAdapter; import it.niedermann.owncloud.notes.model.Note; @@ -61,7 +62,7 @@ public void onCreate(Bundle savedInstanceState) { * * @param noteList List<Note> */ - private void setListView(List noteList) { + private void setListView(List noteList) { List itemList = new ArrayList<>(); itemList.addAll(noteList); adapter = new ItemAdapter(itemList); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/widget/AllNotesWidget.java b/app/src/main/java/it/niedermann/owncloud/notes/android/widget/AllNotesWidget.java index e85c7e645..83a84f785 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/widget/AllNotesWidget.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/widget/AllNotesWidget.java @@ -13,6 +13,8 @@ import java.util.List; import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.model.DBNote; +import it.niedermann.owncloud.notes.model.DBStatus; import it.niedermann.owncloud.notes.model.Note; import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper; @@ -51,7 +53,7 @@ public RemoteViewsFactory onGetViewFactory(Intent intent) { class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory { private static final int mCount = 10; - private List mWidgetItems = new ArrayList<>(); + private List mWidgetItems = new ArrayList<>(); private Context mContext; private int mAppWidgetId; @@ -62,11 +64,11 @@ public StackRemoteViewsFactory(Context context, Intent intent) { NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(mContext); db.synchronizeWithServer(); mWidgetItems = db.getNotes(); - mWidgetItems.add(new Note(0, Calendar.getInstance(), "Test-Titel", "Test-Beschreibung")); + mWidgetItems.add(new DBNote(0, Calendar.getInstance(), "Test-Titel", "Test-Beschreibung", DBStatus.VOID)); } public void onCreate() { - mWidgetItems.add(new Note(0, Calendar.getInstance(), "Test-Titel", "Test-Beschreibung")); + mWidgetItems.add(new DBNote(0, Calendar.getInstance(), "Test-Titel", "Test-Beschreibung", DBStatus.VOID)); } @Override diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/DBNote.java b/app/src/main/java/it/niedermann/owncloud/notes/model/DBNote.java new file mode 100644 index 000000000..646d869c2 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/DBNote.java @@ -0,0 +1,28 @@ +package it.niedermann.owncloud.notes.model; + +import java.util.Calendar; + +import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper; + +public class DBNote extends Note { + + private DBStatus status; + + public DBNote(long id, Calendar modified, String title, String content, DBStatus status) { + super(id, modified, title, content); + this.status = status; + } + + public DBStatus getStatus() { + return status; + } + + public void setStatus(DBStatus status) { + this.status = status; + } + + @Override + public String toString() { + return "#" + getId() + " " + getTitle() + " (" + getModified(NoteSQLiteOpenHelper.DATE_FORMAT) + ") " + getStatus(); + } +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/DBStatus.java b/app/src/main/java/it/niedermann/owncloud/notes/model/DBStatus.java index fc27f8265..ea3393b31 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/model/DBStatus.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/DBStatus.java @@ -17,4 +17,12 @@ public String getTitle() { DBStatus(String title) { this.title = title; } + + public static DBStatus parse(String str) { + if(str.isEmpty()) { + return DBStatus.VOID; + } else { + return DBStatus.valueOf(str); + } + } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java index b0bc49e9f..f7a291049 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/ItemAdapter.java @@ -4,6 +4,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; @@ -37,7 +38,7 @@ public static void setNoteClickListener(NoteClickListener noteClickListener) { * Adds the given note to the top of the list. * @param note Note that should be added. */ - public void add(Note note) { + public void add(DBNote note) { itemList.add(0, note); notifyItemInserted(0); notifyItemChanged(0); @@ -55,12 +56,12 @@ public void removeAll() { * Compares the given List of notes to the current internal holded notes and updates the list if necessairy * @param newNotes List of more up to date notes */ - public void checkForUpdates(List newNotes) { - for(Note newNote : newNotes) { + public void checkForUpdates(List newNotes) { + for(DBNote newNote : newNotes) { boolean foundNewNoteInOldList = false; for(Item oldItem : itemList) { if(!oldItem.isSection()) { - Note oldNote = (Note) oldItem; + DBNote oldNote = (DBNote) oldItem; if(newNote.getId() == oldNote.getId()) { // Notes have the same id, check which is newer if(newNote.getModified().after(oldNote.getModified())) { @@ -109,9 +110,10 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { ((SectionViewHolder) holder).sectionTitle.setText(section.geTitle()); ((SectionViewHolder) holder).setPosition(position); } else { - Note note = (Note) item; + DBNote note = (DBNote) item; ((NoteViewHolder) holder).noteTitle.setText(note.getTitle()); ((NoteViewHolder) holder).noteExcerpt.setText(note.getExcerpt()); + ((NoteViewHolder) holder).noteStatus.setVisibility(DBStatus.VOID.equals(note.getStatus()) ? View.GONE : View.VISIBLE); ((NoteViewHolder) holder).setPosition(position); } } @@ -168,12 +170,14 @@ public static class NoteViewHolder extends RecyclerView.ViewHolder implements Vi // each data item is just a string in this case public TextView noteTitle; public TextView noteExcerpt; + public ImageView noteStatus; public int position = -1; private NoteViewHolder(View v) { super(v); this.noteTitle = (TextView) v.findViewById(R.id.noteTitle); this.noteExcerpt = (TextView) v.findViewById(R.id.noteExcerpt); + this.noteStatus = (ImageView) v.findViewById(R.id.noteStatus); v.setOnClickListener(this); v.setOnLongClickListener(this); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteSQLiteOpenHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteSQLiteOpenHelper.java index d554bd49d..409e152ef 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteSQLiteOpenHelper.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteSQLiteOpenHelper.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Locale; +import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.DBStatus; import it.niedermann.owncloud.notes.model.Note; import it.niedermann.owncloud.notes.util.NoteUtil; @@ -112,7 +113,7 @@ public void addNote(Note note) { * @return requested Note */ @SuppressWarnings("unused") - public Note getNote(long id) { + public DBNote getNote(long id) { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(table_notes, @@ -134,20 +135,21 @@ public Note getNote(long id) { } catch (ParseException e) { e.printStackTrace(); } - Note note = new Note(Long.valueOf(cursor != null ? cursor.getString(0) : null), modified, cursor != null ? cursor.getString(2) : null, cursor.getString(4)); + DBNote note = new DBNote(Long.valueOf(cursor != null ? cursor.getString(0) : null), modified, cursor != null ? cursor.getString(2) : null, cursor.getString(4), DBStatus.parse(cursor.getString(1))); cursor.close(); return note; } /** - * Returns a list of all Notes in the Database - * - * @return List<Note> + * Query the database with a custom raw query. + * @param sql SQL query + * @param selectionArgs Arguments for the SQL query + * @return List of Notes */ - public List getNotes() { - List notes = new ArrayList<>(); - SQLiteDatabase db = this.getReadableDatabase(); - Cursor cursor = db.rawQuery("SELECT * FROM " + table_notes + " WHERE " + key_status + " != ? ORDER BY " + key_modified + " DESC", new String[]{DBStatus.LOCAL_DELETED.getTitle()}); + private List getNotesRawQuery(String sql, String[] selectionArgs) { + SQLiteDatabase db = getReadableDatabase(); + Cursor cursor = db.rawQuery(sql, selectionArgs); + List notes = new ArrayList<>(); if (cursor.moveToFirst()) { do { Calendar modified = Calendar.getInstance(); @@ -158,7 +160,7 @@ public List getNotes() { } catch (ParseException e) { e.printStackTrace(); } - notes.add(new Note(Long.valueOf(cursor.getString(0)), modified, cursor.getString(2), cursor.getString(4))); + notes.add(new DBNote(Long.valueOf(cursor.getString(0)), modified, cursor.getString(2), cursor.getString(4), DBStatus.parse(cursor.getString(1)))); } while (cursor.moveToNext()); } cursor.close(); @@ -170,25 +172,17 @@ public List getNotes() { * * @return List<Note> */ - public List searchNotes(String query) { - List notes = new ArrayList<>(); - SQLiteDatabase db = this.getReadableDatabase(); - Cursor cursor = db.rawQuery("SELECT * FROM " + table_notes + " WHERE " + key_status + " != ? AND " + key_content + " LIKE ? ORDER BY " + key_modified + " DESC", new String[]{DBStatus.LOCAL_DELETED.getTitle(), "%" + query + "%"}); - if (cursor.moveToFirst()) { - do { - Calendar modified = Calendar.getInstance(); - try { - String modifiedStr = cursor.getString(3); - if (modifiedStr != null) - modified.setTime(new SimpleDateFormat(DATE_FORMAT, Locale.GERMANY).parse(modifiedStr)); - } catch (ParseException e) { - e.printStackTrace(); - } - notes.add(new Note(Long.valueOf(cursor.getString(0)), modified, cursor.getString(2), cursor.getString(4))); - } while (cursor.moveToNext()); - } - cursor.close(); - return notes; + public List getNotes() { + return getNotesRawQuery("SELECT * FROM " + table_notes + " WHERE " + key_status + " != ? ORDER BY " + key_modified + " DESC", new String[]{DBStatus.LOCAL_DELETED.getTitle()}); + } + + /** + * Returns a list of all Notes in the Database + * + * @return List<Note> + */ + public List searchNotes(String query) { + return getNotesRawQuery("SELECT * FROM " + table_notes + " WHERE " + key_status + " != ? AND " + key_content + " LIKE ? ORDER BY " + key_modified + " DESC", new String[]{DBStatus.LOCAL_DELETED.getTitle(), "%" + query + "%"}); } /** @@ -196,25 +190,16 @@ public List searchNotes(String query) { * * @return List<Note> */ - public List getNotesByStatus(DBStatus status) { - List notes = new ArrayList<>(); - SQLiteDatabase db = this.getWritableDatabase(); - Cursor cursor = db.rawQuery("SELECT * FROM " + table_notes + " WHERE " + key_status + " = ?", new String[]{status.getTitle()}); - if (cursor.moveToFirst()) { - do { - Calendar modified = Calendar.getInstance(); - try { - String modifiedStr = cursor.getString(3); - if (modifiedStr != null) - modified.setTime(new SimpleDateFormat(DATE_FORMAT, Locale.GERMANY).parse(modifiedStr)); - } catch (ParseException e) { - e.printStackTrace(); - } - notes.add(new Note(Long.valueOf(cursor.getString(0)), modified, cursor.getString(2), cursor.getString(4))); - } while (cursor.moveToNext()); - } - cursor.close(); - return notes; + public List getNotesByStatus(DBStatus status) { + return getNotesRawQuery("SELECT * FROM " + table_notes + " WHERE " + key_status + " = ?", new String[]{status.getTitle()}); + } + /** + * Returns a list of all Notes in the Database with were modified locally + * + * @return List<Note> + */ + public List getLocalModifiedNotes() { + return getNotesRawQuery("SELECT * FROM " + table_notes + " WHERE " + key_status + " != ?", new String[]{DBStatus.VOID.getTitle()}); } /** @@ -224,7 +209,7 @@ public List getNotesByStatus(DBStatus status) { * @return The number of the Rows affected. */ @SuppressWarnings("UnusedReturnValue") - public int updateNoteAndSync(Note note) { + public int updateNoteAndSync(DBNote note) { SQLiteDatabase db = this.getWritableDatabase(); DBStatus newStatus = DBStatus.LOCAL_EDITED; Cursor cursor = @@ -239,11 +224,12 @@ public int updateNoteAndSync(Note note) { if (cursor != null) { cursor.moveToFirst(); String status = cursor.getString(1); - if (!"".equals(status) && DBStatus.valueOf(status) == DBStatus.LOCAL_CREATED) { + if (DBStatus.parse(status) == DBStatus.LOCAL_CREATED) { newStatus = DBStatus.LOCAL_CREATED; } cursor.close(); } + note.setStatus(newStatus); ContentValues values = new ContentValues(); values.put(key_id, note.getId()); values.put(key_status, newStatus.getTitle()); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java index 019ed6e4f..c6335a673 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java @@ -16,6 +16,7 @@ import java.util.List; import it.niedermann.owncloud.notes.android.activity.SettingsActivity; +import it.niedermann.owncloud.notes.model.DBNote; import it.niedermann.owncloud.notes.model.DBStatus; import it.niedermann.owncloud.notes.model.Note; import it.niedermann.owncloud.notes.util.ICallback; @@ -99,7 +100,7 @@ private void asyncTaskFinished() { } public void uploadEditedNotes() { - List notes = db.getNotesByStatus(DBStatus.LOCAL_EDITED); + List notes = db.getNotesByStatus(DBStatus.LOCAL_EDITED); for (Note note : notes) { UploadEditedNotesTask editedNotesTask = new UploadEditedNotesTask(); editedNotesTask.execute(note); @@ -107,7 +108,7 @@ public void uploadEditedNotes() { } public void uploadNewNotes() { - List notes = db.getNotesByStatus(DBStatus.LOCAL_CREATED); + List notes = db.getNotesByStatus(DBStatus.LOCAL_CREATED); for (Note note : notes) { UploadNewNoteTask newNotesTask = new UploadNewNoteTask(); newNotesTask.execute(note); @@ -115,7 +116,7 @@ public void uploadNewNotes() { } public void uploadDeletedNotes() { - List notes = db.getNotesByStatus(DBStatus.LOCAL_DELETED); + List notes = db.getNotesByStatus(DBStatus.LOCAL_DELETED); for (Note note : notes) { UploadDeletedNoteTask deletedNotesTask = new UploadDeletedNoteTask(); deletedNotesTask.execute(note); diff --git a/app/src/main/res/drawable-hdpi/ic_sync_alert_black_18dp.png b/app/src/main/res/drawable-hdpi/ic_sync_alert_black_18dp.png new file mode 100644 index 000000000..d4f7994ef Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_sync_alert_black_18dp.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_sync_alert_black_18dp.png b/app/src/main/res/drawable-mdpi/ic_sync_alert_black_18dp.png new file mode 100644 index 000000000..b4947b753 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_sync_alert_black_18dp.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_sync_alert_black_18dp.png b/app/src/main/res/drawable-xhdpi/ic_sync_alert_black_18dp.png new file mode 100644 index 000000000..031a5c40c Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_sync_alert_black_18dp.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_sync_alert_black_18dp.png b/app/src/main/res/drawable-xxhdpi/ic_sync_alert_black_18dp.png new file mode 100644 index 000000000..83cf8b06c Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_sync_alert_black_18dp.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_sync_alert_black_18dp.png b/app/src/main/res/drawable-xxxhdpi/ic_sync_alert_black_18dp.png new file mode 100644 index 000000000..768785eac Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_sync_alert_black_18dp.png differ diff --git a/app/src/main/res/layout/fragment_notes_list_note_item.xml b/app/src/main/res/layout/fragment_notes_list_note_item.xml index 5a2c834bb..2c38a8a59 100644 --- a/app/src/main/res/layout/fragment_notes_list_note_item.xml +++ b/app/src/main/res/layout/fragment_notes_list_note_item.xml @@ -18,6 +18,7 @@ android:layout_alignParentEnd="false" android:layout_alignParentRight="true" android:layout_alignParentStart="true" + android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignWithParentIfMissing="true" android:ellipsize="end" @@ -38,6 +39,14 @@ android:textColor="@drawable/list_item_color_selector_low" android:textSize="14sp"/> + +