Skip to content

Commit

Permalink
Refactoring and minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
xaverkapeller committed Mar 29, 2017
1 parent 9869974 commit ec401ed
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 29 deletions.
Expand Up @@ -27,7 +27,7 @@

public class MainActivity extends AppCompatActivity implements SearchView.OnQueryTextListener, SortedListAdapter.Callback {

private static final Comparator<WordModel> ALPHABETICAL_COMPARATOR = new SortedListAdapter.ComparatorBuilder<WordModel>()
private static final Comparator<WordModel> COMPARATOR = new SortedListAdapter.ComparatorBuilder<WordModel>()
.setOrderForModel(WordModel.class, new Comparator<WordModel>() {
@Override
public int compare(WordModel a, WordModel b) {
Expand All @@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {

setSupportActionBar(mBinding.toolBar);

mAdapter = new ExampleAdapter(this, ALPHABETICAL_COMPARATOR, new ExampleAdapter.Listener() {
mAdapter = new ExampleAdapter(this, COMPARATOR, new ExampleAdapter.Listener() {
@Override
public void onExampleModelClicked(WordModel model) {
final String message = getString(R.string.model_clicked_pattern, model.getRank(), model.getWord());
Expand Down
Expand Up @@ -18,12 +18,6 @@
*/
public class ExampleAdapter extends SortedListAdapter<WordModel> {

@Override
protected ViewHolder<? extends WordModel> onCreateViewHolder(LayoutInflater inflater, ViewGroup parent, int viewType) {
final ItemWordBinding binding = ItemWordBinding.inflate(inflater, parent, false);
return new WordViewHolder(binding, mListener);
}

public interface Listener {
void onExampleModelClicked(WordModel model);
}
Expand All @@ -34,4 +28,10 @@ public ExampleAdapter(Context context, Comparator<WordModel> comparator, Listene
super(context, WordModel.class, comparator);
mListener = listener;
}

@Override
protected ViewHolder<? extends WordModel> onCreateViewHolder(LayoutInflater inflater, ViewGroup parent, int viewType) {
final ItemWordBinding binding = ItemWordBinding.inflate(inflater, parent, false);
return new WordViewHolder(binding, mListener);
}
}
Expand Up @@ -31,25 +31,6 @@ public String getWord() {
return mWord;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

WordModel wordModel = (WordModel) o;

if (mRank != wordModel.mRank) return false;
return mWord != null ? mWord.equals(wordModel.mWord) : wordModel.mWord == null;

}

@Override
public int hashCode() {
int result = mRank;
result = 31 * result + (mWord != null ? mWord.hashCode() : 0);
return result;
}

@Override
public <T> boolean isSameModelAs(T item) {
if (item instanceof WordModel) {
Expand All @@ -62,7 +43,11 @@ public <T> boolean isSameModelAs(T item) {
@Override
public <T> boolean isContentTheSameAs(T item) {
if (item instanceof WordModel) {
return equals(item);
final WordModel other = (WordModel) item;
if (mRank != other.mRank) {
return false;
}
return mWord != null ? mWord.equals(other.mWord) : other.mWord == null;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -17,4 +17,4 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

0 comments on commit ec401ed

Please sign in to comment.