Pith - wedge_android
wedge_android/app/src/main/java/com/vgmlr/wedge/WedgeData.kt [5.0 kb]
Modified: 00:00:27 153 026 (19 Aug 026)
5 Days Ago
package com.vgmlr.wedge

import android.content.Context
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DataView(vm: MainViewModel, prefs: PreferenceManager, onBack: () -> Unit) {
    val context = LocalContext.current
    val aHeaderFmt by prefs.headerFormat.collectAsState(WedgeConfig.HEADER_FORMAT_DEFAULT)
    val aBkStamp by prefs.backupStamp.collectAsState(initial = 0L)
    val noteEntity by vm.dao.getNote().collectAsState(initial = null)
    val content = noteEntity?.content ?: ""
    val charCount = content.length
    val lineCount = if (content.isEmpty()) 0 else content.count { it == '\n' } + 1

    val modifiedStr = WedgeDate.getOtcMetadata(
        noteEntity?.lastModified ?: System.currentTimeMillis()
    )

    val syncStamp = remember {
        context.getSharedPreferences("sync_prefs", Context.MODE_PRIVATE)
            .getLong("sync_last_stamp", 0L)
    }
    val syncedStr = if (syncStamp == 0L) "[none]" else WedgeDate.getOtcMetadata(syncStamp)

    val archivedStr = if (aBkStamp == 0L) "[none]" else WedgeDate.getOtcMetadata(aBkStamp)

    val headerPreview = remember(aHeaderFmt) {
        try {
            WedgeHeader.render(
                aHeaderFmt.ifBlank { WedgeConfig.HEADER_FORMAT_DEFAULT },
                System.currentTimeMillis()
            )
        } catch (_: Exception) {
            ""
        }
    }

    Scaffold(
        topBar = {
            TopAppBar(
                title = {
                    Text(
                        "Data",
                        color = colorResource(id = R.color.title_color),
                        fontSize = 18.sp
                    )
                },
                colors = TopAppBarDefaults.topAppBarColors(containerColor = Color(0xFF486860)),
                navigationIcon = {
                    IconButton(onClick = onBack) {
                        Icon(
                            Icons.AutoMirrored.Filled.ArrowBack,
                            null,
                            tint = colorResource(id = R.color.title_color)
                        )
                    }
                }
            )
        }
    ) { p ->

        Column(
            Modifier.padding(p).fillMaxSize().background(CBg)
                .padding(horizontal = 16.dp).verticalScroll(rememberScrollState())
        ) {

            Spacer(Modifier.height(24.dp))

            // note

            WgCard {
                DataRow("Lines", "$lineCount")
                WgDivider()
                DataRow("Characters", "$charCount")
                WgDivider()
                DataRow("Modified", modifiedStr)
                WgDivider()
                DataRow("Synced", syncedStr)
                WgDivider()
                DataRow("Archived", archivedStr)
            }
            
            Spacer(Modifier.height(24.dp))

            // syntax

            WgSection("Syntax") {
                DataRow("Math", "123+456=")
                WgDivider()
                DataRow("Days", "20mar()=")
                WgDivider()
                DataRow("Focus", "text!")
                WgDivider()
                DataRow("Italic", "text?")
                WgDivider()
                DataRow("Under-Line", "text*")
                WgDivider()
                DataRow("Strike-Thru", "text~")
                WgDivider()
                DataRow("Comment", "// text")
                WgDivider()
                DataRow("HR", "hr(#)")
                WgDivider()
                DataRow("Dash", "dash(#)")
            }

            // list

            WgSection("Logic") {
                DataRow("List", "1. text[enter]")
                WgDivider()
                DataRow("Sort", "(hierarchic)")
            }

            // calendar

            WgSection("Calendar") {
                DataRow("Header", headerPreview)
                WgDivider()
                DataRow("Alarm", "00:00  text()")
                WgDivider()
                DataRow("Count Down", "00:00  text[]")
            }

            // security

            WgSection("Security") {
                DataRow("Encryption", "AES-256 [wdg:]")
            }

            Spacer(Modifier.height(24.dp))
        }
    }
}

@Composable
private fun DataRow(label: String, value: String) {
    WgRow(label) {
        WgValue(
            text = value,
            mono = true,
            color = CText,
            maxLines = 2,
            modifier = Modifier.weight(1f, fill = false)
        )
    }
}
Updates
Kerf - Android 157.026
Kiln - Android 157.026
Wedge - Android 156.026
Whittle - Linux 155.026
Grit - Firefox/Chrome 154.026

Menu
Calendar
Project Tin (024/029)
Miter
RSS Feed
User Avatar
@vgmlr
=SUM(parts)
0.00215
256,859 (+113)