Skip to content

Commit

Permalink
#1277 Redesign note details
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Niedermann <info@niedermann.it>
  • Loading branch information
stefan-niedermann committed Jun 23, 2021
1 parent fc8baca commit bbf1a7d
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 362 deletions.
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
Expand Up @@ -35,23 +35,18 @@
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.details.NoteDetailsDialogFragment;
import it.niedermann.owncloud.notes.edit.title.EditTitleDialogFragment;
import it.niedermann.owncloud.notes.edit.title.EditTitleDialogFragment.EditTitleListener;
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.DBStatus;
import it.niedermann.owncloud.notes.shared.model.ISyncCallback;
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 it.niedermann.owncloud.notes.NotesApplication.isDarkThemeActive;

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();
Expand Down Expand Up @@ -284,22 +279,13 @@ public void onScheduled() {
}

@Override
public void onCategoryChosen(String category) {
repo.setCategory(localAccount, note.getId(), category);
public void onNoteDetailsEdited(String title, String category) {
titleModified = true;
note.setTitle(title);
note.setCategory(category);
listener.onNoteUpdated(note);
}

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

public void moveNote(Account account) {
final LiveData<Note> moveLiveData = repo.moveNoteToAnotherAccount(account, note);
moveLiveData.observe(this, (v) -> moveLiveData.removeObservers(this));
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import it.niedermann.owncloud.notes.branding.BrandedDialogFragment;
import it.niedermann.owncloud.notes.branding.BrandingUtil;
import it.niedermann.owncloud.notes.databinding.DialogChangeCategoryBinding;
import it.niedermann.owncloud.notes.edit.details.CategoryAdapter;
import it.niedermann.owncloud.notes.edit.details.CategoryViewModel;
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package it.niedermann.owncloud.notes.edit.details;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.databinding.ItemCategoryBinding;
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
import it.niedermann.owncloud.notes.shared.util.NoteUtil;

public class CategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

@NonNull
private final List<NavigationItem> categories = new ArrayList<>();
@NonNull
private final CategoryListener listener;
private final Context context;


public CategoryAdapter(@NonNull Context context, @NonNull CategoryListener categoryListener) {
this.context = context;
this.listener = categoryListener;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_category, parent, false);
return new CategoryViewHolder(v);
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
final NavigationItem category = categories.get(position);
final CategoryViewHolder categoryViewHolder = (CategoryViewHolder) holder;
categoryViewHolder.getIcon().setImageDrawable(ContextCompat.getDrawable(context, category.icon));
categoryViewHolder.getCategoryWrapper().setOnClickListener((v) -> listener.onCategoryChosen(category.label));
categoryViewHolder.getCategory().setText(NoteUtil.extendCategory(category.label));
if (category.count != null && category.count > 0) {
categoryViewHolder.getCount().setText(String.valueOf(category.count));
} else {
categoryViewHolder.getCount().setVisibility(View.GONE);
}
}

@Override
public int getItemCount() {
return categories.size();
}

static class CategoryViewHolder extends RecyclerView.ViewHolder {
private final ItemCategoryBinding binding;

private CategoryViewHolder(View view) {
super(view);
binding = ItemCategoryBinding.bind(view);
}

private View getCategoryWrapper() {
return binding.categoryWrapper;
}

private AppCompatImageView getIcon() {
return binding.icon;
}

private TextView getCategory() {
return binding.category;
}

private TextView getCount() {
return binding.count;
}
}

/**
* @deprecated use {@link #setCategoryList(List)}
*/
public void setCategoryList(List<NavigationItem.CategoryNavigationItem> categories, @Nullable String currentSearchString) {
setCategoryList(categories);
}

public void setCategoryList(@NonNull List<NavigationItem.CategoryNavigationItem> categories) {
this.categories.clear();
this.categories.addAll(categories);
notifyDataSetChanged();
}

public interface CategoryListener {
void onCategoryChosen(String category);

default void onCategoryAdded() {
}

default void onCategoryCleared() {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.niedermann.owncloud.notes.edit.category;
package it.niedermann.owncloud.notes.edit.details;

import android.app.Application;
import android.text.TextUtils;
Expand All @@ -13,6 +13,7 @@
import it.niedermann.owncloud.notes.main.navigation.NavigationItem;
import it.niedermann.owncloud.notes.persistence.NotesRepository;

import static androidx.lifecycle.Transformations.distinctUntilChanged;
import static androidx.lifecycle.Transformations.map;
import static androidx.lifecycle.Transformations.switchMap;
import static it.niedermann.owncloud.notes.shared.util.DisplayUtils.convertToCategoryNavigationItem;
Expand All @@ -35,7 +36,7 @@ public void postSearchTerm(@NonNull String searchTerm) {

@NonNull
public LiveData<List<NavigationItem.CategoryNavigationItem>> getCategories(long accountId) {
return switchMap(this.searchTerm, searchTerm ->
return switchMap(distinctUntilChanged(this.searchTerm), searchTerm ->
map(repo.searchCategories$(accountId, TextUtils.isEmpty(searchTerm) ? "%" : "%" + searchTerm + "%"),
categories -> convertToCategoryNavigationItem(getApplication(), categories)));
}
Expand Down
Loading

0 comments on commit bbf1a7d

Please sign in to comment.