Skip to content

Commit

Permalink
Add setting (off by default) to prevent screenshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
camporter committed Jun 15, 2023
1 parent eb7a7c4 commit d505a97
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Patterns
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
Expand All @@ -26,6 +27,7 @@ import com.jerboa.db.AccountRepository
import com.jerboa.db.AccountViewModel
import com.jerboa.db.AccountViewModelFactory
import com.jerboa.db.AppDB
import com.jerboa.db.AppSettings
import com.jerboa.db.AppSettingsRepository
import com.jerboa.db.AppSettingsViewModel
import com.jerboa.db.AppSettingsViewModelFactory
Expand Down Expand Up @@ -98,6 +100,14 @@ class MainActivity : ComponentActivity() {
AppSettingsViewModelFactory((application as JerboaApplication).appSettingsRepository)
}

private fun updateWindowFlags(appSettings: AppSettings) {
if (appSettings.secureWindow) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -111,6 +121,8 @@ class MainActivity : ComponentActivity() {
val account = getCurrentAccount(accountViewModel)
val appSettings by appSettingsViewModel.appSettings.observeAsState()

appSettings?.let { updateWindowFlags(it) }

JerboaTheme(
appSettings = appSettings,
) {
Expand Down
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 @@ -94,6 +94,11 @@ data class AppSettings(
defaultValue = "0",
)
val usePrivateTabs: Boolean,
@ColumnInfo(
name = "secure_window",
defaultValue = "0",
)
val secureWindow: Boolean,
)

@Dao
Expand Down Expand Up @@ -367,8 +372,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 @@ -406,6 +420,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
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 @@ -181,6 +181,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

0 comments on commit d505a97

Please sign in to comment.