Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,15 +25,15 @@
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;

@Override
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,7 +129,7 @@ public void onClick(View v) {
* @param noteList List<Note>
*/
@SuppressWarnings("WeakerAccess")
public void setListView(List<Note> noteList) {
public void setListView(List<DBNote> noteList) {
List<Item> itemList = new ArrayList<>();
// #12 Create Sections depending on Time
// TODO Move to ItemAdapter?
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void onCreate(Bundle savedInstanceState) {
*
* @param noteList List&lt;Note&gt;
*/
private void setListView(List<Note> noteList) {
private void setListView(List<DBNote> noteList) {
List<Item> itemList = new ArrayList<>();
itemList.addAll(noteList);
adapter = new ItemAdapter(itemList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,7 +53,7 @@ public RemoteViewsFactory onGetViewFactory(Intent intent) {

class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
private static final int mCount = 10;
private List<Note> mWidgetItems = new ArrayList<>();
private List<DBNote> mWidgetItems = new ArrayList<>();
private Context mContext;
private int mAppWidgetId;

Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/it/niedermann/owncloud/notes/model/DBNote.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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<Note> newNotes) {
for(Note newNote : newNotes) {
public void checkForUpdates(List<DBNote> 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())) {
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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&lt;Note&gt;
* 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<Note> getNotes() {
List<Note> 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<DBNote> getNotesRawQuery(String sql, String[] selectionArgs) {
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery(sql, selectionArgs);
List<DBNote> notes = new ArrayList<>();
if (cursor.moveToFirst()) {
do {
Calendar modified = Calendar.getInstance();
Expand All @@ -158,7 +160,7 @@ public List<Note> 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();
Expand All @@ -170,51 +172,34 @@ public List<Note> getNotes() {
*
* @return List&lt;Note&gt;
*/
public List<Note> searchNotes(String query) {
List<Note> 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<DBNote> 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&lt;Note&gt;
*/
public List<DBNote> 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 + "%"});
}

/**
* Returns a list of all Notes in the Database with a sepcial status, e.g. Edited, Deleted,...
*
* @return List&lt;Note&gt;
*/
public List<Note> getNotesByStatus(DBStatus status) {
List<Note> 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<DBNote> 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&lt;Note&gt;
*/
public List<DBNote> getLocalModifiedNotes() {
return getNotesRawQuery("SELECT * FROM " + table_notes + " WHERE " + key_status + " != ?", new String[]{DBStatus.VOID.getTitle()});
}

/**
Expand All @@ -224,7 +209,7 @@ public List<Note> 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 =
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,23 +100,23 @@ private void asyncTaskFinished() {
}

public void uploadEditedNotes() {
List<Note> notes = db.getNotesByStatus(DBStatus.LOCAL_EDITED);
List<DBNote> notes = db.getNotesByStatus(DBStatus.LOCAL_EDITED);
for (Note note : notes) {
UploadEditedNotesTask editedNotesTask = new UploadEditedNotesTask();
editedNotesTask.execute(note);
}
}

public void uploadNewNotes() {
List<Note> notes = db.getNotesByStatus(DBStatus.LOCAL_CREATED);
List<DBNote> notes = db.getNotesByStatus(DBStatus.LOCAL_CREATED);
for (Note note : notes) {
UploadNewNoteTask newNotesTask = new UploadNewNoteTask();
newNotesTask.execute(note);
}
}

public void uploadDeletedNotes() {
List<Note> notes = db.getNotesByStatus(DBStatus.LOCAL_DELETED);
List<DBNote> notes = db.getNotesByStatus(DBStatus.LOCAL_DELETED);
for (Note note : notes) {
UploadDeletedNoteTask deletedNotesTask = new UploadDeletedNoteTask();
deletedNotesTask.execute(note);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading