#831 Migrate from SQLiteOpenHelper to Room

Split Navigation out
This commit is contained in:
Stefan Niedermann 2020-10-09 23:24:37 +02:00
parent daeea89fb4
commit 10fe9d1404
12 changed files with 264 additions and 238 deletions

View file

@ -26,7 +26,7 @@ import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import it.niedermann.owncloud.notes.main.NavigationAdapter;
import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.Note;
import it.niedermann.owncloud.notes.shared.model.Capabilities;

View file

@ -17,8 +17,7 @@ import java.util.List;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.databinding.ItemCategoryBinding;
import it.niedermann.owncloud.notes.main.NavigationAdapter.CategoryNavigationItem;
import it.niedermann.owncloud.notes.main.NavigationAdapter.NavigationItem;
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
import it.niedermann.owncloud.notes.shared.util.NoteUtil;
public class CategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -102,7 +101,7 @@ public class CategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
}
void setCategoryList(List<CategoryNavigationItem> categories, String currentSearchString) {
void setCategoryList(List<NavigationItem.CategoryNavigationItem> categories, String currentSearchString) {
this.categories.clear();
this.categories.addAll(categories);
final NavigationItem clearItem = new NavigationItem(clearItemId, context.getString(R.string.no_category), 0, R.drawable.ic_clear_grey_24dp);

View file

@ -22,7 +22,6 @@ import it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder;
import it.niedermann.owncloud.notes.branding.BrandedDialogFragment;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.databinding.DialogChangeCategoryBinding;
import it.niedermann.owncloud.notes.main.NavigationAdapter;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount;

View file

@ -63,13 +63,14 @@ import it.niedermann.owncloud.notes.databinding.DrawerLayoutBinding;
import it.niedermann.owncloud.notes.edit.EditNoteActivity;
import it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment;
import it.niedermann.owncloud.notes.exception.ExceptionDialogFragment;
import it.niedermann.owncloud.notes.main.NavigationAdapter.CategoryNavigationItem;
import it.niedermann.owncloud.notes.main.NavigationAdapter.NavigationItem;
import it.niedermann.owncloud.notes.main.items.ItemAdapter;
import it.niedermann.owncloud.notes.main.items.grid.GridItemDecoration;
import it.niedermann.owncloud.notes.main.items.list.NotesListViewItemTouchHelper;
import it.niedermann.owncloud.notes.main.items.section.SectionItemDecoration;
import it.niedermann.owncloud.notes.main.menu.MenuAdapter;
import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter;
import it.niedermann.owncloud.notes.main.navigation.NavigationClickListener;
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
import it.niedermann.owncloud.notes.persistence.CapabilitiesClient;
import it.niedermann.owncloud.notes.persistence.CapabilitiesWorker;
import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper;
@ -239,16 +240,6 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
updateSortMethodIcon(method);
});
menuAdapter = new MenuAdapter(getApplicationContext(), localAccount, (menuItem) -> {
@Nullable Integer resultCode = menuItem.getResultCode();
if (resultCode == null) {
startActivity(menuItem.getIntent());
} else {
startActivityForResult(menuItem.getIntent(), menuItem.getResultCode());
}
});
binding.navigationMenu.setAdapter(menuAdapter);
mainViewModel.filterChanged().observe(this, (v) -> {
if (noteWithCategoryLiveData != null) {
noteWithCategoryLiveData.removeObserver(noteWithCategoryObserver);
@ -297,7 +288,21 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
}
});
setupNavigationList();
menuAdapter.updateAccount(a);
if (menuAdapter == null) {
menuAdapter = new MenuAdapter(getApplicationContext(), localAccount, (menuItem) -> {
@Nullable Integer resultCode = menuItem.getResultCode();
if (resultCode == null) {
startActivity(menuItem.getIntent());
} else {
startActivityForResult(menuItem.getIntent(), menuItem.getResultCode());
}
});
binding.navigationMenu.setAdapter(menuAdapter);
} else {
menuAdapter.updateAccount(a);
}
});
new Thread(() -> canMoveNoteToAnotherAccounts = db.getAccountDao().getAccountsCount() > 1).start();
@ -465,7 +470,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
}
private void setupNavigationList() {
adapterCategories = new NavigationAdapter(this, new NavigationAdapter.ClickListener() {
adapterCategories = new NavigationAdapter(this, new NavigationClickListener() {
@Override
public void onItemClick(NavigationItem item) {
selectItem(item, true);
@ -489,8 +494,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, V
break;
}
default: {
if (item.getClass() == CategoryNavigationItem.class) {
mainViewModel.postSelectedCategory(new NavigationCategory(db.getCategoryDao().getCategory(((CategoryNavigationItem) item).categoryId)));
if (item.getClass() == NavigationItem.CategoryNavigationItem.class) {
mainViewModel.postSelectedCategory(new NavigationCategory(db.getCategoryDao().getCategory(((NavigationItem.CategoryNavigationItem) item).categoryId)));
} else {
Log.e(TAG, "Unknown item navigation type. Fallback to show " + RECENT);
mainViewModel.postSelectedCategory(new NavigationCategory(RECENT));

View file

@ -13,7 +13,8 @@ import java.util.ArrayList;
import java.util.List;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.main.NavigationAdapter.NavigationItem;
import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter;
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.Category;
@ -160,7 +161,7 @@ public class MainViewModel extends AndroidViewModel {
if (currentAccount != null && selectedCategory != null) {
return distinctUntilChanged(
map(db.getCategoryDao().getCategoriesLiveData(currentAccount.getId()), fromDatabase -> {
List<NavigationAdapter.CategoryNavigationItem> categories = convertToCategoryNavigationItem(getApplication(), db.getCategoryDao().getCategories(currentAccount.getId()));
List<NavigationItem.CategoryNavigationItem> categories = convertToCategoryNavigationItem(getApplication(), db.getCategoryDao().getCategories(currentAccount.getId()));
NavigationItem itemRecent = new NavigationItem(ADAPTER_KEY_RECENT, getApplication().getString(R.string.label_all_notes), db.getNoteDao().count(currentAccount.getId()), R.drawable.ic_access_time_grey600_24dp, RECENT);
NavigationItem itemFavorites = new NavigationItem(ADAPTER_KEY_STARRED, getApplication().getString(R.string.label_favorites), db.getNoteDao().getFavoritesCount(currentAccount.getId()), R.drawable.ic_star_yellow_24dp, FAVORITES);

View file

@ -1,192 +0,0 @@
package it.niedermann.owncloud.notes.main;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.databinding.ItemNavigationBinding;
import it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType;
import it.niedermann.owncloud.notes.shared.util.NoteUtil;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.UNCATEGORIZED;
import static java.util.Objects.requireNonNull;
public class NavigationAdapter extends RecyclerView.Adapter<NavigationAdapter.ViewHolder> {
@NonNull
private final Context context;
@ColorInt
private int mainColor;
@DrawableRes
public static final int ICON_FOLDER = R.drawable.ic_folder_grey600_24dp;
@DrawableRes
public static final int ICON_NOFOLDER = R.drawable.ic_folder_open_grey600_24dp;
@DrawableRes
public static final int ICON_SUB_FOLDER = R.drawable.ic_folder_grey600_18dp;
@DrawableRes
public static final int ICON_MULTIPLE = R.drawable.ic_create_new_folder_grey600_24dp;
@DrawableRes
public static final int ICON_MULTIPLE_OPEN = R.drawable.ic_folder_grey600_24dp;
@DrawableRes
public static final int ICON_SUB_MULTIPLE = R.drawable.ic_create_new_folder_grey600_18dp;
public void applyBrand(int mainColor, int textColor) {
this.mainColor = BrandingUtil.getSecondaryForegroundColorDependingOnTheme(context, mainColor);
notifyDataSetChanged();
}
public static class NavigationItem {
@NonNull
public String id;
@NonNull
public String label;
@DrawableRes
public int icon;
@Nullable
public Integer count;
@Nullable
public ENavigationCategoryType type;
public NavigationItem(@NonNull String id, @NonNull String label, @Nullable Integer count, @DrawableRes int icon) {
this.id = id;
this.label = label;
this.type = TextUtils.isEmpty(label) ? UNCATEGORIZED : null;
this.count = count;
this.icon = icon;
}
public NavigationItem(@NonNull String id, @NonNull String label, @Nullable Integer count, @DrawableRes int icon, @NonNull ENavigationCategoryType type) {
this.id = id;
this.label = label;
this.type = type;
this.count = count;
this.icon = icon;
}
}
public static class CategoryNavigationItem extends NavigationItem {
@NonNull
public Long categoryId;
public CategoryNavigationItem(@NonNull String id, @NonNull String label, @Nullable Integer count, @DrawableRes int icon, @NonNull Long categoryId) {
super(id, label, count, icon, ENavigationCategoryType.DEFAULT_CATEGORY);
this.categoryId = categoryId;
}
}
class ViewHolder extends RecyclerView.ViewHolder {
@NonNull
private final View view;
@NonNull
private final TextView name;
@NonNull
private final TextView count;
@NonNull
private final ImageView icon;
private NavigationItem currentItem;
ViewHolder(@NonNull View itemView, @NonNull final ClickListener clickListener) {
super(itemView);
view = itemView;
ItemNavigationBinding binding = ItemNavigationBinding.bind(view);
this.name = binding.navigationItemLabel;
this.count = binding.navigationItemCount;
this.icon = binding.navigationItemIcon;
icon.setOnClickListener(view -> clickListener.onIconClick(currentItem));
itemView.setOnClickListener(view -> clickListener.onItemClick(currentItem));
}
private void bind(@NonNull NavigationItem item) {
currentItem = item;
boolean isSelected = item.id.equals(selectedItem);
name.setText(NoteUtil.extendCategory(item.label));
count.setVisibility(item.count == null ? View.GONE : View.VISIBLE);
count.setText(String.valueOf(item.count));
if (item.icon > 0) {
icon.setImageDrawable(DrawableCompat.wrap(requireNonNull(ContextCompat.getDrawable(icon.getContext(), item.icon))));
icon.setVisibility(View.VISIBLE);
} else {
icon.setVisibility(View.GONE);
}
int textColor = isSelected ? mainColor : view.getResources().getColor(R.color.fg_default);
name.setTextColor(textColor);
count.setTextColor(textColor);
icon.setColorFilter(isSelected ? textColor : 0);
view.setSelected(isSelected);
}
}
public interface ClickListener {
void onItemClick(NavigationItem item);
void onIconClick(NavigationItem item);
}
@NonNull
private List<NavigationItem> items = new ArrayList<>();
private String selectedItem = null;
@NonNull
private final ClickListener clickListener;
public NavigationAdapter(@NonNull Context context, @NonNull ClickListener clickListener) {
this.context = context;
this.mainColor = BrandingUtil.getSecondaryForegroundColorDependingOnTheme(context, BrandingUtil.readBrandMainColor(context));
this.clickListener = clickListener;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_navigation, parent, false);
return new ViewHolder(v, clickListener);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.bind(items.get(position));
}
@Override
public int getItemCount() {
return items.size();
}
public void setItems(@NonNull List<NavigationItem> items) {
for (NavigationItem item : items) {
if (TextUtils.isEmpty(item.label)) {
item.label = context.getString(R.string.action_uncategorized);
item.icon = NavigationAdapter.ICON_NOFOLDER;
item.type = UNCATEGORIZED;
break;
}
}
this.items = items;
notifyDataSetChanged();
}
public void setSelectedItem(String id) {
selectedItem = id;
notifyDataSetChanged();
}
}

View file

@ -0,0 +1,92 @@
package it.niedermann.owncloud.notes.main.navigation;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.UNCATEGORIZED;
public class NavigationAdapter extends RecyclerView.Adapter<NavigationViewHolder> {
@NonNull
private final Context context;
@ColorInt
private int mainColor;
@DrawableRes
public static final int ICON_FOLDER = R.drawable.ic_folder_grey600_24dp;
@DrawableRes
public static final int ICON_NOFOLDER = R.drawable.ic_folder_open_grey600_24dp;
@DrawableRes
public static final int ICON_SUB_FOLDER = R.drawable.ic_folder_grey600_18dp;
@DrawableRes
public static final int ICON_MULTIPLE = R.drawable.ic_create_new_folder_grey600_24dp;
@DrawableRes
public static final int ICON_MULTIPLE_OPEN = R.drawable.ic_folder_grey600_24dp;
@DrawableRes
public static final int ICON_SUB_MULTIPLE = R.drawable.ic_create_new_folder_grey600_18dp;
public void applyBrand(int mainColor, int textColor) {
this.mainColor = BrandingUtil.getSecondaryForegroundColorDependingOnTheme(context, mainColor);
notifyDataSetChanged();
}
@NonNull
private List<NavigationItem> items = new ArrayList<>();
private String selectedItem = null;
@NonNull
private final NavigationClickListener navigationClickListener;
public NavigationAdapter(@NonNull Context context, @NonNull NavigationClickListener navigationClickListener) {
this.context = context;
this.mainColor = BrandingUtil.getSecondaryForegroundColorDependingOnTheme(context, BrandingUtil.readBrandMainColor(context));
this.navigationClickListener = navigationClickListener;
}
@NonNull
@Override
public NavigationViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new NavigationViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_navigation, parent, false), navigationClickListener);
}
@Override
public void onBindViewHolder(@NonNull NavigationViewHolder holder, int position) {
holder.bind(items.get(position), mainColor, selectedItem);
}
@Override
public int getItemCount() {
return items.size();
}
public void setItems(@NonNull List<NavigationItem> items) {
for (NavigationItem item : items) {
if (TextUtils.isEmpty(item.label)) {
item.label = context.getString(R.string.action_uncategorized);
item.icon = NavigationAdapter.ICON_NOFOLDER;
item.type = UNCATEGORIZED;
break;
}
}
this.items = items;
notifyDataSetChanged();
}
public void setSelectedItem(String id) {
selectedItem = id;
notifyDataSetChanged();
}
}

View file

@ -0,0 +1,7 @@
package it.niedermann.owncloud.notes.main.navigation;
public interface NavigationClickListener {
void onItemClick(NavigationItem item);
void onIconClick(NavigationItem item);
}

View file

@ -0,0 +1,50 @@
package it.niedermann.owncloud.notes.main.navigation;
import android.text.TextUtils;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.UNCATEGORIZED;
public class NavigationItem {
@NonNull
public String id;
@NonNull
public String label;
@DrawableRes
public int icon;
@Nullable
public Integer count;
@Nullable
public ENavigationCategoryType type;
public NavigationItem(@NonNull String id, @NonNull String label, @Nullable Integer count, @DrawableRes int icon) {
this.id = id;
this.label = label;
this.type = TextUtils.isEmpty(label) ? UNCATEGORIZED : null;
this.count = count;
this.icon = icon;
}
public NavigationItem(@NonNull String id, @NonNull String label, @Nullable Integer count, @DrawableRes int icon, @NonNull ENavigationCategoryType type) {
this.id = id;
this.label = label;
this.type = type;
this.count = count;
this.icon = icon;
}
public static class CategoryNavigationItem extends NavigationItem {
@NonNull
public Long categoryId;
public CategoryNavigationItem(@NonNull String id, @NonNull String label, @Nullable Integer count, @DrawableRes int icon, @NonNull Long categoryId) {
super(id, label, count, icon, ENavigationCategoryType.DEFAULT_CATEGORY);
this.categoryId = categoryId;
}
}
}

View file

@ -0,0 +1,63 @@
package it.niedermann.owncloud.notes.main.navigation;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.recyclerview.widget.RecyclerView;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.databinding.ItemNavigationBinding;
import it.niedermann.owncloud.notes.shared.util.NoteUtil;
import static java.util.Objects.requireNonNull;
class NavigationViewHolder extends RecyclerView.ViewHolder {
@NonNull
private final View view;
@NonNull
private final TextView name;
@NonNull
private final TextView count;
@NonNull
private final ImageView icon;
private NavigationItem currentItem;
NavigationViewHolder(@NonNull View itemView, @NonNull final NavigationClickListener navigationClickListener) {
super(itemView);
view = itemView;
ItemNavigationBinding binding = ItemNavigationBinding.bind(view);
this.name = binding.navigationItemLabel;
this.count = binding.navigationItemCount;
this.icon = binding.navigationItemIcon;
icon.setOnClickListener(view -> navigationClickListener.onIconClick(currentItem));
itemView.setOnClickListener(view -> navigationClickListener.onItemClick(currentItem));
}
public void bind(@NonNull NavigationItem item, @ColorInt int mainColor, String selectedItem) {
currentItem = item;
boolean isSelected = item.id.equals(selectedItem);
name.setText(NoteUtil.extendCategory(item.label));
count.setVisibility(item.count == null ? View.GONE : View.VISIBLE);
count.setText(String.valueOf(item.count));
if (item.icon > 0) {
icon.setImageDrawable(DrawableCompat.wrap(requireNonNull(ContextCompat.getDrawable(icon.getContext(), item.icon))));
icon.setVisibility(View.VISIBLE);
} else {
icon.setVisibility(View.GONE);
}
int textColor = isSelected ? mainColor : view.getResources().getColor(R.color.fg_default);
name.setTextColor(textColor);
count.setTextColor(textColor);
icon.setColorFilter(isSelected ? textColor : 0);
view.setSelected(isSelected);
}
}

View file

@ -40,7 +40,8 @@ import java.util.regex.Pattern;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.main.NavigationAdapter;
import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter;
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount;
import static it.niedermann.owncloud.notes.shared.util.ColorUtil.isColorDark;
@ -136,15 +137,15 @@ public class DisplayUtils {
}
}
public static List<NavigationAdapter.CategoryNavigationItem> convertToCategoryNavigationItem(@NonNull Context context, @NonNull Collection<CategoryWithNotesCount> counter) {
List<NavigationAdapter.CategoryNavigationItem> result = new ArrayList<>(counter.size());
public static List<NavigationItem.CategoryNavigationItem> convertToCategoryNavigationItem(@NonNull Context context, @NonNull Collection<CategoryWithNotesCount> counter) {
List<NavigationItem.CategoryNavigationItem> result = new ArrayList<>(counter.size());
for(CategoryWithNotesCount count: counter) {
result.add(convertToCategoryNavigationItem(context, count));
}
return result;
}
public static NavigationAdapter.CategoryNavigationItem convertToCategoryNavigationItem(@NonNull Context context, @NonNull CategoryWithNotesCount counter) {
public static NavigationItem.CategoryNavigationItem convertToCategoryNavigationItem(@NonNull Context context, @NonNull CategoryWithNotesCount counter) {
Resources res = context.getResources();
String category = counter.getTitle().toLowerCase();
int icon = NavigationAdapter.ICON_FOLDER;
@ -155,6 +156,6 @@ public class DisplayUtils {
} else if (category.equals(res.getString(R.string.category_work).toLowerCase())) {
icon = R.drawable.ic_work_grey600_24dp;
}
return new NavigationAdapter.CategoryNavigationItem("category:" + counter.getTitle(), counter.getTitle(), counter.getTotalNotes(), icon, counter.getId());
return new NavigationItem.CategoryNavigationItem("category:" + counter.getTitle(), counter.getTitle(), counter.getTotalNotes(), icon, counter.getId());
}
}

View file

@ -23,8 +23,9 @@ import it.niedermann.owncloud.notes.LockedActivity;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.main.MainActivity;
import it.niedermann.owncloud.notes.main.NavigationAdapter;
import it.niedermann.owncloud.notes.main.NavigationAdapter.CategoryNavigationItem;
import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter;
import it.niedermann.owncloud.notes.main.navigation.NavigationClickListener;
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData;
@ -43,8 +44,8 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
private Account localAccount = null;
private NavigationAdapter adapterCategories;
private NavigationAdapter.NavigationItem itemRecent;
private NavigationAdapter.NavigationItem itemFavorites;
private NavigationItem itemRecent;
private NavigationItem itemFavorites;
private NotesDatabase db = null;
@Override
@ -76,20 +77,20 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
finish();
}
itemRecent = new NavigationAdapter.NavigationItem(MainActivity.ADAPTER_KEY_RECENT,
itemRecent = new NavigationItem(MainActivity.ADAPTER_KEY_RECENT,
getString(R.string.label_all_notes),
null,
R.drawable.ic_access_time_grey600_24dp);
itemFavorites = new NavigationAdapter.NavigationItem(MainActivity.ADAPTER_KEY_STARRED,
itemFavorites = new NavigationItem(MainActivity.ADAPTER_KEY_STARRED,
getString(R.string.label_favorites),
null,
R.drawable.ic_star_yellow_24dp);
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
adapterCategories = new NavigationAdapter(this, new NavigationAdapter.ClickListener() {
adapterCategories = new NavigationAdapter(this, new NavigationClickListener() {
@Override
public void onItemClick(NavigationAdapter.NavigationItem item) {
public void onItemClick(NavigationItem item) {
NotesListWidgetData data = new NotesListWidgetData();
data.setId(appWidgetId);
@ -99,8 +100,8 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
data.setMode(MODE_DISPLAY_STARRED);
} else {
data.setMode(MODE_DISPLAY_CATEGORY);
if (item instanceof CategoryNavigationItem) {
data.setCategoryId(((CategoryNavigationItem) item).categoryId);
if (item instanceof NavigationItem.CategoryNavigationItem) {
data.setCategoryId(((NavigationItem.CategoryNavigationItem) item).categoryId);
} else {
throw new IllegalStateException("Tried to choose a category, but ");
}
@ -119,7 +120,7 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
finish();
}
public void onIconClick(NavigationAdapter.NavigationItem item) {
public void onIconClick(NavigationItem item) {
onItemClick(item);
}
});
@ -141,14 +142,14 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
public void applyBrand(int mainColor, int textColor) {
}
private class LoadCategoryListTask extends AsyncTask<Void, Void, List<NavigationAdapter.NavigationItem>> {
private class LoadCategoryListTask extends AsyncTask<Void, Void, List<NavigationItem>> {
@Override
protected List<NavigationAdapter.NavigationItem> doInBackground(Void... voids) {
protected List<NavigationItem> doInBackground(Void... voids) {
if (localAccount == null) {
return new ArrayList<>();
}
NavigationAdapter.NavigationItem itemUncategorized;
List<CategoryNavigationItem> categories = convertToCategoryNavigationItem(NoteListWidgetConfigurationActivity.this, db.getCategoryDao().getCategories(localAccount.getId()));
NavigationItem itemUncategorized;
List<NavigationItem.CategoryNavigationItem> categories = convertToCategoryNavigationItem(NoteListWidgetConfigurationActivity.this, db.getCategoryDao().getCategories(localAccount.getId()));
if (!categories.isEmpty() && categories.get(0).label.isEmpty()) {
itemUncategorized = categories.get(0);
@ -159,11 +160,11 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
itemFavorites.count = db.getNoteDao().getFavoritesCount(localAccount.getId());
itemRecent.count = db.getNoteDao().count(localAccount.getId());
ArrayList<NavigationAdapter.NavigationItem> items = new ArrayList<>();
ArrayList<NavigationItem> items = new ArrayList<>();
items.add(itemRecent);
items.add(itemFavorites);
for (NavigationAdapter.NavigationItem item : categories) {
for (NavigationItem item : categories) {
int slashIndex = item.label.indexOf('/');
item.label = slashIndex < 0 ? item.label : item.label.substring(0, slashIndex);
@ -174,7 +175,7 @@ public class NoteListWidgetConfigurationActivity extends LockedActivity {
}
@Override
protected void onPostExecute(List<NavigationAdapter.NavigationItem> items) {
protected void onPostExecute(List<NavigationItem> items) {
adapterCategories.setItems(items);
}
}