Skip to content

Commit

Permalink
Fix bottom navigation bar
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Feb 16, 2024
1 parent 82e3130 commit f1bdf2a
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 124 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/com/maxrave/simpmusic/common/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@ const val DB_NAME = "Music Database"
const val FIRST_TIME_MIGRATION = "first_time_migration"
const val SELECTED_LANGUAGE = "selected_language"

const val STATUS_DONE = "status_done"
const val STATUS_DONE = "status_done"

const val RESTORE_SUCCESSFUL = "restore_successful"
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ class DataStoreManager @Inject constructor(private val settingsDataStore: DataSt
preferences[QUALITY] ?: COMMON_QUALITY.items[0].toString()
}

suspend fun restore(isRestoring: Boolean) {
withContext(Dispatchers.IO) {
settingsDataStore.edit { settings ->
settings[IS_RESTORING_DATABASE] = if (isRestoring) TRUE else FALSE
}
}
}

suspend fun setQuality(quality: String) {
withContext(Dispatchers.IO) {
settingsDataStore.edit { settings ->
Expand All @@ -69,9 +61,6 @@ class DataStoreManager @Inject constructor(private val settingsDataStore: DataSt
}
}

val isRestoringDatabase: Flow<String> = settingsDataStore.data.map { preferences ->
preferences[IS_RESTORING_DATABASE] ?: FALSE
}
val loggedIn: Flow<String> = settingsDataStore.data.map { preferences ->
preferences[LOGGED_IN] ?: FALSE
}
Expand Down Expand Up @@ -482,7 +471,6 @@ class DataStoreManager @Inject constructor(private val settingsDataStore: DataSt
val LOCATION = stringPreferencesKey("location")
val QUALITY = stringPreferencesKey("quality")
val NORMALIZE_VOLUME = stringPreferencesKey("normalize_volume")
val IS_RESTORING_DATABASE = stringPreferencesKey("is_restoring_database")
val SKIP_SILENT = stringPreferencesKey("skip_silent")
val SAVE_STATE_OF_PLAYBACK = stringPreferencesKey("save_state_of_playback")
val SAVE_RECENT_SONG = stringPreferencesKey("save_recent_song")
Expand Down
33 changes: 25 additions & 8 deletions app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.maxrave.kotlinytmusicscraper.models.YouTubeLocale
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.common.Config
import com.maxrave.simpmusic.common.FIRST_TIME_MIGRATION
import com.maxrave.simpmusic.common.RESTORE_SUCCESSFUL
import com.maxrave.simpmusic.common.SELECTED_LANGUAGE
import com.maxrave.simpmusic.common.SPONSOR_BLOCK
import com.maxrave.simpmusic.common.STATUS_DONE
Expand Down Expand Up @@ -427,13 +428,23 @@ class MainActivity : AppCompatActivity() {
val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_container_view)
val navController = navHostFragment?.findNavController()
binding.bottomNavigationView.setupWithNavController(navController!!)
binding.bottomNavigationView.setOnItemReselectedListener {
val id = navController.currentDestination?.id
if (id != R.id.bottom_navigation_item_home && id != R.id.bottom_navigation_item_search && id != R.id.bottom_navigation_item_library) {
navController.popBackStack(it.itemId, inclusive = false)
} else if (id == R.id.bottom_navigation_item_home) {
viewModel.homeRefresh()
}
}
when (action) {
"com.maxrave.simpmusic.action.HOME" -> {
binding.bottomNavigationView.selectedItemId = R.id.bottom_navigation_item_home
}

"com.maxrave.simpmusic.action.SEARCH" -> {
binding.bottomNavigationView.selectedItemId = R.id.bottom_navigation_item_search
}

"com.maxrave.simpmusic.action.LIBRARY" -> {
binding.bottomNavigationView.selectedItemId = R.id.bottom_navigation_item_library
}
Expand All @@ -452,7 +463,7 @@ class MainActivity : AppCompatActivity() {
true
}

R.id.bottom_navigation_item_library, R.id.downloadedFragment, R.id.mostPlayedFragment, R.id.followedFragment, R.id.favoriteFragment -> {
R.id.bottom_navigation_item_library, R.id.downloadedFragment, R.id.mostPlayedFragment, R.id.followedFragment, R.id.favoriteFragment, R.id.localPlaylistFragment -> {
binding.bottomNavigationView.menu.findItem(R.id.bottom_navigation_item_library)?.isChecked =
true
}
Expand Down Expand Up @@ -511,17 +522,23 @@ class MainActivity : AppCompatActivity() {
lifecycleScope.launch {
val job1 = launch {
viewModel.intent.collectLatest { intent ->
if (intent != null){
if (intent != null) {
if (intent.action == RESTORE_SUCCESSFUL) {
viewModel.checkIsRestoring()
}
data = intent.data ?: intent.getStringExtra(Intent.EXTRA_TEXT)?.toUri()
Log.d("MainActivity", "onCreate: $data")
if (data != null) {
when (val path = data!!.pathSegments.firstOrNull()) {
"playlist" -> data!!.getQueryParameter("list")?.let { playlistId ->
if (playlistId.startsWith("OLAK5uy_")) {
viewModel.intent.value = null
navController.navigateSafe(R.id.action_global_albumFragment, Bundle().apply {
putString("browseId", playlistId)
})
"playlist" -> data!!.getQueryParameter("list")
?.let { playlistId ->
if (playlistId.startsWith("OLAK5uy_")) {
viewModel.intent.value = null
navController.navigateSafe(
R.id.action_global_albumFragment,
Bundle().apply {
putString("browseId", playlistId)
})
}
else if (playlistId.startsWith("VL")) {
viewModel.intent.value = null
Expand Down
Loading

0 comments on commit f1bdf2a

Please sign in to comment.