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

speed-up synchronization and introduce categories #181

Merged
merged 1 commit into from
Mar 3, 2017
Merged
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 @@ -11,7 +11,7 @@
public class NoteTest extends TestCase {

public void testMarkDownStrip() {
CloudNote note = new CloudNote(0, Calendar.getInstance(), "#Title", "", false);
CloudNote note = new CloudNote(0, Calendar.getInstance(), "#Title", "", false, null, null);
assertTrue("Title".equals(note.getTitle()));
note.setTitle("* Aufzählung");
assertTrue("Aufzählung".equals(note.getTitle()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_create_save:
editTextField.setEnabled(false);
String content = editTextField.getText().toString();
NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(this);
NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper.getInstance(this);
Intent data = new Intent();
data.putExtra(NotesListViewActivity.CREATED_NOTE, db.getNote(db.addNoteAndSync(content)));
setResult(RESULT_OK, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void onNext(CharSequence charSequence) {
}
});

db = new NoteSQLiteOpenHelper(this);
db = NoteSQLiteOpenHelper.getInstance(this);
actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(note.getTitle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_notes_list_view);

// Display Data
db = new NoteSQLiteOpenHelper(this);
db = NoteSQLiteOpenHelper.getInstance(this);
initList();
refreshList();

Expand Down Expand Up @@ -417,7 +417,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
} else if (requestCode == server_settings) {
// Create new Instance with new URL and credentials
db = new NoteSQLiteOpenHelper(this);
db = NoteSQLiteOpenHelper.getInstance(this);
if(db.getNoteServerSyncHelper().isSyncPossible()) {
adapter.removeAll();
swipeRefreshLayout.setRefreshing(true);
Expand Down Expand Up @@ -468,7 +468,7 @@ public void onNoteClick(int position, View v) {
@Override
public void onNoteFavoriteClick(int position, View view) {
DBNote note = (DBNote) adapter.getItem(position);
NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(view.getContext());
NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper.getInstance(view.getContext());
db.toggleFavorite(note, syncCallBack);
adapter.notifyItemChanged(position);
refreshList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onCreate(Bundle savedInstanceState) {
setResult(RESULT_CANCELED);
setContentView(R.layout.activity_select_single_note);
// Display Data
db = new NoteSQLiteOpenHelper(this);
db = NoteSQLiteOpenHelper.getInstance(this);
db.getNoteServerSyncHelper().scheduleSync(false);
setListView(db.getNotes());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public StackRemoteViewsFactory(Context context, Intent intent) {
mContext = context;
mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
NoteSQLiteOpenHelper db = new NoteSQLiteOpenHelper(mContext);
NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper.getInstance(mContext);
db.getNoteServerSyncHelper().scheduleSync(false);
mWidgetItems = db.getNotes();
mWidgetItems.add(new DBNote(0, 0, Calendar.getInstance(), "Test-Titel", "Test-Beschreibung", false, DBStatus.VOID));
mWidgetItems.add(new DBNote(0, 0, Calendar.getInstance(), "Test-Titel", "Test-Beschreibung", false, null, null, DBStatus.VOID));
}

public void onCreate() {
mWidgetItems.add(new DBNote(0, 0, Calendar.getInstance(), "Test-Titel", "Test-Beschreibung", false, DBStatus.VOID));
mWidgetItems.add(new DBNote(0, 0, Calendar.getInstance(), "Test-Titel", "Test-Beschreibung", false, null, null, DBStatus.VOID));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ public class CloudNote implements Serializable {
private Calendar modified = null;
private String content = "";
private boolean favorite = false;
private String category = "";
private String etag = "";

public CloudNote(long remoteId, Calendar modified, String title, String content, boolean favorite) {
public CloudNote(long remoteId, Calendar modified, String title, String content, boolean favorite, String category, String etag) {
this.remoteId = remoteId;
if (title != null)
setTitle(title);
setTitle(title);
setContent(content);
setFavorite(favorite);
setCategory(category);
setEtag(etag);
this.modified = modified;
}

Expand All @@ -51,8 +55,9 @@ public Calendar getModified() {
}

public String getModified(String format) {
return new SimpleDateFormat(format, Locale.GERMANY)
.format(this.getModified().getTimeInMillis());
if(modified==null)
return null;
return new SimpleDateFormat(format, Locale.GERMANY) .format(this.getModified().getTimeInMillis());
}

public void setModified(Calendar modified) {
Expand All @@ -75,8 +80,24 @@ public void setFavorite(boolean favorite) {
this.favorite = favorite;
}

public String getEtag() {
return etag;
}

public void setEtag(String etag) {
this.etag = etag;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category==null ? "" : category;
}

@Override
public String toString() {
return "#" + getRemoteId() + " " + (isFavorite() ? " (*) " : " ") + getTitle() + " (" + getModified(NoteSQLiteOpenHelper.DATE_FORMAT) + ")";
return "R" + getRemoteId() + " " + (isFavorite() ? " (*) " : " ") + getCategory() + " / " + getTitle() + " (" + getModified(NoteSQLiteOpenHelper.DATE_FORMAT) + " / " + getEtag() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.Serializable;
import java.util.Calendar;

import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
import it.niedermann.owncloud.notes.util.NoteUtil;

/**
Expand All @@ -16,8 +15,8 @@ public class DBNote extends CloudNote implements Item, Serializable {
private DBStatus status;
private String excerpt = "";

public DBNote(long id, long remoteId, Calendar modified, String title, String content, boolean favorite, DBStatus status) {
super(remoteId, modified, title, content, favorite);
public DBNote(long id, long remoteId, Calendar modified, String title, String content, boolean favorite, String category, String etag, DBStatus status) {
super(remoteId, modified, title, content, favorite, category, etag);
this.id = id;
setExcerpt(content);
this.status = status;
Expand Down Expand Up @@ -55,6 +54,6 @@ public boolean isSection() {

@Override
public String toString() {
return "#" + getId() + "/R"+getRemoteId()+" " + (isFavorite() ? " (*) " : " ") + getTitle() + " (" + getModified(NoteSQLiteOpenHelper.DATE_FORMAT) + ") " + getStatus();
return "#"+getId()+"/" + super.toString() + " " + getStatus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position)
final DBNote note = (DBNote) item;
final NoteViewHolder nvHolder = ((NoteViewHolder) holder);
nvHolder.noteTitle.setText(note.getTitle());
nvHolder.noteCategory.setVisibility(note.getCategory().isEmpty() ? View.GONE : View.VISIBLE);
nvHolder.noteCategory.setText(note.getCategory());
nvHolder.noteExcerpt.setText(note.getExcerpt());
nvHolder.noteStatus.setVisibility(DBStatus.VOID.equals(note.getStatus()) ? View.GONE : View.VISIBLE);
nvHolder.noteFavorite.setImageResource(note.isFavorite() ? R.drawable.ic_star_grey600_24dp : R.drawable.ic_star_outline_grey600_24dp);
Expand Down Expand Up @@ -156,6 +158,7 @@ public interface NoteClickListener {
public class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnLongClickListener, View.OnClickListener {
// each data item is just a string in this case
public TextView noteTitle;
public TextView noteCategory;
public TextView noteExcerpt;
public ImageView noteStatus;
public ImageView noteFavorite;
Expand All @@ -164,6 +167,7 @@ public class NoteViewHolder extends RecyclerView.ViewHolder implements View.OnLo
private NoteViewHolder(View v) {
super(v);
this.noteTitle = (TextView) v.findViewById(R.id.noteTitle);
this.noteCategory = (TextView) v.findViewById(R.id.noteCategory);
this.noteExcerpt = (TextView) v.findViewById(R.id.noteExcerpt);
this.noteStatus = (ImageView) v.findViewById(R.id.noteStatus);
this.noteFavorite = (ImageView) v.findViewById(R.id.noteFavorite);
Expand Down
Loading