Search in sources :

Example 1 with Fragment

use of androidx.fragment.app.Fragment in project orgzly-android by orgzly.

the class MainActivity method setupViewModel.

private void setupViewModel() {
    sharedMainActivityViewModel.getDrawerLockState().observe(this, isLocked -> {
        DrawerLayout layout = mDrawerLayout;
        if (layout != null) {
            if (isLocked == null || !isLocked) {
                layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            } else {
                layout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            }
        }
    });
    sharedMainActivityViewModel.getFragmentState().observe(this, state -> {
        if (BuildConfig.LOG_DEBUG)
            LogUtils.d(TAG, "Observed fragment state: " + state);
        if (state != null) {
            getSupportActionBar().setTitle(state.getTitle());
            // Clean up whitespace for multi-line query
            CharSequence subTitle = state.getSubTitle();
            if (subTitle != null) {
                subTitle = subTitle.toString().replaceAll("\\s{2,}", " ");
            }
            getSupportActionBar().setSubtitle(subTitle);
            drawerNavigationView.updateActiveFragment(state.getTag());
            /* Update floating action button. */
            MainFab.updateFab(this, state.getTag(), state.getSelectionCount());
        }
    });
    viewModel.getOpenNoteWithPropertyRequestEvent().observeSingle(this, pair -> {
        if (pair != null) {
            UseCase action = pair.getFirst();
            UseCaseResult result = pair.getSecond();
            if (action instanceof NoteFindWithProperty) {
                NoteFindWithProperty thisAction = (NoteFindWithProperty) action;
                if (result.getUserData() != null) {
                    NoteDao.NoteIdBookId note = (NoteDao.NoteIdBookId) result.getUserData();
                    DisplayManager.displayExistingNote(getSupportFragmentManager(), note.getBookId(), note.getNoteId());
                } else {
                    showSnackbar(getString(R.string.no_such_link_target, thisAction.getName(), thisAction.getValue()));
                }
            }
        }
    });
    viewModel.getOpenFileLinkRequestEvent().observeSingle(this, result -> {
        if (result != null && result.getUserData() != null) {
            Object userData = result.getUserData();
            if (userData instanceof Book) {
                Book book = (Book) userData;
                Intent intent = new Intent(AppIntent.ACTION_OPEN_BOOK);
                intent.putExtra(AppIntent.EXTRA_BOOK_ID, book.getId());
                LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
                if (BuildConfig.LOG_DEBUG)
                    LogUtils.d(TAG, "sending intent", intent);
            } else if (userData instanceof File) {
                File file = (File) userData;
                openFileIfExists(file);
            }
        }
    });
    viewModel.getOpenNoteRequestEvent().observeSingle(this, note -> MainActivity.openSpecificNote(note.getPosition().getBookId(), note.getId()));
    viewModel.getSetBookLinkRequestEvent().observeSingle(this, result -> {
        Book book = result.getBook();
        List<Repo> links = result.getLinks();
        CharSequence[] urls = result.getUrls();
        int checked = result.getSelected();
        if (links.isEmpty()) {
            showSnackbarWithReposLink(getString(R.string.no_repos));
        } else {
            ArrayAdapter<Repo> adapter = new ArrayAdapter<>(this, R.layout.item_repo, R.id.item_repo_url);
            adapter.addAll(links);
            dialog = new AlertDialog.Builder(this).setTitle(R.string.book_link).setSingleChoiceItems(urls, checked, (d, which) -> {
                mSyncFragment.run(new BookLinkUpdate(book.getId(), links.get(which)));
                dialog.dismiss();
                dialog = null;
            }).setNeutralButton(R.string.remove_notebook_link, (dialog, which) -> {
                mSyncFragment.run(new BookLinkUpdate(book.getId()));
            }).setNegativeButton(R.string.cancel, null).show();
        }
    });
    viewModel.getSavedSearchedExportEvent().observeSingle(this, count -> {
        showSnackbar(getResources().getQuantityString(R.plurals.exported_searches, count, count));
    });
    viewModel.getSavedSearchedImportEvent().observeSingle(this, count -> {
        showSnackbar(getResources().getQuantityString(R.plurals.imported_searches, count, count));
    });
    viewModel.getErrorEvent().observeSingle(this, error -> {
        if (error != null) {
            showSnackbar(error.getLocalizedMessage());
        }
    });
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) NoteDelete(com.orgzly.android.usecase.NoteDelete) UseCase(com.orgzly.android.usecase.UseCase) ActivityUtils(com.orgzly.android.ui.util.ActivityUtils) Query(com.orgzly.android.query.Query) Handler(android.os.Handler) Fragment(androidx.fragment.app.Fragment) BookFormat(com.orgzly.android.BookFormat) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) NoteUpdateState(com.orgzly.android.usecase.NoteUpdateState) NoteFindWithProperty(com.orgzly.android.usecase.NoteFindWithProperty) IntentFilter(android.content.IntentFilter) Set(java.util.Set) SearchView(androidx.appcompat.widget.SearchView) Book(com.orgzly.android.db.entity.Book) BuildConfig(com.orgzly.BuildConfig) CommonActivity(com.orgzly.android.ui.CommonActivity) Note(com.orgzly.android.db.entity.Note) BookImportFromUri(com.orgzly.android.usecase.BookImportFromUri) DottedQueryBuilder(com.orgzly.android.query.user.DottedQueryBuilder) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) NotePaste(com.orgzly.android.usecase.NotePaste) BookExportToUri(com.orgzly.android.usecase.BookExportToUri) SavedSearchUpdate(com.orgzly.android.usecase.SavedSearchUpdate) NoteDao(com.orgzly.android.db.dao.NoteDao) SavedSearchFragment(com.orgzly.android.ui.savedsearch.SavedSearchFragment) R(com.orgzly.R) SyncService(com.orgzly.android.sync.SyncService) Menu(android.view.Menu) NoteFragment(com.orgzly.android.ui.note.NoteFragment) ActionModeListener(com.orgzly.android.ui.ActionModeListener) BookFragment(com.orgzly.android.ui.notes.book.BookFragment) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NoteDemote(com.orgzly.android.usecase.NoteDemote) IOException(java.io.IOException) SavedSearchMoveUp(com.orgzly.android.usecase.SavedSearchMoveUp) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter) NotePromote(com.orgzly.android.usecase.NotePromote) Configuration(android.content.res.Configuration) BottomActionBar(com.orgzly.android.ui.BottomActionBar) Notifications(com.orgzly.android.ui.notifications.Notifications) LogUtils(com.orgzly.android.util.LogUtils) SavedSearchCreate(com.orgzly.android.usecase.SavedSearchCreate) BookForceSave(com.orgzly.android.usecase.BookForceSave) NoteUpdateDeadlineTime(com.orgzly.android.usecase.NoteUpdateDeadlineTime) SavedSearchExport(com.orgzly.android.usecase.SavedSearchExport) BookSparseTreeForNote(com.orgzly.android.usecase.BookSparseTreeForNote) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) View(android.view.View) NoteMove(com.orgzly.android.usecase.NoteMove) NoteUpdateStateToggle(com.orgzly.android.usecase.NoteUpdateStateToggle) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) Nullable(org.jetbrains.annotations.Nullable) Repo(com.orgzly.android.db.entity.Repo) List(java.util.List) App(com.orgzly.android.App) BookCreate(com.orgzly.android.usecase.BookCreate) Toolbar(androidx.appcompat.widget.Toolbar) BookPrefaceFragment(com.orgzly.android.ui.notes.book.BookPrefaceFragment) BookImportGettingStarted(com.orgzly.android.usecase.BookImportGettingStarted) SimpleOneLinerDialog(com.orgzly.android.ui.dialogs.SimpleOneLinerDialog) BooksFragment(com.orgzly.android.ui.books.BooksFragment) ReposActivity(com.orgzly.android.ui.repos.ReposActivity) NotNull(org.jetbrains.annotations.NotNull) Snackbar(com.google.android.material.snackbar.Snackbar) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) AutoSync(com.orgzly.android.sync.AutoSync) BookExport(com.orgzly.android.usecase.BookExport) Context(android.content.Context) UseCaseRunner(com.orgzly.android.usecase.UseCaseRunner) SavedSearchMoveDown(com.orgzly.android.usecase.SavedSearchMoveDown) NavigationView(com.google.android.material.navigation.NavigationView) Intent(android.content.Intent) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) DisplayManager(com.orgzly.android.ui.DisplayManager) AppPermissions(com.orgzly.android.util.AppPermissions) MenuItem(android.view.MenuItem) SettingsActivity(com.orgzly.android.ui.settings.SettingsActivity) Lifecycle(androidx.lifecycle.Lifecycle) NoteCut(com.orgzly.android.usecase.NoteCut) AppPreferences(com.orgzly.android.prefs.AppPreferences) LifecycleOwner(androidx.lifecycle.LifecycleOwner) AppIntent(com.orgzly.android.AppIntent) SavedSearchDelete(com.orgzly.android.usecase.SavedSearchDelete) Place(com.orgzly.android.ui.Place) OutputStream(java.io.OutputStream) SavedSearchesFragment(com.orgzly.android.ui.savedsearches.SavedSearchesFragment) NotesClipboard(com.orgzly.android.db.NotesClipboard) BookLinkUpdate(com.orgzly.android.usecase.BookLinkUpdate) GravityCompat(androidx.core.view.GravityCompat) SavedSearch(com.orgzly.android.db.entity.SavedSearch) ActionMode(androidx.appcompat.view.ActionMode) NotePlace(com.orgzly.android.ui.NotePlace) NoteCopy(com.orgzly.android.usecase.NoteCopy) UseCaseResult(com.orgzly.android.usecase.UseCaseResult) BookForceLoad(com.orgzly.android.usecase.BookForceLoad) Condition(com.orgzly.android.query.Condition) BookUpdatePreface(com.orgzly.android.usecase.BookUpdatePreface) NoteUpdateScheduledTime(com.orgzly.android.usecase.NoteUpdateScheduledTime) BookName(com.orgzly.android.BookName) NoteDao(com.orgzly.android.db.dao.NoteDao) DottedQueryBuilder(com.orgzly.android.query.user.DottedQueryBuilder) UseCase(com.orgzly.android.usecase.UseCase) UseCaseResult(com.orgzly.android.usecase.UseCaseResult) Intent(android.content.Intent) AppIntent(com.orgzly.android.AppIntent) NoteFindWithProperty(com.orgzly.android.usecase.NoteFindWithProperty) Repo(com.orgzly.android.db.entity.Repo) Book(com.orgzly.android.db.entity.Book) BookLinkUpdate(com.orgzly.android.usecase.BookLinkUpdate) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with Fragment

use of androidx.fragment.app.Fragment in project orgzly-android by orgzly.

the class DisplayManager method displayQuery.

public static void displayQuery(FragmentManager fragmentManager, @NonNull String queryString) {
    // If the same query is already displayed, don't do anything.
    String displayedQuery = getDisplayedQuery(fragmentManager);
    if (displayedQuery != null && displayedQuery.equals(queryString)) {
        return;
    }
    // Parse query
    QueryParser queryParser = new InternalQueryParser();
    Query query = queryParser.parse(queryString);
    Fragment fragment;
    String tag;
    // Display agenda or query fragment
    if (query.getOptions().getAgendaDays() > 0) {
        fragment = AgendaFragment.getInstance(queryString);
        tag = AgendaFragment.FRAGMENT_TAG;
    } else {
        fragment = SearchFragment.getInstance(queryString);
        tag = SearchFragment.FRAGMENT_TAG;
    }
    // Add fragment.
    fragmentManager.beginTransaction().setCustomAnimations(R.anim.fragment_enter, R.anim.fragment_exit, R.anim.fragment_enter, R.anim.fragment_exit).addToBackStack(null).replace(R.id.single_pane_container, fragment, tag).commit();
}
Also used : InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) QueryParser(com.orgzly.android.query.QueryParser) InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) Query(com.orgzly.android.query.Query) SearchFragment(com.orgzly.android.ui.notes.query.search.SearchFragment) AgendaFragment(com.orgzly.android.ui.notes.query.agenda.AgendaFragment) SavedSearchesFragment(com.orgzly.android.ui.savedsearches.SavedSearchesFragment) SavedSearchFragment(com.orgzly.android.ui.savedsearch.SavedSearchFragment) Fragment(androidx.fragment.app.Fragment) BookPrefaceFragment(com.orgzly.android.ui.notes.book.BookPrefaceFragment) BooksFragment(com.orgzly.android.ui.books.BooksFragment) NoteFragment(com.orgzly.android.ui.note.NoteFragment) BookFragment(com.orgzly.android.ui.notes.book.BookFragment)

Example 3 with Fragment

use of androidx.fragment.app.Fragment in project orgzly-android by orgzly.

the class DisplayManager method onSavedSearchEditRequest.

/**
 * Displays fragment for existing saved search.
 */
public static void onSavedSearchEditRequest(FragmentManager fragmentManager, long id) {
    /* Create fragment. */
    Fragment fragment = SavedSearchFragment.getInstance(id);
    /* Add fragment. */
    fragmentManager.beginTransaction().setCustomAnimations(R.anim.fragment_enter, R.anim.fragment_exit, R.anim.fragment_enter, R.anim.fragment_exit).addToBackStack(null).replace(R.id.single_pane_container, fragment, SavedSearchFragment.FRAGMENT_TAG).commit();
}
Also used : SearchFragment(com.orgzly.android.ui.notes.query.search.SearchFragment) AgendaFragment(com.orgzly.android.ui.notes.query.agenda.AgendaFragment) SavedSearchesFragment(com.orgzly.android.ui.savedsearches.SavedSearchesFragment) SavedSearchFragment(com.orgzly.android.ui.savedsearch.SavedSearchFragment) Fragment(androidx.fragment.app.Fragment) BookPrefaceFragment(com.orgzly.android.ui.notes.book.BookPrefaceFragment) BooksFragment(com.orgzly.android.ui.books.BooksFragment) NoteFragment(com.orgzly.android.ui.note.NoteFragment) BookFragment(com.orgzly.android.ui.notes.book.BookFragment)

Example 4 with Fragment

use of androidx.fragment.app.Fragment in project orgzly-android by orgzly.

the class DisplayManager method getDisplayedQuery.

public static String getDisplayedQuery(FragmentManager fragmentManager) {
    Fragment qf = fragmentManager.findFragmentByTag(SearchFragment.FRAGMENT_TAG);
    Fragment af = fragmentManager.findFragmentByTag(AgendaFragment.FRAGMENT_TAG);
    if (qf != null && qf.isVisible()) {
        return ((SearchFragment) qf).getCurrentQuery();
    } else if (af != null && af.isVisible()) {
        return ((AgendaFragment) af).getCurrentQuery();
    }
    return null;
}
Also used : SearchFragment(com.orgzly.android.ui.notes.query.search.SearchFragment) SavedSearchFragment(com.orgzly.android.ui.savedsearch.SavedSearchFragment) SearchFragment(com.orgzly.android.ui.notes.query.search.SearchFragment) AgendaFragment(com.orgzly.android.ui.notes.query.agenda.AgendaFragment) SavedSearchesFragment(com.orgzly.android.ui.savedsearches.SavedSearchesFragment) SavedSearchFragment(com.orgzly.android.ui.savedsearch.SavedSearchFragment) Fragment(androidx.fragment.app.Fragment) BookPrefaceFragment(com.orgzly.android.ui.notes.book.BookPrefaceFragment) BooksFragment(com.orgzly.android.ui.books.BooksFragment) NoteFragment(com.orgzly.android.ui.note.NoteFragment) BookFragment(com.orgzly.android.ui.notes.book.BookFragment)

Example 5 with Fragment

use of androidx.fragment.app.Fragment in project orgzly-android by orgzly.

the class DisplayManager method displaySavedSearches.

public static void displaySavedSearches(FragmentManager fragmentManager) {
    if (isFragmentDisplayed(fragmentManager, SavedSearchesFragment.getFRAGMENT_TAG()) != null) {
        return;
    }
    Fragment fragment = SavedSearchesFragment.getInstance();
    FragmentTransaction t = fragmentManager.beginTransaction().setCustomAnimations(R.anim.fragment_enter, R.anim.fragment_exit, R.anim.fragment_enter, R.anim.fragment_exit).addToBackStack(null).replace(R.id.single_pane_container, fragment, SavedSearchesFragment.getFRAGMENT_TAG());
    t.commit();
}
Also used : FragmentTransaction(androidx.fragment.app.FragmentTransaction) SearchFragment(com.orgzly.android.ui.notes.query.search.SearchFragment) AgendaFragment(com.orgzly.android.ui.notes.query.agenda.AgendaFragment) SavedSearchesFragment(com.orgzly.android.ui.savedsearches.SavedSearchesFragment) SavedSearchFragment(com.orgzly.android.ui.savedsearch.SavedSearchFragment) Fragment(androidx.fragment.app.Fragment) BookPrefaceFragment(com.orgzly.android.ui.notes.book.BookPrefaceFragment) BooksFragment(com.orgzly.android.ui.books.BooksFragment) NoteFragment(com.orgzly.android.ui.note.NoteFragment) BookFragment(com.orgzly.android.ui.notes.book.BookFragment)

Aggregations

Fragment (androidx.fragment.app.Fragment)239 FragmentTransaction (androidx.fragment.app.FragmentTransaction)54 Bundle (android.os.Bundle)46 FragmentManager (androidx.fragment.app.FragmentManager)38 FileFragment (com.owncloud.android.ui.fragment.FileFragment)23 DialogFragment (androidx.fragment.app.DialogFragment)22 View (android.view.View)21 FileDetailFragment (com.owncloud.android.ui.fragment.FileDetailFragment)20 OCFileListFragment (com.owncloud.android.ui.fragment.OCFileListFragment)20 Intent (android.content.Intent)19 SortingOrderDialogFragment (com.owncloud.android.ui.dialog.SortingOrderDialogFragment)19 GalleryFragment (com.owncloud.android.ui.fragment.GalleryFragment)18 TaskRetainerFragment (com.owncloud.android.ui.fragment.TaskRetainerFragment)18 UnifiedSearchFragment (com.owncloud.android.ui.fragment.UnifiedSearchFragment)18 PreviewImageFragment (com.owncloud.android.ui.preview.PreviewImageFragment)18 PreviewMediaFragment (com.owncloud.android.ui.preview.PreviewMediaFragment)18 PreviewTextFileFragment (com.owncloud.android.ui.preview.PreviewTextFileFragment)18 PreviewTextFragment (com.owncloud.android.ui.preview.PreviewTextFragment)18 PreviewTextStringFragment (com.owncloud.android.ui.preview.PreviewTextStringFragment)18 PreviewPdfFragment (com.owncloud.android.ui.preview.pdf.PreviewPdfFragment)18