Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
feat: option to disable search history
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Jan 8, 2024
1 parent 0df127e commit 32823bc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ interface SearchDao {

@Query("SELECT * from SearchQuery")
fun getSearchHistory(): List<SearchQuery>

@Query("DELETE from SearchQuery")
fun deleteAll()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import app.suhasdissa.vibeyou.backend.data.Artist
import app.suhasdissa.vibeyou.backend.data.Song
import app.suhasdissa.vibeyou.backend.database.dao.SearchDao
import app.suhasdissa.vibeyou.backend.database.entities.SearchQuery
import app.suhasdissa.vibeyou.utils.Pref
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

Expand Down Expand Up @@ -269,7 +270,11 @@ class LocalMusicRepository(
return ContentUris.withAppendedId(sArtworkUri, albumId)
}

fun saveSearchQuery(query: String) = searchDao.addSearchQuery(SearchQuery(id = 0, query))
fun saveSearchQuery(query: String) {
if (Pref.sharedPreferences.getBoolean(Pref.disableSearchHistoryKey, false)) return

searchDao.addSearchQuery(SearchQuery(id = 0, query))
}
fun getSearchHistory() = searchDao.getSearchHistory()

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import app.suhasdissa.vibeyou.backend.models.SearchFilter
import app.suhasdissa.vibeyou.backend.models.artists.Channel
import app.suhasdissa.vibeyou.backend.models.artists.ChannelTab
import app.suhasdissa.vibeyou.backend.models.playlists.PlaylistInfo
import app.suhasdissa.vibeyou.utils.Pref
import app.suhasdissa.vibeyou.utils.RetrofitHelper
import app.suhasdissa.vibeyou.utils.asAlbum
import app.suhasdissa.vibeyou.utils.asArtist
Expand Down Expand Up @@ -111,6 +112,10 @@ class PipedMusicRepository(
fun searchLocalSong(query: String): List<Song> =
songsDao.search(query).map { it.asSong }

fun saveSearchQuery(query: String) = searchDao.addSearchQuery(SearchQuery(id = 0, query))
fun saveSearchQuery(query: String) {
if (Pref.sharedPreferences.getBoolean(Pref.disableSearchHistoryKey, false)) return

searchDao.addSearchQuery(SearchQuery(id = 0, query))
}
fun getSearchHistory() = searchDao.getSearchHistory()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.suhasdissa.vibeyou.ui.screens.settings

import android.annotation.SuppressLint
import android.app.Activity
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
Expand All @@ -16,14 +17,19 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.viewmodel.compose.viewModel
import app.suhasdissa.vibeyou.MellowMusicApplication
import app.suhasdissa.vibeyou.R
import app.suhasdissa.vibeyou.backend.viewmodel.DatabaseViewModel
import app.suhasdissa.vibeyou.ui.components.SettingItem
import app.suhasdissa.vibeyou.utils.Pref
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.text.SimpleDateFormat
import java.util.Date

Expand Down Expand Up @@ -62,6 +68,20 @@ fun DatabaseSettingsScreen(
.padding(innerPadding)
.nestedScroll(topBarBehavior.nestedScrollConnection)
) {
item {
val scope = rememberCoroutineScope()

SwitchPref(
prefKey = Pref.disableSearchHistoryKey,
title = stringResource(R.string.disable_search_history)
) { newValue ->
if (newValue) scope.launch(Dispatchers.IO) {
val app = ((context as Activity).application as MellowMusicApplication)
app.container.database.searchDao().deleteAll()
}
}
}

item {
SettingItem(
title = stringResource(R.string.backup),
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/app/suhasdissa/vibeyou/utils/Pref.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object Pref {
const val latestSongsSortOrderKey = "LatestSongsSortOrderKey"
const val latestReverseSongsPrefKey = "LatestReverseSongsPrefKey"
const val customPipedInstanceKey = "CustomPipedInstanceKey"
const val disableSearchHistoryKey = "DisableSearchHistory"

lateinit var sharedPreferences: SharedPreferences

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@
<string name="delete_playlist">Delete Playlist</string>
<string name="delete_playlist_and_songs">Delete playlist and songs</string>
<string name="clear_playlist">Clear Playlist</string>
<string name="disable_search_history">Disable search history</string>
</resources>

0 comments on commit 32823bc

Please sign in to comment.