Functionality to search songs is operational. Next step is to work on the styling of the searchbar. Currently it is barely visible due to the color and the sizing #44
This commit is contained in:
@@ -5,6 +5,7 @@ import android.os.Bundle
|
|||||||
import android.support.annotation.RequiresApi
|
import android.support.annotation.RequiresApi
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.SearchView
|
||||||
|
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
import kotlinx.android.synthetic.main.activity_song_view.*
|
import kotlinx.android.synthetic.main.activity_song_view.*
|
||||||
@@ -14,6 +15,9 @@ import com.example.mear.adapters.RecyclerAdapter
|
|||||||
import com.example.mear.models.TrackItems
|
import com.example.mear.models.TrackItems
|
||||||
import com.example.mear.R
|
import com.example.mear.R
|
||||||
import com.example.mear.repositories.TrackRepository
|
import com.example.mear.repositories.TrackRepository
|
||||||
|
import android.R as RDroid
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SongViewActivity : BaseServiceActivity() {
|
class SongViewActivity : BaseServiceActivity() {
|
||||||
|
|
||||||
@@ -33,6 +37,7 @@ class SongViewActivity : BaseServiceActivity() {
|
|||||||
window.statusBarColor = resources.getColor(R.color.track_seek)
|
window.statusBarColor = resources.getColor(R.color.track_seek)
|
||||||
doBindService()
|
doBindService()
|
||||||
initializeAdapter()
|
initializeAdapter()
|
||||||
|
initializeSongSearchListener()
|
||||||
}
|
}
|
||||||
catch (ex: Exception) {
|
catch (ex: Exception) {
|
||||||
var exMsg = ex.message
|
var exMsg = ex.message
|
||||||
@@ -47,6 +52,10 @@ class SongViewActivity : BaseServiceActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun playTrack(trackItems: TrackItems) {
|
||||||
|
val id = trackItems.id
|
||||||
|
musicService!!.playTrack(id)
|
||||||
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N)
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
private fun initializeAdapter() {
|
private fun initializeAdapter() {
|
||||||
@@ -58,10 +67,9 @@ class SongViewActivity : BaseServiceActivity() {
|
|||||||
|
|
||||||
adapter = RecyclerAdapter({trackItem: TrackItems -> playTrack(trackItem)}, trackListItems)
|
adapter = RecyclerAdapter({trackItem: TrackItems -> playTrack(trackItem)}, trackListItems)
|
||||||
adapter.configureActivity(this)
|
adapter.configureActivity(this)
|
||||||
|
|
||||||
trackList.adapter = adapter
|
trackList.adapter = adapter
|
||||||
trackList.setOnClickListener {
|
|
||||||
val temp = "dddd"
|
|
||||||
}
|
|
||||||
trackList.setHasFixedSize(true)
|
trackList.setHasFixedSize(true)
|
||||||
trackList.setItemViewCacheSize(20);
|
trackList.setItemViewCacheSize(20);
|
||||||
trackList.setDrawingCacheEnabled(true);
|
trackList.setDrawingCacheEnabled(true);
|
||||||
@@ -94,8 +102,23 @@ class SongViewActivity : BaseServiceActivity() {
|
|||||||
return trackItems!!
|
return trackItems!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playTrack(trackItems: TrackItems) {
|
private fun initializeSongSearchListener() {
|
||||||
val id = trackItems.id
|
songSearch.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||||
musicService!!.playTrack(id)
|
override fun onQueryTextSubmit(query: String): Boolean {
|
||||||
|
try {
|
||||||
|
adapter.filter.filter(query)
|
||||||
|
}
|
||||||
|
catch (ex: Exception) {
|
||||||
|
val exMsg = ex.message
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onQueryTextChange(newText: String): Boolean {
|
||||||
|
// TODO: Implement text change
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import android.app.Activity
|
|||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.Filter
|
||||||
|
import android.widget.Filterable
|
||||||
|
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
import kotlinx.android.synthetic.main.fragment_song_view.view.*
|
import kotlinx.android.synthetic.main.fragment_song_view.view.*
|
||||||
@@ -16,26 +18,62 @@ import com.example.mear.models.TrackItems
|
|||||||
import com.example.mear.R
|
import com.example.mear.R
|
||||||
|
|
||||||
|
|
||||||
class RecyclerAdapter(val mOnClickListenerI: (TrackItems) -> Unit , private val trackItemsSourceInit: ArrayList<TrackItems>) :
|
class RecyclerAdapter(val mOnClickListenerI: (TrackItems) -> Unit,
|
||||||
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
var trackItemsSourceInit: ArrayList<TrackItems>):
|
||||||
|
RecyclerView.Adapter<RecyclerAdapter.TrackItemsHolder>(), Filterable {
|
||||||
|
|
||||||
open interface trackItemClickListener{
|
var allTrackItems = trackItemsSourceInit
|
||||||
fun onClick(view: View)
|
val adp = this
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: TrackItemsHolder, position: Int) {
|
||||||
|
val itemPhoto = trackItemsSourceInit!![position]
|
||||||
|
holder.bindTrackItems(itemPhoto, mOnClickListenerI)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, position: Int): TrackItemsHolder {
|
||||||
|
val inflatedView = parent.inflate(R.layout.fragment_song_view, false)
|
||||||
|
return TrackItemsHolder(inflatedView)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getFilter(): Filter {
|
||||||
|
return object: Filter() {
|
||||||
|
override fun performFiltering(constraint: CharSequence?): FilterResults {
|
||||||
|
val fr = FilterResults()
|
||||||
|
|
||||||
|
val sortedList = mutableListOf<TrackItems>()
|
||||||
|
|
||||||
|
for (trackItm in allTrackItems) {
|
||||||
|
if (trackItm.artistTitle.contains(constraint!!, true) ||
|
||||||
|
trackItm.trackTitle.contains(constraint!!, true)) {
|
||||||
|
sortedList.add(trackItm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fr.count = sortedList.size
|
||||||
|
fr.values = sortedList
|
||||||
|
|
||||||
|
return fr
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
|
||||||
|
try {
|
||||||
|
val itms = results!!.values as ArrayList<TrackItems>
|
||||||
|
|
||||||
|
adp.trackItemsSourceInit = itms
|
||||||
|
}
|
||||||
|
catch (ex: Exception) {
|
||||||
|
val exMsg = ex.message
|
||||||
|
}
|
||||||
|
|
||||||
|
adp.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
return trackItemsSourceInit!!.size
|
return trackItemsSourceInit!!.size
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
|
||||||
val itemPhoto = trackItemsSourceInit!![position]
|
|
||||||
(holder as TrackItemsHolder).bindTrackItems(itemPhoto, mOnClickListenerI)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, position: Int): RecyclerView.ViewHolder {
|
|
||||||
val inflatedView = parent.inflate(R.layout.fragment_song_view, false)
|
|
||||||
return TrackItemsHolder(inflatedView)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun configureActivity(actvity: Activity) {
|
fun configureActivity(actvity: Activity) {
|
||||||
}
|
}
|
||||||
@@ -48,27 +86,27 @@ class RecyclerAdapter(val mOnClickListenerI: (TrackItems) -> Unit , private va
|
|||||||
private val imgHeight = 90
|
private val imgHeight = 90
|
||||||
private var mBound = false
|
private var mBound = false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun bindTrackItems(trackItems: TrackItems, clickList: (TrackItems) -> Unit) {
|
fun bindTrackItems(trackItems: TrackItems, clickList: (TrackItems) -> Unit) {
|
||||||
try {
|
try {
|
||||||
var context = view.context
|
var context = view.context
|
||||||
|
|
||||||
this.trackItem = trackItems
|
this.trackItem = trackItems
|
||||||
|
|
||||||
view.trackTitle.text = trackItem!!.trackTitle
|
view.trackTitle.text = trackItem!!.trackTitle
|
||||||
view.trackArtist.text = trackItem!!.artistTitle
|
view.trackArtist.text = trackItem!!.artistTitle
|
||||||
|
|
||||||
val id = trackItems.id
|
val id = trackItems.id
|
||||||
|
|
||||||
var trackCoverPath = "${context.filesDir}/${Filenames.TRACK_COVERS}"
|
var trackCoverPath = "${context.filesDir}/${Filenames.TRACK_COVERS}"
|
||||||
trackCoverPath = "${trackCoverPath}${id}.bmp"
|
trackCoverPath = "${trackCoverPath}${id}.bmp"
|
||||||
|
|
||||||
Picasso.get().load(trackCoverPath).into(view.trackCover)
|
Picasso.get().load(trackCoverPath).into(view.trackCover)
|
||||||
|
|
||||||
view.setOnClickListener { clickList(trackItem!!) }
|
view.setOnClickListener { clickList(trackItem!!) }
|
||||||
}
|
}
|
||||||
catch (ex:Exception) {
|
catch (ex:Exception) {
|
||||||
val exMsg = ex.message
|
val exMsg = ex.message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,15 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<SearchView
|
||||||
|
android:id="@+id/songSearch"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/trackList"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/space2"
|
||||||
|
tools:layout_editor_absoluteX="8dp" />
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/trackList"
|
android:id="@+id/trackList"
|
||||||
marginTop="?android:attr/actionBarSize"
|
marginTop="?android:attr/actionBarSize"
|
||||||
|
|||||||
Reference in New Issue
Block a user