diff --git a/app/src/main/java/com/starry/myne/MainActivity.kt b/app/src/main/java/com/starry/myne/MainActivity.kt index 4a8efc5..0d5395b 100644 --- a/app/src/main/java/com/starry/myne/MainActivity.kt +++ b/app/src/main/java/com/starry/myne/MainActivity.kt @@ -58,7 +58,6 @@ class MainActivity : AppCompatActivity() { } enableEdgeToEdge() // enable edge to edge for the activity. - setAppShortcuts() // set launcher shortcuts for the app. setContent { MyneTheme(settingsViewModel = settingsViewModel) { @@ -86,7 +85,12 @@ class MainActivity : AppCompatActivity() { } } - private fun setAppShortcuts() { + override fun onPause() { + super.onPause() + updateShortcuts() + } + + private fun updateShortcuts() { val shortcutManager = getSystemService(ShortcutManager::class.java) mainViewModel.buildDynamicShortcuts( context = this, diff --git a/app/src/main/java/com/starry/myne/database/reader/ReaderDao.kt b/app/src/main/java/com/starry/myne/database/reader/ReaderDao.kt index 337b046..08e722f 100644 --- a/app/src/main/java/com/starry/myne/database/reader/ReaderDao.kt +++ b/app/src/main/java/com/starry/myne/database/reader/ReaderDao.kt @@ -44,5 +44,5 @@ interface ReaderDao { fun getAllReaderItems(): List @Query("SELECT * FROM reader_table WHERE library_item_id = :libraryItemId") - fun getReaderDataAsFlow(libraryItemId: Int): Flow + fun getReaderDataAsFlow(libraryItemId: Int): Flow? } \ No newline at end of file diff --git a/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt index 38bf86d..84c67b8 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/reader/viewmodels/ReaderDetailViewModel.kt @@ -61,16 +61,19 @@ class ReaderDetailViewModel @Inject constructor( var state by mutableStateOf(ReaderDetailScreenState()) - val readerData: Flow? - get() = _readerData - private var _readerData: Flow? = null + var readerData: Flow? = null + private set fun loadEbookData(libraryItemId: String, networkStatus: NetworkObserver.Status) { viewModelScope.launch(Dispatchers.IO) { - // Library item is not null as this screen is only accessible from the library. - val libraryItem = libraryDao.getItemById(libraryItemId.toInt())!! + val libraryItem = libraryDao.getItemById(libraryItemId.toInt()) + // Check if library item exists. + if (libraryItem == null) { + state = state.copy(isLoading = false, error = "Library item not found.") + return@launch + } // Get reader data if it exists. - _readerData = readerDao.getReaderDataAsFlow(libraryItemId.toInt()) + readerData = readerDao.getReaderDataAsFlow(libraryItemId.toInt()) val coverImage: String? = try { if (!libraryItem.isExternalBook && networkStatus == NetworkObserver.Status.Available