Start of library fragment: basic layout

With hardcoded library id
This commit is contained in:
Jarne Demeulemeester 2021-06-18 23:35:25 +02:00
parent 141087ff22
commit 0b663b1d17
No known key found for this signature in database
GPG key ID: 60884A0C1EBA43E5
10 changed files with 137 additions and 3 deletions

View file

@ -7,7 +7,6 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import dev.jdtech.jellyfin.databinding.BaseItemBinding import dev.jdtech.jellyfin.databinding.BaseItemBinding
import dev.jdtech.jellyfin.models.ViewItem
import org.jellyfin.sdk.model.api.BaseItemDto import org.jellyfin.sdk.model.api.BaseItemDto
class ViewItemListAdapter : class ViewItemListAdapter :
@ -18,7 +17,7 @@ class ViewItemListAdapter :
binding.item = item binding.item = item
binding.itemName.text = if (item.type == "Episode") item.seriesName else item.name binding.itemName.text = if (item.type == "Episode") item.seriesName else item.name
binding.itemCount.visibility = binding.itemCount.visibility =
if (item.userData?.unplayedItemCount != null) View.VISIBLE else View.GONE if (item.userData?.unplayedItemCount != null && item.userData?.unplayedItemCount!! > 0) View.VISIBLE else View.GONE
binding.executePendingBindings() binding.executePendingBindings()
} }
} }

View file

@ -0,0 +1,39 @@
package dev.jdtech.jellyfin.fragments
import androidx.lifecycle.ViewModelProvider
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import dev.jdtech.jellyfin.viewmodels.LibraryViewModel
import dev.jdtech.jellyfin.adapters.ViewItemListAdapter
import dev.jdtech.jellyfin.databinding.FragmentLibraryBinding
class LibraryFragment : Fragment() {
companion object {
fun newInstance() = LibraryFragment()
}
private lateinit var binding: FragmentLibraryBinding
private lateinit var viewModel: LibraryViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentLibraryBinding.inflate(inflater, container, false)
binding.lifecycleOwner = this
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel = ViewModelProvider(this).get(LibraryViewModel::class.java)
binding.viewModel = viewModel
binding.itemsRecyclerView.adapter = ViewItemListAdapter()
}
}

View file

@ -6,6 +6,8 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import dev.jdtech.jellyfin.R
import dev.jdtech.jellyfin.adapters.CollectionListAdapter import dev.jdtech.jellyfin.adapters.CollectionListAdapter
import dev.jdtech.jellyfin.databinding.FragmentMediaBinding import dev.jdtech.jellyfin.databinding.FragmentMediaBinding
import dev.jdtech.jellyfin.viewmodels.MediaViewModel import dev.jdtech.jellyfin.viewmodels.MediaViewModel
@ -32,6 +34,10 @@ class MediaFragment : Fragment() {
} }
}) })
binding.button.setOnClickListener {
findNavController().navigate(R.id.action_navigation_media_to_libraryFragment)
}
return binding.root return binding.root
} }
} }

View file

@ -0,0 +1,35 @@
package dev.jdtech.jellyfin.viewmodels
import android.app.Application
import androidx.lifecycle.*
import dev.jdtech.jellyfin.api.JellyfinApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.jellyfin.sdk.model.api.BaseItemDto
import java.util.*
class LibraryViewModel(application: Application) : AndroidViewModel(application) {
private val jellyfinApi = JellyfinApi.getInstance(application, "")
private val _items = MutableLiveData<List<BaseItemDto>>()
val items: LiveData<List<BaseItemDto>> = _items
private val _finishedLoading = MutableLiveData<Boolean>()
val finishedLoading: LiveData<Boolean> = _finishedLoading
init {
viewModelScope.launch {
_items.value = getItems(jellyfinApi.userId!!, UUID.fromString("0c419071-40d8-02bb-5843-0fed7e2cd79e"))
_finishedLoading.value = true
}
}
private suspend fun getItems(userId: UUID, parentId: UUID): List<BaseItemDto> {
val items: List<BaseItemDto>
withContext(Dispatchers.IO) {
items = jellyfinApi.itemsApi.getItems(userId, parentId = parentId).content.items!!
}
return items
}
}

View file

@ -0,0 +1,35 @@
<?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="viewModel"
type="dev.jdtech.jellyfin.viewmodels.LibraryViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.LibraryFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/items_recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:clipToPadding="false"
android:paddingHorizontal="12dp"
android:paddingTop="16dp"
app:items="@{viewModel.items}"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:spanCount="@integer/library_colums"
tools:itemCount="6"
tools:listitem="@layout/base_item" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -43,5 +43,13 @@
app:spanCount="@integer/collection_colums" app:spanCount="@integer/collection_colums"
tools:itemCount="4" tools:itemCount="4"
tools:listitem="@layout/collection_item" /> tools:listitem="@layout/collection_item" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</layout> </layout>

View file

@ -15,11 +15,20 @@
android:id="@+id/navigation_media" android:id="@+id/navigation_media"
android:name="dev.jdtech.jellyfin.fragments.MediaFragment" android:name="dev.jdtech.jellyfin.fragments.MediaFragment"
android:label="@string/title_media" android:label="@string/title_media"
tools:layout="@layout/fragment_media" /> tools:layout="@layout/fragment_media" >
<action
android:id="@+id/action_navigation_media_to_libraryFragment"
app:destination="@id/libraryFragment" />
</fragment>
<fragment <fragment
android:id="@+id/navigation_settings" android:id="@+id/navigation_settings"
android:name="dev.jdtech.jellyfin.fragments.SettingsFragment" android:name="dev.jdtech.jellyfin.fragments.SettingsFragment"
android:label="@string/title_settings" android:label="@string/title_settings"
tools:layout="@layout/fragment_settings" /> tools:layout="@layout/fragment_settings" />
<fragment
android:id="@+id/libraryFragment"
android:name="dev.jdtech.jellyfin.fragments.LibraryFragment"
android:label="library_fragment"
tools:layout="@layout/fragment_library" />
</navigation> </navigation>

View file

@ -3,5 +3,6 @@
<dimen name="setup_container_width">400dp</dimen> <dimen name="setup_container_width">400dp</dimen>
<item name="server_colums" type="integer">6</item> <item name="server_colums" type="integer">6</item>
<item name="collection_colums" type="integer">2</item> <item name="collection_colums" type="integer">2</item>
<item name="library_colums" type="integer">4</item>
<item name="recyclerview_animation_duration" type="integer">450</item> <item name="recyclerview_animation_duration" type="integer">450</item>
</resources> </resources>

View file

@ -2,4 +2,5 @@
<resources> <resources>
<item name="server_colums" type="integer">8</item> <item name="server_colums" type="integer">8</item>
<item name="collection_colums" type="integer">3</item> <item name="collection_colums" type="integer">3</item>
<item name="library_colums" type="integer">6</item>
</resources> </resources>

View file

@ -5,5 +5,6 @@
<dimen name="setup_container_width">@dimen/match_parent</dimen> <dimen name="setup_container_width">@dimen/match_parent</dimen>
<item name="server_colums" type="integer">3</item> <item name="server_colums" type="integer">3</item>
<item name="collection_colums" type="integer">1</item> <item name="collection_colums" type="integer">1</item>
<item name="library_colums" type="integer">2</item>
<item name="recyclerview_animation_duration" type="integer">250</item> <item name="recyclerview_animation_duration" type="integer">250</item>
</resources> </resources>