Skip to content

Commit

Permalink
feat: disable screenshot, close #1492
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang committed Aug 30, 2024
1 parent e07e96d commit 02fa201
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 11 deletions.
20 changes: 20 additions & 0 deletions app/src/main/java/com/zionhuang/music/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.graphics.drawable.BitmapDrawable
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.AnimatedVisibility
Expand Down Expand Up @@ -99,6 +100,7 @@ import com.zionhuang.innertube.models.SongItem
import com.zionhuang.music.constants.AppBarHeight
import com.zionhuang.music.constants.DarkModeKey
import com.zionhuang.music.constants.DefaultOpenTabKey
import com.zionhuang.music.constants.DisableScreenshotKey
import com.zionhuang.music.constants.DynamicThemeKey
import com.zionhuang.music.constants.MiniPlayerHeight
import com.zionhuang.music.constants.NavigationBarAnimationSpec
Expand Down Expand Up @@ -146,6 +148,8 @@ import com.zionhuang.music.utils.urlEncode
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.net.URLDecoder
Expand Down Expand Up @@ -202,6 +206,22 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)

lifecycleScope.launch {
dataStore.data
.map { it[DisableScreenshotKey] ?: false }
.distinctUntilChanged()
.collectLatest {
if (it) {
window.setFlags(
WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE
)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}
}

setContent {
LaunchedEffect(Unit) {
if (System.currentTimeMillis() - Updater.lastCheckTime > 1.days.inWholeMilliseconds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ enum class GridCellSize {
const val SYSTEM_DEFAULT = "SYSTEM_DEFAULT"
val ContentLanguageKey = stringPreferencesKey("contentLanguage")
val ContentCountryKey = stringPreferencesKey("contentCountry")
val EnableKugouKey = booleanPreferencesKey("enableKugou")
val EnableLrcLibKey = booleanPreferencesKey("enableLrcLib")
val HideExplicitKey = booleanPreferencesKey("hideExplicit")
val ProxyEnabledKey = booleanPreferencesKey("proxyEnabled")
val ProxyUrlKey = stringPreferencesKey("proxyUrl")
val ProxyTypeKey = stringPreferencesKey("proxyType")
Expand All @@ -46,9 +49,7 @@ val MaxSongCacheSizeKey = intPreferencesKey("maxSongCacheSize")

val PauseListenHistoryKey = booleanPreferencesKey("pauseListenHistory")
val PauseSearchHistoryKey = booleanPreferencesKey("pauseSearchHistory")
val EnableKugouKey = booleanPreferencesKey("enableKugou")
val EnableLrcLibKey = booleanPreferencesKey("enableLrcLib")
val HideExplicitKey = booleanPreferencesKey("hideExplicit")
val DisableScreenshotKey = booleanPreferencesKey("disableScreenshot")

val DiscordTokenKey = stringPreferencesKey("discordToken")
val DiscordInfoDismissedKey = booleanPreferencesKey("discordInfoDismissed_v2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import androidx.navigation.NavController
import com.zionhuang.music.LocalDatabase
import com.zionhuang.music.LocalPlayerAwareWindowInsets
import com.zionhuang.music.R
import com.zionhuang.music.constants.DisableScreenshotKey
import com.zionhuang.music.constants.PauseListenHistoryKey
import com.zionhuang.music.constants.PauseSearchHistoryKey
import com.zionhuang.music.ui.component.DefaultDialog
import com.zionhuang.music.ui.component.IconButton
import com.zionhuang.music.ui.component.PreferenceEntry
import com.zionhuang.music.ui.component.PreferenceGroupTitle
import com.zionhuang.music.ui.component.SwitchPreference
import com.zionhuang.music.ui.utils.backToMain
import com.zionhuang.music.utils.rememberPreference
Expand All @@ -46,11 +48,9 @@ fun PrivacySettings(
val database = LocalDatabase.current
val (pauseListenHistory, onPauseListenHistoryChange) = rememberPreference(key = PauseListenHistoryKey, defaultValue = false)
val (pauseSearchHistory, onPauseSearchHistoryChange) = rememberPreference(key = PauseSearchHistoryKey, defaultValue = false)
val (disableScreenshot, onDisableScreenshotChange) = rememberPreference(key = DisableScreenshotKey, defaultValue = false)

var showClearListenHistoryDialog by remember {
mutableStateOf(false)
}

var showClearListenHistoryDialog by remember { mutableStateOf(false) }
if (showClearListenHistoryDialog) {
DefaultDialog(
onDismiss = { showClearListenHistoryDialog = false },
Expand Down Expand Up @@ -82,10 +82,7 @@ fun PrivacySettings(
)
}

var showClearSearchHistoryDialog by remember {
mutableStateOf(false)
}

var showClearSearchHistoryDialog by remember { mutableStateOf(false) }
if (showClearSearchHistoryDialog) {
DefaultDialog(
onDismiss = { showClearSearchHistoryDialog = false },
Expand Down Expand Up @@ -124,28 +121,51 @@ fun PrivacySettings(
) {
Spacer(Modifier.windowInsetsPadding(LocalPlayerAwareWindowInsets.current.only(WindowInsetsSides.Top)))

PreferenceGroupTitle(
title = stringResource(R.string.listen_history)
)

SwitchPreference(
title = { Text(stringResource(R.string.pause_listen_history)) },
icon = { Icon(painterResource(R.drawable.history), null) },
checked = pauseListenHistory,
onCheckedChange = onPauseListenHistoryChange
)

PreferenceEntry(
title = { Text(stringResource(R.string.clear_listen_history)) },
icon = { Icon(painterResource(R.drawable.delete_history), null) },
onClick = { showClearListenHistoryDialog = true }
)

PreferenceGroupTitle(
title = stringResource(R.string.search_history)
)

SwitchPreference(
title = { Text(stringResource(R.string.pause_search_history)) },
icon = { Icon(painterResource(R.drawable.search_off), null) },
checked = pauseSearchHistory,
onCheckedChange = onPauseSearchHistoryChange
)

PreferenceEntry(
title = { Text(stringResource(R.string.clear_search_history)) },
icon = { Icon(painterResource(R.drawable.clear_all), null) },
onClick = { showClearSearchHistoryDialog = true }
)

PreferenceGroupTitle(
title = stringResource(R.string.misc)
)

SwitchPreference(
title = { Text(stringResource(R.string.disable_screenshot)) },
description = stringResource(R.string.disable_screenshot_desc),
icon = { Icon(painterResource(R.drawable.screenshot), null) },
checked = disableScreenshot,
onCheckedChange = onDisableScreenshotChange
)
}

TopAppBar(
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/screenshot.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M480,680L480,620L580,620L580,520L640,520L640,680L480,680ZM320,440L320,280L480,280L480,340L380,340L380,440L320,440ZM280,920Q247,920 223.5,896.5Q200,873 200,840L200,120Q200,87 223.5,63.5Q247,40 280,40L680,40Q713,40 736.5,63.5Q760,87 760,120L760,840Q760,873 736.5,896.5Q713,920 680,920L280,920ZM280,800L280,840Q280,840 280,840Q280,840 280,840L680,840Q680,840 680,840Q680,840 680,840L680,800L280,800ZM280,720L680,720L680,240L280,240L280,720ZM280,160L680,160L680,120Q680,120 680,120Q680,120 680,120L280,120Q280,120 280,120Q280,120 280,120L280,160ZM280,160L280,120Q280,120 280,120Q280,120 280,120L280,120Q280,120 280,120Q280,120 280,120L280,160ZM280,800L280,800L280,840Q280,840 280,840Q280,840 280,840L280,840Q280,840 280,840Q280,840 280,840L280,800Z" />
</vector>
4 changes: 4 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,16 @@
<string name="size_used">已使用 %s</string>

<string name="privacy">隱私</string>
<string name="listen_history">觀看記錄</string>
<string name="pause_listen_history">暫停觀看記錄</string>
<string name="clear_listen_history">清除觀看記錄</string>
<string name="clear_listen_history_confirm">您確定要清除所有觀看記錄嗎?</string>
<string name="search_history">搜尋記錄</string>
<string name="pause_search_history">暫停搜尋記錄</string>
<string name="clear_search_history">清除搜尋記錄</string>
<string name="clear_search_history_confirm">您確定要清除所有搜尋記錄嗎?</string>
<string name="disable_screenshot">禁用截圖</string>
<string name="disable_screenshot_desc">當此選項開啟時,您無法截圖,也無法在「最近使用」中看到此應用程式的畫面。</string>
<string name="enable_lrclib">使用 LrcLib 提供歌詞</string>
<string name="enable_kugou">使用酷狗音樂提供歌詞</string>
<string name="hide_explicit">移除不適當內容</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,16 @@
<string name="size_used">%s used</string>

<string name="privacy">Privacy</string>
<string name="listen_history">Listen history</string>
<string name="pause_listen_history">Pause listen history</string>
<string name="clear_listen_history">Clear listen history</string>
<string name="clear_listen_history_confirm">Are you sure you want to clear all listen history?</string>
<string name="search_history">Search history</string>
<string name="pause_search_history">Pause search history</string>
<string name="clear_search_history">Clear search history</string>
<string name="clear_search_history_confirm">Are you sure you want to clear all search history?</string>
<string name="disable_screenshot">Disable screenshot</string>
<string name="disable_screenshot_desc">When this option is on, screenshots and the app\'s view in Recents are disabled.</string>
<string name="enable_lrclib">Enable LrcLib lyrics provider</string>
<string name="enable_kugou">Enable KuGou lyrics provider</string>
<string name="hide_explicit">Hide explicit content</string>
Expand Down

0 comments on commit 02fa201

Please sign in to comment.