Skip to content

Commit

Permalink
Add opening last song navigation menu
Browse files Browse the repository at this point in the history
  • Loading branch information
igrek51 committed Feb 19, 2020
1 parent ae649d5 commit b7bc95c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,6 +59,8 @@ class NavigationMenuController {
lateinit var randomSongOpener: Lazy<RandomSongOpener>
@Inject
lateinit var sendMessageService: Lazy<SendMessageService>
@Inject
lateinit var songOpener: Lazy<SongOpener>

private var drawerLayout: DrawerLayout? = null
private var navigationView: NavigationView? = null
Expand Down Expand Up @@ -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) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
preferencesUpdater.get().restoreTransposition = value
}
)

}

private fun toggleAllMultiPreference(excludeLanguagesPreference: MultiSelectListPreference) {
Expand Down
35 changes: 33 additions & 2 deletions app/src/main/java/igrek/songbook/songpreview/SongOpener.kt
Original file line number Diff line number Diff line change
@@ -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<LayoutController>
lateinit var layoutController: Lazy<LayoutController>
@Inject
lateinit var songPreviewLayoutController: dagger.Lazy<SongPreviewLayoutController>
lateinit var songPreviewLayoutController: Lazy<SongPreviewLayoutController>
@Inject
lateinit var songsRepository: SongsRepository
@Inject
lateinit var uiInfoService: UiInfoService

init {
DaggerIoc.factoryComponent.inject(this)
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Disposable>()

init {
Expand Down
20 changes: 12 additions & 8 deletions app/src/main/res/menu/menu_nav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
android:id="@+id/nav_playlists"
android:icon="@drawable/playlist"
android:title="@string/nav_playlists"/>
<item
android:id="@+id/nav_custom_songs"
android:icon="@drawable/edit"
android:title="@string/nav_custom_song" />
<item
android:id="@+id/nav_favourites"
android:icon="@drawable/star_filled"
android:title="@string/nav_favourites_song"/>
<item
android:id="@+id/nav_custom_songs"
android:icon="@drawable/edit"
android:title="@string/nav_custom_song"/>
<item
android:id="@+id/nav_latest"
android:icon="@drawable/newest"
Expand All @@ -35,6 +35,10 @@
<group
android:id="@+id/nav_group2"
android:checkableBehavior="single">
<item
android:id="@+id/nav_last_song"
android:icon="@drawable/note"
android:title="@string/nav_last_song" />
<item
android:id="@+id/nav_update_db"
android:icon="@drawable/sync"
Expand All @@ -51,14 +55,14 @@
android:id="@+id/nav_settings"
android:icon="@drawable/settings"
android:title="@string/nav_settings"/>
<item
android:id="@+id/nav_missing_song"
android:icon="@drawable/add"
android:title="@string/nav_missing_song" />
<item
android:id="@+id/nav_contact"
android:icon="@drawable/send"
android:title="@string/nav_contact"/>
<item
android:id="@+id/nav_missing_song"
android:icon="@drawable/add"
android:title="@string/nav_missing_song" />
<item
android:id="@+id/nav_help"
android:icon="@drawable/help"
Expand Down
20 changes: 12 additions & 8 deletions app/src/main/res/menu/menu_nav_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
android:id="@+id/nav_playlists"
android:icon="@drawable/playlist"
android:title="@string/nav_playlists" />
<item
android:id="@+id/nav_favourites"
android:icon="@drawable/star_filled"
android:title="@string/nav_favourites_song" />
<item
android:id="@+id/nav_custom_songs"
android:icon="@drawable/edit"
Expand All @@ -27,6 +23,10 @@
android:id="@+id/nav_admin_antechamber"
android:icon="@drawable/edit"
android:title="@string/nav_admin_antechamber" />
<item
android:id="@+id/nav_favourites"
android:icon="@drawable/star_filled"
android:title="@string/nav_favourites_song" />
<item
android:id="@+id/nav_latest"
android:icon="@drawable/newest"
Expand All @@ -39,6 +39,10 @@
<group
android:id="@+id/nav_group2"
android:checkableBehavior="single">
<item
android:id="@+id/nav_last_song"
android:icon="@drawable/note"
android:title="@string/nav_last_song" />
<item
android:id="@+id/nav_update_db"
android:icon="@drawable/sync"
Expand All @@ -55,14 +59,14 @@
android:id="@+id/nav_settings"
android:icon="@drawable/settings"
android:title="@string/nav_settings" />
<item
android:id="@+id/nav_missing_song"
android:icon="@drawable/add"
android:title="@string/nav_missing_song" />
<item
android:id="@+id/nav_contact"
android:icon="@drawable/send"
android:title="@string/nav_contact" />
<item
android:id="@+id/nav_missing_song"
android:icon="@drawable/add"
android:title="@string/nav_missing_song" />
<item
android:id="@+id/nav_help"
android:icon="@drawable/help"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,6 @@
<string name="confirm_unsaved_changes_title">Niezapisane zmiany</string>
<string name="song_details_namespace_custom">Moja piosenka</string>
<string name="song_details_namespace_public">Publiczna piosenka</string>
<string name="nav_last_song">Ostatnia piosenka</string>
<string name="no_last_song">Nie otworzyłeś jeszcze żadnej piosenki.</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,6 @@
<string name="confirm_unsaved_changes_title">Unsaved changes</string>
<string name="song_details_namespace_custom">Custom song</string>
<string name="song_details_namespace_public">Public song</string>
<string name="nav_last_song">Last song</string>
<string name="no_last_song">You haven\'t open any song yet.</string>
</resources>

0 comments on commit b7bc95c

Please sign in to comment.