/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2019 Tobias Kaminsky
* Copyright (C) 2019 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see
* MUST BE KEPT: the system uses it when tries to re-instantiate a fragment automatically (for instance, when the * device is turned a aside). *
* DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction */ public PreviewTextStringFragment() { super(); } /** * {@inheritDoc} */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); Bundle args = getArguments(); if (args.containsKey(FileDisplayActivity.EXTRA_SEARCH_QUERY)) { searchQuery = args.getString(FileDisplayActivity.EXTRA_SEARCH_QUERY); } searchOpen = args.getBoolean(FileDisplayActivity.EXTRA_SEARCH, false); handler = new Handler(); } /** * {@inheritDoc} */ @Override public void onSaveInstanceState(@NonNull Bundle outState) { outState.putParcelable(PreviewTextStringFragment.EXTRA_FILE, getFile()); super.onSaveInstanceState(outState); } @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); if (view == null) { throw new RuntimeException("View may not be null"); } FloatingActionButton fabMain = requireActivity().findViewById(R.id.fab_main); fabMain.setVisibility(View.VISIBLE); fabMain.setEnabled(true); fabMain.setOnClickListener(v -> edit()); ThemeUtils.colorFloatingActionButton(fabMain, R.drawable.ic_edit, requireContext()); return view; } /** * {@inheritDoc} */ @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MenuItem menuItem = menu.findItem(R.id.action_search); menuItem.setVisible(true); searchView = (SearchView) MenuItemCompat.getActionView(menuItem); searchView.setOnQueryTextListener(this); searchView.setMaxWidth(Integer.MAX_VALUE); if (searchOpen) { searchView.setIconified(false); searchView.setQuery(searchQuery, true); searchView.clearFocus(); } } void loadAndShowTextPreview() { originalText = getFile().getRichWorkspace(); setText(binding.textPreview, originalText, getFile(), requireActivity(), true, false); binding.textPreview.setVisibility(View.VISIBLE); binding.emptyListProgress.setVisibility(View.GONE); } private void edit() { new Thread(() -> { RemoteOperationResult result = new RichWorkspaceDirectEditingRemoteOperation(getFile().getRemotePath()) .execute(accountManager.getUser().toPlatformAccount(), getContext()); if (result.isSuccess()) { String url = (String) result.getSingleData(); containerActivity.getFileOperationsHelper().openRichWorkspaceWithTextEditor(getFile(), url, getContext()); } else { DisplayUtils.showSnackMessage(getView(), "Error"); } }).start(); } // TODO on close clean search query }