Skip to content

Commit

Permalink
feat: disable screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang authored and Malopieds committed Aug 30, 2024
1 parent 94aee05 commit 652fb7d
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 12 deletions.
19 changes: 19 additions & 0 deletions app/src/main/java/com/malopieds/innertune/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 @@ -128,6 +129,8 @@ import com.valentinilk.shimmer.LocalShimmerTheme
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 @@ -189,6 +192,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 @@ -22,6 +22,9 @@ enum class SliderStyle {
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 @@ -45,9 +48,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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.navigation.NavController
import com.malopieds.innertune.LocalDatabase
import com.malopieds.innertune.LocalPlayerAwareWindowInsets
import com.malopieds.innertune.R
import com.malopieds.innertune.constants.DisableScreenshotKey
import com.malopieds.innertune.constants.EnableKugouKey
import com.malopieds.innertune.constants.EnableLrcLibKey
import com.malopieds.innertune.constants.PauseListenHistoryKey
Expand All @@ -41,6 +42,7 @@ import com.malopieds.innertune.ui.component.DefaultDialog
import com.malopieds.innertune.ui.component.IconButton
import com.malopieds.innertune.ui.component.ListPreference
import com.malopieds.innertune.ui.component.PreferenceEntry
import com.malopieds.innertune.ui.component.PreferenceGroupTitle
import com.malopieds.innertune.ui.component.SwitchPreference
import com.malopieds.innertune.ui.utils.backToMain
import com.malopieds.innertune.utils.rememberEnumPreference
Expand All @@ -62,11 +64,9 @@ fun PrivacySettings(
key = PreferredLyricsProviderKey,
defaultValue = PreferredLyricsProvider.LRCLIB,
)
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 @@ -98,10 +98,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 @@ -140,23 +137,34 @@ 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) },
Expand All @@ -182,6 +190,18 @@ fun PrivacySettings(
valueText = { it.name.toLowerCase(Locale.current).capitalize(Locale.current) },
onValueSelected = onPreferredProviderChange,
)

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>
5 changes: 4 additions & 1 deletion app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,17 @@
<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_kugou">使用酷狗音樂提供歌詞</string>
<string name="enable_lrclib">使用 LrcLib 提供歌詞</string>
<string name="set_first_lyrics_provider">設定首選的歌詞提供服務商</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 @@ -310,12 +310,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_kugou">Enable KuGou lyrics provider</string>
<string name="enable_lrclib">Enable LrcLib lyrics provider</string>
<string name="set_first_lyrics_provider">Set the first lyrics provider</string>
Expand Down

0 comments on commit 652fb7d

Please sign in to comment.