use of it.niedermann.owncloud.notes.main.navigation.NavigationAdapter in project nextcloud-notes by stefan-niedermann.
the class NoteListWidgetConfigurationActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setResult(RESULT_CANCELED);
repo = NotesRepository.getInstance(this);
final var args = getIntent().getExtras();
if (args != null) {
appWidgetId = args.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
Log.d(TAG, "INVALID_APPWIDGET_ID");
finish();
}
viewModel = new ViewModelProvider(this).get(NoteListViewModel.class);
binding = ActivityNoteListConfigurationBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
adapterCategories = new NavigationAdapter(this, new NavigationClickListener() {
@Override
public void onItemClick(NavigationItem item) {
final var data = new NotesListWidgetData();
data.setId(appWidgetId);
if (item.type != null) {
switch(item.type) {
case RECENT:
{
data.setMode(MODE_DISPLAY_ALL);
break;
}
case FAVORITES:
{
data.setMode(MODE_DISPLAY_STARRED);
break;
}
case UNCATEGORIZED:
{
data.setMode(MODE_DISPLAY_CATEGORY);
data.setCategory(null);
}
case DEFAULT_CATEGORY:
default:
{
if (item.getClass() == NavigationItem.CategoryNavigationItem.class) {
data.setMode(MODE_DISPLAY_CATEGORY);
data.setCategory(((NavigationItem.CategoryNavigationItem) item).category);
} else {
data.setMode(MODE_DISPLAY_ALL);
Log.e(TAG, "Unknown item navigation type. Fallback to show " + RECENT);
}
}
}
} else {
data.setMode(MODE_DISPLAY_ALL);
Log.e(TAG, "Unknown item navigation type. Fallback to show " + RECENT);
}
data.setAccountId(localAccount.getId());
data.setThemeMode(NotesApplication.getAppTheme(getApplicationContext()).getModeId());
executor.submit(() -> {
repo.createOrUpdateNoteListWidgetData(data);
final var updateIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, getApplicationContext(), NoteListWidget.class).putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(RESULT_OK, updateIntent);
getApplicationContext().sendBroadcast(updateIntent);
finish();
});
}
public void onIconClick(NavigationItem item) {
onItemClick(item);
}
});
binding.recyclerView.setAdapter(adapterCategories);
executor.submit(() -> {
try {
this.localAccount = repo.getAccountByName(SingleAccountHelper.getCurrentSingleSignOnAccount(this).name);
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
e.printStackTrace();
Toast.makeText(this, R.string.widget_not_logged_in, Toast.LENGTH_LONG).show();
// TODO Present user with app login screen
Log.w(TAG, "onCreate: user not logged in");
finish();
}
runOnUiThread(() -> viewModel.getAdapterCategories(localAccount.getId()).observe(this, (navigationItems) -> adapterCategories.setItems(navigationItems)));
});
}
use of it.niedermann.owncloud.notes.main.navigation.NavigationAdapter in project nextcloud-notes by stefan-niedermann.
the class MainActivity method setupNavigationList.
private void setupNavigationList() {
adapterCategories = new NavigationAdapter(this, new NavigationClickListener() {
@Override
public void onItemClick(NavigationItem item) {
selectItem(item, true);
}
private void selectItem(NavigationItem item, boolean closeNavigation) {
adapterCategories.setSelectedItem(item.id);
// update current selection
if (item.type != null) {
switch(item.type) {
case RECENT:
{
mainViewModel.postSelectedCategory(new NavigationCategory(RECENT));
break;
}
case FAVORITES:
{
mainViewModel.postSelectedCategory(new NavigationCategory(FAVORITES));
break;
}
case UNCATEGORIZED:
{
mainViewModel.postSelectedCategory(new NavigationCategory(UNCATEGORIZED));
break;
}
default:
{
if (item.getClass() == NavigationItem.CategoryNavigationItem.class) {
mainViewModel.postSelectedCategory(new NavigationCategory(((NavigationItem.CategoryNavigationItem) item).accountId, ((NavigationItem.CategoryNavigationItem) item).category));
} else {
throw new IllegalStateException(NavigationItem.class.getSimpleName() + " type is " + DEFAULT_CATEGORY + ", but item is not of type " + NavigationItem.CategoryNavigationItem.class.getSimpleName() + ".");
}
}
}
} else {
Log.e(TAG, "Unknown item navigation type. Fallback to show " + RECENT);
mainViewModel.postSelectedCategory(new NavigationCategory(RECENT));
}
if (closeNavigation) {
binding.drawerLayout.closeDrawer(GravityCompat.START);
}
}
@Override
public void onIconClick(NavigationItem item) {
final var expandedCategoryLiveData = mainViewModel.getExpandedCategory();
expandedCategoryLiveData.observe(MainActivity.this, expandedCategory -> {
if (item.icon == NavigationAdapter.ICON_MULTIPLE && !item.label.equals(expandedCategory)) {
mainViewModel.postExpandedCategory(item.label);
selectItem(item, false);
} else if (item.icon == NavigationAdapter.ICON_MULTIPLE || item.icon == NavigationAdapter.ICON_MULTIPLE_OPEN && item.label.equals(expandedCategory)) {
mainViewModel.postExpandedCategory(null);
} else {
onItemClick(item);
}
expandedCategoryLiveData.removeObservers(MainActivity.this);
});
}
});
adapterCategories.setSelectedItem(ADAPTER_KEY_RECENT);
binding.navigationList.setAdapter(adapterCategories);
}
Aggregations