Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting (off by default) to prevent screenshots. #685

Merged
merged 3 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/src/main/java/com/jerboa/db/AppDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ data class AppSettings(
defaultValue = "0",
)
val usePrivateTabs: Boolean,
@ColumnInfo(
name = "secure_window",
defaultValue = "0",
)
val secureWindow: Boolean,
)

@Dao
Expand Down Expand Up @@ -400,8 +405,17 @@ val MIGRATION_13_14 = object : Migration(13, 14) {
}
}

val MIGRATION_14_15 = object : Migration(14, 15) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(UPDATE_APP_CHANGELOG_UNVIEWED)
database.execSQL(
"ALTER TABLE AppSettings add column secure_window INTEGER NOT NULL default 0",
)
}
}

@Database(
version = 14,
version = 15,
entities = [Account::class, AppSettings::class],
exportSchema = true,
)
Expand Down Expand Up @@ -439,6 +453,7 @@ abstract class AppDB : RoomDatabase() {
MIGRATION_11_12,
MIGRATION_12_13,
MIGRATION_13_14,
MIGRATION_14_15,
)
// Necessary because it can't insert data on creation
.addCallback(object : Callback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ fun LookAndFeelActivity(
val useCustomTabsState = rememberBooleanSettingState(settings?.useCustomTabs ?: true)
val usePrivateTabsState = rememberBooleanSettingState(settings?.usePrivateTabs ?: false)

val secureWindowState = rememberBooleanSettingState(settings?.secureWindow ?: false)

val snackbarHostState = remember { SnackbarHostState() }

val scrollState = rememberScrollState()
Expand All @@ -81,6 +83,7 @@ fun LookAndFeelActivity(
showVotingArrowsInListView = showVotingArrowsInListViewState.value,
useCustomTabs = useCustomTabsState.value,
usePrivateTabs = usePrivateTabsState.value,
secureWindow = secureWindowState.value,
),
)
}
Expand Down Expand Up @@ -209,6 +212,13 @@ fun LookAndFeelActivity(
},
onCheckedChange = { updateAppSettings() },
)
SettingsCheckbox(
state = secureWindowState,
title = {
Text(text = stringResource(R.string.look_and_feel_secure_window))
},
onCheckedChange = { updateAppSettings() },
)
}
},
)
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/jerboa/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jerboa.ui.theme

import android.app.Activity
import android.os.Build
import android.view.WindowManager
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -84,6 +85,14 @@ fun JerboaTheme(
else -> true
}

appSettings?.let {
if (it.secureWindow) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}

window.statusBarColor = colors.background.toArgb()
// The navigation bar color is also set on BottomAppBarAll
window.navigationBarColor = colors.background.toArgb()
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 @@ -182,6 +182,7 @@
<string name="look_and_feel_post_view_card">Card</string>
<string name="look_and_feel_post_view_list">List</string>
<string name="look_and_feel_post_view_small_card">Small Card</string>
<string name="look_and_feel_secure_window">Prevent Screenshots</string>
<string name="look_and_feel_show_action_bar_for_comments">Show action bar by default for comments</string>
<string name="look_and_feel_show_navigation_bar">Show navigation bar</string>
<string name="look_and_feel_show_voting_arrows_list_view">Show voting arrows in list view</string>
Expand Down