Add first dependency
This commit is contained in:
parent
5e6099de93
commit
25ee7d05af
11 changed files with 117 additions and 42 deletions
|
@ -4,6 +4,7 @@ plugins {
|
||||||
id 'kotlin-parcelize'
|
id 'kotlin-parcelize'
|
||||||
id 'kotlin-kapt'
|
id 'kotlin-kapt'
|
||||||
id 'androidx.navigation.safeargs.kotlin'
|
id 'androidx.navigation.safeargs.kotlin'
|
||||||
|
id 'dagger.hilt.android.plugin'
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
|
@ -37,12 +38,18 @@ android {
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
dataBinding true
|
dataBinding true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kapt {
|
||||||
|
javacOptions {
|
||||||
|
// These options are normally set automatically via the Hilt Gradle plugin, but we
|
||||||
|
// set them manually to workaround a bug in the Kotlin 1.5.20
|
||||||
|
option("-Adagger.fastInit=ENABLED")
|
||||||
|
option("-Adagger.hilt.android.internal.disableAndroidSuperclassValidation=true")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
def room_version = "2.3.0"
|
|
||||||
def jellyfin_version = "1.0.0-beta.9"
|
|
||||||
|
|
||||||
implementation 'androidx.core:core-ktx:1.6.0'
|
implementation 'androidx.core:core-ktx:1.6.0'
|
||||||
implementation 'androidx.core:core-splashscreen:1.0.0-alpha01'
|
implementation 'androidx.core:core-splashscreen:1.0.0-alpha01'
|
||||||
implementation 'androidx.appcompat:appcompat:1.3.0'
|
implementation 'androidx.appcompat:appcompat:1.3.0'
|
||||||
|
@ -62,17 +69,24 @@ dependencies {
|
||||||
implementation "androidx.recyclerview:recyclerview-selection:1.1.0"
|
implementation "androidx.recyclerview:recyclerview-selection:1.1.0"
|
||||||
|
|
||||||
// Room
|
// Room
|
||||||
|
def room_version = "2.3.0"
|
||||||
implementation "androidx.room:room-runtime:$room_version"
|
implementation "androidx.room:room-runtime:$room_version"
|
||||||
kapt "androidx.room:room-compiler:$room_version"
|
kapt "androidx.room:room-compiler:$room_version"
|
||||||
implementation "androidx.room:room-ktx:$room_version"
|
implementation "androidx.room:room-ktx:$room_version"
|
||||||
|
|
||||||
// Jellyfin
|
// Jellyfin
|
||||||
|
def jellyfin_version = "1.0.0-beta.9"
|
||||||
implementation "org.jellyfin.sdk:jellyfin-platform-android:$jellyfin_version"
|
implementation "org.jellyfin.sdk:jellyfin-platform-android:$jellyfin_version"
|
||||||
|
|
||||||
// Glide
|
// Glide
|
||||||
implementation 'com.github.bumptech.glide:glide:4.12.0'
|
implementation 'com.github.bumptech.glide:glide:4.12.0'
|
||||||
kapt 'com.github.bumptech.glide:compiler:4.12.0'
|
kapt 'com.github.bumptech.glide:compiler:4.12.0'
|
||||||
|
|
||||||
|
// Hilt
|
||||||
|
def hilt_version = "2.37"
|
||||||
|
implementation "com.google.dagger:hilt-android:$hilt_version"
|
||||||
|
kapt "com.google.dagger:hilt-compiler:$hilt_version"
|
||||||
|
|
||||||
// Testing
|
// Testing
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
android:name=".BaseApplication"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
|
8
app/src/main/java/dev/jdtech/jellyfin/BaseApplication.kt
Normal file
8
app/src/main/java/dev/jdtech/jellyfin/BaseApplication.kt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package dev.jdtech.jellyfin
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
|
|
||||||
|
@HiltAndroidApp
|
||||||
|
class BaseApplication : Application() {
|
||||||
|
}
|
|
@ -7,8 +7,10 @@ import androidx.navigation.fragment.NavHostFragment
|
||||||
import androidx.navigation.ui.AppBarConfiguration
|
import androidx.navigation.ui.AppBarConfiguration
|
||||||
import androidx.navigation.ui.setupActionBarWithNavController
|
import androidx.navigation.ui.setupActionBarWithNavController
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import dev.jdtech.jellyfin.databinding.ActivityMainBinding
|
import dev.jdtech.jellyfin.databinding.ActivityMainBinding
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var binding: ActivityMainBinding
|
private lateinit var binding: ActivityMainBinding
|
||||||
|
|
|
@ -3,7 +3,9 @@ package dev.jdtech.jellyfin
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
class SetupActivity : AppCompatActivity() {
|
class SetupActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
20
app/src/main/java/dev/jdtech/jellyfin/di/AppModule.kt
Normal file
20
app/src/main/java/dev/jdtech/jellyfin/di/AppModule.kt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package dev.jdtech.jellyfin.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import dev.jdtech.jellyfin.BaseApplication
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
class AppModule {
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideApplication(@ApplicationContext app: Context): BaseApplication {
|
||||||
|
return app as BaseApplication
|
||||||
|
}
|
||||||
|
}
|
29
app/src/main/java/dev/jdtech/jellyfin/di/DatabaseModule.kt
Normal file
29
app/src/main/java/dev/jdtech/jellyfin/di/DatabaseModule.kt
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package dev.jdtech.jellyfin.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.room.Room
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import dev.jdtech.jellyfin.database.ServerDatabase
|
||||||
|
import dev.jdtech.jellyfin.database.ServerDatabaseDao
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
class DatabaseModule {
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
fun provideServerDatabaseDao(@ApplicationContext app: Context): ServerDatabaseDao {
|
||||||
|
return Room.databaseBuilder(
|
||||||
|
app.applicationContext,
|
||||||
|
ServerDatabase::class.java,
|
||||||
|
"servers"
|
||||||
|
)
|
||||||
|
.fallbackToDestructiveMigration()
|
||||||
|
.build()
|
||||||
|
.serverDatabaseDao
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,33 +6,30 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import androidx.lifecycle.ViewModelProvider
|
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import dev.jdtech.jellyfin.R
|
import dev.jdtech.jellyfin.R
|
||||||
import dev.jdtech.jellyfin.database.ServerDatabase
|
|
||||||
import dev.jdtech.jellyfin.databinding.FragmentServerSelectBinding
|
import dev.jdtech.jellyfin.databinding.FragmentServerSelectBinding
|
||||||
import dev.jdtech.jellyfin.dialogs.DeleteServerDialogFragment
|
import dev.jdtech.jellyfin.dialogs.DeleteServerDialogFragment
|
||||||
import dev.jdtech.jellyfin.adapters.ServerGridAdapter
|
import dev.jdtech.jellyfin.adapters.ServerGridAdapter
|
||||||
import dev.jdtech.jellyfin.viewmodels.ServerSelectViewModelFactory
|
|
||||||
import dev.jdtech.jellyfin.viewmodels.ServerSelectViewModel
|
import dev.jdtech.jellyfin.viewmodels.ServerSelectViewModel
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
class ServerSelectFragment : Fragment() {
|
class ServerSelectFragment : Fragment() {
|
||||||
|
|
||||||
|
private lateinit var binding: FragmentServerSelectBinding
|
||||||
|
private val viewModel: ServerSelectViewModel by viewModels()
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
val binding = FragmentServerSelectBinding.inflate(inflater)
|
binding = FragmentServerSelectBinding.inflate(inflater)
|
||||||
|
|
||||||
val application = requireNotNull(this.activity).application
|
|
||||||
|
|
||||||
val dataSource = ServerDatabase.getInstance(application).serverDatabaseDao
|
|
||||||
|
|
||||||
val viewModelFactory = ServerSelectViewModelFactory(dataSource, application)
|
|
||||||
val viewModel: ServerSelectViewModel by viewModels { viewModelFactory }
|
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
|
|
||||||
binding.viewModel = viewModel
|
binding.viewModel = viewModel
|
||||||
|
|
||||||
binding.serversRecyclerView.adapter =
|
binding.serversRecyclerView.adapter =
|
||||||
ServerGridAdapter(ServerGridAdapter.OnClickListener { server ->
|
ServerGridAdapter(ServerGridAdapter.OnClickListener { server ->
|
||||||
viewModel.connectToServer(server)
|
viewModel.connectToServer(server)
|
||||||
|
@ -45,16 +42,24 @@ class ServerSelectFragment : Fragment() {
|
||||||
})
|
})
|
||||||
|
|
||||||
binding.buttonAddServer.setOnClickListener {
|
binding.buttonAddServer.setOnClickListener {
|
||||||
this.findNavController().navigate(R.id.action_serverSelectFragment_to_addServerFragment)
|
navigateToAddServerFragment()
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.navigateToMain.observe(viewLifecycleOwner, {
|
viewModel.navigateToMain.observe(viewLifecycleOwner, {
|
||||||
if (it) {
|
if (it) {
|
||||||
findNavController().navigate(R.id.action_serverSelectFragment_to_mainActivity)
|
navigateToMainActivity()
|
||||||
viewModel.doneNavigatingToMain()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun navigateToAddServerFragment() {
|
||||||
|
findNavController().navigate(R.id.action_serverSelectFragment_to_addServerFragment)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun navigateToMainActivity() {
|
||||||
|
findNavController().navigate(R.id.action_serverSelectFragment_to_mainActivity)
|
||||||
|
viewModel.doneNavigatingToMain()
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import dev.jdtech.jellyfin.api.JellyfinApi
|
import dev.jdtech.jellyfin.api.JellyfinApi
|
||||||
import dev.jdtech.jellyfin.database.Server
|
import dev.jdtech.jellyfin.database.Server
|
||||||
import dev.jdtech.jellyfin.database.ServerDatabaseDao
|
import dev.jdtech.jellyfin.database.ServerDatabaseDao
|
||||||
|
@ -12,11 +13,16 @@ import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ServerSelectViewModel(
|
@HiltViewModel
|
||||||
val database: ServerDatabaseDao,
|
class ServerSelectViewModel
|
||||||
val application: Application,
|
@Inject
|
||||||
|
constructor(
|
||||||
|
private val application: Application,
|
||||||
|
private val database: ServerDatabaseDao,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _servers = database.getAllServers()
|
private val _servers = database.getAllServers()
|
||||||
val servers: LiveData<List<Server>> = _servers
|
val servers: LiveData<List<Server>> = _servers
|
||||||
|
|
||||||
|
@ -56,7 +62,12 @@ class ServerSelectViewModel(
|
||||||
|
|
||||||
private suspend fun postCapabilities(jellyfinApi: JellyfinApi) {
|
private suspend fun postCapabilities(jellyfinApi: JellyfinApi) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
jellyfinApi.sessionApi.postCapabilities(playableMediaTypes = listOf("Video"), supportsMediaControl = false, supportsSync = false, supportsPersistentIdentifier = true)
|
jellyfinApi.sessionApi.postCapabilities(
|
||||||
|
playableMediaTypes = listOf("Video"),
|
||||||
|
supportsMediaControl = false,
|
||||||
|
supportsSync = false,
|
||||||
|
supportsPersistentIdentifier = true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
package dev.jdtech.jellyfin.viewmodels
|
|
||||||
|
|
||||||
import android.app.Application
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.ViewModelProvider
|
|
||||||
import dev.jdtech.jellyfin.database.ServerDatabaseDao
|
|
||||||
import java.lang.IllegalArgumentException
|
|
||||||
|
|
||||||
class ServerSelectViewModelFactory(
|
|
||||||
private val dataSource: ServerDatabaseDao,
|
|
||||||
private val application: Application
|
|
||||||
) : ViewModelProvider.Factory {
|
|
||||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
|
||||||
if (modelClass.isAssignableFrom(ServerSelectViewModel::class.java)) {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
return ServerSelectViewModel(dataSource, application) as T
|
|
||||||
}
|
|
||||||
throw IllegalArgumentException("Unknown ViewModel class")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,6 +13,9 @@ buildscript {
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
def nav_version = "2.3.5"
|
def nav_version = "2.3.5"
|
||||||
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
|
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
|
||||||
|
|
||||||
|
def hilt_version = "2.37"
|
||||||
|
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue