commit ed0a6cb1859e0777d80a52c90bd7279f2d1ecb4a Author: Robin Schanbacher Date: Wed Jul 8 16:48:29 2026 +0200 Initial commit (files only) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..639c779 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..7061a0d --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,61 @@ + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b2c751a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.kotlin/errors/errors-1776355108600.log b/.kotlin/errors/errors-1776355108600.log new file mode 100644 index 0000000..1219b50 --- /dev/null +++ b/.kotlin/errors/errors-1776355108600.log @@ -0,0 +1,4 @@ +kotlin version: 2.0.21 +error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output: + 1. Kotlin compile daemon is ready + diff --git a/README.md b/README.md new file mode 100644 index 0000000..ee2757a --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Screenity +by Robin Schanbacher (robin@schanbros.de) +![App-Icon](images/screenity.png) + +# What does it do? +If you install Screenity on all your devices (currently just android possible), it shows you all your screentime – from all devices. + +# What is it able to do? +- collect your screentime and send it to a self-hosted server +- show your today's, local's and each device's screentime +- multiple accounts + +# What is planned to implement? +- Widgets +- filters +- admin-page (web) +- internal und extetnal connection to server +- optimize and publish server files + +# Else +As you hopefully noticed, the project is very new. It is also my first bigger project, so i'm sorry for the mistakes i'll make :) +Since i'm currently lerning Kotlin with Jetpack Compose, this is a project for my personal education. If i've enough experience, i'll try to start more projects. + +Since i'm still a student i'd be glad for any help. Thank you! + +[![Get it on Obtainium](https://raw.githubusercontent.com/ImranR98/Obtainium/main/assets/graphics/badge_obtainium.png)](https://apps.obtainium.imranr.dev/redirect?r=obtainium://add/https://github.com/RobinS-T470s/Screenity) diff --git a/android_build.yml b/android_build.yml new file mode 100644 index 0000000..8c06f04 --- /dev/null +++ b/android_build.yml @@ -0,0 +1,37 @@ +name: Android Build & Release + +# Der Bot startet nur, wenn du ein "Tag" pushst (z.B. v1.0) +on: + push: + tags: + - 'v*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Java einrichten + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + + - name: Berechtigung für Gradle setzen + run: chmod +x gradlew + + - name: APK bauen (Debug Version) + run: ./gradlew assembleDebug + + - name: Release erstellen und APK hochladen + uses: softprops/action-gh-release@v2 + with: + files: app/build/outputs/apk/debug/*.apk + name: Release ${{ github.ref_name }} + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..57dca72 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,96 @@ +import org.gradle.kotlin.dsl.create +import org.gradle.kotlin.dsl.getByName +import org.gradle.kotlin.dsl.release + +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.compose) +} + +android { + namespace = "de.schanbro.screenity" + compileSdk = 36 + + defaultConfig { + applicationId = "de.schanbro.screenity" + minSdk = 29 + targetSdk = 36 + + val gitVersion = System.getenv("APP_VERSION") ?: "0.0.1-local" + versionName = gitVersion.removePrefix("v") + versionCode = (System.currentTimeMillis() / 600000).toInt() + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + signingConfigs { + create("release") { + storeFile = file("keystore.jks") + storePassword = System.getenv("KEY_STORE_PASSWORD") + keyAlias = System.getenv("ALIAS") + keyPassword = System.getenv("KEY_PASSWORD") + } + } + + buildTypes { + release { + isMinifyEnabled = false + // Hier kommt alles in EINEN Block: + signingConfig = signingConfigs.getByName("release") + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } + buildFeatures { + compose = true + } + + // Optional: Damit die Datei auf GitHub auch den richtigen Namen hat + applicationVariants.all { + outputs.all { + val output = this as com.android.build.gradle.internal.api.ApkVariantOutputImpl + output.outputFileName = "Screenity-${versionName}.apk" + } + } +} + +dependencies { + implementation(libs.androidx.compose.animation) + val workVersion = "2.9.0" // Prüfe hier gern auf die aktuellste Version + implementation("androidx.work:work-runtime-ktx:$workVersion") + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.graphics) + implementation(libs.androidx.compose.ui.tooling.preview) + implementation(libs.androidx.compose.material3) + implementation(libs.androidx.navigation.compose) + implementation(libs.androidx.ui) + implementation(libs.androidx.material3) + implementation(libs.androidx.ui.graphics) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.androidx.compose.ui.test.junit4) + debugImplementation(libs.androidx.compose.ui.tooling) + debugImplementation(libs.androidx.compose.ui.test.manifest) + implementation("androidx.compose.material:material-icons-extended") + implementation("com.squareup.okhttp3:okhttp:4.12.0") + implementation("com.google.code.gson:gson:2.10.1") + implementation("androidx.glance:glance-appwidget:1.1.0") // Oder aktuellste Version + implementation("androidx.glance:glance-material3:1.1.0") +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/de/schanbro/screenity/ExampleInstrumentedTest.kt b/app/src/androidTest/java/de/schanbro/screenity/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..c00b789 --- /dev/null +++ b/app/src/androidTest/java/de/schanbro/screenity/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package de.schanbro.screenity + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("de.schanbro.screenity", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..7f38e09 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/CommunikationToServer.kt b/app/src/main/java/de/schanbro/screenity/CommunikationToServer.kt new file mode 100644 index 0000000..f35a0ce --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/CommunikationToServer.kt @@ -0,0 +1,50 @@ +package de.schanbro.screenity + +import android.content.Context +import android.provider.Settings +import com.google.gson.Gson +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import okhttp3.* +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.RequestBody.Companion.toRequestBody +import java.text.SimpleDateFormat +import java.util.* + +data class DeviceFullData( + val device_id: String, + val device_name: String, + val reports: Map +) + +// --- NETZWERK LOGIK --- +suspend fun sendDataToServer( + context: Context, + url: String, + totalMs: Long, + usageList: List, + detailedEvents: List +): Boolean = withContext(Dispatchers.IO) { + if (url.isBlank()) return@withContext false + val client = OkHttpClient() + val reportData = mapOf( + "device_id" to Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID), + "device_name" to android.os.Build.MODEL, + "report_date" to SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date()), + "total_screen_time_ms" to totalMs, + "apps" to usageList.map { mapOf("app_name" to it.appName, "usage_ms" to it.usageMs) } + ) + try { + val body = Gson().toJson(reportData).toRequestBody("application/json".toMediaType()) + val request = Request.Builder().url("${url.trim().removeSuffix("/")}/report").post(body).build() + client.newCall(request).execute().isSuccessful + } catch (e: Exception) { false } +} + +suspend fun getSummaryFromServer(url: String): ServerSummary = withContext(Dispatchers.IO) { + val client = OkHttpClient() + val request = Request.Builder().url("${url.trim().removeSuffix("/")}/summary").build() + val response = client.newCall(request).execute() + if (!response.isSuccessful) throw Exception("Code: ${response.code}") + Gson().fromJson(response.body?.string(), ServerSummary::class.java) +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/DeviceDetailScreen.kt b/app/src/main/java/de/schanbro/screenity/DeviceDetailScreen.kt new file mode 100644 index 0000000..1815bdb --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/DeviceDetailScreen.kt @@ -0,0 +1,164 @@ +package de.schanbro.screenity + +import android.content.Context +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Refresh +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import com.google.gson.Gson +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import okhttp3.OkHttpClient +import okhttp3.Request +import java.text.SimpleDateFormat +import java.util.* + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun DeviceDetailScreen(deviceId: String, onBack: () -> Unit) { + val context = LocalContext.current + val scope = rememberCoroutineScope() + val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) } + val serverUrl = prefs.getString("server_url", "") ?: "" + + var isLoading by remember { mutableStateOf(true) } + var appsFromToday by remember { mutableStateOf>(emptyList()) } + var deviceName by remember { mutableStateOf("Gerät") } + + val todayStr = SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date()) + + fun fetch() { + android.util.Log.d("SCREENITY_CHECK", "1. fetch() gestartet für ID: $deviceId") + if (serverUrl.isBlank()) return + + scope.launch { + isLoading = true + try { + val client = OkHttpClient() + val fullUrl = "${serverUrl.trim().removeSuffix("/")}/summary" + val request = Request.Builder().url(fullUrl).build() + + val response = withContext(Dispatchers.IO) { client.newCall(request).execute() } + + if (response.isSuccessful) { + // WICHTIG: Body nur einmal auslesen und in Variable speichern + val responseBodyString = withContext(Dispatchers.IO) { response.body?.string() } ?: "" + android.util.Log.d("SCREENITY_CHECK", "2. JSON geladen, Länge: ${responseBodyString.length}") + + if (responseBodyString.isNotBlank()) { + try { + val fullSummary = Gson().fromJson(responseBodyString, ServerSummary::class.java) + + // Gerät in der Liste suchen + val device = fullSummary.devices.find { it.device_id.trim() == deviceId.trim() } + + if (device != null) { + deviceName = device.device_name + android.util.Log.d("SCREENITY_CHECK", "3. Gerät gefunden: ${device.device_name}") + + // Report für heute heraussuchen + val report = device.reports?.get(todayStr) + if (report != null) { + appsFromToday = report.apps ?: emptyList() + android.util.Log.d("SCREENITY_CHECK", "4. Apps für heute gefunden: ${appsFromToday.size}") + } else { + android.util.Log.w("SCREENITY_CHECK", "Hinweis: Kein Report für $todayStr vorhanden.") + // Debug: Zeige welche Tage da sind + android.util.Log.d("SCREENITY_CHECK", "Verfügbare Tage: ${device.reports?.keys}") + } + } else { + android.util.Log.e("SCREENITY_CHECK", "Fehler: Gerät mit ID $deviceId nicht in Liste.") + } + } catch (e: Exception) { + android.util.Log.e("SCREENITY_CHECK", "Parsing-Fehler: ${e.message}") + android.util.Log.d("SCREENITY_CHECK", "Fehlerhaftes JSON: $responseBodyString") + } + } + } else { + android.util.Log.e("SCREENITY_CHECK", "Server Fehler-Code: ${response.code}") + } + } catch (e: Exception) { + android.util.Log.e("SCREENITY_CHECK", "Netzwerk-Fehler: ${e.message}") + } + isLoading = false + } + } + + LaunchedEffect(Unit) { fetch() } + + ScreenWrapper( + title = "Details: $deviceName", + headerAction = { + IconButton(onClick = { fetch() }) { + Icon(Icons.Default.Refresh, contentDescription = "Aktualisieren") + } + } + ) { + if (isLoading) { + Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + CircularProgressIndicator() + } + } else { + Column(Modifier.fillMaxSize()) { + Text( + text = "App-Nutzung heute ($todayStr):", + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.primary, + modifier = Modifier.padding(bottom = 16.dp) + ) + + if (appsFromToday.isEmpty()) { + Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + Text("Keine detaillierten Daten für heute gefunden.", style = MaterialTheme.typography.bodyMedium) + } + } else { + LazyColumn( + modifier = Modifier.fillMaxSize(), + contentPadding = PaddingValues(bottom = 24.dp) + ) { + items(appsFromToday.sortedByDescending { it.usage_ms }) { app -> + AppUsageRow(app) + HorizontalDivider(modifier = Modifier.padding(vertical = 4.dp), thickness = 0.5.dp) + } + } + } + } + } + } +} + +@Composable +fun AppUsageRow(app: AppUsageDetail) { + val h = app.usage_ms / 3600000 + val m = (app.usage_ms % 3600000) / 60000 + val s = (app.usage_ms % 60000) / 1000 + + Row( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 12.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Text( + text = app.app_name, + modifier = Modifier.weight(1f), + style = MaterialTheme.typography.bodyLarge + ) + Text( + text = if (h > 0) String.format("%dh %02dm", h, m) else String.format("%dm %02ds", m, s), + style = MaterialTheme.typography.bodyMedium, + fontWeight = FontWeight.Bold, + fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/DevicesScreen.kt b/app/src/main/java/de/schanbro/screenity/DevicesScreen.kt new file mode 100644 index 0000000..af87153 --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/DevicesScreen.kt @@ -0,0 +1,148 @@ +package de.schanbro.screenity + +import android.app.usage.UsageEvents +import android.app.usage.UsageStatsManager +import android.content.Context +import android.content.Intent +import android.provider.Settings +import android.widget.Toast +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.CloudUpload +import androidx.compose.material.icons.filled.Refresh +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.google.gson.Gson +import com.google.gson.annotations.SerializedName +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody +import java.text.SimpleDateFormat +import java.util.* + +data class DeviceSummary( + val device_id: String, + val device_name: String, + val total_screen_time_hours: Double, + val today_ms: Long, + val reports: Map? // Wichtig: Hier müssen die Reports drin sein! +) + +data class DayReport( + @SerializedName("total_screen_time_ms") val totalMs: Long, + val apps: List? = null +) + +data class AppUsageDetail( + @SerializedName("app_name") val app_name: String, + @SerializedName("usage_ms") val usage_ms: Long +) + +@Composable +fun DevicesScreen(onNavigateToDetail: (String) -> Unit) { + val context = LocalContext.current + val scope = rememberCoroutineScope() + val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) } + val serverUrl = prefs.getString("server_url", "") ?: "" + + var devicesList by remember { mutableStateOf(emptyList()) } + var isLoading by remember { mutableStateOf(false) } + + fun fetch() { + if (serverUrl.isBlank()) return + scope.launch { + isLoading = true + try { + val result = getSummaryFromServer(serverUrl) + // Hier greifen wir auf die Liste der Geräte zu: + val fetchedDevices = result.devices + devicesList = fetchedDevices + + // --- AB HIER NEU: Echte Geräte für das Widget sichern --- + // Wir ziehen uns alle Gerätenamen aus der Liste heraus + val deviceNames = fetchedDevices.map { it.device_name }.toSet() + + // Wir speichern das Set in den SharedPreferences ab + prefs.edit().putStringSet("known_device_ids", deviceNames).apply() + // --- ENDE NEU --- + + } catch (e: Exception) { + // Fehlerbehandlung (z.B. Loggen oder Toast) + } + isLoading = false + } + } + + LaunchedEffect(Unit) { fetch() } + + ScreenWrapper( + title = stringResource(R.string.devices_overview), + headerAction = { + IconButton(onClick = { fetch() }) { + Icon(Icons.Default.Refresh, contentDescription = null) + } + } + ) { + if (isLoading) { + Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + CircularProgressIndicator() + } + } else { + LazyColumn(modifier = Modifier.fillMaxSize()) { + items( + items = devicesList, + key = { it.device_id } + ) { device -> + DeviceUsageRow( + device = device, + onClick = { onNavigateToDetail(device.device_id) } + ) + } + } + } + } +} + +@Composable +fun DeviceUsageRow(device: DeviceSummary, onClick: () -> Unit) { + val h = device.today_ms / 3600000 + val m = (device.today_ms % 3600000) / 60000 + + Card( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 6.dp) + .clickable { onClick() }, + elevation = CardDefaults.cardElevation(2.dp) + ) { + Row( + modifier = Modifier.padding(16.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Column(modifier = Modifier.weight(1f)) { + Text(device.device_name, style = MaterialTheme.typography.titleMedium) + Text("ID: ${device.device_id.take(8)}...", style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant) + } + Text( + text = String.format("%dh %02dm", h, m), + fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace, + style = MaterialTheme.typography.titleLarge, + color = MaterialTheme.colorScheme.primary + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/LocalScreen.kt b/app/src/main/java/de/schanbro/screenity/LocalScreen.kt new file mode 100644 index 0000000..c0c5de9 --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/LocalScreen.kt @@ -0,0 +1,288 @@ +package de.schanbro.screenity + +import android.app.usage.UsageEvents +import android.app.usage.UsageStatsManager +import android.content.Context +import android.content.Intent +import android.provider.Settings +import android.widget.Toast +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.CloudUpload +import androidx.compose.material.icons.filled.Refresh +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.google.gson.Gson +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody +import java.text.SimpleDateFormat +import java.util.* + +// --- DATENMODELL --- +data class AppUsageInfo( + val appName: String, + val usageMs: Long +) + +@Composable +@Preview +fun LocalScreen() { + val context = LocalContext.current + val scope = rememberCoroutineScope() + val snackbarHostState = remember { SnackbarHostState() } + val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) } + val serverUrl = prefs.getString("server_url", "") ?: "" + + var usageList by remember { mutableStateOf>(emptyList()) } + var totalMs by remember { mutableLongStateOf(0L) } + val detailedEvents = getDetailedEvents(context) + var isSending by remember { mutableStateOf(false) } + + fun load() { + scope.launch { + // getTodayUsageEvents solltest du am besten auch auf suspend umstellen! + usageList = getTodayUsageEvents(context) + + // Hier rufen wir unsere neue asynchrone Funktion auf + totalMs = getTotalScreenTime(context) + } + } + + // Beim ersten Start des Screens laden + LaunchedEffect(Unit) { + load() + } + + Scaffold(snackbarHost = { SnackbarHost(snackbarHostState) }) { padding -> + ScreenWrapper( + title = stringResource(R.string.this_device), + headerAction = { + IconButton(onClick = { load() }) { Icon(Icons.Default.Refresh, null) } + } + ) { + TotalTimeCard(totalMs) + Spacer(Modifier.height(12.dp)) + + val successMessage = stringResource(R.string.sent) + val errorMessage = stringResource(R.string.error) + + Button( + onClick = { + scope.launch { + isSending = true + val ok = sendDataToServer(context, serverUrl, totalMs, usageList, detailedEvents) + snackbarHostState.showSnackbar(if(ok) successMessage else errorMessage) + isSending = false + } + }, + modifier = Modifier.fillMaxWidth(), + enabled = !isSending && serverUrl.isNotBlank() + ) { + if (isSending) CircularProgressIndicator(Modifier.size(20.dp)) + else Text(stringResource(R.string.upload_data)) + } + + Spacer(Modifier.height(12.dp)) // Kleiner Abstand zur Liste + + LazyColumn(Modifier.weight(1f)) { + items(usageList) { app -> AppUsageRow(app) } + } + } + } +} + +// --- UI KOMPONENTEN --- + +@Composable +fun TotalTimeCard(totalMs: Long) { + val h = totalMs / 3600000 + val m = (totalMs % 3600000) / 60000 + val s = (totalMs % 60000) / 1000 + + Card( + modifier = Modifier.fillMaxWidth(), + colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primaryContainer) + ) { + Column(Modifier.padding(16.dp)) { + Text(text = stringResource(R.string.all_time), style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.primary) + Text( + text = String.format("%02dh %02dm %02ds", h, m, s), + style = MaterialTheme.typography.displayMedium, + fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace + ) + } + } +} + +@Composable +fun AppUsageRow(app: AppUsageInfo) { + val hours = app.usageMs / 3600000 + val minutes = (app.usageMs % 3600000) / 60000 + val seconds = (app.usageMs % 60000) / 1000 + + Card(modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) { + Row( + modifier = Modifier.padding(16.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Text(app.appName, modifier = Modifier.weight(1f), style = MaterialTheme.typography.titleSmall) + Text( + text = String.format("%02dh %02dm %02ds", hours, minutes, seconds), + fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace, + color = MaterialTheme.colorScheme.primary, + style = MaterialTheme.typography.bodyMedium + ) + } + } +} + +// --- SYSTEM LOGIK (PROFI-METHODEN) --- + +suspend fun getTodayUsageEvents(context: Context): List = withContext(Dispatchers.IO) { + val usm = context.getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager + val calendar = Calendar.getInstance().apply { + set(Calendar.HOUR_OF_DAY, 0); set(Calendar.MINUTE, 0); set(Calendar.SECOND, 0); set(Calendar.MILLISECOND, 0) + } + + val events = usm.queryEvents(calendar.timeInMillis, System.currentTimeMillis()) + val event = UsageEvents.Event() + + val appUsageMap = mutableMapOf() + val openApps = mutableMapOf() + + var lastActivePackageName: String? = null + var screenOnTime: Long? = null + + while (events.hasNextEvent()) { + events.getNextEvent(event) + val packageName = event.packageName + + when (event.eventType) { + UsageEvents.Event.MOVE_TO_FOREGROUND -> { + // Wenn der Bildschirm gerade erst angegangen ist UND direkt eine NEUE App startet, + // löschen wir den Verdacht, dass die alte App weiterlief! + if (screenOnTime != null && packageName != lastActivePackageName) { + screenOnTime = null + } + + // Falls der Verdacht stimmte und die ALTE App weiterlief: + if (screenOnTime != null && lastActivePackageName != null) { + openApps[lastActivePackageName] = screenOnTime!! + screenOnTime = null + } + + openApps[packageName] = event.timeStamp + lastActivePackageName = packageName + } + + UsageEvents.Event.MOVE_TO_BACKGROUND -> { + val start = openApps.remove(packageName) + if (start != null) { + val duration = event.timeStamp - start + appUsageMap[packageName] = appUsageMap.getOrDefault(packageName, 0L) + duration + } + } + + UsageEvents.Event.SCREEN_NON_INTERACTIVE -> { + val now = event.timeStamp + openApps.forEach { (pkg, start) -> + appUsageMap[pkg] = appUsageMap.getOrDefault(pkg, 0L) + (now - start) + } + openApps.clear() + screenOnTime = null + } + + UsageEvents.Event.SCREEN_INTERACTIVE -> { + // Wir merken uns NUR den Zeitpunkt. Wir tragen die App noch nicht als "laufend" ein! + // Wir warten ab, was das nächste Event sagt. + screenOnTime = event.timeStamp + } + } + } + + // Am Ende der Schleife: Falls der Bildschirm an ging und DANACH kein Event mehr kam, + // lief die letzte App tatsächlich weiter. + if (screenOnTime != null && lastActivePackageName != null) { + openApps[lastActivePackageName] = screenOnTime!! + } + + // Abrechnung bis JETZT + val now = System.currentTimeMillis() + openApps.forEach { (pkg, start) -> + appUsageMap[pkg] = appUsageMap.getOrDefault(pkg, 0L) + (now - start) + } + + val pm = context.packageManager + appUsageMap.map { (pkg, ms) -> + val name = try { pm.getApplicationLabel(pm.getApplicationInfo(pkg, 0)).toString() } catch (e: Exception) { pkg } + AppUsageInfo(name, ms) + }.sortedByDescending { it.usageMs } +} + +suspend fun getTotalScreenTime(context: Context): Long = withContext(Dispatchers.IO) { + val usm = context.getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager + val calendar = Calendar.getInstance().apply { + set(Calendar.HOUR_OF_DAY, 0) + set(Calendar.MINUTE, 0) + set(Calendar.SECOND, 0) + set(Calendar.MILLISECOND, 0) + } + + val events = usm.queryEvents(calendar.timeInMillis, System.currentTimeMillis()) + val event = UsageEvents.Event() + + var totalTime = 0L + var sessionStartTime = 0L + val openApps = mutableSetOf() + + while (events.hasNextEvent()) { + events.getNextEvent(event) + val packageName = event.packageName + + when (event.eventType) { + UsageEvents.Event.MOVE_TO_FOREGROUND -> { + if (openApps.isEmpty()) { + sessionStartTime = event.timeStamp + } + openApps.add(packageName) + } + + UsageEvents.Event.MOVE_TO_BACKGROUND -> { + openApps.remove(packageName) + if (openApps.isEmpty() && sessionStartTime != 0L) { + totalTime += (event.timeStamp - sessionStartTime) + sessionStartTime = 0L + } + } + + UsageEvents.Event.SCREEN_NON_INTERACTIVE -> { + if (sessionStartTime != 0L) { + totalTime += (event.timeStamp - sessionStartTime) + sessionStartTime = 0L + } + openApps.clear() + } + } + } + + if (sessionStartTime != 0L) { + totalTime += (System.currentTimeMillis() - sessionStartTime) + } + + // Das Ergebnis wird automatisch zurückgegeben + return@withContext totalTime +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/MainActivity.kt b/app/src/main/java/de/schanbro/screenity/MainActivity.kt new file mode 100644 index 0000000..3c0e675 --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/MainActivity.kt @@ -0,0 +1,268 @@ +package de.schanbro.screenity + +import android.content.Context +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.animation.core.tween +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.scaleIn +import androidx.compose.animation.scaleOut +import androidx.compose.animation.slideInHorizontally +import androidx.compose.animation.slideOutHorizontally +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.List +import androidx.compose.material.icons.filled.Edit +import androidx.compose.material.icons.filled.Info +import androidx.compose.material.icons.filled.Today +import androidx.compose.material.icons.filled.Devices +import androidx.compose.material.icons.filled.Settings +import androidx.compose.material3.Button +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.NavigationBar +import androidx.compose.material3.NavigationBarItem +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import androidx.navigation.compose.currentBackStackEntryAsState +import androidx.navigation.compose.rememberNavController +import androidx.compose.foundation.layout.height +import androidx.compose.material.icons.filled.PinDrop +import de.schanbro.screenity.ui.theme.ScreenityTheme +import androidx.compose.runtime.LaunchedEffect +import androidx.work.Constraints +import androidx.work.ExistingPeriodicWorkPolicy +import androidx.work.NetworkType +import androidx.work.PeriodicWorkRequestBuilder +import androidx.work.WorkManager +import java.util.concurrent.TimeUnit + +sealed class Screen(val route: String) { + object Today : Screen("today_screen") + + object Local : Screen("local_screen") + object Devices : Screen("devices_screen") + object Settings : Screen("settings_screen") + object DeviceDetail : Screen("device_detail/{deviceId}") +} + +class MainActivity : ComponentActivity() { + @OptIn(ExperimentalMaterial3Api::class) + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContent { + ScreenityTheme { + val context = androidx.compose.ui.platform.LocalContext.current + val prefs = remember { context.getSharedPreferences("ScreenityPrefs", android.content.Context.MODE_PRIVATE) } + var serverUrl by remember { + mutableStateOf(prefs.getString("server_url", "") ?: "") + } + + val savedInterval = prefs.getInt("upload_interval_mins", 15) + + if (serverUrl.isBlank()) { + // Zeige Setup, wenn keine URL da ist + SetupScreen(onUrlSaved = { neueUrl -> + prefs.edit().putString("server_url", neueUrl).apply() + serverUrl = neueUrl // State-Update triggert Re-Composition + }) + } else { + LaunchedEffect(serverUrl) { + if (serverUrl.isNotBlank()) { + // 1. SOFORTIGER UPLOAD BEIM APP-START + val totalMs = getTotalScreenTime(context) + val usageList = getTodayUsageEvents(context) + val detailedEvents = getDetailedEvents(applicationContext) + sendDataToServer(context, serverUrl, totalMs, usageList, detailedEvents) + + // 2. 15-MINUTEN-AUTOMATISIERUNG EINRICHTEN + val constraints = Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) // Nur wenn Internet da ist + .build() + + val uploadWorkRequest = PeriodicWorkRequestBuilder( + 15, TimeUnit.MINUTES // Alle 15 Minuten (Minimum bei Android!) + ) + .setConstraints(constraints) + .build() + + // Dem System übergeben + WorkManager.getInstance(context).enqueueUniquePeriodicWork( + "ScreentimeUploadWork", + ExistingPeriodicWorkPolicy.KEEP, // Behält den alten Timer, falls die App neu startet + uploadWorkRequest + ) + } + } + + val navController = rememberNavController() + val currentBackStack by navController.currentBackStackEntryAsState() + val currentRoute = currentBackStack?.destination?.route + Scaffold( + modifier = Modifier.fillMaxSize(), + topBar = { + TopAppBar( + title = { Text(stringResource(R.string.app_name)) }, + colors = TopAppBarDefaults.topAppBarColors( + containerColor = MaterialTheme.colorScheme.primaryContainer, + titleContentColor = MaterialTheme.colorScheme.primary + ) + ) + }, + bottomBar = { + NavigationBar { + NavigationBarItem( + selected = currentRoute == Screen.Today.route, + onClick = { navController.navigate(Screen.Today.route) }, + icon = { Icon(Icons.Default.Today, contentDescription = null) }, + label = { Text(stringResource(R.string.Today)) } + ) + NavigationBarItem( + selected = currentRoute == Screen.Local.route, + onClick = { navController.navigate(Screen.Local.route) }, + icon = { Icon(Icons.Default.PinDrop, contentDescription = null) }, + label = { Text(stringResource(R.string.Local)) } + ) + NavigationBarItem( + selected = currentRoute == Screen.Devices.route, + onClick = { navController.navigate(Screen.Devices.route) }, + icon = { + Icon( + Icons.Default.Devices, + contentDescription = null + ) + }, + label = { Text(stringResource(R.string.Devices)) } + ) + NavigationBarItem( + selected = currentRoute == Screen.Settings.route, + onClick = { navController.navigate(Screen.Settings.route) }, + icon = { + Icon( + Icons.Default.Settings, + contentDescription = null + ) + }, + label = { Text(stringResource(R.string.Settings)) } + ) + } + } + ) { innerPadding -> + NavHost( + navController = navController, + startDestination = de.schanbro.screenity.Screen.Today.route, + modifier = Modifier.padding(innerPadding), + enterTransition = { fadeIn(animationSpec = tween(220)) + scaleIn(initialScale = 0.92f) }, + exitTransition = { fadeOut(animationSpec = tween(90)) }, + popEnterTransition = { fadeIn(animationSpec = tween(220)) }, + popExitTransition = { fadeOut(animationSpec = tween(90)) + scaleOut(targetScale = 0.92f) } + ) { + composable(de.schanbro.screenity.Screen.Today.route) { + TodayScreen() + } + composable(de.schanbro.screenity.Screen.Local.route) { + LocalScreen() + } + composable(de.schanbro.screenity.Screen.Devices.route) { + DevicesScreen(onNavigateToDetail = { id -> + navController.navigate("device_detail/$id") + }) + } + composable(de.schanbro.screenity.Screen.Settings.route) { + SettingsScreen() + } + composable(Screen.DeviceDetail.route) { backStackEntry -> + val deviceId = backStackEntry.arguments?.getString("deviceId") ?: "" + DeviceDetailScreen( + deviceId = deviceId, + onBack = { navController.popBackStack() } // Geht zurück zum TodayScreen + ) + } + } + } + } + } + } + } +} + +@Composable +fun SetupScreen(onUrlSaved: (String) -> Unit) { + var urlInput by remember { mutableStateOf("") } + + Column( + modifier = Modifier.fillMaxSize().padding(24.dp), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text(stringResource(R.string.welcome)+"!", style = MaterialTheme.typography.headlineSmall) + Text(stringResource(R.string.pls_enter_url)) + + Spacer(Modifier.height(16.dp)) + + OutlinedTextField( + value = urlInput, + onValueChange = { urlInput = it }, + label = { Text(stringResource(R.string.ex_server_url)) }, + modifier = Modifier.fillMaxWidth(), + placeholder = { Text("http://...") } + ) + + Spacer(Modifier.height(16.dp)) + + Button( + onClick = { if (urlInput.isNotBlank()) onUrlSaved(urlInput) }, + modifier = Modifier.fillMaxWidth(), + enabled = urlInput.startsWith("http") // Kleine Sicherheitssperre + ) { + Text(stringResource(R.string.connect_and_start)) + } + } +} + +fun updateUploadWork(context: Context, intervalMinutes: Long) { + val constraints = Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .build() + + val uploadWorkRequest = PeriodicWorkRequestBuilder( + intervalMinutes, TimeUnit.MINUTES + ) + .setConstraints(constraints) + .build() + + // UPDATE steht hier für "REPLACE" + // Wenn sich das Intervall ändert, bricht Android den alten Timer ab + // und fängt mit der neuen Zeit von vorne an zu zählen! + WorkManager.getInstance(context).enqueueUniquePeriodicWork( + "ScreentimeUploadWork", + ExistingPeriodicWorkPolicy.REPLACE, + uploadWorkRequest + ) +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/ScreentimeWidget.kt b/app/src/main/java/de/schanbro/screenity/ScreentimeWidget.kt new file mode 100644 index 0000000..d7cf437 --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/ScreentimeWidget.kt @@ -0,0 +1,87 @@ +package de.schanbro.screenity + +import android.content.Context +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.dp +import androidx.glance.GlanceId +import androidx.glance.GlanceModifier +import androidx.glance.appwidget.GlanceAppWidget +import androidx.glance.appwidget.GlanceAppWidgetReceiver +import androidx.glance.appwidget.GlanceAppWidgetManager +import androidx.glance.appwidget.provideContent +import androidx.glance.background +import androidx.glance.layout.* +import androidx.glance.text.FontWeight +import androidx.glance.text.Text +import androidx.glance.text.TextStyle +import androidx.glance.unit.ColorProvider +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +class ScreentimeWidget : GlanceAppWidget() { + + override suspend fun provideGlance(context: Context, id: GlanceId) { + val appWidgetId = GlanceAppWidgetManager(context).getAppWidgetId(id) + val prefs = context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) + + // 1. Welche Geräte hat der Nutzer in der Config gewählt? + val selectedDevices = prefs.getStringSet("widget_${appWidgetId}_devices", emptySet()) ?: emptySet() + val serverUrl = prefs.getString("server_url", "") ?: "" + + var totalMs = 0L + + // 2. ECHTE DATEN VOM SERVER HOLEN + if (serverUrl.isNotBlank()) { + try { + val result = withContext(Dispatchers.IO) { + getSummaryFromServer(serverUrl) + } + + // HIER IST DIE KORREKTUR: Wir greifen erst auf .devices zu! + val allDevices = result.devices + + // Jetzt können wir filtern + val filteredDevices = allDevices.filter { it.device_id in selectedDevices || it.device_name in selectedDevices } + totalMs = filteredDevices.sumOf { it.today_ms } + + } catch (e: Exception) { + // Bei Netzwerkfehlern bleibt totalMs einfach auf 0 oder du nimmst einen Cache + } + } + + // Zeit in Stunden und Minuten umrechnen + val hours = totalMs / 3600000 + val minutes = (totalMs % 3600000) / 60000 + val totalTimeText = String.format("%02dh %02dm", hours, minutes) + + provideContent { + Column( + modifier = GlanceModifier + .fillMaxSize() + .background(Color.White) + .padding(12.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = "Gesamtzeit", + style = TextStyle(fontWeight = FontWeight.Bold, color = ColorProvider(Color.Black)) + ) + Spacer(GlanceModifier.height(4.dp)) + Text( + text = totalTimeText, + style = TextStyle(fontWeight = FontWeight.Bold, color = ColorProvider(Color.Blue)) + ) + Spacer(GlanceModifier.height(4.dp)) + Text( + text = "${selectedDevices.size} Geräte", + style = TextStyle(color = ColorProvider(Color.Gray)) + ) + } + } + } +} + +class ScreentimeWidgetReceiver : GlanceAppWidgetReceiver() { + override val glanceAppWidget: GlanceAppWidget = ScreentimeWidget() +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/SettingsScreen.kt b/app/src/main/java/de/schanbro/screenity/SettingsScreen.kt new file mode 100644 index 0000000..d7a246f --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/SettingsScreen.kt @@ -0,0 +1,150 @@ +package de.schanbro.screenity + +import android.content.Context +import androidx.compose.foundation.layout.* +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.CheckCircle +import androidx.compose.material.icons.filled.Error +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import de.schanbro.screenity.ui.theme.SuccessGreen +import kotlinx.coroutines.launch +import kotlin.math.roundToInt + +// 1. ConnectionState erweitert, um Fehlermeldungen direkt mitzuführen +sealed class ConnectionState { + object Idle : ConnectionState() + object Loading : ConnectionState() + object Success : ConnectionState() + data class Error(val message: String) : ConnectionState() // Fehler trägt seine Nachricht selbst! +} + +@Composable +fun SettingsScreen() { + val context = LocalContext.current + val scope = rememberCoroutineScope() + val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) } + + var urlInput by remember { mutableStateOf(prefs.getString("server_url", "") ?: "") } + var status by remember { mutableStateOf(ConnectionState.Idle) } + + // Intervall auslesen (Standard: 15 Minuten) + var selectedInterval by remember { mutableIntStateOf(prefs.getInt("upload_interval_mins", 15)) } + + ScreenWrapper(title = stringResource(R.string.Settings)) { + + OutlinedTextField( + value = urlInput, + onValueChange = { urlInput = it; status = ConnectionState.Idle }, + label = { Text(stringResource(R.string.server_url)) }, + modifier = Modifier.fillMaxWidth() + ) + + Spacer(Modifier.height(24.dp)) + + // --- MATERIAL 3 SLIDER --- + Text( + text = "Upload-Intervall: $selectedInterval Minuten", + style = MaterialTheme.typography.titleSmall + ) + + Slider( + value = selectedInterval.toFloat(), + onValueChange = { + selectedInterval = it.roundToInt() + }, + valueRange = 15f..120f, + steps = 6 + ) + + // Kleine Beschriftung unter dem Slider + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Text("15 min", style = MaterialTheme.typography.bodySmall) + Text("120 min", style = MaterialTheme.typography.bodySmall) + } + + Spacer(Modifier.height(32.dp)) + + val errorMessage = stringResource(R.string.error) + + Button( + onClick = { + // 1. Einstellungen speichern + prefs.edit() + .putString("server_url", urlInput) + .putInt("upload_interval_mins", selectedInterval) + .apply() + + // 2. WorkManager mit neuem Intervall updaten! + updateUploadWork(context, selectedInterval.toLong()) + + scope.launch { + status = ConnectionState.Loading + try { + getSummaryFromServer(urlInput) + status = ConnectionState.Success + } catch (e: Exception) { + val detail = e.localizedMessage ?: errorMessage + status = ConnectionState.Error(detail) + } + } + }, + modifier = Modifier.fillMaxWidth() + ) { + Text(stringResource(R.string.save_and_try)) + } + + Spacer(Modifier.height(24.dp)) + + ConnectionStatusWidget(state = status) + } +} + +@Composable +fun ConnectionStatusWidget(state: ConnectionState) { + when (state) { + is ConnectionState.Loading -> { + Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { + CircularProgressIndicator() + } + } + is ConnectionState.Success -> { + Row(verticalAlignment = Alignment.CenterVertically) { + Icon(Icons.Default.CheckCircle, "OK", tint = SuccessGreen) + Spacer(Modifier.width(8.dp)) + Text( + text = stringResource(R.string.connection_successful), + color = SuccessGreen, + style = MaterialTheme.typography.titleSmall + ) + } + } + is ConnectionState.Error -> { + Row(verticalAlignment = Alignment.CenterVertically) { + Icon(Icons.Default.Error, stringResource(R.string.error), tint = MaterialTheme.colorScheme.error) + Spacer(Modifier.width(8.dp)) + Column { + Text( + text = stringResource(R.string.server_not_reachable), + color = MaterialTheme.colorScheme.error, + style = MaterialTheme.typography.titleSmall + ) + Text( + text = state.message, + color = MaterialTheme.colorScheme.error, + style = MaterialTheme.typography.bodySmall + ) + } + } + } + else -> {} + } +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/ThemeUtils.kt b/app/src/main/java/de/schanbro/screenity/ThemeUtils.kt new file mode 100644 index 0000000..fb3cf2e --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/ThemeUtils.kt @@ -0,0 +1,42 @@ +package de.schanbro.screenity + +import androidx.compose.foundation.layout.* +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp + +// Das ist wie eine CSS-Klasse für die Screen-Struktur! +@Composable +fun ScreenWrapper( + title: String, + headerAction: @Composable (() -> Unit)? = null, + content: @Composable ColumnScope.() -> Unit +) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(16.dp) // Zentrales Padding für die gesamte App + ) { + // Einheitlicher Header für alle Screens + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.Top + ) { + Text( + text = title, + style = MaterialTheme.typography.headlineMedium, + color = MaterialTheme.colorScheme.onSurface + ) + headerAction?.invoke() + } + + Spacer(Modifier.height(16.dp)) + + // Hier wird der eigentliche Inhalt des Screens eingesetzt + content() + } +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/TodayScreen.kt b/app/src/main/java/de/schanbro/screenity/TodayScreen.kt new file mode 100644 index 0000000..caa274c --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/TodayScreen.kt @@ -0,0 +1,112 @@ +package de.schanbro.screenity + +import android.app.usage.UsageEvents +import android.app.usage.UsageStatsManager +import android.content.Context +import android.content.Intent +import android.provider.Settings +import android.widget.Toast +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.CloudUpload +import androidx.compose.material.icons.filled.Refresh +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.google.gson.Gson +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody +import java.text.SimpleDateFormat +import java.util.* + +data class ServerSummary( + val devices: List, + val total_all_devices_hours: Double, + val today_total_all_devices_ms: Long +) + +@Composable +fun TodayScreen() { + val context = LocalContext.current + val scope = rememberCoroutineScope() + val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) } + val serverUrl = prefs.getString("server_url", "") ?: "" + + var summary by remember { mutableStateOf(null) } + var isLoading by remember { mutableStateOf(false) } + + fun fetch() { + if (serverUrl.isBlank()) return + scope.launch { + isLoading = true + try { + summary = getSummaryFromServer(serverUrl) + } catch (e: Exception) { + } + isLoading = false + } + } + + LaunchedEffect(Unit) { fetch() } + + ScreenWrapper( + title = stringResource(R.string.all_time), + headerAction = { + IconButton(onClick = { fetch() }) { + Icon(Icons.Default.Refresh, contentDescription = null) + } + } + ) { + if (isLoading) { + Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + CircularProgressIndicator() + } + } else { + summary?.let { + // Nutzt die bereits definierte Card für die große Anzeige + TotalAllDevicesCard(it.today_total_all_devices_ms) + } + } + } +} + +@Composable +fun TotalAllDevicesCard(totalMs: Long) { + val h = totalMs / 3600000 + val m = (totalMs % 3600000) / 60000 + val s = (totalMs % 60000) / 1000 + + Card( + modifier = Modifier + .fillMaxWidth() + .padding(bottom = 16.dp), + colors = CardDefaults.cardColors( + containerColor = MaterialTheme.colorScheme.tertiaryContainer + ) + ) { + Column(Modifier.padding(16.dp)) { + Text( + text = stringResource(R.string.all_time), + style = MaterialTheme.typography.titleSmall, + color = MaterialTheme.colorScheme.onTertiary + ) + Text( + text = String.format("%02dh %02dm %02ds", h, m, s), + style = MaterialTheme.typography.displayMedium, + fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/UploadWorker.kt b/app/src/main/java/de/schanbro/screenity/UploadWorker.kt new file mode 100644 index 0000000..77de280 --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/UploadWorker.kt @@ -0,0 +1,46 @@ +package de.schanbro.screenity + +import android.content.Context +import androidx.work.CoroutineWorker +import androidx.work.WorkerParameters +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +class UploadWorker( + appContext: Context, + workerParams: WorkerParameters +) : CoroutineWorker(appContext, workerParams) { + + override suspend fun doWork(): Result = withContext(Dispatchers.IO) { + val prefs = applicationContext.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) + val serverUrl = prefs.getString("server_url", "") ?: "" + + if (serverUrl.isBlank()) { + return@withContext Result.failure() + } + + try { + // 1. Daten sammeln (Nutzt deine optimierten Funktionen!) + val totalMs = getTotalScreenTime(applicationContext) + val usageList = getTodayUsageEvents(applicationContext) + val detailedEvents = getDetailedEvents(applicationContext) + + // 2. An den Server senden (deine bestehende Funktion) + val success = sendDataToServer( + applicationContext, + serverUrl, + totalMs, + usageList, + detailedEvents + ) + + if (success) { + Result.success() + } else { + Result.retry() // Android versucht es später nochmal, falls der Server offline war + } + } catch (e: Exception) { + Result.failure() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/UsageUtils.kt b/app/src/main/java/de/schanbro/screenity/UsageUtils.kt new file mode 100644 index 0000000..a629f8d --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/UsageUtils.kt @@ -0,0 +1,46 @@ +package de.schanbro.screenity + +import android.annotation.SuppressLint +import android.app.usage.UsageEvents +import android.app.usage.UsageStatsManager +import android.content.Context +import java.util.Calendar + +data class ScreenEvent( + val timestamp: Long, + val type: String, // "SCREEN_ON", "SCREEN_OFF", "APP_OPEN", "APP_CLOSE" + val packageName: String? = null +) + +@SuppressLint("ServiceCast") +fun getDetailedEvents(context: Context): List { + val usageStatsManager = context.getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager + val calendar = Calendar.getInstance() + calendar.set(Calendar.HOUR_OF_DAY, 0) + calendar.set(Calendar.MINUTE, 0) + calendar.set(Calendar.SECOND, 0) + + val events = usageStatsManager.queryEvents(calendar.timeInMillis, System.currentTimeMillis()) + val eventList = mutableListOf() + val event = UsageEvents.Event() + + while (events.hasNextEvent()) { + events.getNextEvent(event) + val type = when (event.eventType) { + UsageEvents.Event.SCREEN_INTERACTIVE -> "SCREEN_ON" + UsageEvents.Event.SCREEN_NON_INTERACTIVE -> "SCREEN_OFF" + UsageEvents.Event.ACTIVITY_RESUMED -> "APP_OPEN" + UsageEvents.Event.ACTIVITY_PAUSED -> "APP_CLOSE" + else -> null + } + + if (type != null) { + eventList.add(ScreenEvent( + timestamp = event.timeStamp, + type = type, + packageName = if (type.startsWith("APP")) event.packageName else null + )) + } + } + return eventList +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/WidgetConfigActivity.kt b/app/src/main/java/de/schanbro/screenity/WidgetConfigActivity.kt new file mode 100644 index 0000000..32c2a44 --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/WidgetConfigActivity.kt @@ -0,0 +1,103 @@ +package de.schanbro.screenity + +import android.app.Activity +import android.appwidget.AppWidgetManager +import android.content.Context +import android.content.Intent +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.unit.dp + +class WidgetConfigActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + val appWidgetId = intent?.extras?.getInt( + AppWidgetManager.EXTRA_APPWIDGET_ID, + AppWidgetManager.INVALID_APPWIDGET_ID + ) ?: AppWidgetManager.INVALID_APPWIDGET_ID + + if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { + finish() + return + } + + setContent { + MaterialTheme { + Surface(modifier = Modifier.fillMaxSize()) { + WidgetConfigScreen(appWidgetId = appWidgetId) { + val resultValue = Intent().apply { + putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) + } + setResult(Activity.RESULT_OK, resultValue) + finish() + } + } + } + } + } +} + +@Composable +fun WidgetConfigScreen(appWidgetId: Int, onFinished: () -> Unit) { + val context = LocalContext.current + val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) } + + // ECHTE DATEN: Wir lesen die bekannten Geräte-IDs aus den SharedPreferences + // (Diese Liste füllst du am besten immer auf, wenn du Daten vom Server erfolgreich abrufst) + val deviceIds = remember { + prefs.getStringSet("known_device_ids", setOf("Dieses Gerät")) ?: setOf("Dieses Gerät") + }.toList() + + val selectedDevices = remember { mutableStateListOf() } + + Column(modifier = Modifier.padding(16.dp)) { + Text("Widget konfigurieren", style = MaterialTheme.typography.headlineSmall) + Spacer(Modifier.height(8.dp)) + Text("Wähle die Geräte aus, deren Zeit addiert werden soll:", style = MaterialTheme.typography.bodyMedium) + + Spacer(Modifier.height(16.dp)) + + // LazyColumn für den Fall, dass du sehr viele Geräte hast + LazyColumn(modifier = Modifier.weight(1f)) { + items(deviceIds) { deviceId -> + Row( + modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Text(deviceId, style = MaterialTheme.typography.bodyLarge) + Checkbox( + checked = selectedDevices.contains(deviceId), + onCheckedChange = { checked -> + if (checked) selectedDevices.add(deviceId) else selectedDevices.remove(deviceId) + } + ) + } + } + } + + Spacer(Modifier.height(16.dp)) + + Button( + onClick = { + // Konfiguration für dieses spezifische Widget speichern + prefs.edit().putStringSet("widget_${appWidgetId}_devices", selectedDevices.toSet()).apply() + onFinished() + }, + modifier = Modifier.fillMaxWidth(), + enabled = selectedDevices.isNotEmpty() + ) { + Text("Widget erstellen") + } + } +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/ui/theme/Color.kt b/app/src/main/java/de/schanbro/screenity/ui/theme/Color.kt new file mode 100644 index 0000000..fb91137 --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/ui/theme/Color.kt @@ -0,0 +1,12 @@ +package de.schanbro.screenity.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) +val SuccessGreen = Color(0xFF4CAF50) \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/ui/theme/Theme.kt b/app/src/main/java/de/schanbro/screenity/ui/theme/Theme.kt new file mode 100644 index 0000000..5bf5a2b --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/ui/theme/Theme.kt @@ -0,0 +1,58 @@ +package de.schanbro.screenity.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun ScreenityTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/app/src/main/java/de/schanbro/screenity/ui/theme/Type.kt b/app/src/main/java/de/schanbro/screenity/ui/theme/Type.kt new file mode 100644 index 0000000..c3d8bf5 --- /dev/null +++ b/app/src/main/java/de/schanbro/screenity/ui/theme/Type.kt @@ -0,0 +1,81 @@ +package de.schanbro.screenity.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + displayMedium = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Black, + fontSize = 32.sp, + lineHeight = 40.sp, + letterSpacing = 0.sp + ), + headlineLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Black, + fontSize = 32.sp, + lineHeight = 40.sp, + letterSpacing = 0.sp + ), + headlineMedium = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Black, + fontSize = 28.sp, + lineHeight = 36.sp, + letterSpacing = 0.sp + ), + headlineSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Bold, + fontSize = 24.sp, + lineHeight = 32.sp, + letterSpacing = 0.sp + ), + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Bold, + fontSize = 20.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + titleMedium = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Bold, + fontSize = 18.sp, + lineHeight = 24.sp, + letterSpacing = 0.15.sp + ), + titleSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 14.sp, + lineHeight = 20.sp, + letterSpacing = 0.1.sp + ), + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ), + bodyMedium = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 14.sp, + lineHeight = 20.sp, + letterSpacing = 0.25.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) +) \ No newline at end of file diff --git a/app/src/main/res/drawable-nodpi/screenity_edited.xml b/app/src/main/res/drawable-nodpi/screenity_edited.xml new file mode 100644 index 0000000..2c39020 --- /dev/null +++ b/app/src/main/res/drawable-nodpi/screenity_edited.xml @@ -0,0 +1,14 @@ + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..845a082 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/screenity_edited_background.xml b/app/src/main/res/drawable/screenity_edited_background.xml new file mode 100644 index 0000000..ca3826a --- /dev/null +++ b/app/src/main/res/drawable/screenity_edited_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/screenity_edited_foreground.xml b/app/src/main/res/drawable/screenity_edited_foreground.xml new file mode 100644 index 0000000..3cdfef2 --- /dev/null +++ b/app/src/main/res/drawable/screenity_edited_foreground.xml @@ -0,0 +1,19 @@ + + + + + diff --git a/app/src/main/res/font/outfit_variable.ttf b/app/src/main/res/font/outfit_variable.ttf new file mode 100644 index 0000000..466d624 Binary files /dev/null and b/app/src/main/res/font/outfit_variable.ttf differ diff --git a/app/src/main/res/mipmap-anydpi-v26/screenity_edited.xml b/app/src/main/res/mipmap-anydpi-v26/screenity_edited.xml new file mode 100644 index 0000000..a3d004a --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/screenity_edited.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/screenity_edited_round.xml b/app/src/main/res/mipmap-anydpi-v26/screenity_edited_round.xml new file mode 100644 index 0000000..a3d004a --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/screenity_edited_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/app/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-hdpi/screenity_edited.webp b/app/src/main/res/mipmap-hdpi/screenity_edited.webp new file mode 100644 index 0000000..e4e7a23 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/screenity_edited.webp differ diff --git a/app/src/main/res/mipmap-hdpi/screenity_edited_round.webp b/app/src/main/res/mipmap-hdpi/screenity_edited_round.webp new file mode 100644 index 0000000..2a03ffc Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/screenity_edited_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/screenity_edited.webp b/app/src/main/res/mipmap-mdpi/screenity_edited.webp new file mode 100644 index 0000000..98d565d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/screenity_edited.webp differ diff --git a/app/src/main/res/mipmap-mdpi/screenity_edited_round.webp b/app/src/main/res/mipmap-mdpi/screenity_edited_round.webp new file mode 100644 index 0000000..96fc8ad Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/screenity_edited_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/screenity_edited.webp b/app/src/main/res/mipmap-xhdpi/screenity_edited.webp new file mode 100644 index 0000000..9f12766 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/screenity_edited.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/screenity_edited_round.webp b/app/src/main/res/mipmap-xhdpi/screenity_edited_round.webp new file mode 100644 index 0000000..128327a Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/screenity_edited_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/screenity_edited.webp b/app/src/main/res/mipmap-xxhdpi/screenity_edited.webp new file mode 100644 index 0000000..1e7fb9a Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/screenity_edited.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/screenity_edited_round.webp b/app/src/main/res/mipmap-xxhdpi/screenity_edited_round.webp new file mode 100644 index 0000000..2f65b61 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/screenity_edited_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/screenity_edited.webp b/app/src/main/res/mipmap-xxxhdpi/screenity_edited.webp new file mode 100644 index 0000000..e4935f3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/screenity_edited.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/screenity_edited_round.webp b/app/src/main/res/mipmap-xxxhdpi/screenity_edited_round.webp new file mode 100644 index 0000000..fb0fbf4 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/screenity_edited_round.webp differ diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml new file mode 100644 index 0000000..f82d1ae --- /dev/null +++ b/app/src/main/res/values-en/strings.xml @@ -0,0 +1,28 @@ + + + Today + Devices + Settings + Welcome + Please enter the server-URL to start. + Local time of usage + Refresh + Couldn\'t find any data. Did you gave the permission? + Open settings! + Local + All time + Server-URL (e. g. http://192.168.178.50:5000) + Connect and start + Overview of devices + All devices combined + This divice + Sent + Error + Upload data + Server-URL + Save and try + Connection successful! + Server not reachable + Server responses with code: + Unknown network error + \ No newline at end of file diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml new file mode 100644 index 0000000..f995a99 --- /dev/null +++ b/app/src/main/res/values-fr-rFR/strings.xml @@ -0,0 +1,28 @@ + + + Aujourd’hui + Appareils + Paramètres + Bienvenue + Veuillez saisir l’URL du serveur pour démarrer + Temps locale de utiliser + Acutaliser + Grrrr les francais!!! + Ouvrir les parametrès! + Locale + Tout les temps + L\'URL du serveur (p. e. http://192.168.178.50:5000) + Connecter et parir + \? + \? + Ce appareil + \? + \? + \? + L\'URL du serveur + Saver et essayer + \? + \? + Codé: + \? + \ No newline at end of file diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml new file mode 100644 index 0000000..c191960 --- /dev/null +++ b/app/src/main/res/values-ru/strings.xml @@ -0,0 +1,28 @@ + + + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \? + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/app/src/main/res/values/screenity_edited_background.xml b/app/src/main/res/values/screenity_edited_background.xml new file mode 100644 index 0000000..7df4872 --- /dev/null +++ b/app/src/main/res/values/screenity_edited_background.xml @@ -0,0 +1,4 @@ + + + #3DDC84 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..3648901 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,28 @@ + + Screenity + Heute + Geräte + Einstellungen + Willkommen + Bitte gib die Server-URL ein, um zu starten. + Lokale Nutzungszeit + Aktualisieren + Keine Daten gefunden. Hast du die Berechtigung erteilt? + Einstellungen öffnen! + Lokal + Gesamte Bildschirmzeit + Server URL (z.B. http://192.168.178.50:5000) + Verbinden und Starten + Geräteübersicht + Alle Geräte kombiniert + Dieses Gerät + Gesendet + Fehler + Daten hochladen + Server URL + Speichern und testen + Verbindung erfolgreich! + Server nicht erreichbar + Server antwortet mit Code: + Unbekannter Netzwerkfehler + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..279d33a --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +