Merge remote-tracking branch 'origin/enhance-category-handling' into enhance-category-handling

# Conflicts:
#	app/src/main/java/it/niedermann/owncloud/notes/android/fragment/CategoryDialogFragment.java
#	app/src/main/res/layout/dialog_change_category.xml
This commit is contained in:
stefan-niedermann 2020-01-24 18:23:04 +01:00
commit b446e17aca
3 changed files with 82 additions and 1 deletions

View file

@ -15,7 +15,6 @@ import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDialogFragment;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;

View file

@ -0,0 +1,71 @@
package it.niedermann.owncloud.notes.model;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import it.niedermann.owncloud.notes.R;
public class CategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<String> categoryList;
public CategoryAdapter() {
this.categoryList = new ArrayList<>();
}
/**
* Updates the item list and notifies respective view to update.
*
* @param categoryList List of items to be set
*/
public void setCategoryList(@NonNull List<String> categoryList) {
this.categoryList = categoryList;
notifyDataSetChanged();
}
/**
* Adds the given note to the top of the list.
*
* @param category Category that should be added.
*/
public void add(@NonNull String category) {
categoryList.add(0, category);
notifyItemInserted(0);
notifyItemChanged(0);
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new CategoryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.dialog_change_category_single, parent, false));
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
((CategoryViewHolder) holder).title.setText(categoryList.get(position));
}
@Override
public int getItemCount() {
return categoryList.size();
}
static class CategoryViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.title)
TextView title;
CategoryViewHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
}
}

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:padding="36dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Category" />
</LinearLayout>