-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathSettingsActivity.kt
More file actions
54 lines (46 loc) · 1.97 KB
/
SettingsActivity.kt
File metadata and controls
54 lines (46 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package net.activitywatch.android
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.switchmaterial.SwitchMaterial
class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.title = getString(R.string.settings_title)
val prefs = AWPreferences(this)
val switchNetworkAccess = findViewById<SwitchMaterial>(R.id.switchNetworkAccess)
switchNetworkAccess.isChecked = prefs.isNetworkAccessEnabled()
switchNetworkAccess.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
// Show security warning before enabling
AlertDialog.Builder(this)
.setTitle(R.string.network_access_warning_title)
.setMessage(R.string.network_access_warning_message)
.setPositiveButton(R.string.network_access_warning_enable) { _, _ ->
prefs.setNetworkAccessEnabled(true)
showRestartNotice()
}
.setNegativeButton(android.R.string.cancel) { _, _ ->
switchNetworkAccess.isChecked = false
}
.setOnCancelListener {
switchNetworkAccess.isChecked = false
}
.show()
} else {
prefs.setNetworkAccessEnabled(false)
showRestartNotice()
}
}
}
private fun showRestartNotice() {
Toast.makeText(this, R.string.network_access_restart_notice, Toast.LENGTH_LONG).show()
}
override fun onSupportNavigateUp(): Boolean {
finish()
return true
}
}