From b7bc95c3f2b9a10d3e9197e5bd11296e5c3264df Mon Sep 17 00:00:00 2001 From: igrek51 Date: Wed, 19 Feb 2020 19:29:06 +0100 Subject: [PATCH] Add opening last song navigation menu --- .../navigation/NavigationMenuController.kt | 4 +++ .../songbook/settings/SettingsFragment.kt | 1 + .../igrek/songbook/songpreview/SongOpener.kt | 35 +++++++++++++++++-- .../history/OpenHistoryLayoutController.kt | 2 -- app/src/main/res/menu/menu_nav.xml | 20 ++++++----- app/src/main/res/menu/menu_nav_admin.xml | 20 ++++++----- app/src/main/res/values-pl/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 8 files changed, 66 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/igrek/songbook/layout/navigation/NavigationMenuController.kt b/app/src/main/java/igrek/songbook/layout/navigation/NavigationMenuController.kt index 28eba57f..290e2b75 100644 --- a/app/src/main/java/igrek/songbook/layout/navigation/NavigationMenuController.kt +++ b/app/src/main/java/igrek/songbook/layout/navigation/NavigationMenuController.kt @@ -24,6 +24,7 @@ import igrek.songbook.layout.LayoutController import igrek.songbook.persistence.general.SongsUpdater import igrek.songbook.playlist.PlaylistLayoutController import igrek.songbook.settings.SettingsLayoutController +import igrek.songbook.songpreview.SongOpener import igrek.songbook.songselection.favourite.FavouritesLayoutController import igrek.songbook.songselection.history.OpenHistoryLayoutController import igrek.songbook.songselection.latest.LatestSongsLayoutController @@ -58,6 +59,8 @@ class NavigationMenuController { lateinit var randomSongOpener: Lazy @Inject lateinit var sendMessageService: Lazy + @Inject + lateinit var songOpener: Lazy private var drawerLayout: DrawerLayout? = null private var navigationView: NavigationView? = null @@ -85,6 +88,7 @@ class NavigationMenuController { actionsMap[R.id.nav_missing_song] = { sendMessageService.get().requestMissingSong() } actionsMap[R.id.nav_history] = { layoutController.get().showLayout(OpenHistoryLayoutController::class) } actionsMap[R.id.nav_latest] = { layoutController.get().showLayout(LatestSongsLayoutController::class) } + actionsMap[R.id.nav_last_song] = { songOpener.get().openLastSong() } actionsMap[R.id.nav_admin_antechamber] = { layoutController.get().showLayout(AdminSongsLayoutContoller::class) } } diff --git a/app/src/main/java/igrek/songbook/settings/SettingsFragment.kt b/app/src/main/java/igrek/songbook/settings/SettingsFragment.kt index f89ef527..61c02789 100644 --- a/app/src/main/java/igrek/songbook/settings/SettingsFragment.kt +++ b/app/src/main/java/igrek/songbook/settings/SettingsFragment.kt @@ -234,6 +234,7 @@ class SettingsFragment : PreferenceFragmentCompat() { preferencesUpdater.get().restoreTransposition = value } ) + } private fun toggleAllMultiPreference(excludeLanguagesPreference: MultiSelectListPreference) { diff --git a/app/src/main/java/igrek/songbook/songpreview/SongOpener.kt b/app/src/main/java/igrek/songbook/songpreview/SongOpener.kt index 7059ed14..699b59db 100644 --- a/app/src/main/java/igrek/songbook/songpreview/SongOpener.kt +++ b/app/src/main/java/igrek/songbook/songpreview/SongOpener.kt @@ -1,19 +1,27 @@ package igrek.songbook.songpreview +import dagger.Lazy +import igrek.songbook.R import igrek.songbook.dagger.DaggerIoc +import igrek.songbook.info.UiInfoService import igrek.songbook.layout.LayoutController import igrek.songbook.persistence.general.model.Song +import igrek.songbook.persistence.general.model.SongIdentifier +import igrek.songbook.persistence.general.model.SongNamespace import igrek.songbook.persistence.repository.SongsRepository +import igrek.songbook.persistence.user.history.OpenedSong import javax.inject.Inject class SongOpener { @Inject - lateinit var layoutController: dagger.Lazy + lateinit var layoutController: Lazy @Inject - lateinit var songPreviewLayoutController: dagger.Lazy + lateinit var songPreviewLayoutController: Lazy @Inject lateinit var songsRepository: SongsRepository + @Inject + lateinit var uiInfoService: UiInfoService init { DaggerIoc.factoryComponent.inject(this) @@ -24,4 +32,27 @@ class SongOpener { layoutController.get().showLayout(SongPreviewLayoutController::class) songsRepository.openHistoryDao.registerOpenedSong(song.id, song.isCustom()) } + + fun openLastSong() { + if (songPreviewLayoutController.get().currentSong != null) { + layoutController.get().showLayout(SongPreviewLayoutController::class) + return + } + + val openedSong: OpenedSong? = songsRepository.openHistoryDao.historyDb.songs.firstOrNull() + if (openedSong != null) { + val namespace = when { + openedSong.custom -> SongNamespace.Custom + else -> SongNamespace.Public + } + val songIdentifier = SongIdentifier(openedSong.songId, namespace) + val song: Song? = songsRepository.songsDb?.songFinder?.find(songIdentifier) + if (song != null) { + openSongPreview(song) + return + } + } + + uiInfoService.showInfo(R.string.no_last_song) + } } \ No newline at end of file diff --git a/app/src/main/java/igrek/songbook/songselection/history/OpenHistoryLayoutController.kt b/app/src/main/java/igrek/songbook/songselection/history/OpenHistoryLayoutController.kt index a1b0d42f..2905d7dc 100644 --- a/app/src/main/java/igrek/songbook/songselection/history/OpenHistoryLayoutController.kt +++ b/app/src/main/java/igrek/songbook/songselection/history/OpenHistoryLayoutController.kt @@ -45,9 +45,7 @@ class OpenHistoryLayoutController : InflatedLayout( lateinit var songOpener: SongOpener private var itemsListView: SongListView? = null - private var storedScroll: ListScrollPosition? = null - private var subscriptions = mutableListOf() init { diff --git a/app/src/main/res/menu/menu_nav.xml b/app/src/main/res/menu/menu_nav.xml index 497f040b..e7977f33 100644 --- a/app/src/main/res/menu/menu_nav.xml +++ b/app/src/main/res/menu/menu_nav.xml @@ -15,14 +15,14 @@ android:id="@+id/nav_playlists" android:icon="@drawable/playlist" android:title="@string/nav_playlists"/> + - + - + - + + - + Niezapisane zmiany Moja piosenka Publiczna piosenka + Ostatnia piosenka + Nie otworzyłeś jeszcze żadnej piosenki. \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 027f6827..49346666 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -318,4 +318,6 @@ Unsaved changes Custom song Public song + Last song + You haven\'t open any song yet.