Skip to content

Commit

Permalink
add pref_useNoteIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
hg42 committed Jul 24, 2024
1 parent 48ca84a commit 030ada9
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ val pref_refreshAppInfoTimeout = IntPref(

//---------------------------------------- developer settings - implementation alternatives

val pref_useNoteIcon = BooleanPref(
key = "dev-alt.useNoteIcon",
summary = "use the icon instead of the big fat 'edit note' button",
defaultValue = false
)
val pref_paranoidBackupLists = BooleanPref(
key = "dev-alt.paranoidBackupLists",
summary = "verify file system after adding or deleting backups (slower, especially remote)",
Expand Down Expand Up @@ -350,7 +355,7 @@ val pref_useYamlProperties = BooleanPref(
defaultValue = false
)

val pref_prettyJson = BooleanPref(
val pref_prettyJson = BooleanPref( //TODO hg42 to be removed
key = "dev-alt.prettyJson",
summary = "create human readable json files. Note they should be compatible in both directions",
defaultValue = true
Expand Down Expand Up @@ -378,7 +383,7 @@ val pref_busyHitTime = IntPref(
defaultValue = 2000
)

val pref_earlyEmptyBackups = BooleanPref(
val pref_earlyEmptyBackups = BooleanPref( //TODO hg42 to be removed
key = "dev-alt.earlyEmptyBackups",
summary = "empty backup lists for installed packages early, to prevent single scanning",
defaultValue = true
Expand All @@ -391,7 +396,7 @@ val pref_flatStructure = BooleanPref(
)

val pref_propertiesInDir = BooleanPref(
key = "$debug-alt.propertiesInDir", //TODO hg42 currently not working in scanner
key = "$debug-alt.propertiesInDir", //TODO hg42 currently not working in scanner (hmm, I think it works now)
summary = "store the properties inside the backup directory",
defaultValue = false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.Checkbox
import androidx.compose.material3.ListItem
Expand Down Expand Up @@ -74,6 +75,7 @@ fun BackupItem_headlineContent(
item,
onNote = onNote,
)
Spacer(modifier = Modifier.width(16.dp))
BackupLabels(item = item)
}
}
Expand Down
130 changes: 107 additions & 23 deletions src/main/java/com/machiav3lli/backup/ui/compose/item/Tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,26 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.machiav3lli.backup.OABX
import com.machiav3lli.backup.R
import com.machiav3lli.backup.dbs.entity.Backup
import com.machiav3lli.backup.dbs.entity.PackageInfo
import com.machiav3lli.backup.preferences.pref_useNoteIcon
import com.machiav3lli.backup.ui.compose.icons.Phosphor
import com.machiav3lli.backup.ui.compose.icons.phosphor.NotePencil
import com.machiav3lli.backup.ui.compose.icons.phosphor.PlusCircle
import com.machiav3lli.backup.ui.compose.icons.phosphor.X
import com.machiav3lli.backup.ui.compose.icons.phosphor.XCircle
import java.time.LocalDateTime

@OptIn(ExperimentalLayoutApi::class)
@Composable
Expand Down Expand Up @@ -111,35 +119,111 @@ fun TagItem(

@Composable
fun NoteTagItem(
item: Backup,
modifier: Modifier = Modifier,
tag: String,
action: Boolean = false,
onClick: () -> Unit,
useIcon: Boolean = pref_useNoteIcon.value,
onNote: ((Backup) -> Unit)? = null,
) {
Badge(
modifier = modifier
.widthIn(min = 32.dp, max = 128.dp)
.clip(MaterialTheme.shapes.medium)
.clickable(onClick = onClick)
.border(
BorderStroke(1.dp, MaterialTheme.colorScheme.primary),
MaterialTheme.shapes.medium
),
containerColor = if (action) MaterialTheme.colorScheme.primary
else Color.Transparent,
contentColor = if (action) MaterialTheme.colorScheme.onPrimary
else MaterialTheme.colorScheme.onSurface,
) {
Text(
modifier = Modifier.padding(2.dp),
text = tag.ifEmpty { stringResource(id = R.string.edit_note) },
style = MaterialTheme.typography.bodyMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
val tag = item.note
val fillChip = useIcon || (tag.isEmpty() && onNote != null)
val showIcon = useIcon && tag.isEmpty() && onNote != null
val showBadge = tag.isNotEmpty() || (!useIcon && onNote != null)

if (showIcon) {
Icon(
modifier = Modifier.clickable { onNote?.let { it(item) } },
imageVector = Phosphor.NotePencil,
contentDescription = stringResource(id = R.string.edit_note),
tint = MaterialTheme.colorScheme.onSurfaceVariant
)
} else if (showBadge) {
Badge(
modifier = modifier
.widthIn(min = 32.dp, max = 128.dp)
.clip(MaterialTheme.shapes.medium)
.clickable(onClick = { onNote?.let { it(item) } })
.border(
BorderStroke(1.dp, MaterialTheme.colorScheme.primary),
MaterialTheme.shapes.medium
),
containerColor = (
if (fillChip) MaterialTheme.colorScheme.primary
else Color.Transparent),
contentColor = (
if (fillChip) MaterialTheme.colorScheme.onPrimary
else MaterialTheme.colorScheme.onSurface),
) {
Text(
modifier = Modifier.padding(2.dp),
text = tag.ifEmpty { stringResource(id = R.string.edit_note) },
style = MaterialTheme.typography.bodyMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
}

@Preview
@Composable
fun NoteTagItemPreview() {

OABX.fakeContext = LocalContext.current.applicationContext

val packageInfo = PackageInfo(
packageName = "com.machiav3lli.backup",
versionName = "1.0",
versionCode = 1,
)
val backup = Backup(
base = packageInfo,
backupDate = LocalDateTime.parse("2000-01-01T00:00:00"),
hasApk = true,
hasAppData = true,
hasDevicesProtectedData = true,
hasExternalData = true,
hasObbData = true,
hasMediaData = true,
compressionType = "zst",
cipherType = "aes-256-gcm",
iv = byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16),
cpuArch = "aarch64",
permissions = emptyList(),
size = 12345,
persistent = false,
note = "",
)
val backup_with_note = backup.copy(note = "note text")

Column {
Text("text:")
Row {
Text("RestoreItem: ")
NoteTagItem(useIcon = false, item = backup_with_note)
Text(" empty: ")
NoteTagItem(useIcon = false, item = backup)
}
Row {
Text("BackupItem: ")
NoteTagItem(useIcon = false, item = backup_with_note, onNote = {})
Text(" empty: ")
NoteTagItem(useIcon = false, item = backup, onNote = {})
}
Text("icon:")
Row {
Text("RestoreItem: ")
NoteTagItem(useIcon = true, item = backup_with_note)
Text(" empty: ")
NoteTagItem(useIcon = true, item = backup)
}
Row {
Text("BackupItem: ")
NoteTagItem(useIcon = true, item = backup_with_note, onNote = {})
Text(" empty: ")
NoteTagItem(useIcon = true, item = backup, onNote = {})
}
}
}

@Composable
fun AddTagView(
Expand Down

0 comments on commit 030ada9

Please sign in to comment.