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
App Git Repo | |
https://github.com/AmaroNeto/Campina | |
ssh: git@github.com:AmaroNeto/Campina.git | |
http: https://github.com/AmaroNeto/Campina.git | |
Server Git Repo | |
https://github.com/jflima/campina_server |
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
interface AdapterObject { | |
fun layoutId() : Int | |
fun isFilterable(filter: String) : Boolean | |
} |
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
class Movie( | |
val title: String, | |
val year: Int, | |
val director: String, | |
val studio: String): AdapterObject { | |
override fun layoutId(): Int { | |
return R.layout.movie_item_list | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools"> | |
<data> | |
<variable | |
name="model" | |
type="com.example.genericadapter.Movie"/> | |
</data> |
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
class GenericAdapter<T: AdapterObject>(val mList : List<T>) : | |
RecyclerView.Adapter<GenericAdapter<T>.ViewHolder<ViewDataBinding>>(), Filterable { | |
private var searchList : List<T> | |
var listener : AppAdapterListener<T>? = null | |
interface AppAdapterListener<T> { | |
fun onItemClick(model: T, position: Int) | |
} |
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
class GenericAdapter<T: AdapterObject>(val mList : List<T>) : | |
RecyclerView.Adapter<GenericAdapter<T>.ViewHolder<ViewDataBinding>>(), Filterable { |
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
var listener : AppAdapterListener<T>? = null | |
interface AppAdapterListener<T> { | |
fun onItemClick(model: T, position: Int) | |
} |
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
override fun getFilter(): Filter { | |
return object : Filter() { | |
override fun performFiltering(constraint: CharSequence?): FilterResults { | |
val charString = constraint.toString() | |
var searchResult: List<T> = listOf() | |
if(charString.isEmpty()) { | |
searchResult = mList | |
} else { | |
val filteredList = ArrayList<T>() | |
mList.forEach {row -> |
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
class MainActivity: AppCompatActivity(), GenericAdapter.AppAdapterListener<Movie> { | |
private lateinit var recyclerView: RecyclerView | |
private lateinit var searchView: SearchView | |
private var adapter: GenericAdapter<Movie>? = null | |
// ... | |
private fun setupAdapter(movies: List<Movie>) { | |
adapter = GenericAdapter<Movie>(movies) |
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
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : ViewHolder<ViewDataBinding> { | |
val bind : ViewDataBinding = DataBindingUtil.bind(LayoutInflater | |
.from(parent.context) | |
.inflate(viewType,parent,false))!! | |
return ViewHolder(bind) | |
} |
OlderNewer