Search in sources :

Example 1 with CategorySortingMethod

use of it.niedermann.owncloud.notes.shared.model.CategorySortingMethod in project nextcloud-notes by stefan-niedermann.

the class NotesRepository method getCategoryOrder.

/**
 * Gets the sorting method of a {@link NavigationCategory}, the category can be normal
 * {@link CategoryOptions} or one of {@link ENavigationCategoryType}.
 * If the category no normal {@link CategoryOptions}, sorting method will be got from
 * {@link SharedPreferences}.
 * <p>
 * The sorting method of the category can be used to decide to use which sorting method to show
 * the notes for each categories.
 *
 * @param selectedCategory The category
 * @return The sorting method in CategorySortingMethod enum format
 */
@NonNull
@MainThread
public LiveData<CategorySortingMethod> getCategoryOrder(@NonNull NavigationCategory selectedCategory) {
    final var sp = PreferenceManager.getDefaultSharedPreferences(context);
    String prefKey;
    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);
                break;
            }
        case FAVORITES:
            {
                prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.label_favorites);
                break;
            }
        case UNCATEGORIZED:
            {
                prefKey = context.getString(R.string.action_sorting_method) + ' ' + context.getString(R.string.action_uncategorized);
                break;
            }
        case DEFAULT_CATEGORY:
        default:
            {
                final String category = selectedCategory.getCategory();
                if (category != null) {
                    return db.getCategoryOptionsDao().getCategoryOrder(selectedCategory.getAccountId(), category);
                } else {
                    Log.e(TAG, "Cannot read " + CategorySortingMethod.class.getSimpleName() + " for " + ENavigationCategoryType.DEFAULT_CATEGORY + ".");
                    return new MutableLiveData<>(CategorySortingMethod.SORT_MODIFIED_DESC);
                }
            }
    }
    return map(new SharedPreferenceIntLiveData(sp, prefKey, CategorySortingMethod.SORT_MODIFIED_DESC.getId()), CategorySortingMethod::findById);
}
Also used : CategorySortingMethod(it.niedermann.owncloud.notes.shared.model.CategorySortingMethod) SharedPreferenceIntLiveData(it.niedermann.android.sharedpreferences.SharedPreferenceIntLiveData) MainThread(androidx.annotation.MainThread) NonNull(androidx.annotation.NonNull)

Aggregations

MainThread (androidx.annotation.MainThread)1 NonNull (androidx.annotation.NonNull)1 SharedPreferenceIntLiveData (it.niedermann.android.sharedpreferences.SharedPreferenceIntLiveData)1 CategorySortingMethod (it.niedermann.owncloud.notes.shared.model.CategorySortingMethod)1