2019-08-19 16:50:33 +02:00
|
|
|
package com.github.apognu.otter.fragments
|
|
|
|
|
|
|
|
import android.view.View
|
|
|
|
import android.view.animation.AccelerateDecelerateInterpolator
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import androidx.transition.Fade
|
|
|
|
import androidx.transition.Slide
|
|
|
|
import com.github.apognu.otter.R
|
|
|
|
import com.github.apognu.otter.activities.MainActivity
|
|
|
|
import com.github.apognu.otter.adapters.PlaylistsAdapter
|
2020-07-13 23:32:42 +02:00
|
|
|
import com.github.apognu.otter.models.api.FunkwhalePlaylist
|
|
|
|
import com.github.apognu.otter.models.dao.PlaylistEntity
|
2020-07-17 16:23:49 +02:00
|
|
|
import com.github.apognu.otter.repositories.FavoritesRepository
|
2019-08-19 16:50:33 +02:00
|
|
|
import com.github.apognu.otter.repositories.PlaylistsRepository
|
|
|
|
import com.github.apognu.otter.utils.AppContext
|
2020-07-13 23:32:42 +02:00
|
|
|
import com.github.apognu.otter.viewmodels.PlaylistsViewModel
|
2019-08-19 16:50:33 +02:00
|
|
|
import kotlinx.android.synthetic.main.fragment_playlists.*
|
2020-07-17 16:23:49 +02:00
|
|
|
import org.koin.android.ext.android.inject
|
|
|
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
|
|
|
import org.koin.core.parameter.parametersOf
|
2019-08-19 16:50:33 +02:00
|
|
|
|
2020-08-03 15:22:52 +02:00
|
|
|
class PlaylistsFragment : OtterFragment<FunkwhalePlaylist, PlaylistEntity, PlaylistsAdapter>() {
|
2020-07-17 16:23:49 +02:00
|
|
|
override val repository by inject<PlaylistsRepository>()
|
|
|
|
override val adapter by inject<PlaylistsAdapter> { parametersOf(context, OnPlaylistClickListener()) }
|
|
|
|
override val viewModel by viewModel<PlaylistsViewModel>()
|
|
|
|
override val liveData by lazy { viewModel.playlists }
|
|
|
|
|
2019-08-19 16:50:33 +02:00
|
|
|
override val viewRes = R.layout.fragment_playlists
|
|
|
|
override val recycler: RecyclerView get() = playlists
|
2020-07-10 20:28:44 +02:00
|
|
|
override val alwaysRefresh = false
|
2019-08-19 16:50:33 +02:00
|
|
|
|
2020-07-17 16:23:49 +02:00
|
|
|
private val favoritesRepository by inject<FavoritesRepository>()
|
2019-08-19 16:50:33 +02:00
|
|
|
|
|
|
|
inner class OnPlaylistClickListener : PlaylistsAdapter.OnPlaylistClickListener {
|
2020-07-13 23:32:42 +02:00
|
|
|
override fun onClick(holder: View?, playlist: PlaylistEntity) {
|
2019-08-19 16:50:33 +02:00
|
|
|
(context as? MainActivity)?.let { activity ->
|
|
|
|
exitTransition = Fade().apply {
|
|
|
|
duration = AppContext.TRANSITION_DURATION
|
|
|
|
interpolator = AccelerateDecelerateInterpolator()
|
|
|
|
|
|
|
|
view?.let {
|
|
|
|
addTarget(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-17 16:23:49 +02:00
|
|
|
val fragment = PlaylistTracksFragment.new(playlist, favoritesRepository).apply {
|
2019-08-19 16:50:33 +02:00
|
|
|
enterTransition = Slide().apply {
|
|
|
|
duration = AppContext.TRANSITION_DURATION
|
|
|
|
interpolator = AccelerateDecelerateInterpolator()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
activity.supportFragmentManager
|
|
|
|
.beginTransaction()
|
|
|
|
.replace(R.id.container, fragment)
|
|
|
|
.addToBackStack(null)
|
|
|
|
.commit()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|