Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1277 Redesign note details #1278

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import androidx.lifecycle.MediatorLiveData;
import androidx.preference.PreferenceManager;

import com.google.android.material.textfield.TextInputLayout;

import it.niedermann.android.sharedpreferences.SharedPreferenceIntLiveData;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R;
Expand Down Expand Up @@ -161,4 +163,15 @@ public static void applyBrandToLayerDrawable(@NonNull LayerDrawable check, @IdRe
DrawableCompat.setTint(drawable, mainColor);
}
}

public static void applyBrandToEditTextInputLayout(@ColorInt int color, @NonNull TextInputLayout til) {
final int colorPrimary = ContextCompat.getColor(til.getContext(), R.color.primary);
final int colorAccent = ContextCompat.getColor(til.getContext(), R.color.accent);
final ColorStateList colorDanger = ColorStateList.valueOf(ContextCompat.getColor(til.getContext(), R.color.design_default_color_error));
til.setBoxStrokeColor(contrastRatioIsSufficient(color, colorPrimary) ? color : colorAccent);
til.setHintTextColor(ColorStateList.valueOf(contrastRatioIsSufficient(color, colorPrimary) ? color : colorAccent));
til.setErrorTextColor(colorDanger);
til.setBoxStrokeErrorColor(colorDanger);
til.setErrorIconTintList(colorDanger);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package it.niedermann.owncloud.notes.edit;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.Color;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
Expand Down Expand Up @@ -40,33 +35,22 @@
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.accountpicker.AccountPickerDialogFragment;
import it.niedermann.owncloud.notes.branding.BrandedFragment;
import it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment;
import it.niedermann.owncloud.notes.edit.category.CategoryDialogFragment.CategoryDialogListener;
import it.niedermann.owncloud.notes.edit.title.EditTitleDialogFragment;
import it.niedermann.owncloud.notes.edit.title.EditTitleDialogFragment.EditTitleListener;
import it.niedermann.owncloud.notes.edit.details.NoteDetailsDialogFragment;
import it.niedermann.owncloud.notes.persistence.NotesRepository;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.Note;
import it.niedermann.owncloud.notes.shared.model.ApiVersion;
import it.niedermann.owncloud.notes.shared.model.DBStatus;
import it.niedermann.owncloud.notes.shared.model.ISyncCallback;
import it.niedermann.owncloud.notes.shared.util.ApiVersionUtil;
import it.niedermann.owncloud.notes.shared.util.NoteUtil;
import it.niedermann.owncloud.notes.shared.util.NotesColorUtil;
import it.niedermann.owncloud.notes.shared.util.ShareUtil;

import static androidx.core.content.pm.ShortcutManagerCompat.isRequestPinShortcutSupported;
import static it.niedermann.owncloud.notes.NotesApplication.isDarkThemeActive;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.tintMenuIcon;
import static it.niedermann.owncloud.notes.edit.EditNoteActivity.ACTION_SHORTCUT;
import static java.lang.Boolean.TRUE;

public abstract class BaseNoteFragment extends BrandedFragment implements CategoryDialogListener, EditTitleListener {
public abstract class BaseNoteFragment extends BrandedFragment implements NoteDetailsDialogFragment.NoteDetailsListener {

private static final String TAG = BaseNoteFragment.class.getSimpleName();
protected final ExecutorService executor = Executors.newCachedThreadPool();

protected static final int MENU_ID_PIN = -1;
public static final String PARAM_NOTE_ID = "noteId";
public static final String PARAM_ACCOUNT_ID = "accountId";
public static final String PARAM_CONTENT = "content";
Expand Down Expand Up @@ -185,31 +169,9 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.menu_note_fragment, menu);

if (isRequestPinShortcutSupported(requireActivity()) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
menu.add(Menu.NONE, MENU_ID_PIN, 110, R.string.pin_to_homescreen);
}

super.onCreateOptionsMenu(menu, inflater);
}

@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
if (note != null) {
prepareFavoriteOption(menu.findItem(R.id.menu_favorite));

final ApiVersion preferredApiVersion = ApiVersionUtil.getPreferredApiVersion(localAccount.getApiVersion());
menu.findItem(R.id.menu_title).setVisible(preferredApiVersion != null && preferredApiVersion.compareTo(ApiVersion.API_VERSION_1_0) >= 0);
menu.findItem(R.id.menu_delete).setVisible(!isNew);
}
}

private void prepareFavoriteOption(MenuItem item) {
item.setIcon(TRUE.equals(note.getFavorite()) ? R.drawable.ic_star_white_24dp : R.drawable.ic_star_border_white_24dp);
item.setChecked(note.getFavorite());
tintMenuIcon(item, colorAccent);
}

/**
* Main-Menu-Handler
*/
Expand All @@ -230,46 +192,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
repo.deleteNoteAndSync(localAccount, note.getId());
listener.close();
return true;
} else if (itemId == R.id.menu_favorite) {
repo.toggleFavoriteAndSync(localAccount, note.getId());
listener.onNoteUpdated(note);
prepareFavoriteOption(item);
return true;
} else if (itemId == R.id.menu_category) {
showCategorySelector();
return true;
} else if (itemId == R.id.menu_title) {
showEditTitleDialog();
return true;
} else if (itemId == R.id.menu_move) {
executor.submit(() -> AccountPickerDialogFragment
.newInstance(new ArrayList<>(repo.getAccounts()), note.getAccountId())
.show(requireActivity().getSupportFragmentManager(), BaseNoteFragment.class.getSimpleName()));
return true;
} else if (itemId == R.id.menu_share) {
ShareUtil.openShareDialog(requireContext(), note.getTitle(), note.getContent());
return false;
} else if (itemId == MENU_ID_PIN) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final ShortcutManager shortcutManager = requireActivity().getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
if (shortcutManager.isRequestPinShortcutSupported()) {
final ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(getActivity(), note.getId() + "")
.setShortLabel(note.getTitle())
.setIcon(Icon.createWithResource(requireActivity().getApplicationContext(), TRUE.equals(note.getFavorite()) ? R.drawable.ic_star_yellow_24dp : R.drawable.ic_star_grey_ccc_24dp))
.setIntent(new Intent(getActivity(), EditNoteActivity.class).putExtra(EditNoteActivity.PARAM_NOTE_ID, note.getId()).setAction(ACTION_SHORTCUT))
.build();

shortcutManager.requestPinShortcut(pinShortcutInfo, PendingIntent.getBroadcast(getActivity(), 0, shortcutManager.createShortcutResultIntent(pinShortcutInfo), 0).getIntentSender());
} else {
Log.i(TAG, "RequestPinShortcut is not supported");
}
} else {
Log.e(TAG, ShortcutManager.class.getSimpleName() + " is null");
}
}

return true;
}
return super.onOptionsItemSelected(item);
}
Expand Down Expand Up @@ -312,6 +239,7 @@ protected void saveNote(@Nullable ISyncCallback callback) {
} else {
Log.v(TAG, "... not saving, since nothing has changed");
}
if (callback != null) callback.onScheduled();
} else {
// FIXME requires database queries on main thread!
note = repo.updateNoteAndSync(localAccount, note, newContent, null, callback);
Expand All @@ -328,49 +256,34 @@ protected void saveNote(@Nullable ISyncCallback callback) {
/**
* Opens a dialog in order to chose a category
*/
private void showCategorySelector() {
final String fragmentId = "fragment_category";
FragmentManager manager = requireActivity().getSupportFragmentManager();
Fragment frag = manager.findFragmentByTag(fragmentId);
if (frag != null) {
manager.beginTransaction().remove(frag).commit();
}
final DialogFragment categoryFragment = CategoryDialogFragment.newInstance(note.getAccountId(), note.getCategory());
categoryFragment.setTargetFragment(this, 0);
categoryFragment.show(manager, fragmentId);
}
public void showNoteDetailsDialog() {
saveNote(new ISyncCallback() {
@Override
public void onFinish() {

/**
* Opens a dialog in order to chose a category
*/
public void showEditTitleDialog() {
saveNote(null);
final String fragmentId = "fragment_edit_title";
FragmentManager manager = requireActivity().getSupportFragmentManager();
Fragment frag = manager.findFragmentByTag(fragmentId);
if (frag != null) {
manager.beginTransaction().remove(frag).commit();
}
DialogFragment editTitleFragment = EditTitleDialogFragment.newInstance(note.getTitle());
editTitleFragment.setTargetFragment(this, 0);
editTitleFragment.show(manager, fragmentId);
}
}

@Override
public void onCategoryChosen(String category) {
repo.setCategory(localAccount, note.getId(), category);
note.setCategory(category);
listener.onNoteUpdated(note);
@Override
public void onScheduled() {
final String fragmentId = "fragment_note_details";
final FragmentManager manager = requireActivity().getSupportFragmentManager();
Fragment frag = manager.findFragmentByTag(fragmentId);
if (frag != null) {
manager.beginTransaction().remove(frag).commit();
}
DialogFragment noteDetailsFragment = NoteDetailsDialogFragment.newInstance(localAccount, note.getId());
noteDetailsFragment.setTargetFragment(BaseNoteFragment.this, 0);
noteDetailsFragment.show(manager, fragmentId);
}
});
}

@Override
public void onTitleEdited(String newTitle) {
public void onNoteDetailsEdited(String title, String category) {
titleModified = true;
note.setTitle(newTitle);
executor.submit(() -> {
note = repo.updateNoteAndSync(localAccount, note, note.getContent(), newTitle, null);
requireActivity().runOnUiThread(() -> listener.onNoteUpdated(note));
});
note.setTitle(title);
note.setCategory(category);
listener.onNoteUpdated(note);
}

public void moveNote(Account account) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.accountpicker.AccountPickerListener;
import it.niedermann.owncloud.notes.databinding.ActivityEditBinding;
import it.niedermann.owncloud.notes.databinding.ActivityEditBinding;
import it.niedermann.owncloud.notes.edit.category.CategoryViewModel;
import it.niedermann.owncloud.notes.edit.details.CategoryViewModel;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.Note;
import it.niedermann.owncloud.notes.shared.model.DBStatus;
import it.niedermann.owncloud.notes.shared.model.NavigationCategory;
import it.niedermann.owncloud.notes.shared.util.NoteUtil;
import it.niedermann.owncloud.notes.shared.util.ShareUtil;
Expand Down Expand Up @@ -84,7 +82,7 @@ protected void onCreate(final Bundle savedInstanceState) {
}

setSupportActionBar(binding.toolbar);
binding.toolbar.setOnClickListener((v) -> fragment.showEditTitleDialog());
binding.toolbar.setOnClickListener((v) -> fragment.showNoteDetailsDialog());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ public class NoteReadonlyFragment extends NotePreviewFragment {
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_favorite).setVisible(false);
menu.findItem(R.id.menu_edit).setVisible(false);
menu.findItem(R.id.menu_preview).setVisible(false);
menu.findItem(R.id.menu_cancel).setVisible(false);
menu.findItem(R.id.menu_delete).setVisible(false);
menu.findItem(R.id.menu_share).setVisible(false);
menu.findItem(R.id.menu_move).setVisible(false);
menu.findItem(R.id.menu_category).setVisible(false);
menu.findItem(R.id.menu_title).setVisible(false);
if (menu.findItem(MENU_ID_PIN) != null)
menu.findItem(MENU_ID_PIN).setVisible(false);
}

@Nullable
Expand All @@ -44,11 +38,6 @@ protected void registerInternalNoteLinkHandler() {
// Do nothing
}

@Override
public void showEditTitleDialog() {
// Do nothing
}

@Override
public void onCloseNote() {
// Do nothing
Expand Down
Loading