Browse Source

Open artists and albums in search results.

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
98b2b31e20
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 16
      app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt
  2. 2
      app/src/main/java/com/github/apognu/otter/adapters/PlaylistTracksAdapter.kt
  3. 19
      app/src/main/java/com/github/apognu/otter/adapters/SearchAdapter.kt
  4. 3
      app/src/main/java/com/github/apognu/otter/fragments/AlbumsFragment.kt
  5. 3
      app/src/main/java/com/github/apognu/otter/fragments/ArtistsFragment.kt
  6. 1
      app/src/main/res/layout-land/fragment_tracks.xml
  7. 128
      app/src/main/res/layout/activity_search.xml
  8. 3
      app/src/main/res/layout/fragment_tracks.xml

16
app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt

@ -6,7 +6,11 @@ import androidx.appcompat.app.AppCompatActivity @@ -6,7 +6,11 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.apognu.otter.R
import com.github.apognu.otter.adapters.SearchAdapter
import com.github.apognu.otter.fragments.AlbumsFragment
import com.github.apognu.otter.fragments.ArtistsFragment
import com.github.apognu.otter.repositories.*
import com.github.apognu.otter.utils.Album
import com.github.apognu.otter.utils.Artist
import com.github.apognu.otter.utils.untilNetwork
import kotlinx.android.synthetic.main.activity_search.*
import java.net.URLEncoder
@ -26,7 +30,7 @@ class SearchActivity : AppCompatActivity() { @@ -26,7 +30,7 @@ class SearchActivity : AppCompatActivity() {
setContentView(R.layout.activity_search)
adapter = SearchAdapter(this, FavoriteListener()).also {
adapter = SearchAdapter(this, SearchResultClickListener(), FavoriteListener()).also {
results.layoutManager = LinearLayoutManager(this)
results.adapter = it
}
@ -95,6 +99,16 @@ class SearchActivity : AppCompatActivity() { @@ -95,6 +99,16 @@ class SearchActivity : AppCompatActivity() {
})
}
inner class SearchResultClickListener : SearchAdapter.OnSearchResultClickListener {
override fun onArtistClick(holder: View?, artist: Artist) {
ArtistsFragment.openAlbums(this@SearchActivity, artist)
}
override fun onAlbumClick(holder: View?, album: Album) {
AlbumsFragment.openTracks(this@SearchActivity, album)
}
}
inner class FavoriteListener : SearchAdapter.OnFavoriteListener {
override fun onToggleFavorite(id: Int, state: Boolean) {
when (state) {

2
app/src/main/java/com/github/apognu/otter/adapters/PlaylistTracksAdapter.kt

@ -145,7 +145,7 @@ class PlaylistTracksAdapter(private val context: Context?, private val favoriteL @@ -145,7 +145,7 @@ class PlaylistTracksAdapter(private val context: Context?, private val favoriteL
CommandBus.send(Command.MoveFromQueue(oldPosition, newPosition))
}
inner class ViewHolder(view: View, val context: Context?) : RecyclerView.ViewHolder(view), View.OnClickListener {
inner class ViewHolder(view: View, val context: Context?) : RecyclerView.ViewHolder(view), View.OnClickListener {
val handle = view.handle
val cover = view.cover
val title = view.title

19
app/src/main/java/com/github/apognu/otter/adapters/SearchAdapter.kt

@ -16,7 +16,12 @@ import com.squareup.picasso.Picasso @@ -16,7 +16,12 @@ import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.row_track.view.*
class SearchAdapter(private val context: Context?, private val favoriteListener: OnFavoriteListener? = null) : RecyclerView.Adapter<SearchAdapter.ViewHolder>() {
class SearchAdapter(private val context: Context?, private val listener: OnSearchResultClickListener? = null, private val favoriteListener: OnFavoriteListener? = null) : RecyclerView.Adapter<SearchAdapter.ViewHolder>() {
interface OnSearchResultClickListener {
fun onArtistClick(holder: View?, artist: Artist)
fun onAlbumClick(holder: View?, album: Album)
}
interface OnFavoriteListener {
fun onToggleFavorite(id: Int, state: Boolean)
}
@ -188,6 +193,18 @@ class SearchAdapter(private val context: Context?, private val favoriteListener: @@ -188,6 +193,18 @@ class SearchAdapter(private val context: Context?, private val favoriteListener:
override fun onClick(view: View?) {
when (getItemViewType(layoutPosition)) {
ResultType.Artist.ordinal -> {
val position = layoutPosition - 1
listener?.onArtistClick(view, artists[position])
}
ResultType.Album.ordinal -> {
val position = layoutPosition - artists.size - 2
listener?.onAlbumClick(view, albums[position])
}
ResultType.Track.ordinal -> {
val position = layoutPosition - artists.size - albums.size - SECTION_COUNT

3
app/src/main/java/com/github/apognu/otter/fragments/AlbumsFragment.kt

@ -7,6 +7,7 @@ import android.util.DisplayMetrics @@ -7,6 +7,7 @@ import android.util.DisplayMetrics
import android.view.Gravity
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import androidx.appcompat.app.AppCompatActivity
import androidx.core.graphics.drawable.toDrawable
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
@ -60,7 +61,9 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() { @@ -60,7 +61,9 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() {
}
}
}
}
(context as? AppCompatActivity)?.let { activity ->
val fragment = TracksFragment.new(album).apply {
enterTransition = Slide().apply {
duration = AppContext.TRANSITION_DURATION

3
app/src/main/java/com/github/apognu/otter/fragments/ArtistsFragment.kt

@ -4,6 +4,7 @@ import android.content.Context @@ -4,6 +4,7 @@ import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import androidx.transition.Fade
@ -36,7 +37,9 @@ class ArtistsFragment : FunkwhaleFragment<Artist, ArtistsAdapter>() { @@ -36,7 +37,9 @@ class ArtistsFragment : FunkwhaleFragment<Artist, ArtistsAdapter>() {
}
}
}
}
(context as? AppCompatActivity)?.let { activity ->
val fragment = AlbumsFragment.new(artist, art).apply {
enterTransition = Slide().apply {
duration = AppContext.TRANSITION_DURATION

1
app/src/main/res/layout-land/fragment_tracks.xml

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
style="@style/AppTheme.Fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:transitionGroup="true">
<androidx.core.widget.NestedScrollView

128
app/src/main/res/layout/activity_search.xml

@ -1,71 +1,89 @@ @@ -1,71 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.SearchActivity">
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:elevation="4dp">
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context=".activities.SearchActivity">
<androidx.appcompat.widget.SearchView
android:id="@+id/search"
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:iconifiedByDefault="false"
app:queryBackground="@android:color/transparent"
app:queryHint="@string/search_placeholder" />
android:layout_margin="8dp"
android:elevation="4dp">
</androidx.cardview.widget.CardView>
<androidx.appcompat.widget.SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:iconifiedByDefault="false"
app:queryBackground="@android:color/transparent"
app:queryHint="@string/search_placeholder" />
<ProgressBar
android:id="@+id/search_spinner"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:indeterminate="true"
android:visibility="gone" />
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/search_empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:drawableTop="@drawable/ottericon"
android:drawablePadding="16dp"
android:drawableTint="#525252"
android:text="@string/search_welcome"
android:textAlignment="center"
android:textSize="14sp" />
<ProgressBar
android:id="@+id/search_spinner"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:layout_marginTop="16dp"
android:indeterminate="true"
android:visibility="gone" />
<TextView
android:id="@+id/search_no_results"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:drawableTop="@drawable/ottericon"
android:drawablePadding="16dp"
android:drawableTint="#525252"
android:text="@string/search_no_results"
android:textAlignment="center"
android:textSize="14sp"
android:visibility="gone" />
<TextView
android:id="@+id/search_empty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:drawableTop="@drawable/ottericon"
android:drawablePadding="16dp"
android:drawableTint="#525252"
android:text="@string/search_welcome"
android:textAlignment="center"
android:textSize="14sp" />
<TextView
android:id="@+id/search_no_results"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:drawableTop="@drawable/ottericon"
android:drawablePadding="16dp"
android:drawableTint="#525252"
android:text="@string/search_no_results"
android:textAlignment="center"
android:textSize="14sp"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/results"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:itemCount="10"
tools:listitem="@layout/row_track" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/results"
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:itemCount="10"
tools:listitem="@layout/row_track" />
</LinearLayout>
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

3
app/src/main/res/layout/fragment_tracks.xml

@ -6,6 +6,9 @@ @@ -6,6 +6,9 @@
style="@style/AppTheme.Fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:clipChildren="false"
android:clipToPadding="false"
android:transitionGroup="true">
<androidx.core.widget.NestedScrollView

Loading…
Cancel
Save