Remove InitializingFragment
This commit is contained in:
parent
ac7c3405da
commit
8984493bb0
7 changed files with 33 additions and 82 deletions
|
@ -12,7 +12,7 @@ import androidx.navigation.ui.setupActionBarWithNavController
|
||||||
import androidx.navigation.ui.setupWithNavController
|
import androidx.navigation.ui.setupWithNavController
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import dev.jdtech.jellyfin.databinding.ActivityMainBinding
|
import dev.jdtech.jellyfin.databinding.ActivityMainBinding
|
||||||
import dev.jdtech.jellyfin.fragments.InitializingFragmentDirections
|
import dev.jdtech.jellyfin.fragments.HomeFragmentDirections
|
||||||
import dev.jdtech.jellyfin.viewmodels.MainViewModel
|
import dev.jdtech.jellyfin.viewmodels.MainViewModel
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
|
@ -59,18 +59,10 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
viewModel.navigateToAddServer.observe(this, {
|
viewModel.navigateToAddServer.observe(this, {
|
||||||
if (it) {
|
if (it) {
|
||||||
navController.navigate(InitializingFragmentDirections.actionInitializingFragmentToAddServerFragment3())
|
navController.navigate(HomeFragmentDirections.actionHomeFragmentToAddServerFragment())
|
||||||
viewModel.doneNavigateToAddServer()
|
viewModel.doneNavigateToAddServer()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
viewModel.doneLoading.observe(this, {
|
|
||||||
if (it) {
|
|
||||||
if (navController.currentDestination!!.id == R.id.initializingFragment) {
|
|
||||||
navController.navigate(InitializingFragmentDirections.actionInitializingFragmentToNavigationHome())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSupportNavigateUp(): Boolean {
|
override fun onSupportNavigateUp(): Boolean {
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package dev.jdtech.jellyfin.di
|
package dev.jdtech.jellyfin.di
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import dev.jdtech.jellyfin.api.JellyfinApi
|
import dev.jdtech.jellyfin.api.JellyfinApi
|
||||||
|
import dev.jdtech.jellyfin.database.ServerDatabaseDao
|
||||||
|
import java.util.*
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
|
@ -14,7 +17,23 @@ import javax.inject.Singleton
|
||||||
object ApiModule {
|
object ApiModule {
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
fun provideJellyfinApi(@ApplicationContext application: Context): JellyfinApi {
|
fun provideJellyfinApi(
|
||||||
return JellyfinApi.getInstance(application, "")
|
@ApplicationContext application: Context,
|
||||||
|
sharedPreferences: SharedPreferences,
|
||||||
|
serverDatabase: ServerDatabaseDao
|
||||||
|
): JellyfinApi {
|
||||||
|
val jellyfinApi = JellyfinApi.getInstance(application, "")
|
||||||
|
|
||||||
|
val serverId = sharedPreferences.getString("selectedServer", null)
|
||||||
|
if (serverId != null) {
|
||||||
|
val server = serverDatabase.get(serverId)
|
||||||
|
jellyfinApi.apply {
|
||||||
|
api.baseUrl = server.address
|
||||||
|
api.accessToken = server.accessToken
|
||||||
|
userId = UUID.fromString(server.userId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return jellyfinApi
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,6 +23,7 @@ object DatabaseModule {
|
||||||
"servers"
|
"servers"
|
||||||
)
|
)
|
||||||
.fallbackToDestructiveMigration()
|
.fallbackToDestructiveMigration()
|
||||||
|
.allowMainThreadQueries()
|
||||||
.build()
|
.build()
|
||||||
.serverDatabaseDao
|
.serverDatabaseDao
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package dev.jdtech.jellyfin.fragments
|
|
||||||
|
|
||||||
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.R
|
|
||||||
|
|
||||||
|
|
||||||
class InitializingFragment : Fragment() {
|
|
||||||
|
|
||||||
override fun onCreateView(
|
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
|
||||||
savedInstanceState: Bundle?
|
|
||||||
): View? {
|
|
||||||
// Inflate the layout for this fragment
|
|
||||||
return inflater.inflate(R.layout.fragment_initializing, container, false)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +1,23 @@
|
||||||
package dev.jdtech.jellyfin.viewmodels
|
package dev.jdtech.jellyfin.viewmodels
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import androidx.lifecycle.LiveData
|
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 dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
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
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class MainViewModel
|
class MainViewModel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val sharedPreferences: SharedPreferences,
|
|
||||||
private val database: ServerDatabaseDao,
|
private val database: ServerDatabaseDao,
|
||||||
private val jellyfinApi: JellyfinApi,
|
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _doneLoading = MutableLiveData<Boolean>()
|
private val _doneLoading = MutableLiveData<Boolean>()
|
||||||
|
@ -40,21 +35,10 @@ constructor(
|
||||||
}
|
}
|
||||||
if (servers.isEmpty()) {
|
if (servers.isEmpty()) {
|
||||||
_navigateToAddServer.value = true
|
_navigateToAddServer.value = true
|
||||||
} else {
|
|
||||||
val serverId = sharedPreferences.getString("selectedServer", null)
|
|
||||||
val selectedServer = servers.find { server -> server.id == serverId }
|
|
||||||
Timber.d("Selected server: $selectedServer")
|
|
||||||
if (selectedServer != null) {
|
|
||||||
jellyfinApi.apply {
|
|
||||||
api.baseUrl = selectedServer.address
|
|
||||||
api.accessToken = selectedServer.accessToken
|
|
||||||
userId = UUID.fromString(selectedServer.userId)
|
|
||||||
}
|
|
||||||
Timber.d("Finish Main")
|
|
||||||
}
|
|
||||||
_doneLoading.value = true
|
|
||||||
}
|
}
|
||||||
|
_doneLoading.value = true
|
||||||
}
|
}
|
||||||
|
_doneLoading.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doneNavigateToAddServer() {
|
fun doneNavigateToAddServer() {
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".fragments.InitializingFragment">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:text="@string/initializing" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
|
@ -3,7 +3,7 @@
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/main_navigation"
|
android:id="@+id/main_navigation"
|
||||||
app:startDestination="@+id/initializingFragment">
|
app:startDestination="@+id/homeFragment">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/homeFragment"
|
android:id="@+id/homeFragment"
|
||||||
|
@ -34,6 +34,11 @@
|
||||||
app:exitAnim="@anim/nav_default_exit_anim"
|
app:exitAnim="@anim/nav_default_exit_anim"
|
||||||
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
|
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
|
||||||
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
|
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_homeFragment_to_addServerFragment"
|
||||||
|
app:destination="@id/addServerFragment"
|
||||||
|
app:popUpTo="@id/homeFragment"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
|
@ -219,23 +224,7 @@
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_loginFragment2_to_navigation_home"
|
android:id="@+id/action_loginFragment2_to_navigation_home"
|
||||||
app:destination="@id/homeFragment"
|
app:destination="@id/homeFragment"
|
||||||
app:popUpTo="@id/initializingFragment"
|
app:popUpTo="@id/homeFragment"
|
||||||
app:popUpToInclusive="true" />
|
|
||||||
</fragment>
|
|
||||||
<fragment
|
|
||||||
android:id="@+id/initializingFragment"
|
|
||||||
android:name="dev.jdtech.jellyfin.fragments.InitializingFragment"
|
|
||||||
android:label="@string/initializing"
|
|
||||||
tools:layout="@layout/fragment_initializing">
|
|
||||||
<action
|
|
||||||
android:id="@+id/action_initializingFragment_to_navigation_home"
|
|
||||||
app:destination="@id/homeFragment"
|
|
||||||
app:popUpTo="@id/initializingFragment"
|
|
||||||
app:popUpToInclusive="true" />
|
|
||||||
<action
|
|
||||||
android:id="@+id/action_initializingFragment_to_addServerFragment3"
|
|
||||||
app:destination="@id/addServerFragment"
|
|
||||||
app:popUpTo="@id/initializingFragment"
|
|
||||||
app:popUpToInclusive="true" />
|
app:popUpToInclusive="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue