-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Roaim/search
search
- Loading branch information
Showing
8 changed files
with
316 additions
and
15 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
105 changes: 105 additions & 0 deletions
105
app/src/main/java/com/roaimsapp/findit/adapter/SearchAdapter.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,105 @@ | ||
package com.roaimsapp.findit.adapter; | ||
|
||
import android.databinding.DataBindingUtil; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.ViewGroup; | ||
|
||
import com.roaimsapp.findit.R; | ||
import com.roaimsapp.findit.adapter.viewholder.NumberViewHolder; | ||
import com.roaimsapp.findit.adapter.viewholder.SearchViewHolder; | ||
import com.roaimsapp.findit.data.model.Number; | ||
import com.roaimsapp.findit.databinding.ItemNumberBinding; | ||
import com.roaimsapp.findit.databinding.ItemSearchBinding; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by Roaim on 21-Jul-18. | ||
*/ | ||
|
||
public class SearchAdapter extends RecyclerView.Adapter<SearchViewHolder> { | ||
private List<Number> mList; | ||
private int length; | ||
|
||
public void setLength(int length) { | ||
this.length = length; | ||
} | ||
|
||
public SearchAdapter() { | ||
mList = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public SearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||
LayoutInflater inflater = LayoutInflater.from(parent.getContext()); | ||
ItemSearchBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_search, parent, false); | ||
return new SearchViewHolder(binding); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull SearchViewHolder holder, int position) { | ||
Number number = getNumber(position); | ||
holder.bind(number, length); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mList.size(); | ||
} | ||
|
||
public Number getNumber(int position) { | ||
return mList.get(position); | ||
} | ||
|
||
public int getIndexOf(Number number) { | ||
return mList.indexOf(number); | ||
} | ||
|
||
public void update(Number number, int index) { | ||
mList.set(index, number); | ||
} | ||
|
||
public void update(int startIndex, Number... numbers) { | ||
for (int i = 0; i < numbers.length; i++) { | ||
int index = startIndex - 1 - i; | ||
mList.set(index, numbers[i]); | ||
} | ||
} | ||
|
||
public void update(Number... numbers) { | ||
for (int i = 0; i < numbers.length; i++) { | ||
int index = mList.size() - 1 - i; | ||
mList.set(index, numbers[i]); | ||
} | ||
} | ||
|
||
public void addAll(List<Number> list) { | ||
clear(); | ||
mList.addAll(list); | ||
notifyDataSetChanged(); | ||
} | ||
|
||
public void addNumber(Number number) { | ||
mList.add(number); | ||
} | ||
|
||
public void removeNumber(Number number) { | ||
mList.remove(number); | ||
} | ||
|
||
@Override | ||
public void onViewDetachedFromWindow(SearchViewHolder holder) { | ||
super.onViewDetachedFromWindow(holder); | ||
holder.unBind(); | ||
} | ||
|
||
public void clear() { | ||
if (!mList.isEmpty()) { | ||
mList.removeAll(mList); | ||
} | ||
notifyDataSetChanged(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/roaimsapp/findit/adapter/viewholder/SearchViewHolder.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,35 @@ | ||
package com.roaimsapp.findit.adapter.viewholder; | ||
|
||
import com.roaimsapp.findit.data.model.Number; | ||
import com.roaimsapp.findit.databinding.ItemSearchBinding; | ||
|
||
/** | ||
* Created by Roaim on 22-Jul-18. | ||
*/ | ||
|
||
public class SearchViewHolder extends BaseViewHolder<ItemSearchBinding> { | ||
|
||
public SearchViewHolder(ItemSearchBinding binding) { | ||
super(binding); | ||
} | ||
|
||
public void bind(Number number, int length) { | ||
// binding.setNumber(number); | ||
binding.setPrev(number.getPrev()); | ||
switch (length) { | ||
case 1: | ||
binding.setSearch(number.getNumber()); | ||
binding.setNext(number.getNext1()); | ||
break; | ||
case 2: | ||
binding.setSearch(number.getNumber() + " " + number.getNext1()); | ||
binding.setNext(number.getNext2()); | ||
break; | ||
case 3: | ||
binding.setSearch(number.getNumber() + " " + number.getNext1() + " " + number.getNext2()); | ||
binding.setNext(number.getNext3()); | ||
} | ||
binding.executePendingBindings(); | ||
} | ||
|
||
} |
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.