Skip to content

Commit 7799993

Browse files
Add setting (off by default) to prevent screenshots. (#685)
* Add setting (off by default) to prevent screenshots. * Move secure window handling to the Theme. --------- Co-authored-by: Dessalines <[email protected]>
1 parent 1acf3bf commit 7799993

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

app/src/main/java/com/jerboa/db/AppDB.kt

+16-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ data class AppSettings(
103103
defaultValue = "0",
104104
)
105105
val usePrivateTabs: Boolean,
106+
@ColumnInfo(
107+
name = "secure_window",
108+
defaultValue = "0",
109+
)
110+
val secureWindow: Boolean,
106111
)
107112

108113
@Dao
@@ -400,8 +405,17 @@ val MIGRATION_13_14 = object : Migration(13, 14) {
400405
}
401406
}
402407

408+
val MIGRATION_14_15 = object : Migration(14, 15) {
409+
override fun migrate(database: SupportSQLiteDatabase) {
410+
database.execSQL(UPDATE_APP_CHANGELOG_UNVIEWED)
411+
database.execSQL(
412+
"ALTER TABLE AppSettings add column secure_window INTEGER NOT NULL default 0",
413+
)
414+
}
415+
}
416+
403417
@Database(
404-
version = 14,
418+
version = 15,
405419
entities = [Account::class, AppSettings::class],
406420
exportSchema = true,
407421
)
@@ -439,6 +453,7 @@ abstract class AppDB : RoomDatabase() {
439453
MIGRATION_11_12,
440454
MIGRATION_12_13,
441455
MIGRATION_13_14,
456+
MIGRATION_14_15,
442457
)
443458
// Necessary because it can't insert data on creation
444459
.addCallback(object : Callback() {

app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt

+10
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ fun LookAndFeelActivity(
6262
val useCustomTabsState = rememberBooleanSettingState(settings?.useCustomTabs ?: true)
6363
val usePrivateTabsState = rememberBooleanSettingState(settings?.usePrivateTabs ?: false)
6464

65+
val secureWindowState = rememberBooleanSettingState(settings?.secureWindow ?: false)
66+
6567
val snackbarHostState = remember { SnackbarHostState() }
6668

6769
val scrollState = rememberScrollState()
@@ -81,6 +83,7 @@ fun LookAndFeelActivity(
8183
showVotingArrowsInListView = showVotingArrowsInListViewState.value,
8284
useCustomTabs = useCustomTabsState.value,
8385
usePrivateTabs = usePrivateTabsState.value,
86+
secureWindow = secureWindowState.value,
8487
),
8588
)
8689
}
@@ -209,6 +212,13 @@ fun LookAndFeelActivity(
209212
},
210213
onCheckedChange = { updateAppSettings() },
211214
)
215+
SettingsCheckbox(
216+
state = secureWindowState,
217+
title = {
218+
Text(text = stringResource(R.string.look_and_feel_secure_window))
219+
},
220+
onCheckedChange = { updateAppSettings() },
221+
)
212222
}
213223
},
214224
)

app/src/main/java/com/jerboa/ui/theme/Theme.kt

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.jerboa.ui.theme
22

33
import android.app.Activity
44
import android.os.Build
5+
import android.view.WindowManager
56
import androidx.compose.foundation.isSystemInDarkTheme
67
import androidx.compose.material3.ColorScheme
78
import androidx.compose.material3.MaterialTheme
@@ -84,6 +85,14 @@ fun JerboaTheme(
8485
else -> true
8586
}
8687

88+
appSettings?.let {
89+
if (it.secureWindow) {
90+
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
91+
} else {
92+
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
93+
}
94+
}
95+
8796
window.statusBarColor = colors.background.toArgb()
8897
// The navigation bar color is also set on BottomAppBarAll
8998
window.navigationBarColor = colors.background.toArgb()

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
<string name="look_and_feel_post_view_card">Card</string>
183183
<string name="look_and_feel_post_view_list">List</string>
184184
<string name="look_and_feel_post_view_small_card">Small Card</string>
185+
<string name="look_and_feel_secure_window">Prevent Screenshots</string>
185186
<string name="look_and_feel_show_action_bar_for_comments">Show action bar by default for comments</string>
186187
<string name="look_and_feel_show_navigation_bar">Show navigation bar</string>
187188
<string name="look_and_feel_show_voting_arrows_list_view">Show voting arrows in list view</string>

0 commit comments

Comments
 (0)