Improve home layout and clean up code
This commit is contained in:
parent
f276a26d7d
commit
6a2469ca97
9 changed files with 28 additions and 17 deletions
|
@ -39,7 +39,7 @@ android {
|
|||
|
||||
dependencies {
|
||||
def room_version = "2.3.0"
|
||||
def jellyfin_version = "1.0.0-beta.7"
|
||||
def jellyfin_version = "1.0.0-beta.8"
|
||||
|
||||
implementation 'androidx.core:core-ktx:1.5.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.3.0'
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="dev.jdtech.jellyfin">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
|
|
@ -6,13 +6,13 @@ import android.widget.ImageView
|
|||
import androidx.databinding.BindingAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import dev.jdtech.jellyfin.database.Server
|
||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||
import dev.jdtech.jellyfin.adapters.ServerGridAdapter
|
||||
import dev.jdtech.jellyfin.adapters.ViewItemListAdapter
|
||||
import dev.jdtech.jellyfin.adapters.ViewListAdapter
|
||||
import dev.jdtech.jellyfin.database.Server
|
||||
import dev.jdtech.jellyfin.models.View
|
||||
import dev.jdtech.jellyfin.models.ViewItem
|
||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||
|
||||
@BindingAdapter("servers")
|
||||
fun bindServers(recyclerView: RecyclerView, data: List<Server>?) {
|
||||
|
@ -37,6 +37,7 @@ fun bindItemImage(imageView: ImageView, item: ViewItem) {
|
|||
Glide
|
||||
.with(imageView.context)
|
||||
.load(item.primaryImageUrl)
|
||||
.placeholder(ColorDrawable(Color.GRAY))
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.placeholder(R.color.neutral_800)
|
||||
.into(imageView)
|
||||
}
|
|
@ -32,10 +32,6 @@ class JellyfinApi(context: Context, baseUrl: String) {
|
|||
val itemsApi = ItemsApi(api)
|
||||
val userLibraryApi = UserLibraryApi(api)
|
||||
|
||||
init {
|
||||
Log.i("JellyfinApi", "Constructor called!")
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
private var INSTANCE: JellyfinApi? = null
|
||||
|
|
|
@ -36,8 +36,6 @@ class ServerSelectFragment : Fragment() {
|
|||
binding.viewModel = viewModel
|
||||
binding.serversRecyclerView.adapter =
|
||||
ServerGridAdapter(ServerGridAdapter.OnClickListener { server ->
|
||||
Toast.makeText(application, "You selected server $server", Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
viewModel.connectToServer(server)
|
||||
}, ServerGridAdapter.OnLongClickListener { server ->
|
||||
DeleteServerDialogFragment(viewModel, server).show(
|
||||
|
|
|
@ -8,6 +8,7 @@ import dev.jdtech.jellyfin.models.View
|
|||
import dev.jdtech.jellyfin.models.ViewItem
|
||||
import kotlinx.coroutines.launch
|
||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||
import java.util.*
|
||||
|
||||
class HomeViewModel(
|
||||
application: Application
|
||||
|
@ -25,6 +26,7 @@ class HomeViewModel(
|
|||
val views: MutableList<View> = mutableListOf()
|
||||
|
||||
val result by jellyfinApi.viewsApi.getUserViews(jellyfinApi.userId!!)
|
||||
|
||||
for (view in result.items!!) {
|
||||
val items: MutableList<ViewItem> = mutableListOf()
|
||||
val resultItems by jellyfinApi.userLibraryApi.getLatestMedia(jellyfinApi.userId!!, parentId = view.id)
|
||||
|
@ -48,12 +50,19 @@ class HomeViewModel(
|
|||
}
|
||||
|
||||
private fun BaseItemDto.toViewItem(baseUrl: String) : ViewItem {
|
||||
return ViewItem(
|
||||
return when (type) {
|
||||
"Episode" -> ViewItem(
|
||||
id = seriesId!!,
|
||||
name = seriesName,
|
||||
primaryImageUrl = baseUrl.plus("/items/${seriesId}/Images/Primary")
|
||||
)
|
||||
else -> ViewItem(
|
||||
id = id,
|
||||
name = name,
|
||||
primaryImageUrl = baseUrl.plus("/items/${id}/Images/Primary")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun BaseItemDto.toView() : View {
|
||||
return View(
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="220dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:scaleType="centerCrop"
|
||||
app:itemImage="@{item}"
|
||||
app:shapeAppearanceOverlay="@style/roundedImageView" />
|
||||
|
||||
|
@ -29,7 +30,8 @@
|
|||
style="@style/text_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:text="@{item.name}"
|
||||
tools:text="Movie title" />
|
||||
</LinearLayout>
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:text="View all"
|
||||
android:text="@string/view_all"
|
||||
app:layout_constraintBaseline_toBaselineOf="@id/view_name"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
@ -42,6 +42,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:paddingHorizontal="12dp"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="horizontal"
|
||||
app:items="@{view.items}"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
|
|
|
@ -18,4 +18,5 @@
|
|||
<string name="title_home">Home</string>
|
||||
<string name="title_media">My media</string>
|
||||
<string name="title_settings">Settings</string>
|
||||
<string name="view_all">View all</string>
|
||||
</resources>
|
Loading…
Reference in a new issue