feat(kiosk): add screensaver toggle in settings (default off)
This commit is contained in:
@@ -96,6 +96,7 @@ class KioskActivity : AppCompatActivity() {
|
||||
private const val KEY_URL = "evershelf_url"
|
||||
private const val KEY_SETUP_COMPLETE = "setup_complete"
|
||||
private const val KEY_HAS_SCALE = "has_scale"
|
||||
private const val KEY_SCREENSAVER = "screensaver_enabled"
|
||||
private const val GATEWAY_PACKAGE = "it.dadaloop.evershelf.scalegate"
|
||||
private const val GATEWAY_DOWNLOAD_URL = "https://github.com/dadaloop82/EverShelf/releases/latest/download/evershelf-scale-gateway.apk"
|
||||
private const val KIOSK_DOWNLOAD_URL = "https://github.com/dadaloop82/EverShelf/releases/latest/download/evershelf-kiosk.apk"
|
||||
@@ -428,8 +429,16 @@ class KioskActivity : AppCompatActivity() {
|
||||
webView.loadUrl(url)
|
||||
|
||||
launchGatewayInBackground()
|
||||
applyScreensaverFlag()
|
||||
}
|
||||
|
||||
private fun applyScreensaverFlag() {
|
||||
if (prefs.getBoolean(KEY_SCREENSAVER, false)) {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
} else {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Inject kiosk overlay (exit + refresh buttons) ────────────────────
|
||||
|
||||
@@ -778,6 +787,8 @@ class KioskActivity : AppCompatActivity() {
|
||||
if (prefs.getBoolean(KEY_SETUP_COMPLETE, false) && webView.visibility == View.VISIBLE) {
|
||||
val url = prefs.getString(KEY_URL, "") ?: ""
|
||||
if (url.isNotEmpty() && webView.url != url) webView.loadUrl(url)
|
||||
// Re-apply screensaver flag in case the user changed it in Settings
|
||||
applyScreensaverFlag()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-2
@@ -6,11 +6,13 @@ import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.WindowManager
|
||||
import android.widget.EditText
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.switchmaterial.SwitchMaterial
|
||||
import java.net.URL
|
||||
import javax.net.ssl.HttpsURLConnection
|
||||
import javax.net.ssl.SSLContext
|
||||
@@ -26,6 +28,7 @@ class SettingsActivity : AppCompatActivity() {
|
||||
private const val PREFS_NAME = "evershelf_kiosk"
|
||||
private const val KEY_URL = "evershelf_url"
|
||||
private const val KEY_SETUP_COMPLETE = "setup_complete"
|
||||
private const val KEY_SCREENSAVER = "screensaver_enabled"
|
||||
private const val GATEWAY_PACKAGE = "it.dadaloop.evershelf.scalegate"
|
||||
}
|
||||
|
||||
@@ -38,6 +41,10 @@ class SettingsActivity : AppCompatActivity() {
|
||||
|
||||
urlEdit.setText(prefs.getString(KEY_URL, "") ?: "")
|
||||
|
||||
// Screensaver toggle (default OFF = keep screen on)
|
||||
val switchScreensaver = findViewById<SwitchMaterial>(R.id.switchScreensaver)
|
||||
switchScreensaver.isChecked = prefs.getBoolean(KEY_SCREENSAVER, false)
|
||||
|
||||
// Gateway status
|
||||
val gatewayInstalled = try {
|
||||
packageManager.getPackageInfo(GATEWAY_PACKAGE, 0)
|
||||
@@ -77,8 +84,18 @@ class SettingsActivity : AppCompatActivity() {
|
||||
Toast.makeText(this, "URL cannot be empty", Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
prefs.edit().putString(KEY_URL, url).apply()
|
||||
Toast.makeText(this, "Settings saved", Toast.LENGTH_SHORT).show()
|
||||
val screensaverOn = switchScreensaver.isChecked
|
||||
prefs.edit()
|
||||
.putString(KEY_URL, url)
|
||||
.putBoolean(KEY_SCREENSAVER, screensaverOn)
|
||||
.apply()
|
||||
// Apply FLAG_KEEP_SCREEN_ON immediately based on new setting
|
||||
if (screensaverOn) {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
} else {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
Toast.makeText(this, "Impostazioni salvate", Toast.LENGTH_SHORT).show()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +143,61 @@
|
||||
android:textSize="13sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Screensaver Section -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="SCHERMO"
|
||||
android:textColor="#7c3aed"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold"
|
||||
android:letterSpacing="0.1"
|
||||
android:layout_marginBottom="12dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/card_background"
|
||||
android:padding="16dp"
|
||||
android:layout_marginBottom="24dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Salvaschermo"
|
||||
android:textColor="#cbd5e1"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Oscura lo schermo dopo inattività (default: off)"
|
||||
android:textColor="#64748b"
|
||||
android:textSize="12sp"
|
||||
android:layout_marginTop="2dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/switchScreensaver"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="false" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Danger Zone -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user