Skip to content

Commit

Permalink
[Store category sorting for recent, favorites and uncategorized per a…
Browse files Browse the repository at this point in the history
…ccount](nextcloud#1169)
  • Loading branch information
AlpAcA0072 committed May 15, 2021
1 parent 551aa3c commit 62d9863
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,7 @@ public Note updateNoteAndSync(@NonNull Account localAccount, @NonNull Note oldNo
final Note newNote;
// Re-read the up to date remoteId from the database because the UI might not have the state after synchronization yet
// https://github.com/stefan-niedermann/nextcloud-notes/issues/1198
@Nullable
final Long remoteId = db.getNoteDao().getRemoteId(oldNote.getId());
@Nullable final Long remoteId = db.getNoteDao().getRemoteId(oldNote.getId());
if (newContent == null) {
newNote = new Note(oldNote.getId(), remoteId, oldNote.getModified(), oldNote.getTitle(), oldNote.getContent(), oldNote.getCategory(), oldNote.getFavorite(), oldNote.getETag(), DBStatus.LOCAL_EDITED, localAccount.getId(), oldNote.getExcerpt(), oldNote.getScrollY());
} else {
Expand Down Expand Up @@ -626,18 +625,23 @@ public void modifyCategoryOrder(long accountId, @NonNull NavigationCategory sele
final Context ctx = context.getApplicationContext();
final SharedPreferences.Editor sp = PreferenceManager.getDefaultSharedPreferences(ctx).edit();
int orderIndex = sortingMethod.getId();
final String categoryType = selectedCategory.getType().toString();
final String keyMetaCategory = categoryType.concat(String.valueOf(accountId));

switch (selectedCategory.getType()) {
case FAVORITES: {
sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.label_favorites), orderIndex);
sp.putString(keyMetaCategory, "modified");
break;
}
case UNCATEGORIZED: {
sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.action_uncategorized), orderIndex);
sp.putString(keyMetaCategory, "lexicographically");
break;
}
case RECENT: {
sp.putInt(ctx.getString(R.string.action_sorting_method) + ' ' + ctx.getString(R.string.label_all_notes), orderIndex);
sp.putString(keyMetaCategory, "modified");
break;
}
case DEFAULT_CATEGORY:
Expand Down Expand Up @@ -679,19 +683,19 @@ public void modifyCategoryOrder(long accountId, @NonNull NavigationCategory sele
public LiveData<CategorySortingMethod> getCategoryOrder(@NonNull NavigationCategory selectedCategory) {
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String prefKey;

final String categoryType = selectedCategory.getType().toString();
switch (selectedCategory.getType()) {
// TODO make this account specific
case RECENT: {
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.label_all_notes);
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.label_all_notes + '_') + categoryType;
break;
}
case FAVORITES: {
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.label_favorites);
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.label_favorites + '_') + categoryType;
break;
}
case UNCATEGORIZED: {
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.action_uncategorized);
prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.action_uncategorized + '_') + categoryType;
break;
}
case DEFAULT_CATEGORY:
Expand Down

0 comments on commit 62d9863

Please sign in to comment.