Initial commit (files only)
This commit is contained in:
commit
ed0a6cb185
88 files changed
+2809
No files matched your search
@@ -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<String, DayReport>
|
||||
)
|
||||
|
||||
// --- NETZWERK LOGIK ---
|
||||
suspend fun sendDataToServer(
|
||||
context: Context,
|
||||
url: String,
|
||||
totalMs: Long,
|
||||
usageList: List<AppUsageInfo>,
|
||||
detailedEvents: List<ScreenEvent>
|
||||
): 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)
|
||||
}
|
||||
@@ -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<List<AppUsageDetail>>(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
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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<String, DayReport>? // Wichtig: Hier müssen die Reports drin sein!
|
||||
)
|
||||
|
||||
data class DayReport(
|
||||
@SerializedName("total_screen_time_ms") val totalMs: Long,
|
||||
val apps: List<AppUsageDetail>? = 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<DeviceSummary>()) }
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<List<AppUsageInfo>>(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<AppUsageInfo> = 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<String, Long>()
|
||||
val openApps = mutableMapOf<String, Long>()
|
||||
|
||||
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<String>()
|
||||
|
||||
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
|
||||
}
|
||||
@@ -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<UploadWorker>(
|
||||
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<UploadWorker>(
|
||||
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
|
||||
)
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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>(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 -> {}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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<DeviceSummary>,
|
||||
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<ServerSummary?>(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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<ScreenEvent> {
|
||||
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<ScreenEvent>()
|
||||
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
|
||||
}
|
||||
@@ -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<String>() }
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
)
|
||||
Reference in new issue
Block a user