Search in sources :

Example 1 with NavigationCategory

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

the class MainViewModel method postCurrentAccount.

public void postCurrentAccount(@NonNull Account account) {
    state.set(KEY_CURRENT_ACCOUNT, account);
    BrandingUtil.saveBrandColors(getApplication(), account.getColor(), account.getTextColor());
    SingleAccountHelper.setCurrentAccount(getApplication(), account.getAccountName());
    final var currentAccount = this.currentAccount.getValue();
    // TODO in the long term we should store the last NavigationCategory for each Account
    if (currentAccount == null || currentAccount.getId() != account.getId()) {
        this.currentAccount.setValue(account);
        this.searchTerm.setValue("");
        this.selectedCategory.setValue(new NavigationCategory(RECENT));
    }
}
Also used : NavigationCategory(it.niedermann.owncloud.notes.shared.model.NavigationCategory)

Example 2 with NavigationCategory

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

the class MainViewModel method restoreInstanceState.

public void restoreInstanceState() {
    Log.v(TAG, "[restoreInstanceState]");
    final Account account = state.get(KEY_CURRENT_ACCOUNT);
    if (account != null) {
        postCurrentAccount(account);
    }
    postSearchTerm(state.get(KEY_SEARCH_TERM));
    final NavigationCategory selectedCategory = state.get(KEY_SELECTED_CATEGORY);
    if (selectedCategory != null) {
        postSelectedCategory(selectedCategory);
        Log.v(TAG, "[restoreInstanceState] - selectedCategory: " + selectedCategory);
    }
    postExpandedCategory(state.get(KEY_EXPANDED_CATEGORY));
}
Also used : Account(it.niedermann.owncloud.notes.persistence.entity.Account) NavigationCategory(it.niedermann.owncloud.notes.shared.model.NavigationCategory)

Example 3 with NavigationCategory

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

the class NoteListWidgetFactory method getViewAt.

@Override
public RemoteViews getViewAt(int position) {
    final RemoteViews note_content;
    if (position == 0) {
        final Account localAccount = repo.getAccountById(data.getAccountId());
        final Intent openIntent = new Intent(Intent.ACTION_MAIN).setComponent(new ComponentName(context.getPackageName(), MainActivity.class.getName()));
        final Intent createIntent = new Intent(context, EditNoteActivity.class);
        final Bundle extras = new Bundle();
        extras.putSerializable(PARAM_CATEGORY, data.getMode() == MODE_DISPLAY_STARRED ? new NavigationCategory(ENavigationCategoryType.FAVORITES) : new NavigationCategory(localAccount.getId(), data.getCategory()));
        extras.putLong(EditNoteActivity.PARAM_ACCOUNT_ID, data.getAccountId());
        createIntent.putExtras(extras);
        createIntent.setData(Uri.parse(createIntent.toUri(Intent.URI_INTENT_SCHEME)));
        note_content = new RemoteViews(context.getPackageName(), R.layout.widget_entry_add);
        note_content.setOnClickFillInIntent(R.id.widget_entry_content_tv, openIntent);
        note_content.setOnClickFillInIntent(R.id.widget_entry_fav_icon, createIntent);
        note_content.setTextViewText(R.id.widget_entry_content_tv, getCategoryTitle(context, data.getMode(), data.getCategory()));
        note_content.setImageViewResource(R.id.widget_entry_fav_icon, R.drawable.ic_add_blue_24dp);
        note_content.setInt(R.id.widget_entry_fav_icon, "setColorFilter", NotesColorUtil.contrastRatioIsSufficient(ContextCompat.getColor(context, R.color.widget_background), localAccount.getColor()) ? localAccount.getColor() : ContextCompat.getColor(context, R.color.widget_foreground));
    } else {
        position--;
        if (position > dbNotes.size() - 1 || dbNotes.get(position) == null) {
            Log.e(TAG, "Could not find position \"" + position + "\" in dbNotes list.");
            return null;
        }
        final Note note = dbNotes.get(position);
        final Intent fillInIntent = new Intent(context, EditNoteActivity.class);
        final Bundle extras = new Bundle();
        extras.putLong(EditNoteActivity.PARAM_NOTE_ID, note.getId());
        extras.putLong(EditNoteActivity.PARAM_ACCOUNT_ID, note.getAccountId());
        fillInIntent.putExtras(extras);
        fillInIntent.setData(Uri.parse(fillInIntent.toUri(Intent.URI_INTENT_SCHEME)));
        note_content = new RemoteViews(context.getPackageName(), R.layout.widget_entry);
        note_content.setOnClickFillInIntent(R.id.widget_note_list_entry, fillInIntent);
        note_content.setTextViewText(R.id.widget_entry_content_tv, note.getTitle());
        note_content.setImageViewResource(R.id.widget_entry_fav_icon, note.getFavorite() ? R.drawable.ic_star_yellow_24dp : R.drawable.ic_star_grey_ccc_24dp);
    }
    return note_content;
}
Also used : Account(it.niedermann.owncloud.notes.persistence.entity.Account) RemoteViews(android.widget.RemoteViews) Bundle(android.os.Bundle) NavigationCategory(it.niedermann.owncloud.notes.shared.model.NavigationCategory) Note(it.niedermann.owncloud.notes.persistence.entity.Note) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 4 with NavigationCategory

use of it.niedermann.owncloud.notes.shared.model.NavigationCategory 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);
}
Also used : NavigationAdapter(it.niedermann.owncloud.notes.main.navigation.NavigationAdapter) NavigationItem(it.niedermann.owncloud.notes.main.navigation.NavigationItem) NavigationClickListener(it.niedermann.owncloud.notes.main.navigation.NavigationClickListener) NavigationCategory(it.niedermann.owncloud.notes.shared.model.NavigationCategory)

Example 5 with NavigationCategory

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

the class EditNoteActivity method launchNewNote.

/**
 * Starts the {@link NoteEditFragment} with a new note.
 * Content ("share" functionality), category and favorite attribute can be preset.
 */
private void launchNewNote() {
    final var intent = getIntent();
    String categoryTitle = "";
    boolean favorite = false;
    if (intent.hasExtra(PARAM_CATEGORY)) {
        final NavigationCategory categoryPreselection = (NavigationCategory) Objects.requireNonNull(intent.getSerializableExtra(PARAM_CATEGORY));
        final String category = categoryPreselection.getCategory();
        if (category != null) {
            categoryTitle = category;
        }
        favorite = categoryPreselection.getType() == FAVORITES;
    }
    String content = "";
    if (intent.hasExtra(Intent.EXTRA_TEXT) && MIMETYPE_TEXT_PLAIN.equals(intent.getType()) && (Intent.ACTION_SEND.equals(intent.getAction()) || INTENT_GOOGLE_ASSISTANT.equals(intent.getAction()))) {
        content = ShareUtil.extractSharedText(intent);
    } else if (intent.hasExtra(PARAM_CONTENT)) {
        content = intent.getStringExtra(PARAM_CONTENT);
    }
    if (content == null) {
        content = "";
    }
    final var newNote = new Note(null, Calendar.getInstance(), NoteUtil.generateNonEmptyNoteTitle(content, this), content, categoryTitle, favorite, null);
    fragment = NoteEditFragment.newInstanceWithNewNote(newNote);
    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_view, fragment).commit();
}
Also used : NavigationCategory(it.niedermann.owncloud.notes.shared.model.NavigationCategory) Note(it.niedermann.owncloud.notes.persistence.entity.Note)

Aggregations

NavigationCategory (it.niedermann.owncloud.notes.shared.model.NavigationCategory)5 Account (it.niedermann.owncloud.notes.persistence.entity.Account)2 Note (it.niedermann.owncloud.notes.persistence.entity.Note)2 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 RemoteViews (android.widget.RemoteViews)1 NavigationAdapter (it.niedermann.owncloud.notes.main.navigation.NavigationAdapter)1 NavigationClickListener (it.niedermann.owncloud.notes.main.navigation.NavigationClickListener)1 NavigationItem (it.niedermann.owncloud.notes.main.navigation.NavigationItem)1