use of it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData.MODE_DISPLAY_CATEGORY 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)));
});
}
Aggregations