mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Moved the unnecessary code out of MainActivity.kt
This commit is contained in:
1 parent
3935765491
commit
747a7620b0
3 files changed
+15
-26
No files matched your search
@@ -2,31 +2,18 @@ package com.rtbishop.look4sat.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.rtbishop.look4sat.Look4SatApp
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.dagger.ViewModelFactory
|
||||
import com.rtbishop.look4sat.databinding.ActivityMainBinding
|
||||
import javax.inject.Inject
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@Inject
|
||||
lateinit var factory: ViewModelFactory
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
private lateinit var viewModel: SharedViewModel
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
val binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
val navHost = supportFragmentManager.findFragmentById(R.id.nav_frag) as NavHostFragment
|
||||
val navHost = supportFragmentManager.findFragmentById(R.id.nav_host) as NavHostFragment
|
||||
binding.navBottom.setupWithNavController(navHost.navController)
|
||||
(application as Look4SatApp).appComponent.inject(this)
|
||||
viewModel = ViewModelProvider(this, factory).get(SharedViewModel::class.java)
|
||||
viewModel.setDefaultTleSources()
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,12 @@ class SharedViewModel @Inject constructor(
|
||||
private val repository: Repository
|
||||
) : ViewModel() {
|
||||
|
||||
init {
|
||||
if (prefsManager.isFirstLaunch()) {
|
||||
setDefaultTleSources()
|
||||
}
|
||||
}
|
||||
|
||||
val tleSources = repository.getSources()
|
||||
val allEntries = repository.getAllEntries()
|
||||
val selectedEntries = repository.getSelectedEntries()
|
||||
@@ -113,16 +119,12 @@ class SharedViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun setDefaultTleSources() {
|
||||
if (prefsManager.isFirstLaunch()) {
|
||||
viewModelScope.launch {
|
||||
val defSourcesList = listOf(
|
||||
TleSource("https://celestrak.com/NORAD/elements/active.txt"),
|
||||
TleSource("https://amsat.org/tle/current/nasabare.txt")
|
||||
)
|
||||
repository.updateSources(defSourcesList)
|
||||
}
|
||||
}
|
||||
private fun setDefaultTleSources() {
|
||||
val defaultTleSources = listOf(
|
||||
TleSource("https://celestrak.com/NORAD/elements/active.txt"),
|
||||
TleSource("https://amsat.org/tle/current/nasabare.txt")
|
||||
)
|
||||
viewModelScope.launch { repository.updateSources(defaultTleSources) }
|
||||
}
|
||||
|
||||
private fun getPassesForEntries(
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/nav_frag"
|
||||
android:id="@+id/nav_host"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
|
||||
Reference in new issue
Block a user