-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor example, removed copyright from xml
- Loading branch information
Showing
13 changed files
with
153 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
example/src/main/java/com/yheriatovych/reductor/example/NoteTouchCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.yheriatovych.reductor.example; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.support.v7.widget.helper.ItemTouchHelper; | ||
import rx.functions.Action1; | ||
|
||
class NoteTouchCallback extends ItemTouchHelper.SimpleCallback { | ||
private final Action1<Integer> onDismissed; | ||
public NoteTouchCallback(Action1<Integer> onDismissed) { | ||
super(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT); | ||
this.onDismissed = onDismissed; | ||
} | ||
|
||
@Override | ||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { | ||
int position = viewHolder.getAdapterPosition(); | ||
onDismissed.call(position); | ||
} | ||
|
||
@Override | ||
public boolean isItemViewSwipeEnabled() { | ||
return true; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
example/src/main/java/com/yheriatovych/reductor/example/NotesDiffCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.yheriatovych.reductor.example; | ||
|
||
import android.support.v7.util.DiffUtil; | ||
import com.yheriatovych.reductor.example.model.Note; | ||
|
||
import java.util.List; | ||
|
||
class NotesDiffCallback extends DiffUtil.Callback { | ||
private final List<Note> oldNotes; | ||
private final List<Note> newNotes; | ||
|
||
public NotesDiffCallback(List<Note> oldNotes, List<Note> newNotes) { | ||
this.oldNotes = oldNotes; | ||
this.newNotes = newNotes; | ||
} | ||
|
||
@Override | ||
public int getOldListSize() { | ||
return oldNotes.size(); | ||
} | ||
|
||
@Override | ||
public int getNewListSize() { | ||
return newNotes.size(); | ||
} | ||
|
||
@Override | ||
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { | ||
return oldNotes.get(oldItemPosition).id == newNotes.get(newItemPosition).id; | ||
} | ||
|
||
@Override | ||
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { | ||
return oldNotes.get(oldItemPosition).equals(newNotes.get(newItemPosition)); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
example/src/main/java/com/yheriatovych/reductor/example/TodoAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.yheriatovych.reductor.example; | ||
|
||
import android.support.v7.util.DiffUtil; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.CheckBox; | ||
import com.yheriatovych.reductor.example.model.Note; | ||
import rx.functions.Action1; | ||
|
||
import java.util.List; | ||
|
||
class TodoAdapter extends RecyclerView.Adapter<TodoAdapter.NoteViewHolder> { | ||
private List<Note> notes; | ||
private final Action1<Note> onClickListener; | ||
|
||
public TodoAdapter(List<Note> notes, Action1<Note> onClickListener) { | ||
this.notes = notes; | ||
this.onClickListener = onClickListener; | ||
} | ||
|
||
@Override | ||
public NoteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
return new NoteViewHolder(LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.layout_item, parent, false)); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(NoteViewHolder holder, int position) { | ||
final Note note = notes.get(position); | ||
holder.content.setText(note.note); | ||
holder.content.setChecked(note.checked); | ||
holder.itemView.setOnClickListener(view -> onClickListener.call(note)); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return notes.size(); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return notes.get(position).id; | ||
} | ||
|
||
public void setNotes(List<Note> notes) { | ||
List<Note> oldNotes = this.notes; | ||
this.notes = notes; | ||
DiffUtil.calculateDiff(new NotesDiffCallback(oldNotes, notes), false).dispatchUpdatesTo(this); | ||
} | ||
|
||
static class NoteViewHolder extends RecyclerView.ViewHolder { | ||
|
||
public CheckBox content; | ||
|
||
public NoteViewHolder(View itemView) { | ||
super(itemView); | ||
content = (CheckBox) itemView; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.