Compare commits
1 Commits
20260110-F
...
embeddings
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b5f761d25 |
7
.idea/deviceManager.xml
generated
7
.idea/deviceManager.xml
generated
@@ -5,14 +5,9 @@
|
|||||||
<list>
|
<list>
|
||||||
<ColumnSorterState>
|
<ColumnSorterState>
|
||||||
<option name="column" value="Name" />
|
<option name="column" value="Name" />
|
||||||
<option name="order" value="DESCENDING" />
|
<option name="order" value="ASCENDING" />
|
||||||
</ColumnSorterState>
|
</ColumnSorterState>
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
<option name="groupByAttributes">
|
|
||||||
<list>
|
|
||||||
<option value="Type" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -85,10 +85,4 @@ dependencies {
|
|||||||
|
|
||||||
// Gson for storing FloatArrays in Room
|
// Gson for storing FloatArrays in Room
|
||||||
implementation(libs.gson)
|
implementation(libs.gson)
|
||||||
|
|
||||||
// Zoomable
|
|
||||||
implementation(libs.zoomable)
|
|
||||||
implementation(libs.vico.compose)
|
|
||||||
implementation(libs.vico.compose.m3)
|
|
||||||
implementation(libs.vico.core)
|
|
||||||
}
|
}
|
||||||
@@ -8,33 +8,20 @@ import androidx.activity.ComponentActivity
|
|||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import com.placeholder.sherpai2.domain.repository.ImageRepository
|
import com.placeholder.sherpai2.domain.repository.ImageRepository
|
||||||
import com.placeholder.sherpai2.ui.presentation.MainScreen
|
import com.placeholder.sherpai2.ui.presentation.MainScreen
|
||||||
import com.placeholder.sherpai2.ui.theme.SherpAI2Theme
|
import com.placeholder.sherpai2.ui.theme.SherpAI2Theme
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
|
||||||
* MainActivity - ENHANCED with background ingestion
|
|
||||||
*
|
|
||||||
* Key improvements:
|
|
||||||
* 1. Non-blocking ingestion - app loads immediately
|
|
||||||
* 2. Background processing with progress updates
|
|
||||||
* 3. Graceful handling of large photo collections
|
|
||||||
* 4. User can navigate while ingestion runs
|
|
||||||
*/
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
|
||||||
@@ -59,7 +46,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var ingestionState by remember { mutableStateOf<IngestionState>(IngestionState.NotStarted) }
|
var isIngesting by remember { mutableStateOf(false) }
|
||||||
|
var imagesIngested by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val permissionLauncher = rememberLauncherForActivityResult(
|
val permissionLauncher = rememberLauncherForActivityResult(
|
||||||
ActivityResultContracts.RequestPermission()
|
ActivityResultContracts.RequestPermission()
|
||||||
@@ -67,83 +55,35 @@ class MainActivity : ComponentActivity() {
|
|||||||
hasPermission = granted
|
hasPermission = granted
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start background ingestion when permission granted
|
// Logic: Handle the flow of Permission -> Ingestion
|
||||||
LaunchedEffect(hasPermission) {
|
LaunchedEffect(hasPermission) {
|
||||||
if (hasPermission && ingestionState is IngestionState.NotStarted) {
|
if (hasPermission) {
|
||||||
ingestionState = IngestionState.InProgress(0, 0)
|
if (!imagesIngested && !isIngesting) {
|
||||||
|
isIngesting = true
|
||||||
// Launch in background - NON-BLOCKING
|
imageRepository.ingestImages()
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
imagesIngested = true
|
||||||
try {
|
isIngesting = false
|
||||||
// Check if already ingested
|
|
||||||
val existingCount = imageRepository.getImageCount()
|
|
||||||
|
|
||||||
if (existingCount > 0) {
|
|
||||||
// Already have images, skip ingestion
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
ingestionState = IngestionState.Complete(existingCount)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Start ingestion with progress tracking
|
|
||||||
imageRepository.ingestImagesWithProgress { current, total ->
|
|
||||||
ingestionState = IngestionState.InProgress(current, total)
|
|
||||||
}
|
|
||||||
|
|
||||||
val finalCount = imageRepository.getImageCount()
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
ingestionState = IngestionState.Complete(finalCount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
ingestionState = IngestionState.Error(e.message ?: "Failed to load images")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (!hasPermission) {
|
|
||||||
permissionLauncher.launch(storagePermission)
|
permissionLauncher.launch(storagePermission)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UI State
|
// UI State Mapping
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxSize()
|
|
||||||
) {
|
|
||||||
when {
|
|
||||||
hasPermission -> {
|
|
||||||
// ALWAYS show main screen (non-blocking!)
|
|
||||||
MainScreen()
|
|
||||||
|
|
||||||
// Show progress overlay if still ingesting
|
|
||||||
if (ingestionState is IngestionState.InProgress) {
|
|
||||||
IngestionProgressOverlay(
|
|
||||||
state = ingestionState as IngestionState.InProgress
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Column(
|
when {
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
hasPermission && imagesIngested -> {
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
MainScreen()
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
"Storage Permission Required",
|
|
||||||
style = MaterialTheme.typography.titleLarge,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"SherpAI needs access to your photos",
|
|
||||||
style = MaterialTheme.typography.bodyMedium
|
|
||||||
)
|
|
||||||
Button(onClick = { permissionLauncher.launch(storagePermission) }) {
|
|
||||||
Text("Grant Permission")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
hasPermission && isIngesting -> {
|
||||||
|
// Show a loader so you know it's working!
|
||||||
|
CircularProgressIndicator()
|
||||||
}
|
}
|
||||||
|
else -> {
|
||||||
|
Text("Please grant storage permission to continue.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,79 +91,3 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Ingestion state with progress tracking
|
|
||||||
*/
|
|
||||||
sealed class IngestionState {
|
|
||||||
object NotStarted : IngestionState()
|
|
||||||
data class InProgress(val current: Int, val total: Int) : IngestionState()
|
|
||||||
data class Complete(val imageCount: Int) : IngestionState()
|
|
||||||
data class Error(val message: String) : IngestionState()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Non-intrusive progress overlay
|
|
||||||
* Shows at bottom of screen, doesn't block UI
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun IngestionProgressOverlay(state: IngestionState.InProgress) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentAlignment = Alignment.BottomCenter
|
|
||||||
) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer
|
|
||||||
),
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 8.dp)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "Loading photos...",
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
|
|
||||||
if (state.total > 0) {
|
|
||||||
Text(
|
|
||||||
text = "${state.current} / ${state.total}",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.total > 0) {
|
|
||||||
LinearProgressIndicator(
|
|
||||||
progress = { state.current.toFloat() / state.total.toFloat() },
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
LinearProgressIndicator(
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = "You can start using the app while photos load in the background",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,34 +9,6 @@ import com.placeholder.sherpai2.data.local.entity.ImageEntity
|
|||||||
import com.placeholder.sherpai2.data.local.model.ImageWithEverything
|
import com.placeholder.sherpai2.data.local.model.ImageWithEverything
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
/**
|
|
||||||
* Data classes for statistics queries
|
|
||||||
*/
|
|
||||||
data class DateCount(
|
|
||||||
val date: String, // YYYY-MM-DD format
|
|
||||||
val count: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
data class MonthCount(
|
|
||||||
val month: String, // YYYY-MM format
|
|
||||||
val count: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
data class YearCount(
|
|
||||||
val year: String, // YYYY format
|
|
||||||
val count: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
data class DayOfWeekCount(
|
|
||||||
val dayOfWeek: Int, // 0 = Sunday, 6 = Saturday
|
|
||||||
val count: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
data class HourCount(
|
|
||||||
val hour: Int, // 0-23
|
|
||||||
val count: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface ImageDao {
|
interface ImageDao {
|
||||||
|
|
||||||
@@ -100,145 +72,4 @@ interface ImageDao {
|
|||||||
*/
|
*/
|
||||||
@Query("SELECT * FROM images WHERE imageId IN (:imageIds)")
|
@Query("SELECT * FROM images WHERE imageId IN (:imageIds)")
|
||||||
suspend fun getImagesByIds(imageIds: List<String>): List<ImageEntity>
|
suspend fun getImagesByIds(imageIds: List<String>): List<ImageEntity>
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM images")
|
|
||||||
suspend fun getImageCount(): Int
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all images (for utilities processing)
|
|
||||||
*/
|
|
||||||
@Query("SELECT * FROM images ORDER BY capturedAt DESC")
|
|
||||||
suspend fun getAllImages(): List<ImageEntity>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all images sorted by time (for burst detection)
|
|
||||||
*/
|
|
||||||
@Query("SELECT * FROM images ORDER BY capturedAt ASC")
|
|
||||||
suspend fun getAllImagesSortedByTime(): List<ImageEntity>
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// STATISTICS QUERIES - ADDED FOR STATS SECTION
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get photo counts by date (daily granularity)
|
|
||||||
* Returns all days that have at least one photo
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
date(capturedAt/1000, 'unixepoch') as date,
|
|
||||||
COUNT(*) as count
|
|
||||||
FROM images
|
|
||||||
GROUP BY date
|
|
||||||
ORDER BY date ASC
|
|
||||||
""")
|
|
||||||
suspend fun getPhotoCountsByDate(): List<DateCount>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get photo counts by month (monthly granularity)
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
strftime('%Y-%m', capturedAt/1000, 'unixepoch') as month,
|
|
||||||
COUNT(*) as count
|
|
||||||
FROM images
|
|
||||||
GROUP BY month
|
|
||||||
ORDER BY month ASC
|
|
||||||
""")
|
|
||||||
suspend fun getPhotoCountsByMonth(): List<MonthCount>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get photo counts by year (yearly granularity)
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
strftime('%Y', capturedAt/1000, 'unixepoch') as year,
|
|
||||||
COUNT(*) as count
|
|
||||||
FROM images
|
|
||||||
GROUP BY year
|
|
||||||
ORDER BY year DESC
|
|
||||||
""")
|
|
||||||
suspend fun getPhotoCountsByYear(): List<YearCount>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get photo counts by year (Flow version for reactive UI)
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
strftime('%Y', capturedAt/1000, 'unixepoch') as year,
|
|
||||||
COUNT(*) as count
|
|
||||||
FROM images
|
|
||||||
GROUP BY year
|
|
||||||
ORDER BY year DESC
|
|
||||||
""")
|
|
||||||
fun getPhotoCountsByYearFlow(): Flow<List<YearCount>>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get photo counts by day of week (0 = Sunday, 6 = Saturday)
|
|
||||||
* Shows which days you take the most photos
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
CAST(strftime('%w', capturedAt/1000, 'unixepoch') AS INTEGER) as dayOfWeek,
|
|
||||||
COUNT(*) as count
|
|
||||||
FROM images
|
|
||||||
GROUP BY dayOfWeek
|
|
||||||
ORDER BY dayOfWeek ASC
|
|
||||||
""")
|
|
||||||
suspend fun getPhotoCountsByDayOfWeek(): List<DayOfWeekCount>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get photo counts by hour of day (0-23)
|
|
||||||
* Shows when you take the most photos
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
CAST(strftime('%H', capturedAt/1000, 'unixepoch') AS INTEGER) as hour,
|
|
||||||
COUNT(*) as count
|
|
||||||
FROM images
|
|
||||||
GROUP BY hour
|
|
||||||
ORDER BY hour ASC
|
|
||||||
""")
|
|
||||||
suspend fun getPhotoCountsByHour(): List<HourCount>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get earliest and latest photo timestamps
|
|
||||||
* Used for date range calculations
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
MIN(capturedAt) as earliest,
|
|
||||||
MAX(capturedAt) as latest
|
|
||||||
FROM images
|
|
||||||
""")
|
|
||||||
suspend fun getPhotoDateRange(): PhotoDateRange?
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get photo count for a specific year
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT COUNT(*) FROM images
|
|
||||||
WHERE strftime('%Y', capturedAt/1000, 'unixepoch') = :year
|
|
||||||
""")
|
|
||||||
suspend fun getPhotoCountForYear(year: String): Int
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get average photos per day (for stats display)
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
CAST(COUNT(*) AS REAL) /
|
|
||||||
CAST((MAX(capturedAt) - MIN(capturedAt)) / 86400000 AS REAL) as avgPerDay
|
|
||||||
FROM images
|
|
||||||
WHERE (SELECT COUNT(*) FROM images) > 0
|
|
||||||
""")
|
|
||||||
suspend fun getAveragePhotosPerDay(): Float?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Data class for date range result
|
|
||||||
*/
|
|
||||||
data class PhotoDateRange(
|
|
||||||
val earliest: Long,
|
|
||||||
val latest: Long
|
|
||||||
)
|
|
||||||
@@ -9,15 +9,6 @@ import com.placeholder.sherpai2.data.local.entity.ImageTagEntity
|
|||||||
import com.placeholder.sherpai2.data.local.entity.TagEntity
|
import com.placeholder.sherpai2.data.local.entity.TagEntity
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
/**
|
|
||||||
* Data class for burst statistics
|
|
||||||
*/
|
|
||||||
data class BurstStats(
|
|
||||||
val totalBurstPhotos: Int,
|
|
||||||
val estimatedBurstGroups: Int,
|
|
||||||
val burstRepresentatives: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface ImageTagDao {
|
interface ImageTagDao {
|
||||||
|
|
||||||
@@ -53,90 +44,4 @@ interface ImageTagDao {
|
|||||||
WHERE it.imageId = :imageId AND it.visibility = 'PUBLIC'
|
WHERE it.imageId = :imageId AND it.visibility = 'PUBLIC'
|
||||||
""")
|
""")
|
||||||
fun getTagsForImage(imageId: String): Flow<List<TagEntity>>
|
fun getTagsForImage(imageId: String): Flow<List<TagEntity>>
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert image tag (for utilities tagging)
|
|
||||||
*/
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
|
||||||
suspend fun insert(imageTag: ImageTagEntity): Long
|
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// BURST STATISTICS - ADDED FOR STATS SECTION
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get comprehensive burst statistics
|
|
||||||
* Returns total burst photos, estimated groups, and representative count
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
(SELECT COUNT(DISTINCT it.imageId)
|
|
||||||
FROM image_tags it
|
|
||||||
INNER JOIN tags t ON it.tagId = t.tagId
|
|
||||||
WHERE t.value = 'burst') as totalBurstPhotos,
|
|
||||||
(SELECT COUNT(DISTINCT it.imageId) / 3
|
|
||||||
FROM image_tags it
|
|
||||||
INNER JOIN tags t ON it.tagId = t.tagId
|
|
||||||
WHERE t.value = 'burst') as estimatedBurstGroups,
|
|
||||||
(SELECT COUNT(DISTINCT it.imageId)
|
|
||||||
FROM image_tags it
|
|
||||||
INNER JOIN tags t ON it.tagId = t.tagId
|
|
||||||
WHERE t.value = 'burst_representative') as burstRepresentatives
|
|
||||||
""")
|
|
||||||
suspend fun getBurstStats(): BurstStats?
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get burst statistics (Flow version for reactive UI)
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
(SELECT COUNT(DISTINCT it.imageId)
|
|
||||||
FROM image_tags it
|
|
||||||
INNER JOIN tags t ON it.tagId = t.tagId
|
|
||||||
WHERE t.value = 'burst') as totalBurstPhotos,
|
|
||||||
(SELECT COUNT(DISTINCT it.imageId) / 3
|
|
||||||
FROM image_tags it
|
|
||||||
INNER JOIN tags t ON it.tagId = t.tagId
|
|
||||||
WHERE t.value = 'burst') as estimatedBurstGroups,
|
|
||||||
(SELECT COUNT(DISTINCT it.imageId)
|
|
||||||
FROM image_tags it
|
|
||||||
INNER JOIN tags t ON it.tagId = t.tagId
|
|
||||||
WHERE t.value = 'burst_representative') as burstRepresentatives
|
|
||||||
""")
|
|
||||||
fun getBurstStatsFlow(): Flow<BurstStats?>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get count of burst photos
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT COUNT(DISTINCT it.imageId)
|
|
||||||
FROM image_tags it
|
|
||||||
INNER JOIN tags t ON it.tagId = t.tagId
|
|
||||||
WHERE t.value = 'burst'
|
|
||||||
""")
|
|
||||||
suspend fun getBurstPhotoCount(): Int
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get count of burst representative photos
|
|
||||||
* (photos marked as the best in each burst sequence)
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT COUNT(DISTINCT it.imageId)
|
|
||||||
FROM image_tags it
|
|
||||||
INNER JOIN tags t ON it.tagId = t.tagId
|
|
||||||
WHERE t.value = 'burst_representative'
|
|
||||||
""")
|
|
||||||
suspend fun getBurstRepresentativeCount(): Int
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get estimated number of burst groups
|
|
||||||
* Assumes average of 3 photos per burst
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT COUNT(DISTINCT it.imageId) / 3
|
|
||||||
FROM image_tags it
|
|
||||||
INNER JOIN tags t ON it.tagId = t.tagId
|
|
||||||
WHERE t.value = 'burst'
|
|
||||||
""")
|
|
||||||
suspend fun getEstimatedBurstGroupCount(): Int
|
|
||||||
}
|
}
|
||||||
@@ -9,16 +9,6 @@ import com.placeholder.sherpai2.data.local.entity.TagEntity
|
|||||||
import com.placeholder.sherpai2.data.local.entity.TagWithUsage
|
import com.placeholder.sherpai2.data.local.entity.TagWithUsage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
/**
|
|
||||||
* Data class for tag statistics
|
|
||||||
*/
|
|
||||||
data class TagStat(
|
|
||||||
val tagValue: String,
|
|
||||||
val tagType: String,
|
|
||||||
val imageCount: Int,
|
|
||||||
val tagId: String
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TagDao - Tag management with face recognition integration
|
* TagDao - Tag management with face recognition integration
|
||||||
*
|
*
|
||||||
@@ -228,70 +218,4 @@ interface TagDao {
|
|||||||
LIMIT :limit
|
LIMIT :limit
|
||||||
""")
|
""")
|
||||||
suspend fun searchTagsWithUsage(query: String, limit: Int): List<TagWithUsage>
|
suspend fun searchTagsWithUsage(query: String, limit: Int): List<TagWithUsage>
|
||||||
|
|
||||||
// ==========================================
|
|
||||||
// STATISTICS QUERIES - ADDED FOR STATS SECTION
|
|
||||||
// ==========================================
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get system tag statistics (for utilities stats display)
|
|
||||||
* Returns tag value, type, and count of tagged images
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
t.value as tagValue,
|
|
||||||
t.type as tagType,
|
|
||||||
COUNT(DISTINCT it.imageId) as imageCount,
|
|
||||||
t.tagId as tagId
|
|
||||||
FROM tags t
|
|
||||||
INNER JOIN image_tags it ON t.tagId = it.tagId
|
|
||||||
WHERE t.type = 'SYSTEM'
|
|
||||||
GROUP BY t.tagId
|
|
||||||
ORDER BY imageCount DESC
|
|
||||||
""")
|
|
||||||
suspend fun getSystemTagStats(): List<TagStat>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get system tag statistics (Flow version for reactive UI)
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
t.value as tagValue,
|
|
||||||
t.type as tagType,
|
|
||||||
COUNT(DISTINCT it.imageId) as imageCount,
|
|
||||||
t.tagId as tagId
|
|
||||||
FROM tags t
|
|
||||||
INNER JOIN image_tags it ON t.tagId = it.tagId
|
|
||||||
WHERE t.type = 'SYSTEM'
|
|
||||||
GROUP BY t.tagId
|
|
||||||
ORDER BY imageCount DESC
|
|
||||||
""")
|
|
||||||
fun getSystemTagStatsFlow(): Flow<List<TagStat>>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get count of photos with a specific system tag
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT COUNT(DISTINCT it.imageId)
|
|
||||||
FROM image_tags it
|
|
||||||
INNER JOIN tags t ON it.tagId = t.tagId
|
|
||||||
WHERE t.value = :tagValue AND t.type = 'SYSTEM'
|
|
||||||
""")
|
|
||||||
suspend fun getSystemTagCount(tagValue: String): Int
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all tag types with counts
|
|
||||||
* Shows breakdown of SYSTEM vs USER vs GENERIC tags
|
|
||||||
*/
|
|
||||||
@Query("""
|
|
||||||
SELECT
|
|
||||||
t.type as tagValue,
|
|
||||||
t.type as tagType,
|
|
||||||
COUNT(DISTINCT t.tagId) as imageCount,
|
|
||||||
'' as tagId
|
|
||||||
FROM tags t
|
|
||||||
GROUP BY t.type
|
|
||||||
ORDER BY imageCount DESC
|
|
||||||
""")
|
|
||||||
suspend fun getTagTypeBreakdown(): List<TagStat>
|
|
||||||
}
|
}
|
||||||
@@ -1,46 +1,23 @@
|
|||||||
package com.placeholder.sherpai2.data.local.model
|
package com.placeholder.sherpai2.data.local.model
|
||||||
|
|
||||||
import androidx.room.Embedded
|
import androidx.room.Embedded
|
||||||
import androidx.room.Junction
|
|
||||||
import androidx.room.Relation
|
import androidx.room.Relation
|
||||||
import com.placeholder.sherpai2.data.local.entity.*
|
import com.placeholder.sherpai2.data.local.entity.*
|
||||||
|
|
||||||
/**
|
|
||||||
* ImageWithEverything - Fully hydrated image with ALL relationships
|
|
||||||
*
|
|
||||||
* Room loads this in ONE query using @Transaction!
|
|
||||||
* NO N+1 problem - all tags and face tags loaded together
|
|
||||||
*
|
|
||||||
* Usage:
|
|
||||||
* - ImageAggregateDao.observeAllImagesWithEverything()
|
|
||||||
* - Search, Explore, Albums
|
|
||||||
*/
|
|
||||||
data class ImageWithEverything(
|
data class ImageWithEverything(
|
||||||
|
|
||||||
@Embedded
|
@Embedded
|
||||||
val image: ImageEntity,
|
val image: ImageEntity,
|
||||||
|
|
||||||
/**
|
|
||||||
* Tags for this image (via image_tags join table)
|
|
||||||
* Room automatically joins through ImageTagEntity
|
|
||||||
*/
|
|
||||||
@Relation(
|
|
||||||
parentColumn = "imageId",
|
|
||||||
entityColumn = "tagId",
|
|
||||||
associateBy = Junction(
|
|
||||||
value = ImageTagEntity::class,
|
|
||||||
parentColumn = "imageId",
|
|
||||||
entityColumn = "tagId"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val tags: List<TagEntity>,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Face tags for this image
|
|
||||||
* Room automatically loads all PhotoFaceTagEntity for this imageId
|
|
||||||
*/
|
|
||||||
@Relation(
|
@Relation(
|
||||||
parentColumn = "imageId",
|
parentColumn = "imageId",
|
||||||
entityColumn = "imageId"
|
entityColumn = "imageId"
|
||||||
)
|
)
|
||||||
val faceTags: List<PhotoFaceTagEntity>
|
val tags: List<ImageTagEntity>,
|
||||||
|
|
||||||
|
@Relation(
|
||||||
|
parentColumn = "imageId",
|
||||||
|
entityColumn = "imageId"
|
||||||
|
)
|
||||||
|
val events: List<ImageEventEntity>
|
||||||
)
|
)
|
||||||
@@ -23,23 +23,9 @@ interface ImageRepository {
|
|||||||
* This function:
|
* This function:
|
||||||
* - deduplicates
|
* - deduplicates
|
||||||
* - assigns events automatically
|
* - assigns events automatically
|
||||||
* - BLOCKS until complete (old behavior)
|
|
||||||
*/
|
*/
|
||||||
suspend fun ingestImages()
|
suspend fun ingestImages()
|
||||||
|
|
||||||
/**
|
|
||||||
* Ingest images with progress callback (NEW!)
|
|
||||||
*
|
|
||||||
* @param onProgress Called with (current, total) for progress updates
|
|
||||||
*/
|
|
||||||
suspend fun ingestImagesWithProgress(onProgress: (current: Int, total: Int) -> Unit)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get total image count (NEW!)
|
|
||||||
* Fast query to check if images already loaded
|
|
||||||
*/
|
|
||||||
suspend fun getImageCount(): Int
|
|
||||||
|
|
||||||
fun getAllImages(): Flow<List<ImageWithEverything>>
|
fun getAllImages(): Flow<List<ImageWithEverything>>
|
||||||
fun findImagesByTag(tag: String): Flow<List<ImageWithEverything>>
|
fun findImagesByTag(tag: String): Flow<List<ImageWithEverything>>
|
||||||
|
|
||||||
|
|||||||
@@ -15,21 +15,11 @@ import dagger.hilt.android.qualifiers.ApplicationContext
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.yield
|
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
/**
|
|
||||||
* ImageRepositoryImpl - ENHANCED for large photo collections
|
|
||||||
*
|
|
||||||
* Key improvements:
|
|
||||||
* 1. Batched processing (100 images at a time)
|
|
||||||
* 2. Progress callbacks
|
|
||||||
* 3. Yields to prevent ANR
|
|
||||||
* 4. Fast image count check
|
|
||||||
*/
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class ImageRepositoryImpl @Inject constructor(
|
class ImageRepositoryImpl @Inject constructor(
|
||||||
private val imageDao: ImageDao,
|
private val imageDao: ImageDao,
|
||||||
@@ -44,85 +34,38 @@ class ImageRepositoryImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get total image count - FAST
|
* Ingest all images from MediaStore.
|
||||||
*/
|
* Uses _ID and DATE_ADDED to ensure no image is skipped, even if DATE_TAKEN is identical.
|
||||||
override suspend fun getImageCount(): Int = withContext(Dispatchers.IO) {
|
|
||||||
return@withContext imageDao.getImageCount()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Original blocking ingestion (for backward compatibility)
|
|
||||||
*/
|
*/
|
||||||
override suspend fun ingestImages(): Unit = withContext(Dispatchers.IO) {
|
override suspend fun ingestImages(): Unit = withContext(Dispatchers.IO) {
|
||||||
ingestImagesWithProgress { _, _ -> }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enhanced ingestion with progress tracking
|
|
||||||
* Processes in batches to prevent ANR and memory issues
|
|
||||||
* SCANS ALL FOLDERS RECURSIVELY (including nested directories)
|
|
||||||
*/
|
|
||||||
override suspend fun ingestImagesWithProgress(
|
|
||||||
onProgress: (current: Int, total: Int) -> Unit
|
|
||||||
): Unit = withContext(Dispatchers.IO) {
|
|
||||||
try {
|
try {
|
||||||
|
val imageList = mutableListOf<ImageEntity>()
|
||||||
|
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
MediaStore.Images.Media._ID,
|
MediaStore.Images.Media._ID,
|
||||||
MediaStore.Images.Media.DISPLAY_NAME,
|
MediaStore.Images.Media.DISPLAY_NAME,
|
||||||
MediaStore.Images.Media.DATE_TAKEN,
|
MediaStore.Images.Media.DATE_TAKEN,
|
||||||
MediaStore.Images.Media.DATE_ADDED,
|
MediaStore.Images.Media.DATE_ADDED,
|
||||||
MediaStore.Images.Media.WIDTH,
|
MediaStore.Images.Media.WIDTH,
|
||||||
MediaStore.Images.Media.HEIGHT,
|
MediaStore.Images.Media.HEIGHT
|
||||||
MediaStore.Images.Media.DATA // Full file path
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val sortOrder = "${MediaStore.Images.Media.DATE_ADDED} ASC"
|
val sortOrder = "${MediaStore.Images.Media.DATE_ADDED} ASC"
|
||||||
|
|
||||||
// IMPORTANT: Don't filter by BUCKET_ID or folder
|
|
||||||
// This scans ALL images on device including nested folders
|
|
||||||
val selection = null // No WHERE clause = all images
|
|
||||||
val selectionArgs = null
|
|
||||||
|
|
||||||
// First pass: Count total images
|
|
||||||
var totalImages = 0
|
|
||||||
context.contentResolver.query(
|
|
||||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
|
||||||
arrayOf(MediaStore.Images.Media._ID),
|
|
||||||
selection,
|
|
||||||
selectionArgs,
|
|
||||||
null
|
|
||||||
)?.use { cursor ->
|
|
||||||
totalImages = cursor.count
|
|
||||||
}
|
|
||||||
|
|
||||||
if (totalImages == 0) {
|
|
||||||
Log.i("ImageRepository", "No images found on device")
|
|
||||||
return@withContext
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.i("ImageRepository", "Found $totalImages images to process (ALL folders)")
|
|
||||||
onProgress(0, totalImages)
|
|
||||||
|
|
||||||
// Second pass: Process in batches
|
|
||||||
val batchSize = 100
|
|
||||||
var processed = 0
|
|
||||||
|
|
||||||
context.contentResolver.query(
|
context.contentResolver.query(
|
||||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||||
projection,
|
projection,
|
||||||
selection,
|
null,
|
||||||
selectionArgs,
|
null,
|
||||||
sortOrder
|
sortOrder
|
||||||
)?.use { cursor ->
|
)?.use { cursor ->
|
||||||
|
|
||||||
val idCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)
|
val idCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)
|
||||||
val nameCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME)
|
val nameCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME)
|
||||||
val dateTakenCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_TAKEN)
|
val dateTakenCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_TAKEN)
|
||||||
val dateAddedCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_ADDED)
|
val dateAddedCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_ADDED)
|
||||||
val widthCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.WIDTH)
|
val widthCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.WIDTH)
|
||||||
val heightCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.HEIGHT)
|
val heightCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.HEIGHT)
|
||||||
val dataCol = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)
|
|
||||||
|
|
||||||
val batch = mutableListOf<ImageEntity>()
|
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val id = cursor.getLong(idCol)
|
val id = cursor.getLong(idCol)
|
||||||
@@ -131,14 +74,16 @@ class ImageRepositoryImpl @Inject constructor(
|
|||||||
val dateAdded = cursor.getLong(dateAddedCol)
|
val dateAdded = cursor.getLong(dateAddedCol)
|
||||||
val width = cursor.getInt(widthCol)
|
val width = cursor.getInt(widthCol)
|
||||||
val height = cursor.getInt(heightCol)
|
val height = cursor.getInt(heightCol)
|
||||||
val filePath = cursor.getString(dataCol)
|
|
||||||
|
|
||||||
val contentUri: Uri = ContentUris.withAppendedId(
|
val contentUri: Uri = ContentUris.withAppendedId(
|
||||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id
|
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id
|
||||||
)
|
)
|
||||||
|
|
||||||
// Skip SHA256 computation for speed - use URI as unique identifier
|
val sha256 = computeSHA256(contentUri)
|
||||||
val sha256 = computeSHA256Fast(contentUri) ?: contentUri.toString()
|
if (sha256 == null) {
|
||||||
|
Log.w("ImageRepository", "Skipped image: $displayName (cannot read bytes)")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
val imageEntity = ImageEntity(
|
val imageEntity = ImageEntity(
|
||||||
imageId = UUID.randomUUID().toString(),
|
imageId = UUID.randomUUID().toString(),
|
||||||
@@ -148,73 +93,36 @@ class ImageRepositoryImpl @Inject constructor(
|
|||||||
ingestedAt = System.currentTimeMillis(),
|
ingestedAt = System.currentTimeMillis(),
|
||||||
width = width,
|
width = width,
|
||||||
height = height,
|
height = height,
|
||||||
source = determineSource(filePath)
|
source = "CAMERA" // or SCREENSHOT / IMPORTED
|
||||||
)
|
)
|
||||||
|
|
||||||
batch.add(imageEntity)
|
imageList += imageEntity
|
||||||
processed++
|
Log.i("ImageRepository", "Processing image: $displayName, SHA256: $sha256")
|
||||||
|
|
||||||
// Insert batch and update progress
|
|
||||||
if (batch.size >= batchSize) {
|
|
||||||
imageDao.insertImages(batch)
|
|
||||||
batch.clear()
|
|
||||||
|
|
||||||
// Update progress on main thread
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
onProgress(processed, totalImages)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Yield to prevent blocking
|
|
||||||
yield()
|
|
||||||
|
|
||||||
Log.d("ImageRepository", "Processed $processed/$totalImages images")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert remaining batch
|
if (imageList.isNotEmpty()) {
|
||||||
if (batch.isNotEmpty()) {
|
imageDao.insertImages(imageList)
|
||||||
imageDao.insertImages(batch)
|
Log.i("ImageRepository", "Ingested ${imageList.size} images")
|
||||||
withContext(Dispatchers.Main) {
|
} else {
|
||||||
onProgress(processed, totalImages)
|
Log.i("ImageRepository", "No images found on device")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.i("ImageRepository", "Ingestion complete: $processed images from ALL folders")
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("ImageRepository", "Error ingesting images", e)
|
Log.e("ImageRepository", "Error ingesting images", e)
|
||||||
throw e
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine image source from file path
|
* Compute SHA256 from a MediaStore Uri safely.
|
||||||
*/
|
*/
|
||||||
private fun determineSource(filePath: String?): String {
|
private fun computeSHA256(uri: Uri): String? {
|
||||||
if (filePath == null) return "CAMERA"
|
|
||||||
|
|
||||||
return when {
|
|
||||||
filePath.contains("DCIM", ignoreCase = true) -> "CAMERA"
|
|
||||||
filePath.contains("Screenshot", ignoreCase = true) -> "SCREENSHOT"
|
|
||||||
filePath.contains("Download", ignoreCase = true) -> "IMPORTED"
|
|
||||||
filePath.contains("WhatsApp", ignoreCase = true) -> "IMPORTED"
|
|
||||||
else -> "CAMERA"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fast SHA256 computation - only reads first 8KB for speed
|
|
||||||
* For 10,000+ images, this saves significant time
|
|
||||||
*/
|
|
||||||
private fun computeSHA256Fast(uri: Uri): String? {
|
|
||||||
return try {
|
return try {
|
||||||
val digest = MessageDigest.getInstance("SHA-256")
|
val digest = MessageDigest.getInstance("SHA-256")
|
||||||
context.contentResolver.openInputStream(uri)?.use { input ->
|
context.contentResolver.openInputStream(uri)?.use { input ->
|
||||||
// Only read first 8KB for uniqueness check
|
|
||||||
val buffer = ByteArray(8192)
|
val buffer = ByteArray(8192)
|
||||||
val read = input.read(buffer)
|
var read: Int
|
||||||
if (read > 0) {
|
while (input.read(buffer).also { read = it } > 0) {
|
||||||
digest.update(buffer, 0, read)
|
digest.update(buffer, 0, read)
|
||||||
}
|
}
|
||||||
} ?: return null
|
} ?: return null
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import com.placeholder.sherpai2.data.local.entity.PersonEntity
|
|||||||
import com.placeholder.sherpai2.data.local.entity.PhotoFaceTagEntity
|
import com.placeholder.sherpai2.data.local.entity.PhotoFaceTagEntity
|
||||||
import com.placeholder.sherpai2.data.repository.FaceRecognitionRepository
|
import com.placeholder.sherpai2.data.repository.FaceRecognitionRepository
|
||||||
import com.placeholder.sherpai2.ui.search.DateRange
|
import com.placeholder.sherpai2.ui.search.DateRange
|
||||||
|
import com.placeholder.sherpai2.ui.search.DisplayMode
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -24,8 +25,8 @@ import javax.inject.Inject
|
|||||||
* Features:
|
* Features:
|
||||||
* - Search within album
|
* - Search within album
|
||||||
* - Date filtering
|
* - Date filtering
|
||||||
|
* - Simple/Verbose toggle
|
||||||
* - Album stats
|
* - Album stats
|
||||||
* - Export functionality
|
|
||||||
*/
|
*/
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class AlbumViewModel @Inject constructor(
|
class AlbumViewModel @Inject constructor(
|
||||||
@@ -53,6 +54,10 @@ class AlbumViewModel @Inject constructor(
|
|||||||
private val _dateRange = MutableStateFlow(DateRange.ALL_TIME)
|
private val _dateRange = MutableStateFlow(DateRange.ALL_TIME)
|
||||||
val dateRange: StateFlow<DateRange> = _dateRange.asStateFlow()
|
val dateRange: StateFlow<DateRange> = _dateRange.asStateFlow()
|
||||||
|
|
||||||
|
// Display mode
|
||||||
|
private val _displayMode = MutableStateFlow(DisplayMode.SIMPLE)
|
||||||
|
val displayMode: StateFlow<DisplayMode> = _displayMode.asStateFlow()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
loadAlbumData()
|
loadAlbumData()
|
||||||
}
|
}
|
||||||
@@ -88,7 +93,7 @@ class AlbumViewModel @Inject constructor(
|
|||||||
combine(
|
combine(
|
||||||
_searchQuery,
|
_searchQuery,
|
||||||
_dateRange
|
_dateRange
|
||||||
) { query: String, dateRange: DateRange ->
|
) { query, dateRange ->
|
||||||
Pair(query, dateRange)
|
Pair(query, dateRange)
|
||||||
}.collectLatest { (query, dateRange) ->
|
}.collectLatest { (query, dateRange) ->
|
||||||
val imageIds = imageTagDao.findImagesByTag(tag.tagId, 0.5f)
|
val imageIds = imageTagDao.findImagesByTag(tag.tagId, 0.5f)
|
||||||
@@ -114,7 +119,7 @@ class AlbumViewModel @Inject constructor(
|
|||||||
.distinctBy { it.id }
|
.distinctBy { it.id }
|
||||||
|
|
||||||
_uiState.value = AlbumUiState.Success(
|
_uiState.value = AlbumUiState.Success(
|
||||||
albumName = tag.value.replace("_", " ").replaceFirstChar { it.uppercase() },
|
albumName = tag.value.replace("_", " ").capitalize(),
|
||||||
albumType = "Tag",
|
albumType = "Tag",
|
||||||
photos = imagesWithFaces,
|
photos = imagesWithFaces,
|
||||||
personCount = uniquePersons.size,
|
personCount = uniquePersons.size,
|
||||||
@@ -133,7 +138,7 @@ class AlbumViewModel @Inject constructor(
|
|||||||
combine(
|
combine(
|
||||||
_searchQuery,
|
_searchQuery,
|
||||||
_dateRange
|
_dateRange
|
||||||
) { query: String, dateRange: DateRange ->
|
) { query, dateRange ->
|
||||||
Pair(query, dateRange)
|
Pair(query, dateRange)
|
||||||
}.collectLatest { (query, dateRange) ->
|
}.collectLatest { (query, dateRange) ->
|
||||||
val images = faceRecognitionRepository.getImagesForPerson(albumId)
|
val images = faceRecognitionRepository.getImagesForPerson(albumId)
|
||||||
@@ -179,7 +184,7 @@ class AlbumViewModel @Inject constructor(
|
|||||||
combine(
|
combine(
|
||||||
_searchQuery,
|
_searchQuery,
|
||||||
_dateRange
|
_dateRange
|
||||||
) { query: String, _: DateRange ->
|
) { query, _ ->
|
||||||
query
|
query
|
||||||
}.collectLatest { query ->
|
}.collectLatest { query ->
|
||||||
val images = imageDao.getImagesInRange(startTime, endTime)
|
val images = imageDao.getImagesInRange(startTime, endTime)
|
||||||
@@ -219,6 +224,13 @@ class AlbumViewModel @Inject constructor(
|
|||||||
_dateRange.value = range
|
_dateRange.value = range
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun toggleDisplayMode() {
|
||||||
|
_displayMode.value = when (_displayMode.value) {
|
||||||
|
DisplayMode.SIMPLE -> DisplayMode.VERBOSE
|
||||||
|
DisplayMode.VERBOSE -> DisplayMode.SIMPLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun isInDateRange(timestamp: Long, range: DateRange): Boolean {
|
private fun isInDateRange(timestamp: Long, range: DateRange): Boolean {
|
||||||
return when (range) {
|
return when (range) {
|
||||||
DateRange.ALL_TIME -> true
|
DateRange.ALL_TIME -> true
|
||||||
@@ -299,6 +311,10 @@ class AlbumViewModel @Inject constructor(
|
|||||||
set(Calendar.MILLISECOND, 0)
|
set(Calendar.MILLISECOND, 0)
|
||||||
}.timeInMillis
|
}.timeInMillis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.capitalize(): String {
|
||||||
|
return this.replaceFirstChar { it.uppercase() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class AlbumUiState {
|
sealed class AlbumUiState {
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package com.placeholder.sherpai2.ui.album
|
package com.placeholder.sherpai2.ui.album
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyRow
|
import androidx.compose.foundation.lazy.LazyRow
|
||||||
import androidx.compose.foundation.lazy.grid.*
|
import androidx.compose.foundation.lazy.grid.*
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.*
|
import androidx.compose.material.icons.filled.*
|
||||||
@@ -11,24 +12,25 @@ import androidx.compose.material3.*
|
|||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import coil.compose.AsyncImage
|
|
||||||
import com.placeholder.sherpai2.ui.search.DateRange
|
import com.placeholder.sherpai2.ui.search.DateRange
|
||||||
|
import com.placeholder.sherpai2.ui.search.DisplayMode
|
||||||
|
import com.placeholder.sherpai2.ui.search.components.ImageGridItem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AlbumViewScreen - CLEAN VERSION with Export
|
* AlbumViewScreen - Beautiful album detail view
|
||||||
*
|
*
|
||||||
* REMOVED:
|
* Features:
|
||||||
* - DisplayMode toggle
|
* - Album stats
|
||||||
* - Verbose person tags
|
* - Search within album
|
||||||
*
|
* - Date filtering
|
||||||
* ADDED:
|
* - Simple/Verbose toggle
|
||||||
* - Export menu (Folder, Zip, Collage)
|
* - Clean person display
|
||||||
* - Clean simple layout
|
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -40,8 +42,7 @@ fun AlbumViewScreen(
|
|||||||
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
val searchQuery by viewModel.searchQuery.collectAsStateWithLifecycle()
|
val searchQuery by viewModel.searchQuery.collectAsStateWithLifecycle()
|
||||||
val dateRange by viewModel.dateRange.collectAsStateWithLifecycle()
|
val dateRange by viewModel.dateRange.collectAsStateWithLifecycle()
|
||||||
|
val displayMode by viewModel.displayMode.collectAsStateWithLifecycle()
|
||||||
var showExportMenu by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
@@ -73,9 +74,15 @@ fun AlbumViewScreen(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
// Export button
|
IconButton(onClick = { viewModel.toggleDisplayMode() }) {
|
||||||
IconButton(onClick = { showExportMenu = true }) {
|
Icon(
|
||||||
Icon(Icons.Default.FileDownload, "Export")
|
imageVector = if (displayMode == DisplayMode.SIMPLE) {
|
||||||
|
Icons.Default.ViewList
|
||||||
|
} else {
|
||||||
|
Icons.Default.ViewModule
|
||||||
|
},
|
||||||
|
contentDescription = "Toggle view"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -121,6 +128,7 @@ fun AlbumViewScreen(
|
|||||||
state = state,
|
state = state,
|
||||||
searchQuery = searchQuery,
|
searchQuery = searchQuery,
|
||||||
dateRange = dateRange,
|
dateRange = dateRange,
|
||||||
|
displayMode = displayMode,
|
||||||
onSearchChange = { viewModel.setSearchQuery(it) },
|
onSearchChange = { viewModel.setSearchQuery(it) },
|
||||||
onDateRangeChange = { viewModel.setDateRange(it) },
|
onDateRangeChange = { viewModel.setDateRange(it) },
|
||||||
onImageClick = onImageClick,
|
onImageClick = onImageClick,
|
||||||
@@ -129,33 +137,6 @@ fun AlbumViewScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export menu dialog
|
|
||||||
if (showExportMenu) {
|
|
||||||
ExportDialog(
|
|
||||||
albumName = when (val state = uiState) {
|
|
||||||
is AlbumUiState.Success -> state.albumName
|
|
||||||
else -> "Album"
|
|
||||||
},
|
|
||||||
photoCount = when (val state = uiState) {
|
|
||||||
is AlbumUiState.Success -> state.photos.size
|
|
||||||
else -> 0
|
|
||||||
},
|
|
||||||
onDismiss = { showExportMenu = false },
|
|
||||||
onExportToFolder = {
|
|
||||||
// TODO: Implement folder export
|
|
||||||
showExportMenu = false
|
|
||||||
},
|
|
||||||
onExportToZip = {
|
|
||||||
// TODO: Implement zip export
|
|
||||||
showExportMenu = false
|
|
||||||
},
|
|
||||||
onExportToCollage = {
|
|
||||||
// TODO: Implement collage export
|
|
||||||
showExportMenu = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -163,6 +144,7 @@ private fun AlbumContent(
|
|||||||
state: AlbumUiState.Success,
|
state: AlbumUiState.Success,
|
||||||
searchQuery: String,
|
searchQuery: String,
|
||||||
dateRange: DateRange,
|
dateRange: DateRange,
|
||||||
|
displayMode: DisplayMode,
|
||||||
onSearchChange: (String) -> Unit,
|
onSearchChange: (String) -> Unit,
|
||||||
onDateRangeChange: (DateRange) -> Unit,
|
onDateRangeChange: (DateRange) -> Unit,
|
||||||
onImageClick: (String) -> Unit,
|
onImageClick: (String) -> Unit,
|
||||||
@@ -225,8 +207,7 @@ private fun AlbumContent(
|
|||||||
.padding(horizontal = 16.dp),
|
.padding(horizontal = 16.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
) {
|
) {
|
||||||
items(DateRange.entries.size) { index ->
|
items(DateRange.entries) { range ->
|
||||||
val range = DateRange.entries[index]
|
|
||||||
val isActive = dateRange == range
|
val isActive = dateRange == range
|
||||||
FilterChip(
|
FilterChip(
|
||||||
selected = isActive,
|
selected = isActive,
|
||||||
@@ -264,6 +245,7 @@ private fun AlbumContent(
|
|||||||
) { photo ->
|
) { photo ->
|
||||||
PhotoCard(
|
PhotoCard(
|
||||||
photo = photo,
|
photo = photo,
|
||||||
|
displayMode = displayMode,
|
||||||
onImageClick = onImageClick
|
onImageClick = onImageClick
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -273,11 +255,7 @@ private fun AlbumContent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun StatItem(
|
private fun StatItem(icon: androidx.compose.ui.graphics.vector.ImageVector, label: String, value: String) {
|
||||||
icon: androidx.compose.ui.graphics.vector.ImageVector,
|
|
||||||
label: String,
|
|
||||||
value: String
|
|
||||||
) {
|
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||||
@@ -301,180 +279,79 @@ private fun StatItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* PhotoCard - CLEAN VERSION: Simple image + person names
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun PhotoCard(
|
private fun PhotoCard(
|
||||||
photo: AlbumPhoto,
|
photo: AlbumPhoto,
|
||||||
|
displayMode: DisplayMode,
|
||||||
onImageClick: (String) -> Unit
|
onImageClick: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth(),
|
||||||
.fillMaxWidth()
|
|
||||||
.aspectRatio(1f)
|
|
||||||
.clickable { onImageClick(photo.image.imageUri) },
|
|
||||||
shape = RoundedCornerShape(12.dp)
|
shape = RoundedCornerShape(12.dp)
|
||||||
) {
|
) {
|
||||||
Box {
|
Column {
|
||||||
// Image
|
ImageGridItem(
|
||||||
AsyncImage(
|
image = photo.image,
|
||||||
model = photo.image.imageUri,
|
onClick = { onImageClick(photo.image.imageUri) }
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentScale = androidx.compose.ui.layout.ContentScale.Crop
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Person names overlay (if any)
|
|
||||||
if (photo.persons.isNotEmpty()) {
|
if (photo.persons.isNotEmpty()) {
|
||||||
|
when (displayMode) {
|
||||||
|
DisplayMode.SIMPLE -> {
|
||||||
Surface(
|
Surface(
|
||||||
color = MaterialTheme.colorScheme.surface.copy(alpha = 0.9f),
|
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f),
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth()
|
||||||
.align(Alignment.BottomCenter)
|
|
||||||
.fillMaxWidth()
|
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = photo.persons.take(2).joinToString(", ") { it.name },
|
text = photo.persons.take(3).joinToString(", ") { it.name },
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
modifier = Modifier.padding(8.dp),
|
modifier = Modifier.padding(8.dp),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis
|
||||||
fontWeight = FontWeight.Medium
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
DisplayMode.VERBOSE -> {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Export Dialog
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
private fun ExportDialog(
|
|
||||||
albumName: String,
|
|
||||||
photoCount: Int,
|
|
||||||
onDismiss: () -> Unit,
|
|
||||||
onExportToFolder: () -> Unit,
|
|
||||||
onExportToZip: () -> Unit,
|
|
||||||
onExportToCollage: () -> Unit
|
|
||||||
) {
|
|
||||||
AlertDialog(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
icon = { Icon(Icons.Default.FileDownload, null) },
|
|
||||||
title = { Text("Export Album") },
|
|
||||||
text = {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
"$photoCount photos from \"$albumName\"",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
|
|
||||||
// Export to Folder
|
|
||||||
ExportOption(
|
|
||||||
icon = Icons.Default.Folder,
|
|
||||||
title = "Export to Folder",
|
|
||||||
description = "Save all photos to a folder",
|
|
||||||
onClick = onExportToFolder
|
|
||||||
)
|
|
||||||
|
|
||||||
// Export to Zip
|
|
||||||
ExportOption(
|
|
||||||
icon = Icons.Default.FolderZip,
|
|
||||||
title = "Export as ZIP",
|
|
||||||
description = "Create a compressed archive",
|
|
||||||
onClick = onExportToZip
|
|
||||||
)
|
|
||||||
|
|
||||||
// Export to Collage (placeholder)
|
|
||||||
ExportOption(
|
|
||||||
icon = Icons.Default.GridView,
|
|
||||||
title = "Create Collage",
|
|
||||||
description = "Coming soon!",
|
|
||||||
onClick = onExportToCollage,
|
|
||||||
enabled = false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
confirmButton = {
|
|
||||||
TextButton(onClick = onDismiss) {
|
|
||||||
Text("Cancel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun ExportOption(
|
|
||||||
icon: androidx.compose.ui.graphics.vector.ImageVector,
|
|
||||||
title: String,
|
|
||||||
description: String,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
enabled: Boolean = true
|
|
||||||
) {
|
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier
|
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f),
|
||||||
.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
.clickable(enabled = enabled, onClick = onClick),
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
color = if (enabled) {
|
|
||||||
MaterialTheme.colorScheme.surfaceVariant
|
|
||||||
} else {
|
|
||||||
MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f)
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(8.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||||
|
) {
|
||||||
|
photo.persons.take(3).forEachIndexed { index, person ->
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.padding(16.dp),
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Surface(
|
|
||||||
shape = RoundedCornerShape(8.dp),
|
|
||||||
color = MaterialTheme.colorScheme.primary.copy(
|
|
||||||
alpha = if (enabled) 1f else 0.5f
|
|
||||||
),
|
|
||||||
modifier = Modifier.size(40.dp)
|
|
||||||
) {
|
|
||||||
Box(contentAlignment = Alignment.Center) {
|
|
||||||
Icon(
|
Icon(
|
||||||
icon,
|
Icons.Default.Face,
|
||||||
contentDescription = null,
|
null,
|
||||||
modifier = Modifier.size(24.dp),
|
Modifier.size(14.dp),
|
||||||
tint = MaterialTheme.colorScheme.onPrimary
|
MaterialTheme.colorScheme.primary
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.SemiBold,
|
|
||||||
color = if (enabled) {
|
|
||||||
MaterialTheme.colorScheme.onSurface
|
|
||||||
} else {
|
|
||||||
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
description,
|
text = person.name,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
modifier = Modifier.weight(1f),
|
||||||
alpha = if (enabled) 1f else 0.5f
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
)
|
)
|
||||||
|
if (index < photo.faceTags.size) {
|
||||||
|
val confidence = (photo.faceTags[index].confidence * 100).toInt()
|
||||||
|
Text(
|
||||||
|
text = "$confidence%",
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (enabled) {
|
}
|
||||||
Icon(
|
}
|
||||||
Icons.Default.ChevronRight,
|
}
|
||||||
contentDescription = null,
|
}
|
||||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,28 +23,57 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CLEANED ExploreScreen - No gradient header banner
|
* ExploreScreen - REDESIGNED
|
||||||
*
|
|
||||||
* Removed:
|
|
||||||
* - Gradient header box (lines 46-75) that created banner effect
|
|
||||||
* - "Explore" title (MainScreen shows it)
|
|
||||||
*
|
*
|
||||||
* Features:
|
* Features:
|
||||||
* - Rectangular album cards (compact)
|
* - Rectangular album cards (more compact)
|
||||||
* - Stories section (recent highlights)
|
* - Stories section (recent highlights)
|
||||||
* - Clickable navigation to AlbumViewScreen
|
* - Clickable navigation to AlbumViewScreen
|
||||||
* - Beautiful gradients and icons
|
* - Beautiful gradients and icons
|
||||||
* - Mobile-friendly scrolling
|
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun ExploreScreen(
|
fun ExploreScreen(
|
||||||
onAlbumClick: (albumType: String, albumId: String) -> Unit,
|
onAlbumClick: (albumType: String, albumId: String) -> Unit,
|
||||||
viewModel: ExploreViewModel = hiltViewModel(),
|
viewModel: ExploreViewModel = hiltViewModel()
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
) {
|
||||||
val uiState by viewModel.uiState.collectAsState()
|
val uiState by viewModel.uiState.collectAsState()
|
||||||
|
|
||||||
Box(modifier = modifier.fillMaxSize()) {
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
) {
|
||||||
|
// Header with gradient
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(
|
||||||
|
Brush.verticalGradient(
|
||||||
|
colors = listOf(
|
||||||
|
MaterialTheme.colorScheme.primaryContainer,
|
||||||
|
MaterialTheme.colorScheme.surface
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "Explore",
|
||||||
|
style = MaterialTheme.typography.headlineLarge,
|
||||||
|
fontWeight = FontWeight.Bold
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "Your photo collection organized",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
when (val state = uiState) {
|
when (val state = uiState) {
|
||||||
is ExploreViewModel.ExploreUiState.Loading -> {
|
is ExploreViewModel.ExploreUiState.Loading -> {
|
||||||
Box(
|
Box(
|
||||||
@@ -54,18 +83,12 @@ fun ExploreScreen(
|
|||||||
CircularProgressIndicator()
|
CircularProgressIndicator()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is ExploreViewModel.ExploreUiState.Success -> {
|
is ExploreViewModel.ExploreUiState.Success -> {
|
||||||
if (state.smartAlbums.isEmpty()) {
|
|
||||||
EmptyExploreView()
|
|
||||||
} else {
|
|
||||||
ExploreContent(
|
ExploreContent(
|
||||||
smartAlbums = state.smartAlbums,
|
smartAlbums = state.smartAlbums,
|
||||||
onAlbumClick = onAlbumClick
|
onAlbumClick = onAlbumClick
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
is ExploreViewModel.ExploreUiState.Error -> {
|
is ExploreViewModel.ExploreUiState.Error -> {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
@@ -73,25 +96,17 @@ fun ExploreScreen(
|
|||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
modifier = Modifier.padding(32.dp)
|
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Error,
|
Icons.Default.Error,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(64.dp),
|
modifier = Modifier.size(48.dp),
|
||||||
tint = MaterialTheme.colorScheme.error
|
tint = MaterialTheme.colorScheme.error
|
||||||
)
|
)
|
||||||
Text(
|
|
||||||
text = "Error Loading Albums",
|
|
||||||
style = MaterialTheme.typography.titleLarge,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
Text(
|
Text(
|
||||||
text = state.message,
|
text = state.message,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
color = MaterialTheme.colorScheme.error
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,9 +115,6 @@ fun ExploreScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Main content - scrollable album sections
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ExploreContent(
|
private fun ExploreContent(
|
||||||
smartAlbums: List<SmartAlbum>,
|
smartAlbums: List<SmartAlbum>,
|
||||||
@@ -115,14 +127,11 @@ private fun ExploreContent(
|
|||||||
) {
|
) {
|
||||||
// Stories Section (Recent Highlights)
|
// Stories Section (Recent Highlights)
|
||||||
item {
|
item {
|
||||||
val storyAlbums = smartAlbums.filter { it.imageCount > 0 }.take(10)
|
|
||||||
if (storyAlbums.isNotEmpty()) {
|
|
||||||
StoriesSection(
|
StoriesSection(
|
||||||
albums = storyAlbums,
|
albums = smartAlbums.filter { it.imageCount > 0 }.take(10),
|
||||||
onAlbumClick = onAlbumClick
|
onAlbumClick = onAlbumClick
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Time-based Albums
|
// Time-based Albums
|
||||||
val timeAlbums = smartAlbums.filterIsInstance<SmartAlbum.TimeRange>()
|
val timeAlbums = smartAlbums.filterIsInstance<SmartAlbum.TimeRange>()
|
||||||
@@ -216,7 +225,7 @@ private fun ExploreContent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stories section - circular album previews
|
* Stories section - Instagram-style circular highlights
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun StoriesSection(
|
private fun StoriesSection(
|
||||||
@@ -285,8 +294,7 @@ private fun StoryCircle(
|
|||||||
style = MaterialTheme.typography.labelSmall,
|
style = MaterialTheme.typography.labelSmall,
|
||||||
maxLines = 2,
|
maxLines = 2,
|
||||||
modifier = Modifier.width(80.dp),
|
modifier = Modifier.width(80.dp),
|
||||||
fontWeight = FontWeight.Medium,
|
fontWeight = FontWeight.Medium
|
||||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
@@ -334,7 +342,7 @@ private fun AlbumSection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rectangular album card - compact design
|
* Rectangular album card - more compact than square
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun AlbumCard(
|
private fun AlbumCard(
|
||||||
@@ -390,44 +398,6 @@ private fun AlbumCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Empty state
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
private fun EmptyExploreView() {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(32.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.PhotoAlbum,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(80.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f)
|
|
||||||
)
|
|
||||||
|
|
||||||
Text(
|
|
||||||
"No Albums Yet",
|
|
||||||
style = MaterialTheme.typography.titleLarge,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
|
|
||||||
Text(
|
|
||||||
"Add photos to your collection to see smart albums",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get navigation parameters for album
|
* Get navigation parameters for album
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,323 +1,86 @@
|
|||||||
package com.placeholder.sherpai2.ui.imagedetail
|
package com.placeholder.sherpai2.ui.imagedetail
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.lazy.items
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.*
|
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.NavController
|
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import com.placeholder.sherpai2.data.local.entity.TagEntity
|
|
||||||
import com.placeholder.sherpai2.ui.imagedetail.viewmodel.ImageDetailViewModel
|
import com.placeholder.sherpai2.ui.imagedetail.viewmodel.ImageDetailViewModel
|
||||||
import net.engawapg.lib.zoomable.rememberZoomState
|
|
||||||
import net.engawapg.lib.zoomable.zoomable
|
|
||||||
import java.net.URLEncoder
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageDetailScreen - COMPLETE with navigation and tags
|
* ImageDetailScreen
|
||||||
*
|
*
|
||||||
* Features:
|
* Purpose:
|
||||||
* - Full-screen zoomable image
|
* - Add tags
|
||||||
* - Previous/Next navigation buttons
|
* - Remove tags
|
||||||
* - Image counter (3/45)
|
* - Validate write propagation
|
||||||
* - Tags button (toggle show/hide)
|
|
||||||
* - Shows all tags on photo
|
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ImageDetailScreen(
|
fun ImageDetailScreen(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
imageUri: String,
|
imageUri: String,
|
||||||
onBack: () -> Unit,
|
onBack: () -> Unit
|
||||||
navController: NavController? = null,
|
|
||||||
allImageUris: List<String> = emptyList(), // Pass from caller
|
|
||||||
viewModel: ImageDetailViewModel = hiltViewModel() // ✅ FIXED: Use hiltViewModel
|
|
||||||
) {
|
) {
|
||||||
|
val viewModel: ImageDetailViewModel = androidx.lifecycle.viewmodel.compose.viewModel()
|
||||||
|
|
||||||
LaunchedEffect(imageUri) {
|
LaunchedEffect(imageUri) {
|
||||||
viewModel.loadImage(imageUri)
|
viewModel.loadImage(imageUri)
|
||||||
}
|
}
|
||||||
|
|
||||||
val tags by viewModel.tags.collectAsStateWithLifecycle()
|
val tags by viewModel.tags.collectAsStateWithLifecycle()
|
||||||
var showTags by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
// Navigation state
|
var newTag by remember { mutableStateOf("") }
|
||||||
val currentIndex = if (allImageUris.isNotEmpty()) allImageUris.indexOf(imageUri) else -1
|
|
||||||
val hasNavigation = allImageUris.isNotEmpty() && currentIndex >= 0
|
|
||||||
val canGoPrevious = hasNavigation && currentIndex > 0
|
|
||||||
val canGoNext = hasNavigation && currentIndex < allImageUris.size - 1
|
|
||||||
|
|
||||||
Scaffold(
|
|
||||||
topBar = {
|
|
||||||
TopAppBar(
|
|
||||||
title = {
|
|
||||||
if (hasNavigation) {
|
|
||||||
Text(
|
|
||||||
"${currentIndex + 1} / ${allImageUris.size}",
|
|
||||||
style = MaterialTheme.typography.titleMedium
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Text("Photo")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
navigationIcon = {
|
|
||||||
IconButton(onClick = onBack) {
|
|
||||||
Icon(Icons.Default.ArrowBack, "Back")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
actions = {
|
|
||||||
// Tags toggle button
|
|
||||||
IconButton(onClick = { showTags = !showTags }) {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
if (tags.isNotEmpty()) {
|
|
||||||
Badge(
|
|
||||||
containerColor = if (showTags)
|
|
||||||
MaterialTheme.colorScheme.primary
|
|
||||||
else
|
|
||||||
MaterialTheme.colorScheme.surfaceVariant
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
tags.size.toString(),
|
|
||||||
color = if (showTags)
|
|
||||||
MaterialTheme.colorScheme.onPrimary
|
|
||||||
else
|
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Icon(
|
|
||||||
if (showTags) Icons.Default.Label else Icons.Default.LocalOffer,
|
|
||||||
"Show Tags",
|
|
||||||
tint = if (showTags)
|
|
||||||
MaterialTheme.colorScheme.primary
|
|
||||||
else
|
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Previous button (only show if has navigation)
|
|
||||||
if (hasNavigation && navController != null) {
|
|
||||||
IconButton(
|
|
||||||
onClick = {
|
|
||||||
if (canGoPrevious) {
|
|
||||||
val prevUri = allImageUris[currentIndex - 1]
|
|
||||||
val encoded = URLEncoder.encode(prevUri, "UTF-8")
|
|
||||||
navController.navigate("image_detail/$encoded") {
|
|
||||||
popUpTo("image_detail/${URLEncoder.encode(imageUri, "UTF-8")}") {
|
|
||||||
inclusive = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enabled = canGoPrevious
|
|
||||||
) {
|
|
||||||
Icon(Icons.Default.KeyboardArrowLeft, "Previous")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next button (only show if has navigation)
|
|
||||||
IconButton(
|
|
||||||
onClick = {
|
|
||||||
if (canGoNext) {
|
|
||||||
val nextUri = allImageUris[currentIndex + 1]
|
|
||||||
val encoded = URLEncoder.encode(nextUri, "UTF-8")
|
|
||||||
navController.navigate("image_detail/$encoded") {
|
|
||||||
popUpTo("image_detail/${URLEncoder.encode(imageUri, "UTF-8")}") {
|
|
||||||
inclusive = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enabled = canGoNext
|
|
||||||
) {
|
|
||||||
Icon(Icons.Default.KeyboardArrowRight, "Next")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
) { paddingValues ->
|
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(paddingValues)
|
.padding(12.dp)
|
||||||
) {
|
) {
|
||||||
// Zoomable image
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.weight(1f)
|
|
||||||
.background(Color.Black)
|
|
||||||
) {
|
|
||||||
val zoomState = rememberZoomState()
|
|
||||||
|
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = imageUri,
|
model = imageUri,
|
||||||
contentDescription = "Photo",
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.zoomable(zoomState),
|
|
||||||
contentScale = ContentScale.Fit
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tags panel (slides up when enabled)
|
|
||||||
if (showTags) {
|
|
||||||
Surface(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.heightIn(max = 300.dp),
|
|
||||||
color = MaterialTheme.colorScheme.surfaceVariant,
|
|
||||||
tonalElevation = 3.dp
|
|
||||||
) {
|
|
||||||
LazyColumn(
|
|
||||||
contentPadding = PaddingValues(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
item {
|
|
||||||
Text(
|
|
||||||
"Tags (${tags.size})",
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tags.isEmpty()) {
|
|
||||||
item {
|
|
||||||
Text(
|
|
||||||
"No tags yet",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
items(tags, key = { it.tagId }) { tag ->
|
|
||||||
TagCard(
|
|
||||||
tag = tag,
|
|
||||||
onRemove = { viewModel.removeTag(tag) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun TagCard(
|
|
||||||
tag: TagEntity,
|
|
||||||
onRemove: () -> Unit
|
|
||||||
) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = when (tag.type) {
|
|
||||||
"PERSON" -> MaterialTheme.colorScheme.primaryContainer
|
|
||||||
"SYSTEM" -> MaterialTheme.colorScheme.secondaryContainer
|
|
||||||
else -> MaterialTheme.colorScheme.tertiaryContainer
|
|
||||||
}
|
|
||||||
),
|
|
||||||
shape = RoundedCornerShape(8.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(12.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
imageVector = when (tag.type) {
|
|
||||||
"PERSON" -> Icons.Default.Face
|
|
||||||
"SYSTEM" -> Icons.Default.AutoAwesome
|
|
||||||
else -> Icons.Default.Label
|
|
||||||
},
|
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(20.dp),
|
modifier = Modifier
|
||||||
tint = when (tag.type) {
|
.fillMaxWidth()
|
||||||
"PERSON" -> MaterialTheme.colorScheme.primary
|
.aspectRatio(1f)
|
||||||
"SYSTEM" -> MaterialTheme.colorScheme.secondary
|
|
||||||
else -> MaterialTheme.colorScheme.tertiary
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
Text(
|
|
||||||
text = tag.getDisplayValue(), // Uses TagEntity's built-in method
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
|
||||||
fontWeight = FontWeight.SemiBold
|
OutlinedTextField(
|
||||||
|
value = newTag,
|
||||||
|
onValueChange = { newTag = it },
|
||||||
|
label = { Text("Add tag") },
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
viewModel.addTag(newTag)
|
||||||
|
newTag = ""
|
||||||
|
},
|
||||||
|
modifier = Modifier.padding(top = 8.dp)
|
||||||
|
) {
|
||||||
|
Text("Add Tag")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
tags.forEach { tag ->
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(tag.value)
|
||||||
text = tag.type.lowercase().replaceFirstChar { it.uppercase() },
|
TextButton(onClick = { viewModel.removeTag(tag) }) {
|
||||||
style = MaterialTheme.typography.labelSmall,
|
Text("Remove")
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = "•",
|
|
||||||
style = MaterialTheme.typography.labelSmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = formatTimestamp(tag.createdAt),
|
|
||||||
style = MaterialTheme.typography.labelSmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove button (only for user-created tags)
|
|
||||||
if (tag.isUserTag()) {
|
|
||||||
IconButton(
|
|
||||||
onClick = onRemove,
|
|
||||||
colors = IconButtonDefaults.iconButtonColors(
|
|
||||||
contentColor = MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Icon(Icons.Default.Delete, "Remove tag")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Format timestamp to relative time
|
|
||||||
*/
|
|
||||||
private fun formatTimestamp(timestamp: Long): String {
|
|
||||||
val now = System.currentTimeMillis()
|
|
||||||
val diff = now - timestamp
|
|
||||||
|
|
||||||
return when {
|
|
||||||
diff < 60_000 -> "Just now"
|
|
||||||
diff < 3600_000 -> "${diff / 60_000}m ago"
|
|
||||||
diff < 86400_000 -> "${diff / 3600_000}h ago"
|
|
||||||
diff < 604800_000 -> "${diff / 86400_000}d ago"
|
|
||||||
else -> "${diff / 604800_000}w ago"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,23 +14,24 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CLEANED PersonInventoryScreen - No duplicate header
|
* PersonInventoryScreen - Manage trained face models
|
||||||
*
|
*
|
||||||
* Removed:
|
* Features:
|
||||||
* - Scaffold wrapper
|
* - List all trained persons
|
||||||
* - TopAppBar (was creating banner)
|
* - View stats
|
||||||
* - "Trained People" title (MainScreen shows it)
|
* - DELETE models
|
||||||
*
|
* - SCAN LIBRARY to find person in all photos (NEW!)
|
||||||
* FIXED to match ViewModel exactly:
|
|
||||||
* - Uses InventoryUiState.Success with persons
|
|
||||||
* - Uses stats.taggedPhotoCount (not photoCount)
|
|
||||||
* - Passes both personId AND faceModelId to methods
|
|
||||||
*/
|
*/
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun PersonInventoryScreen(
|
fun PersonInventoryScreen(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
@@ -43,171 +44,316 @@ fun PersonInventoryScreen(
|
|||||||
var personToDelete by remember { mutableStateOf<PersonInventoryViewModel.PersonWithStats?>(null) }
|
var personToDelete by remember { mutableStateOf<PersonInventoryViewModel.PersonWithStats?>(null) }
|
||||||
var personToScan by remember { mutableStateOf<PersonInventoryViewModel.PersonWithStats?>(null) }
|
var personToScan by remember { mutableStateOf<PersonInventoryViewModel.PersonWithStats?>(null) }
|
||||||
|
|
||||||
LazyColumn(
|
Scaffold(
|
||||||
modifier = modifier.fillMaxSize(),
|
topBar = {
|
||||||
contentPadding = PaddingValues(16.dp),
|
TopAppBar(
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
title = { Text("Trained People") },
|
||||||
|
colors = TopAppBarDefaults.topAppBarColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.primaryContainer
|
||||||
|
),
|
||||||
|
actions = {
|
||||||
|
IconButton(onClick = { viewModel.loadPersons() }) {
|
||||||
|
Icon(Icons.Default.Refresh, contentDescription = "Refresh")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) { paddingValues ->
|
||||||
|
Box(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(paddingValues)
|
||||||
) {
|
) {
|
||||||
when (val state = uiState) {
|
when (val state = uiState) {
|
||||||
is PersonInventoryViewModel.InventoryUiState.Loading -> {
|
is PersonInventoryViewModel.InventoryUiState.Loading -> {
|
||||||
item {
|
LoadingView()
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(32.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
CircularProgressIndicator()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is PersonInventoryViewModel.InventoryUiState.Success -> {
|
is PersonInventoryViewModel.InventoryUiState.Success -> {
|
||||||
// Summary card
|
|
||||||
item {
|
|
||||||
SummaryCard(
|
|
||||||
peopleCount = state.persons.size,
|
|
||||||
totalPhotos = state.persons.sumOf { it.stats.taggedPhotoCount }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scanning progress
|
|
||||||
val currentScanningState = scanningState
|
|
||||||
if (currentScanningState is PersonInventoryViewModel.ScanningState.Scanning) {
|
|
||||||
item {
|
|
||||||
ScanningProgressCard(currentScanningState)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Person list
|
|
||||||
if (state.persons.isEmpty()) {
|
if (state.persons.isEmpty()) {
|
||||||
item {
|
EmptyView()
|
||||||
EmptyState()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
items(state.persons) { person ->
|
PersonListView(
|
||||||
PersonCard(
|
persons = state.persons,
|
||||||
person = person,
|
onDeleteClick = { personToDelete = it },
|
||||||
onDelete = { personToDelete = person },
|
onScanClick = { personToScan = it },
|
||||||
onScan = { personToScan = person },
|
onViewPhotos = { onViewPersonPhotos(it.person.id) },
|
||||||
onViewPhotos = { onViewPersonPhotos(person.person.id) }
|
scanningState = scanningState
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
is PersonInventoryViewModel.InventoryUiState.Error -> {
|
is PersonInventoryViewModel.InventoryUiState.Error -> {
|
||||||
item {
|
ErrorView(
|
||||||
ErrorCard(message = state.message)
|
message = state.message,
|
||||||
|
onRetry = { viewModel.loadPersons() }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scanning overlay
|
||||||
|
if (scanningState is PersonInventoryViewModel.ScanningState.Scanning) {
|
||||||
|
ScanningOverlay(scanningState as PersonInventoryViewModel.ScanningState.Scanning)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete confirmation
|
// Delete confirmation dialog
|
||||||
personToDelete?.let { person ->
|
personToDelete?.let { personWithStats ->
|
||||||
DeleteDialog(
|
AlertDialog(
|
||||||
person = person,
|
onDismissRequest = { personToDelete = null },
|
||||||
onDismiss = { personToDelete = null },
|
title = { Text("Delete ${personWithStats.person.name}?") },
|
||||||
onConfirm = {
|
text = {
|
||||||
viewModel.deletePerson(person.person.id, person.stats.faceModelId)
|
Text(
|
||||||
|
"This will delete the face model and all ${personWithStats.stats.taggedPhotoCount} " +
|
||||||
|
"face tags. Your photos will NOT be deleted."
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
viewModel.deletePerson(
|
||||||
|
personWithStats.person.id,
|
||||||
|
personWithStats.stats.faceModelId
|
||||||
|
)
|
||||||
personToDelete = null
|
personToDelete = null
|
||||||
|
},
|
||||||
|
colors = ButtonDefaults.textButtonColors(
|
||||||
|
contentColor = MaterialTheme.colorScheme.error
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Text("Delete")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { personToDelete = null }) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan confirmation
|
// Scan library confirmation dialog
|
||||||
personToScan?.let { person ->
|
personToScan?.let { personWithStats ->
|
||||||
ScanDialog(
|
AlertDialog(
|
||||||
person = person,
|
onDismissRequest = { personToScan = null },
|
||||||
onDismiss = { personToScan = null },
|
icon = { Icon(Icons.Default.Search, contentDescription = null) },
|
||||||
onConfirm = {
|
title = { Text("Scan Library for ${personWithStats.person.name}?") },
|
||||||
viewModel.scanLibraryForPerson(person.person.id, person.stats.faceModelId)
|
text = {
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
|
Text(
|
||||||
|
"This will scan your entire photo library and automatically tag " +
|
||||||
|
"all photos containing ${personWithStats.person.name}."
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
"Currently tagged: ${personWithStats.stats.taggedPhotoCount} photos",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
viewModel.scanLibraryForPerson(
|
||||||
|
personWithStats.person.id,
|
||||||
|
personWithStats.stats.faceModelId
|
||||||
|
)
|
||||||
personToScan = null
|
personToScan = null
|
||||||
}
|
}
|
||||||
|
) {
|
||||||
|
Icon(Icons.Default.Search, contentDescription = null)
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
Text("Start Scan")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { personToScan = null }) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Summary card with stats
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun SummaryCard(peopleCount: Int, totalPhotos: Int) {
|
private fun LoadingView() {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
Text(
|
||||||
|
text = "Loading trained models...",
|
||||||
|
style = MaterialTheme.typography.bodyMedium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun EmptyView() {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
modifier = Modifier.padding(32.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Face,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(64.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.primary.copy(alpha = 0.5f)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "No trained people yet",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
fontWeight = FontWeight.Bold
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "Train a person using 10+ photos to start recognizing faces",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ErrorView(
|
||||||
|
message: String,
|
||||||
|
onRetry: () -> Unit
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
modifier = Modifier.padding(32.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Warning,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(64.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.error
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "Error",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
fontWeight = FontWeight.Bold
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = message,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
Button(onClick = onRetry) {
|
||||||
|
Icon(Icons.Default.Refresh, contentDescription = null)
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
Text("Retry")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun PersonListView(
|
||||||
|
persons: List<PersonInventoryViewModel.PersonWithStats>,
|
||||||
|
onDeleteClick: (PersonInventoryViewModel.PersonWithStats) -> Unit,
|
||||||
|
onScanClick: (PersonInventoryViewModel.PersonWithStats) -> Unit,
|
||||||
|
onViewPhotos: (PersonInventoryViewModel.PersonWithStats) -> Unit,
|
||||||
|
scanningState: PersonInventoryViewModel.ScanningState
|
||||||
|
) {
|
||||||
|
LazyColumn(
|
||||||
|
contentPadding = PaddingValues(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
|
) {
|
||||||
|
// Summary card
|
||||||
|
item {
|
||||||
|
SummaryCard(totalPersons = persons.size)
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Person cards
|
||||||
|
items(persons) { personWithStats ->
|
||||||
|
PersonCard(
|
||||||
|
personWithStats = personWithStats,
|
||||||
|
onDeleteClick = { onDeleteClick(personWithStats) },
|
||||||
|
onScanClick = { onScanClick(personWithStats) },
|
||||||
|
onViewPhotos = { onViewPhotos(personWithStats) },
|
||||||
|
isScanning = scanningState is PersonInventoryViewModel.ScanningState.Scanning &&
|
||||||
|
scanningState.personId == personWithStats.person.id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SummaryCard(totalPersons: Int) {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
colors = CardDefaults.cardColors(
|
colors = CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f)
|
containerColor = MaterialTheme.colorScheme.primaryContainer
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly
|
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
) {
|
verticalAlignment = Alignment.CenterVertically
|
||||||
StatItem(
|
|
||||||
icon = Icons.Default.People,
|
|
||||||
value = peopleCount.toString(),
|
|
||||||
label = "People"
|
|
||||||
)
|
|
||||||
VerticalDivider(
|
|
||||||
modifier = Modifier.height(56.dp),
|
|
||||||
color = MaterialTheme.colorScheme.outline.copy(alpha = 0.3f)
|
|
||||||
)
|
|
||||||
StatItem(
|
|
||||||
icon = Icons.Default.PhotoLibrary,
|
|
||||||
value = totalPhotos.toString(),
|
|
||||||
label = "Tagged"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun StatItem(icon: androidx.compose.ui.graphics.vector.ImageVector, value: String, label: String) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
icon,
|
Icons.Default.Face,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(28.dp),
|
modifier = Modifier.size(48.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
|
Column {
|
||||||
Text(
|
Text(
|
||||||
value,
|
text = "$totalPersons trained ${if (totalPersons == 1) "person" else "people"}",
|
||||||
style = MaterialTheme.typography.headlineMedium,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
label,
|
text = "Face recognition models ready",
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Person card with stats and actions
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun PersonCard(
|
private fun PersonCard(
|
||||||
person: PersonInventoryViewModel.PersonWithStats,
|
personWithStats: PersonInventoryViewModel.PersonWithStats,
|
||||||
onDelete: () -> Unit,
|
onDeleteClick: () -> Unit,
|
||||||
onScan: () -> Unit,
|
onScanClick: () -> Unit,
|
||||||
onViewPhotos: () -> Unit
|
onViewPhotos: () -> Unit,
|
||||||
|
isScanning: Boolean
|
||||||
) {
|
) {
|
||||||
|
val stats = personWithStats.stats
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(16.dp),
|
modifier = Modifier
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp)
|
||||||
) {
|
) {
|
||||||
// Header row
|
// Header: Name and actions
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
@@ -217,39 +363,38 @@ private fun PersonCard(
|
|||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
// Avatar
|
Box(
|
||||||
Surface(
|
modifier = Modifier
|
||||||
modifier = Modifier.size(48.dp),
|
.size(48.dp)
|
||||||
shape = CircleShape,
|
.clip(CircleShape)
|
||||||
color = MaterialTheme.colorScheme.primaryContainer
|
.background(MaterialTheme.colorScheme.primary),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Box(contentAlignment = Alignment.Center) {
|
Text(
|
||||||
Icon(
|
text = personWithStats.person.name.take(1).uppercase(),
|
||||||
Icons.Default.Person,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
contentDescription = null,
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier.size(24.dp),
|
color = MaterialTheme.colorScheme.onPrimary
|
||||||
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Name and stats
|
|
||||||
Column {
|
Column {
|
||||||
Text(
|
Text(
|
||||||
text = person.person.name,
|
text = personWithStats.person.name,
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "${person.stats.taggedPhotoCount} photos • ${person.stats.trainingImageCount} trained",
|
text = "ID: ${personWithStats.person.id.take(8)}",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete button
|
IconButton(onClick = onDeleteClick) {
|
||||||
IconButton(onClick = onDelete) {
|
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Delete,
|
Icons.Default.Delete,
|
||||||
contentDescription = "Delete",
|
contentDescription = "Delete",
|
||||||
@@ -258,251 +403,212 @@ private fun PersonCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action buttons
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
// Stats grid
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
horizontalArrangement = Arrangement.SpaceEvenly
|
||||||
) {
|
) {
|
||||||
OutlinedButton(
|
StatItem(
|
||||||
onClick = onScan,
|
icon = Icons.Default.PhotoCamera,
|
||||||
modifier = Modifier.weight(1f)
|
label = "Training",
|
||||||
) {
|
value = "${stats.trainingImageCount}"
|
||||||
Icon(
|
)
|
||||||
Icons.Default.Search,
|
StatItem(
|
||||||
contentDescription = null,
|
icon = Icons.Default.AccountBox,
|
||||||
modifier = Modifier.size(18.dp)
|
label = "Tagged",
|
||||||
|
value = "${stats.taggedPhotoCount}"
|
||||||
|
)
|
||||||
|
StatItem(
|
||||||
|
icon = Icons.Default.CheckCircle,
|
||||||
|
label = "Confidence",
|
||||||
|
value = "${(stats.averageConfidence * 100).toInt()}%",
|
||||||
|
valueColor = if (stats.averageConfidence >= 0.8f) {
|
||||||
|
MaterialTheme.colorScheme.primary
|
||||||
|
} else if (stats.averageConfidence >= 0.6f) {
|
||||||
|
MaterialTheme.colorScheme.tertiary
|
||||||
|
} else {
|
||||||
|
MaterialTheme.colorScheme.error
|
||||||
|
}
|
||||||
)
|
)
|
||||||
Spacer(Modifier.width(4.dp))
|
|
||||||
Text("Scan")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
onClick = onViewPhotos,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.PhotoLibrary,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(18.dp)
|
|
||||||
)
|
|
||||||
Spacer(Modifier.width(4.dp))
|
|
||||||
Text("View")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Last detected
|
||||||
* Scanning progress card
|
stats.lastDetectedAt?.let { timestamp ->
|
||||||
*/
|
Surface(
|
||||||
@Composable
|
|
||||||
private fun ScanningProgressCard(scanningState: PersonInventoryViewModel.ScanningState.Scanning) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
colors = CardDefaults.cardColors(
|
color = MaterialTheme.colorScheme.surfaceVariant,
|
||||||
containerColor = MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.5f)
|
shape = RoundedCornerShape(8.dp)
|
||||||
)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.padding(12.dp),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Text(
|
Icon(
|
||||||
"Scanning for ${scanningState.personName}",
|
Icons.Default.DateRange,
|
||||||
style = MaterialTheme.typography.titleMedium,
|
contentDescription = null,
|
||||||
fontWeight = FontWeight.Bold
|
modifier = Modifier.size(16.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"${scanningState.progress}/${scanningState.total}",
|
text = "Last detected: ${formatDate(timestamp)}",
|
||||||
style = MaterialTheme.typography.bodySmall
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
LinearProgressIndicator(
|
|
||||||
progress = {
|
|
||||||
if (scanningState.total > 0) {
|
|
||||||
scanningState.progress.toFloat() / scanningState.total.toFloat()
|
|
||||||
} else {
|
|
||||||
0f
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
)
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
"Matches found: ${scanningState.facesFound}",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"Faces: ${scanningState.facesDetected}",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
|
// Action buttons row
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
// Scan Library button (PRIMARY ACTION)
|
||||||
|
Button(
|
||||||
|
onClick = onScanClick,
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
enabled = !isScanning,
|
||||||
|
colors = ButtonDefaults.buttonColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
if (isScanning) {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(16.dp),
|
||||||
|
color = MaterialTheme.colorScheme.onPrimary,
|
||||||
|
strokeWidth = 2.dp
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Search,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(18.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
Text(if (isScanning) "Scanning..." else "Scan Library")
|
||||||
|
}
|
||||||
|
|
||||||
|
// View photos button
|
||||||
|
if (stats.taggedPhotoCount > 0) {
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = onViewPhotos,
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Photo,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(18.dp)
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
Text("View (${stats.taggedPhotoCount})")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun StatItem(
|
||||||
|
icon: ImageVector,
|
||||||
|
label: String,
|
||||||
|
value: String,
|
||||||
|
valueColor: Color = MaterialTheme.colorScheme.primary
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(24.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = value,
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = valueColor
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = label,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty state
|
* Scanning overlay showing progress
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun EmptyState() {
|
private fun ScanningOverlay(state: PersonInventoryViewModel.ScanningState.Scanning) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxSize()
|
||||||
.padding(vertical = 48.dp),
|
.background(MaterialTheme.colorScheme.surface.copy(alpha = 0.95f)),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(0.85f)
|
||||||
|
.padding(24.dp),
|
||||||
|
elevation = CardDefaults.cardElevation(defaultElevation = 8.dp)
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
|
modifier = Modifier.padding(24.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.PersonOff,
|
Icons.Default.Search,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(64.dp),
|
modifier = Modifier.size(48.dp),
|
||||||
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f)
|
tint = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
"No People Trained",
|
text = "Scanning Library",
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
"Train face recognition to find people in your photos",
|
text = "Finding ${state.personName} in your photos...",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center
|
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
LinearProgressIndicator(
|
||||||
* Error card
|
progress = { state.progress / state.total.toFloat() },
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
private fun ErrorCard(message: String) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.errorContainer
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.padding(16.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Error,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.error
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
message,
|
text = "${state.progress} / ${state.total} photos scanned",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodySmall
|
||||||
color = MaterialTheme.colorScheme.onErrorContainer
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "${state.facesFound} faces detected",
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
color = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private fun formatDate(timestamp: Long): String {
|
||||||
* Delete confirmation dialog
|
val formatter = SimpleDateFormat("MMM d, yyyy h:mm a", Locale.getDefault())
|
||||||
*/
|
return formatter.format(Date(timestamp))
|
||||||
@Composable
|
|
||||||
private fun DeleteDialog(
|
|
||||||
person: PersonInventoryViewModel.PersonWithStats,
|
|
||||||
onDismiss: () -> Unit,
|
|
||||||
onConfirm: () -> Unit
|
|
||||||
) {
|
|
||||||
AlertDialog(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
icon = {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Warning,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
},
|
|
||||||
title = { Text("Delete ${person.person.name}?") },
|
|
||||||
text = {
|
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
||||||
Text("This will permanently delete:")
|
|
||||||
Text("• Face recognition model", style = MaterialTheme.typography.bodyMedium)
|
|
||||||
Text("• ${person.stats.taggedPhotoCount} tagged photos will be untagged", style = MaterialTheme.typography.bodyMedium)
|
|
||||||
Text(
|
|
||||||
"This action cannot be undone.",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
confirmButton = {
|
|
||||||
Button(
|
|
||||||
onClick = onConfirm,
|
|
||||||
colors = ButtonDefaults.buttonColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Text("Delete")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dismissButton = {
|
|
||||||
TextButton(onClick = onDismiss) {
|
|
||||||
Text("Cancel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scan confirmation dialog
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
private fun ScanDialog(
|
|
||||||
person: PersonInventoryViewModel.PersonWithStats,
|
|
||||||
onDismiss: () -> Unit,
|
|
||||||
onConfirm: () -> Unit
|
|
||||||
) {
|
|
||||||
AlertDialog(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
icon = { Icon(Icons.Default.Search, contentDescription = null) },
|
|
||||||
title = { Text("Scan for ${person.person.name}?") },
|
|
||||||
text = {
|
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
||||||
Text("This will:")
|
|
||||||
Text("• Scan all photos in your library", style = MaterialTheme.typography.bodyMedium)
|
|
||||||
Text("• Detect and tag ${person.person.name}'s face", style = MaterialTheme.typography.bodyMedium)
|
|
||||||
Text("• May take several minutes", style = MaterialTheme.typography.bodyMedium)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
confirmButton = {
|
|
||||||
Button(onClick = onConfirm) {
|
|
||||||
Icon(Icons.Default.Search, contentDescription = null, modifier = Modifier.size(18.dp))
|
|
||||||
Spacer(Modifier.width(8.dp))
|
|
||||||
Text("Start Scan")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dismissButton = {
|
|
||||||
TextButton(onClick = onDismiss) {
|
|
||||||
Text("Cancel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ sealed class AppDestinations(
|
|||||||
description = "Browse smart albums"
|
description = "Browse smart albums"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImageDetail is not in draw er (internal navigation only)
|
// ImageDetail is not in drawer (internal navigation only)
|
||||||
|
|
||||||
// ==================
|
// ==================
|
||||||
// FACE RECOGNITION
|
// FACE RECOGNITION
|
||||||
@@ -49,22 +49,22 @@ sealed class AppDestinations(
|
|||||||
data object Inventory : AppDestinations(
|
data object Inventory : AppDestinations(
|
||||||
route = AppRoutes.INVENTORY,
|
route = AppRoutes.INVENTORY,
|
||||||
icon = Icons.Default.Face,
|
icon = Icons.Default.Face,
|
||||||
label = "People Models",
|
label = "People",
|
||||||
description = "Existing Face Detection Models"
|
description = "Trained face models"
|
||||||
)
|
)
|
||||||
|
|
||||||
data object Train : AppDestinations(
|
data object Train : AppDestinations(
|
||||||
route = AppRoutes.TRAIN,
|
route = AppRoutes.TRAIN,
|
||||||
icon = Icons.Default.ModelTraining,
|
icon = Icons.Default.ModelTraining,
|
||||||
label = "Create Model",
|
label = "Train",
|
||||||
description = "Create a new Person Model"
|
description = "Train new person"
|
||||||
)
|
)
|
||||||
|
|
||||||
data object Models : AppDestinations(
|
data object Models : AppDestinations(
|
||||||
route = AppRoutes.MODELS,
|
route = AppRoutes.MODELS,
|
||||||
icon = Icons.Default.SmartToy,
|
icon = Icons.Default.SmartToy,
|
||||||
label = "Generative",
|
label = "Models",
|
||||||
description = "AI Creation"
|
description = "AI model management"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ==================
|
// ==================
|
||||||
@@ -78,8 +78,8 @@ sealed class AppDestinations(
|
|||||||
description = "Manage photo tags"
|
description = "Manage photo tags"
|
||||||
)
|
)
|
||||||
|
|
||||||
data object UTILITIES : AppDestinations(
|
data object Upload : AppDestinations(
|
||||||
route = AppRoutes.UTILITIES,
|
route = AppRoutes.UPLOAD,
|
||||||
icon = Icons.Default.UploadFile,
|
icon = Icons.Default.UploadFile,
|
||||||
label = "Upload",
|
label = "Upload",
|
||||||
description = "Add new photos"
|
description = "Add new photos"
|
||||||
@@ -117,7 +117,7 @@ val faceRecognitionDestinations = listOf(
|
|||||||
// Organization section
|
// Organization section
|
||||||
val organizationDestinations = listOf(
|
val organizationDestinations = listOf(
|
||||||
AppDestinations.Tags,
|
AppDestinations.Tags,
|
||||||
AppDestinations.UTILITIES
|
AppDestinations.Upload
|
||||||
)
|
)
|
||||||
|
|
||||||
// Settings (separate, pinned to bottom)
|
// Settings (separate, pinned to bottom)
|
||||||
@@ -140,7 +140,7 @@ fun getDestinationByRoute(route: String?): AppDestinations? {
|
|||||||
AppRoutes.TRAIN -> AppDestinations.Train
|
AppRoutes.TRAIN -> AppDestinations.Train
|
||||||
AppRoutes.MODELS -> AppDestinations.Models
|
AppRoutes.MODELS -> AppDestinations.Models
|
||||||
AppRoutes.TAGS -> AppDestinations.Tags
|
AppRoutes.TAGS -> AppDestinations.Tags
|
||||||
AppRoutes.UTILITIES -> AppDestinations.UTILITIES
|
AppRoutes.UPLOAD -> AppDestinations.Upload
|
||||||
AppRoutes.SETTINGS -> AppDestinations.Settings
|
AppRoutes.SETTINGS -> AppDestinations.Settings
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,12 @@ import androidx.compose.runtime.collectAsState
|
|||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.NavType
|
import androidx.navigation.NavType
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.navArgument
|
import androidx.navigation.navArgument
|
||||||
import com.placeholder.sherpai2.ui.devscreens.DummyScreen
|
import com.placeholder.sherpai2.ui.devscreens.DummyScreen
|
||||||
import com.placeholder.sherpai2.ui.album.AlbumViewScreen
|
|
||||||
import com.placeholder.sherpai2.ui.album.AlbumViewModel
|
|
||||||
import com.placeholder.sherpai2.ui.explore.ExploreScreen
|
import com.placeholder.sherpai2.ui.explore.ExploreScreen
|
||||||
import com.placeholder.sherpai2.ui.imagedetail.ImageDetailScreen
|
import com.placeholder.sherpai2.ui.imagedetail.ImageDetailScreen
|
||||||
import com.placeholder.sherpai2.ui.modelinventory.PersonInventoryScreen
|
import com.placeholder.sherpai2.ui.modelinventory.PersonInventoryScreen
|
||||||
@@ -27,17 +24,24 @@ import com.placeholder.sherpai2.ui.trainingprep.ScanResultsScreen
|
|||||||
import com.placeholder.sherpai2.ui.trainingprep.ScanningState
|
import com.placeholder.sherpai2.ui.trainingprep.ScanningState
|
||||||
import com.placeholder.sherpai2.ui.trainingprep.TrainViewModel
|
import com.placeholder.sherpai2.ui.trainingprep.TrainViewModel
|
||||||
import com.placeholder.sherpai2.ui.trainingprep.TrainingScreen
|
import com.placeholder.sherpai2.ui.trainingprep.TrainingScreen
|
||||||
import com.placeholder.sherpai2.ui.utilities.PhotoUtilitiesScreen
|
|
||||||
import java.net.URLDecoder
|
import java.net.URLDecoder
|
||||||
import java.net.URLEncoder
|
import java.net.URLEncoder
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AppNavHost - UPDATED with image list navigation
|
* AppNavHost - Main navigation graph
|
||||||
|
* UPDATED: Added Explore and Tags screens
|
||||||
*
|
*
|
||||||
* Changes:
|
* Complete flow:
|
||||||
* - Search/Album screens pass full image list to detail screen
|
* - Photo browsing (Search, Explore, Detail)
|
||||||
* - Detail screen can navigate prev/next
|
* - Face recognition (Inventory, Train)
|
||||||
* - Image URIs stored in SavedStateHandle for navigation
|
* - Organization (Tags, Upload)
|
||||||
|
* - Settings
|
||||||
|
*
|
||||||
|
* Features:
|
||||||
|
* - URL encoding for safe navigation
|
||||||
|
* - Proper back stack management
|
||||||
|
* - State preservation
|
||||||
|
* - Beautiful placeholders
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun AppNavHost(
|
fun AppNavHost(
|
||||||
@@ -55,39 +59,38 @@ fun AppNavHost(
|
|||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SEARCH SCREEN - UPDATED: Stores image list for navigation
|
* SEARCH SCREEN
|
||||||
|
* Main photo browser with face tag search
|
||||||
*/
|
*/
|
||||||
composable(AppRoutes.SEARCH) {
|
composable(AppRoutes.SEARCH) {
|
||||||
val searchViewModel: SearchViewModel = hiltViewModel()
|
val searchViewModel: SearchViewModel = hiltViewModel()
|
||||||
|
|
||||||
SearchScreen(
|
SearchScreen(
|
||||||
searchViewModel = searchViewModel,
|
searchViewModel = searchViewModel,
|
||||||
onImageClick = { imageUri ->
|
onImageClick = { imageUri ->
|
||||||
// Single image view - no prev/next navigation
|
|
||||||
ImageListHolder.clear() // Clear any previous list
|
|
||||||
|
|
||||||
val encodedUri = URLEncoder.encode(imageUri, "UTF-8")
|
val encodedUri = URLEncoder.encode(imageUri, "UTF-8")
|
||||||
navController.navigate("${AppRoutes.IMAGE_DETAIL}/$encodedUri")
|
navController.navigate("${AppRoutes.IMAGE_DETAIL}/$encodedUri")
|
||||||
},
|
|
||||||
onAlbumClick = { tagValue ->
|
|
||||||
navController.navigate("album/tag/$tagValue")
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EXPLORE SCREEN
|
* EXPLORE SCREEN
|
||||||
|
* Browse smart albums (auto-generated from tags)
|
||||||
*/
|
*/
|
||||||
composable(AppRoutes.EXPLORE) {
|
composable(AppRoutes.EXPLORE) {
|
||||||
ExploreScreen(
|
ExploreScreen(
|
||||||
onAlbumClick = { albumType, albumId ->
|
onAlbumClick = { albumType, albumId ->
|
||||||
navController.navigate("album/$albumType/$albumId")
|
println("Album clicked: type=$albumType id=$albumId")
|
||||||
|
|
||||||
|
// Example future navigation
|
||||||
|
// navController.navigate("${AppRoutes.ALBUM}/$albumType/$albumId")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IMAGE DETAIL SCREEN - UPDATED: Receives image list for navigation
|
* IMAGE DETAIL SCREEN
|
||||||
|
* Single photo view with metadata
|
||||||
*/
|
*/
|
||||||
composable(
|
composable(
|
||||||
route = "${AppRoutes.IMAGE_DETAIL}/{imageUri}",
|
route = "${AppRoutes.IMAGE_DETAIL}/{imageUri}",
|
||||||
@@ -101,56 +104,9 @@ fun AppNavHost(
|
|||||||
?.let { URLDecoder.decode(it, "UTF-8") }
|
?.let { URLDecoder.decode(it, "UTF-8") }
|
||||||
?: error("imageUri missing from navigation")
|
?: error("imageUri missing from navigation")
|
||||||
|
|
||||||
// Get image list from holder
|
|
||||||
val allImageUris = ImageListHolder.getImageList()
|
|
||||||
|
|
||||||
ImageDetailScreen(
|
ImageDetailScreen(
|
||||||
imageUri = imageUri,
|
imageUri = imageUri,
|
||||||
onBack = {
|
onBack = { navController.popBackStack() }
|
||||||
ImageListHolder.clear() // Clean up when leaving
|
|
||||||
navController.popBackStack()
|
|
||||||
},
|
|
||||||
navController = navController,
|
|
||||||
allImageUris = allImageUris
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ALBUM VIEW SCREEN - UPDATED: Stores image list for navigation
|
|
||||||
*/
|
|
||||||
composable(
|
|
||||||
route = "album/{albumType}/{albumId}",
|
|
||||||
arguments = listOf(
|
|
||||||
navArgument("albumType") {
|
|
||||||
type = NavType.StringType
|
|
||||||
},
|
|
||||||
navArgument("albumId") {
|
|
||||||
type = NavType.StringType
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
val albumViewModel: AlbumViewModel = hiltViewModel()
|
|
||||||
val uiState by albumViewModel.uiState.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
AlbumViewScreen(
|
|
||||||
onBack = {
|
|
||||||
navController.popBackStack()
|
|
||||||
},
|
|
||||||
onImageClick = { imageUri ->
|
|
||||||
// Store full album image list
|
|
||||||
val allImageUris = if (uiState is com.placeholder.sherpai2.ui.album.AlbumUiState.Success) {
|
|
||||||
(uiState as com.placeholder.sherpai2.ui.album.AlbumUiState.Success)
|
|
||||||
.photos
|
|
||||||
.map { it.image.imageUri }
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageListHolder.setImageList(allImageUris)
|
|
||||||
|
|
||||||
val encodedUri = URLEncoder.encode(imageUri, "UTF-8")
|
|
||||||
navController.navigate("${AppRoutes.IMAGE_DETAIL}/$encodedUri")
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,10 +116,19 @@ fun AppNavHost(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* PERSON INVENTORY SCREEN
|
* PERSON INVENTORY SCREEN
|
||||||
|
* View all trained face models
|
||||||
|
*
|
||||||
|
* Features:
|
||||||
|
* - List all trained people
|
||||||
|
* - Show stats (training count, tagged photos, confidence)
|
||||||
|
* - Delete models
|
||||||
|
* - View photos containing each person
|
||||||
*/
|
*/
|
||||||
composable(AppRoutes.INVENTORY) {
|
composable(AppRoutes.INVENTORY) {
|
||||||
PersonInventoryScreen(
|
PersonInventoryScreen(
|
||||||
onViewPersonPhotos = { personId ->
|
onViewPersonPhotos = { personId ->
|
||||||
|
// Navigate back to search
|
||||||
|
// TODO: In future, add person filter to search screen
|
||||||
navController.navigate(AppRoutes.SEARCH)
|
navController.navigate(AppRoutes.SEARCH)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -171,13 +136,22 @@ fun AppNavHost(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TRAINING FLOW
|
* TRAINING FLOW
|
||||||
|
* Train new face recognition model
|
||||||
|
*
|
||||||
|
* Flow:
|
||||||
|
* 1. TrainingScreen (select images button)
|
||||||
|
* 2. ImageSelectorScreen (pick 15-50 photos)
|
||||||
|
* 3. ScanResultsScreen (validation + name input)
|
||||||
|
* 4. Training completes → navigate to Inventory
|
||||||
*/
|
*/
|
||||||
composable(AppRoutes.TRAIN) { entry ->
|
composable(AppRoutes.TRAIN) { entry ->
|
||||||
val trainViewModel: TrainViewModel = hiltViewModel()
|
val trainViewModel: TrainViewModel = hiltViewModel()
|
||||||
val uiState by trainViewModel.uiState.collectAsState()
|
val uiState by trainViewModel.uiState.collectAsState()
|
||||||
|
|
||||||
|
// Get images selected from ImageSelector
|
||||||
val selectedUris = entry.savedStateHandle.get<List<Uri>>("selected_image_uris")
|
val selectedUris = entry.savedStateHandle.get<List<Uri>>("selected_image_uris")
|
||||||
|
|
||||||
|
// Start scanning when new images are selected
|
||||||
LaunchedEffect(selectedUris) {
|
LaunchedEffect(selectedUris) {
|
||||||
if (selectedUris != null && uiState is ScanningState.Idle) {
|
if (selectedUris != null && uiState is ScanningState.Idle) {
|
||||||
trainViewModel.scanAndTagFaces(selectedUris)
|
trainViewModel.scanAndTagFaces(selectedUris)
|
||||||
@@ -187,6 +161,7 @@ fun AppNavHost(
|
|||||||
|
|
||||||
when (uiState) {
|
when (uiState) {
|
||||||
is ScanningState.Idle -> {
|
is ScanningState.Idle -> {
|
||||||
|
// Show start screen with "Select Images" button
|
||||||
TrainingScreen(
|
TrainingScreen(
|
||||||
onSelectImages = {
|
onSelectImages = {
|
||||||
navController.navigate(AppRoutes.IMAGE_SELECTOR)
|
navController.navigate(AppRoutes.IMAGE_SELECTOR)
|
||||||
@@ -194,9 +169,11 @@ fun AppNavHost(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
// Show validation results and training UI
|
||||||
ScanResultsScreen(
|
ScanResultsScreen(
|
||||||
state = uiState,
|
state = uiState,
|
||||||
onFinish = {
|
onFinish = {
|
||||||
|
// After training, go to inventory to see new person
|
||||||
navController.navigate(AppRoutes.INVENTORY) {
|
navController.navigate(AppRoutes.INVENTORY) {
|
||||||
popUpTo(AppRoutes.TRAIN) { inclusive = true }
|
popUpTo(AppRoutes.TRAIN) { inclusive = true }
|
||||||
}
|
}
|
||||||
@@ -208,10 +185,12 @@ fun AppNavHost(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* IMAGE SELECTOR SCREEN
|
* IMAGE SELECTOR SCREEN
|
||||||
|
* Pick images for training (internal screen)
|
||||||
*/
|
*/
|
||||||
composable(AppRoutes.IMAGE_SELECTOR) {
|
composable(AppRoutes.IMAGE_SELECTOR) {
|
||||||
ImageSelectorScreen(
|
ImageSelectorScreen(
|
||||||
onImagesSelected = { uris ->
|
onImagesSelected = { uris ->
|
||||||
|
// Pass selected URIs back to Train screen
|
||||||
navController.previousBackStackEntry
|
navController.previousBackStackEntry
|
||||||
?.savedStateHandle
|
?.savedStateHandle
|
||||||
?.set("selected_image_uris", uris)
|
?.set("selected_image_uris", uris)
|
||||||
@@ -222,6 +201,7 @@ fun AppNavHost(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* MODELS SCREEN
|
* MODELS SCREEN
|
||||||
|
* AI model management (placeholder)
|
||||||
*/
|
*/
|
||||||
composable(AppRoutes.MODELS) {
|
composable(AppRoutes.MODELS) {
|
||||||
DummyScreen(
|
DummyScreen(
|
||||||
@@ -236,16 +216,21 @@ fun AppNavHost(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TAGS SCREEN
|
* TAGS SCREEN
|
||||||
|
* Manage photo tags with auto-tagging features
|
||||||
*/
|
*/
|
||||||
composable(AppRoutes.TAGS) {
|
composable(AppRoutes.TAGS) {
|
||||||
TagManagementScreen()
|
TagManagementScreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UTILITIES SCREEN
|
* UPLOAD SCREEN
|
||||||
|
* Import new photos (placeholder)
|
||||||
*/
|
*/
|
||||||
composable(AppRoutes.UTILITIES) {
|
composable(AppRoutes.UPLOAD) {
|
||||||
PhotoUtilitiesScreen()
|
DummyScreen(
|
||||||
|
title = "Upload",
|
||||||
|
subtitle = "Add photos to your library"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
@@ -254,6 +239,7 @@ fun AppNavHost(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* SETTINGS SCREEN
|
* SETTINGS SCREEN
|
||||||
|
* App preferences (placeholder)
|
||||||
*/
|
*/
|
||||||
composable(AppRoutes.SETTINGS) {
|
composable(AppRoutes.SETTINGS) {
|
||||||
DummyScreen(
|
DummyScreen(
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ package com.placeholder.sherpai2.ui.navigation
|
|||||||
object AppRoutes {
|
object AppRoutes {
|
||||||
// Photo browsing
|
// Photo browsing
|
||||||
const val SEARCH = "search"
|
const val SEARCH = "search"
|
||||||
const val EXPLORE = "explore"
|
const val EXPLORE = "explore" // UPDATED: Changed from TOUR
|
||||||
const val IMAGE_DETAIL = "IMAGE_DETAIL"
|
const val IMAGE_DETAIL = "IMAGE_DETAIL"
|
||||||
|
|
||||||
// Face recognition
|
// Face recognition
|
||||||
@@ -23,7 +23,7 @@ object AppRoutes {
|
|||||||
|
|
||||||
// Organization
|
// Organization
|
||||||
const val TAGS = "tags"
|
const val TAGS = "tags"
|
||||||
const val UTILITIES = "utilities" // CHANGED from UPLOAD
|
const val UPLOAD = "upload"
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
const val SETTINGS = "settings"
|
const val SETTINGS = "settings"
|
||||||
@@ -33,8 +33,4 @@ object AppRoutes {
|
|||||||
const val CROP_SCREEN = "CROP_SCREEN"
|
const val CROP_SCREEN = "CROP_SCREEN"
|
||||||
const val TRAINING_SCREEN = "TRAINING_SCREEN"
|
const val TRAINING_SCREEN = "TRAINING_SCREEN"
|
||||||
const val ScanResultsScreen = "First Scan Results"
|
const val ScanResultsScreen = "First Scan Results"
|
||||||
|
|
||||||
// Album view
|
|
||||||
const val ALBUM_VIEW = "album/{albumType}/{albumId}"
|
|
||||||
fun albumRoute(albumType: String, albumId: String) = "album/$albumType/$albumId"
|
|
||||||
}
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.placeholder.sherpai2.ui.navigation
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple holder for passing image lists between screens
|
|
||||||
* Used for prev/next navigation in ImageDetailScreen
|
|
||||||
*/
|
|
||||||
object ImageListHolder {
|
|
||||||
private var imageUris: List<String> = emptyList()
|
|
||||||
|
|
||||||
fun setImageList(uris: List<String>) {
|
|
||||||
imageUris = uris
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getImageList(): List<String> {
|
|
||||||
return imageUris
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clear() {
|
|
||||||
imageUris = emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,8 @@ import androidx.compose.material.icons.filled.*
|
|||||||
import com.placeholder.sherpai2.ui.navigation.AppRoutes
|
import com.placeholder.sherpai2.ui.navigation.AppRoutes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SLIMMED DOWN AppDrawer - 280dp width, inline logo, cleaner sections
|
* Beautiful app drawer with sections, gradient header, and polish
|
||||||
|
* UPDATED: Tour → Explore
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -27,12 +28,12 @@ fun AppDrawerContent(
|
|||||||
onDestinationClicked: (String) -> Unit
|
onDestinationClicked: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
ModalDrawerSheet(
|
ModalDrawerSheet(
|
||||||
modifier = Modifier.width(280.dp), // SLIMMER (was 300dp)
|
modifier = Modifier.width(300.dp),
|
||||||
drawerContainerColor = MaterialTheme.colorScheme.surface
|
drawerContainerColor = MaterialTheme.colorScheme.surface
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.fillMaxSize()) {
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
|
|
||||||
// ===== COMPACT HEADER - Icon + Text Inline =====
|
// ===== BEAUTIFUL GRADIENT HEADER =====
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@@ -44,16 +45,15 @@ fun AppDrawerContent(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.padding(20.dp) // Reduced padding
|
.padding(24.dp)
|
||||||
) {
|
) {
|
||||||
Row(
|
Column(
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
) {
|
||||||
// App icon - smaller
|
// App icon/logo area
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.size(48.dp), // Smaller (was 56dp)
|
modifier = Modifier.size(56.dp),
|
||||||
shape = RoundedCornerShape(14.dp),
|
shape = RoundedCornerShape(16.dp),
|
||||||
color = MaterialTheme.colorScheme.primary,
|
color = MaterialTheme.colorScheme.primary,
|
||||||
shadowElevation = 4.dp
|
shadowElevation = 4.dp
|
||||||
) {
|
) {
|
||||||
@@ -61,47 +61,44 @@ fun AppDrawerContent(
|
|||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Face,
|
Icons.Default.Face,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(28.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.onPrimary
|
tint = MaterialTheme.colorScheme.onPrimary
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Text next to icon
|
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
|
||||||
Text(
|
Text(
|
||||||
"SherpAI",
|
"SherpAI",
|
||||||
style = MaterialTheme.typography.titleLarge, // Smaller (was headlineMedium)
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
"Face Recognition System",
|
"Face Recognition System",
|
||||||
style = MaterialTheme.typography.bodySmall, // Smaller
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(4.dp)) // Reduced spacing
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
// ===== NAVIGATION SECTIONS =====
|
// ===== NAVIGATION SECTIONS =====
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(horizontal = 8.dp), // Reduced padding
|
.padding(horizontal = 12.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(2.dp) // Tighter spacing
|
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// Photos Section
|
// Photos Section
|
||||||
DrawerSection(title = "Photos")
|
DrawerSection(title = "Photos")
|
||||||
|
|
||||||
val photoItems = listOf(
|
val photoItems = listOf(
|
||||||
DrawerItem(AppRoutes.SEARCH, "Search", Icons.Default.Search),
|
DrawerItem(AppRoutes.SEARCH, "Search", Icons.Default.Search, "Find photos by tag or person"),
|
||||||
DrawerItem(AppRoutes.EXPLORE, "Explore", Icons.Default.Explore)
|
DrawerItem(AppRoutes.EXPLORE, "Explore", Icons.Default.Explore, "Browse smart albums")
|
||||||
)
|
)
|
||||||
|
|
||||||
photoItems.forEach { item ->
|
photoItems.forEach { item ->
|
||||||
@@ -112,15 +109,15 @@ fun AppDrawerContent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
// Face Recognition Section
|
// Face Recognition Section
|
||||||
DrawerSection(title = "Face Recognition")
|
DrawerSection(title = "Face Recognition")
|
||||||
|
|
||||||
val faceItems = listOf(
|
val faceItems = listOf(
|
||||||
DrawerItem(AppRoutes.INVENTORY, "People", Icons.Default.Face),
|
DrawerItem(AppRoutes.INVENTORY, "People", Icons.Default.Face, "Trained face models"),
|
||||||
DrawerItem(AppRoutes.TRAIN, "Train New", Icons.Default.ModelTraining),
|
DrawerItem(AppRoutes.TRAIN, "Train", Icons.Default.ModelTraining, "Train new person"),
|
||||||
DrawerItem(AppRoutes.MODELS, "Models", Icons.Default.SmartToy)
|
DrawerItem(AppRoutes.MODELS, "Models", Icons.Default.SmartToy, "AI model management")
|
||||||
)
|
)
|
||||||
|
|
||||||
faceItems.forEach { item ->
|
faceItems.forEach { item ->
|
||||||
@@ -131,14 +128,14 @@ fun AppDrawerContent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
// Organization Section
|
// Organization Section
|
||||||
DrawerSection(title = "Organization")
|
DrawerSection(title = "Organization")
|
||||||
|
|
||||||
val orgItems = listOf(
|
val orgItems = listOf(
|
||||||
DrawerItem(AppRoutes.TAGS, "Tags", Icons.AutoMirrored.Filled.Label),
|
DrawerItem(AppRoutes.TAGS, "Tags", Icons.AutoMirrored.Filled.Label, "Manage photo tags"),
|
||||||
DrawerItem(AppRoutes.UTILITIES, "Utilities", Icons.Default.Build)
|
DrawerItem(AppRoutes.UPLOAD, "Upload", Icons.Default.UploadFile, "Add new photos")
|
||||||
)
|
)
|
||||||
|
|
||||||
orgItems.forEach { item ->
|
orgItems.forEach { item ->
|
||||||
@@ -153,7 +150,7 @@ fun AppDrawerContent(
|
|||||||
|
|
||||||
// Settings at bottom
|
// Settings at bottom
|
||||||
HorizontalDivider(
|
HorizontalDivider(
|
||||||
modifier = Modifier.padding(vertical = 6.dp),
|
modifier = Modifier.padding(vertical = 8.dp),
|
||||||
color = MaterialTheme.colorScheme.outlineVariant
|
color = MaterialTheme.colorScheme.outlineVariant
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -161,34 +158,35 @@ fun AppDrawerContent(
|
|||||||
item = DrawerItem(
|
item = DrawerItem(
|
||||||
AppRoutes.SETTINGS,
|
AppRoutes.SETTINGS,
|
||||||
"Settings",
|
"Settings",
|
||||||
Icons.Default.Settings
|
Icons.Default.Settings,
|
||||||
|
"App preferences"
|
||||||
),
|
),
|
||||||
selected = AppRoutes.SETTINGS == currentRoute,
|
selected = AppRoutes.SETTINGS == currentRoute,
|
||||||
onClick = { onDestinationClicked(AppRoutes.SETTINGS) }
|
onClick = { onDestinationClicked(AppRoutes.SETTINGS) }
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Section header - more compact
|
* Section header in drawer
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun DrawerSection(title: String) {
|
private fun DrawerSection(title: String) {
|
||||||
Text(
|
Text(
|
||||||
text = title,
|
text = title,
|
||||||
style = MaterialTheme.typography.labelSmall, // Smaller
|
style = MaterialTheme.typography.labelMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = MaterialTheme.colorScheme.primary,
|
color = MaterialTheme.colorScheme.primary,
|
||||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 6.dp) // Reduced padding
|
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigation item - cleaner, no subtitle
|
* Individual navigation item with icon, label, and subtitle
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun DrawerNavigationItem(
|
private fun DrawerNavigationItem(
|
||||||
@@ -198,24 +196,33 @@ private fun DrawerNavigationItem(
|
|||||||
) {
|
) {
|
||||||
NavigationDrawerItem(
|
NavigationDrawerItem(
|
||||||
label = {
|
label = {
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = item.label,
|
text = item.label,
|
||||||
style = MaterialTheme.typography.bodyMedium, // Slightly smaller
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
fontWeight = if (selected) FontWeight.SemiBold else FontWeight.Normal
|
fontWeight = if (selected) FontWeight.SemiBold else FontWeight.Normal
|
||||||
)
|
)
|
||||||
|
item.subtitle?.let {
|
||||||
|
Text(
|
||||||
|
text = it,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
icon = {
|
icon = {
|
||||||
Icon(
|
Icon(
|
||||||
item.icon,
|
item.icon,
|
||||||
contentDescription = item.label,
|
contentDescription = item.label,
|
||||||
modifier = Modifier.size(22.dp) // Slightly smaller
|
modifier = Modifier.size(24.dp)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
selected = selected,
|
selected = selected,
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(NavigationDrawerItemDefaults.ItemPadding)
|
.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||||
.clip(RoundedCornerShape(10.dp)), // Slightly smaller radius
|
.clip(RoundedCornerShape(12.dp)),
|
||||||
colors = NavigationDrawerItemDefaults.colors(
|
colors = NavigationDrawerItemDefaults.colors(
|
||||||
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
|
selectedContainerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||||
selectedIconColor = MaterialTheme.colorScheme.primary,
|
selectedIconColor = MaterialTheme.colorScheme.primary,
|
||||||
@@ -226,10 +233,11 @@ private fun DrawerNavigationItem(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simplified drawer item (no subtitle)
|
* Data class for drawer items
|
||||||
*/
|
*/
|
||||||
private data class DrawerItem(
|
private data class DrawerItem(
|
||||||
val route: String,
|
val route: String,
|
||||||
val label: String,
|
val label: String,
|
||||||
val icon: androidx.compose.ui.graphics.vector.ImageVector
|
val icon: androidx.compose.ui.graphics.vector.ImageVector,
|
||||||
|
val subtitle: String? = null
|
||||||
)
|
)
|
||||||
@@ -150,7 +150,7 @@ fun MainScreen() {
|
|||||||
Icon(Icons.Default.Add, "Add Tag")
|
Icon(Icons.Default.Add, "Add Tag")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AppRoutes.UTILITIES -> {
|
AppRoutes.UPLOAD -> {
|
||||||
ExtendedFloatingActionButton(
|
ExtendedFloatingActionButton(
|
||||||
onClick = { /* TODO: Select photos */ },
|
onClick = { /* TODO: Select photos */ },
|
||||||
icon = { Icon(Icons.Default.CloudUpload, "Upload") },
|
icon = { Icon(Icons.Default.CloudUpload, "Upload") },
|
||||||
@@ -185,7 +185,7 @@ private fun getScreenTitle(route: String): String {
|
|||||||
AppRoutes.TRAIN -> "Train New Person"
|
AppRoutes.TRAIN -> "Train New Person"
|
||||||
AppRoutes.MODELS -> "AI Models"
|
AppRoutes.MODELS -> "AI Models"
|
||||||
AppRoutes.TAGS -> "Tag Management"
|
AppRoutes.TAGS -> "Tag Management"
|
||||||
AppRoutes.UTILITIES -> "Photo Util."
|
AppRoutes.UPLOAD -> "Upload Photos"
|
||||||
AppRoutes.SETTINGS -> "Settings"
|
AppRoutes.SETTINGS -> "Settings"
|
||||||
else -> "SherpAI"
|
else -> "SherpAI"
|
||||||
}
|
}
|
||||||
@@ -201,7 +201,7 @@ private fun getScreenSubtitle(route: String): String? {
|
|||||||
AppRoutes.INVENTORY -> "Trained face models"
|
AppRoutes.INVENTORY -> "Trained face models"
|
||||||
AppRoutes.TRAIN -> "Add a new person to recognize"
|
AppRoutes.TRAIN -> "Add a new person to recognize"
|
||||||
AppRoutes.TAGS -> "Organize your photo collection"
|
AppRoutes.TAGS -> "Organize your photo collection"
|
||||||
AppRoutes.UTILITIES -> "Tools for managing collection"
|
AppRoutes.UPLOAD -> "Add photos to your library"
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ private fun shouldShowFab(route: String): Boolean {
|
|||||||
return when (route) {
|
return when (route) {
|
||||||
AppRoutes.SEARCH,
|
AppRoutes.SEARCH,
|
||||||
AppRoutes.TAGS,
|
AppRoutes.TAGS,
|
||||||
AppRoutes.UTILITIES -> true
|
AppRoutes.UPLOAD -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,35 @@
|
|||||||
package com.placeholder.sherpai2.ui.search
|
package com.placeholder.sherpai2.ui.search
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyRow
|
import androidx.compose.foundation.lazy.LazyRow
|
||||||
import androidx.compose.foundation.lazy.grid.*
|
import androidx.compose.foundation.lazy.grid.*
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.rememberScrollState
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.verticalScroll
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.*
|
import androidx.compose.material.icons.filled.*
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import coil.compose.AsyncImage
|
import com.placeholder.sherpai2.ui.search.components.ImageGridItem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADVANCED SearchScreen with Boolean Logic
|
* SearchScreen - COMPLETE REDESIGN
|
||||||
*
|
*
|
||||||
* Features:
|
* Features:
|
||||||
* - Include/Exclude people (visual chips)
|
* - Near-match search ("low" → "low_res")
|
||||||
* - Include/Exclude tags (visual chips)
|
* - Quick tag filter chips
|
||||||
* - Clear visual distinction (green = include, red = exclude)
|
* - Date range filtering
|
||||||
* - Real-time filtering
|
* - Clean person-only display
|
||||||
* - OpenSearch-style query building
|
* - Simple/Verbose toggle
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -36,85 +37,107 @@ fun SearchScreen(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
searchViewModel: SearchViewModel,
|
searchViewModel: SearchViewModel,
|
||||||
onImageClick: (String) -> Unit,
|
onImageClick: (String) -> Unit,
|
||||||
onAlbumClick: ((String) -> Unit)? = null
|
onAlbumClick: (String) -> Unit = {} // For opening album view
|
||||||
) {
|
) {
|
||||||
val searchQuery by searchViewModel.searchQuery.collectAsStateWithLifecycle()
|
|
||||||
val includedPeople by searchViewModel.includedPeople.collectAsStateWithLifecycle()
|
|
||||||
val excludedPeople by searchViewModel.excludedPeople.collectAsStateWithLifecycle()
|
|
||||||
val includedTags by searchViewModel.includedTags.collectAsStateWithLifecycle()
|
|
||||||
val excludedTags by searchViewModel.excludedTags.collectAsStateWithLifecycle()
|
|
||||||
val dateRange by searchViewModel.dateRange.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
val availablePeople by searchViewModel.availablePeople.collectAsStateWithLifecycle()
|
val searchQuery by searchViewModel.searchQuery.collectAsStateWithLifecycle()
|
||||||
val availableTags by searchViewModel.availableTags.collectAsStateWithLifecycle()
|
val activeTagFilters by searchViewModel.activeTagFilters.collectAsStateWithLifecycle()
|
||||||
|
val dateRange by searchViewModel.dateRange.collectAsStateWithLifecycle()
|
||||||
|
val displayMode by searchViewModel.displayMode.collectAsStateWithLifecycle()
|
||||||
|
val systemTags by searchViewModel.systemTags.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
val images by searchViewModel
|
val images by searchViewModel
|
||||||
.searchImages()
|
.searchImages()
|
||||||
.collectAsStateWithLifecycle(initialValue = emptyList())
|
.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||||
|
|
||||||
var showPeoplePicker by remember { mutableStateOf(false) }
|
Scaffold { paddingValues ->
|
||||||
var showTagPicker by remember { mutableStateOf(false) }
|
Column(
|
||||||
|
modifier = modifier
|
||||||
Column(modifier = modifier.fillMaxSize()) {
|
.fillMaxSize()
|
||||||
// Search bar + quick add buttons
|
.padding(paddingValues)
|
||||||
Row(
|
) {
|
||||||
|
// Header with gradient
|
||||||
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
.background(
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
Brush.verticalGradient(
|
||||||
verticalAlignment = Alignment.CenterVertically
|
colors = listOf(
|
||||||
) {
|
MaterialTheme.colorScheme.primaryContainer,
|
||||||
OutlinedTextField(
|
MaterialTheme.colorScheme.surface
|
||||||
value = searchQuery,
|
|
||||||
onValueChange = { searchViewModel.setSearchQuery(it) },
|
|
||||||
placeholder = { Text("Search tags...") },
|
|
||||||
leadingIcon = { Icon(Icons.Default.Search, null) },
|
|
||||||
trailingIcon = {
|
|
||||||
if (searchQuery.isNotEmpty()) {
|
|
||||||
IconButton(onClick = { searchViewModel.setSearchQuery("") }) {
|
|
||||||
Icon(Icons.Default.Close, "Clear")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
singleLine = true,
|
|
||||||
shape = RoundedCornerShape(12.dp)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add person button
|
|
||||||
IconButton(
|
|
||||||
onClick = { showPeoplePicker = true },
|
|
||||||
colors = IconButtonDefaults.iconButtonColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer
|
|
||||||
)
|
)
|
||||||
) {
|
|
||||||
Icon(Icons.Default.PersonAdd, "Add person filter")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add tag button
|
|
||||||
IconButton(
|
|
||||||
onClick = { showTagPicker = true },
|
|
||||||
colors = IconButtonDefaults.iconButtonColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.secondaryContainer
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Icon(Icons.Default.LabelImportant, "Add tag filter")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Active filters display (chips)
|
|
||||||
if (searchViewModel.hasActiveFilters()) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 16.dp, vertical = 4.dp),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f)
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(12.dp),
|
modifier = Modifier
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
|
) {
|
||||||
|
// Title
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
Text(
|
||||||
|
text = "Search Photos",
|
||||||
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
|
fontWeight = FontWeight.Bold
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "Near-match • Filters • Smart tags",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple/Verbose toggle
|
||||||
|
IconButton(
|
||||||
|
onClick = { searchViewModel.toggleDisplayMode() }
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = if (displayMode == DisplayMode.SIMPLE) {
|
||||||
|
Icons.Default.ViewList
|
||||||
|
} else {
|
||||||
|
Icons.Default.ViewModule
|
||||||
|
},
|
||||||
|
contentDescription = "Toggle view mode",
|
||||||
|
tint = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search bar
|
||||||
|
OutlinedTextField(
|
||||||
|
value = searchQuery,
|
||||||
|
onValueChange = { searchViewModel.setSearchQuery(it) },
|
||||||
|
placeholder = { Text("Search... (e.g., 'low', 'gro', 'nig')") },
|
||||||
|
leadingIcon = {
|
||||||
|
Icon(Icons.Default.Search, contentDescription = null)
|
||||||
|
},
|
||||||
|
trailingIcon = {
|
||||||
|
if (searchQuery.isNotEmpty()) {
|
||||||
|
IconButton(onClick = { searchViewModel.setSearchQuery("") }) {
|
||||||
|
Icon(Icons.Default.Clear, contentDescription = "Clear")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
singleLine = true,
|
||||||
|
shape = RoundedCornerShape(16.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quick Tag Filters
|
||||||
|
if (systemTags.isNotEmpty()) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
@@ -122,421 +145,265 @@ fun SearchScreen(
|
|||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
"Active Filters",
|
text = "Quick Filters",
|
||||||
style = MaterialTheme.typography.labelLarge,
|
style = MaterialTheme.typography.labelLarge,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
TextButton(
|
if (activeTagFilters.isNotEmpty()) {
|
||||||
onClick = { searchViewModel.clearAllFilters() },
|
TextButton(onClick = { searchViewModel.clearTagFilters() }) {
|
||||||
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp)
|
Text("Clear all")
|
||||||
) {
|
}
|
||||||
Text("Clear All", style = MaterialTheme.typography.labelMedium)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Included People (GREEN)
|
|
||||||
if (includedPeople.isNotEmpty()) {
|
|
||||||
LazyRow(
|
LazyRow(
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
contentPadding = PaddingValues(vertical = 4.dp)
|
|
||||||
) {
|
) {
|
||||||
items(includedPeople.toList()) { personId ->
|
items(systemTags) { tag ->
|
||||||
val person = availablePeople.find { it.id == personId }
|
val isActive = tag.value in activeTagFilters
|
||||||
if (person != null) {
|
|
||||||
FilterChip(
|
FilterChip(
|
||||||
selected = true,
|
selected = isActive,
|
||||||
onClick = { searchViewModel.excludePerson(personId) },
|
onClick = { searchViewModel.toggleTagFilter(tag.value) },
|
||||||
onLongClick = { searchViewModel.removePersonFilter(personId) },
|
label = {
|
||||||
label = { Text(person.name) },
|
Row(
|
||||||
leadingIcon = {
|
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
Icon(Icons.Default.Person, null, Modifier.size(16.dp))
|
verticalAlignment = Alignment.CenterVertically
|
||||||
},
|
) {
|
||||||
trailingIcon = {
|
Text(
|
||||||
Icon(Icons.Default.Check, null, Modifier.size(16.dp))
|
text = getTagEmoji(tag.value),
|
||||||
},
|
style = MaterialTheme.typography.bodyMedium
|
||||||
colors = FilterChipDefaults.filterChipColors(
|
|
||||||
selectedContainerColor = Color(0xFF4CAF50), // Green
|
|
||||||
selectedLabelColor = Color.White
|
|
||||||
)
|
)
|
||||||
|
Text(
|
||||||
|
text = tag.value.replace("_", " "),
|
||||||
|
style = MaterialTheme.typography.bodySmall
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
leadingIcon = if (isActive) {
|
||||||
|
{ Icon(Icons.Default.Check, null, Modifier.size(16.dp)) }
|
||||||
|
} else null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Excluded People (RED)
|
// Date Range Filters
|
||||||
if (excludedPeople.isNotEmpty()) {
|
|
||||||
LazyRow(
|
LazyRow(
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
modifier = Modifier
|
||||||
contentPadding = PaddingValues(vertical = 4.dp)
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
) {
|
) {
|
||||||
items(excludedPeople.toList()) { personId ->
|
items(DateRange.entries) { range ->
|
||||||
val person = availablePeople.find { it.id == personId }
|
val isActive = dateRange == range
|
||||||
if (person != null) {
|
|
||||||
FilterChip(
|
FilterChip(
|
||||||
selected = true,
|
selected = isActive,
|
||||||
onClick = { searchViewModel.includePerson(personId) },
|
onClick = { searchViewModel.setDateRange(range) },
|
||||||
onLongClick = { searchViewModel.removePersonFilter(personId) },
|
label = { Text(range.displayName) },
|
||||||
label = { Text(person.name) },
|
leadingIcon = if (isActive) {
|
||||||
leadingIcon = {
|
{ Icon(Icons.Default.DateRange, null, Modifier.size(16.dp)) }
|
||||||
Icon(Icons.Default.Person, null, Modifier.size(16.dp))
|
} else null
|
||||||
},
|
|
||||||
trailingIcon = {
|
|
||||||
Icon(Icons.Default.Close, null, Modifier.size(16.dp))
|
|
||||||
},
|
|
||||||
colors = FilterChipDefaults.filterChipColors(
|
|
||||||
selectedContainerColor = Color(0xFFF44336), // Red
|
|
||||||
selectedLabelColor = Color.White
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Included Tags (GREEN)
|
HorizontalDivider(
|
||||||
if (includedTags.isNotEmpty()) {
|
modifier = Modifier.padding(horizontal = 16.dp),
|
||||||
LazyRow(
|
color = MaterialTheme.colorScheme.outlineVariant
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
|
||||||
contentPadding = PaddingValues(vertical = 4.dp)
|
|
||||||
) {
|
|
||||||
items(includedTags.toList()) { tagValue ->
|
|
||||||
FilterChip(
|
|
||||||
selected = true,
|
|
||||||
onClick = { searchViewModel.excludeTag(tagValue) },
|
|
||||||
onLongClick = { searchViewModel.removeTagFilter(tagValue) },
|
|
||||||
label = { Text(tagValue) },
|
|
||||||
leadingIcon = {
|
|
||||||
Icon(Icons.Default.Label, null, Modifier.size(16.dp))
|
|
||||||
},
|
|
||||||
trailingIcon = {
|
|
||||||
Icon(Icons.Default.Check, null, Modifier.size(16.dp))
|
|
||||||
},
|
|
||||||
colors = FilterChipDefaults.filterChipColors(
|
|
||||||
selectedContainerColor = Color(0xFF4CAF50),
|
|
||||||
selectedLabelColor = Color.White
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Excluded Tags (RED)
|
|
||||||
if (excludedTags.isNotEmpty()) {
|
|
||||||
LazyRow(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
|
||||||
contentPadding = PaddingValues(vertical = 4.dp)
|
|
||||||
) {
|
|
||||||
items(excludedTags.toList()) { tagValue ->
|
|
||||||
FilterChip(
|
|
||||||
selected = true,
|
|
||||||
onClick = { searchViewModel.includeTag(tagValue) },
|
|
||||||
onLongClick = { searchViewModel.removeTagFilter(tagValue) },
|
|
||||||
label = { Text(tagValue) },
|
|
||||||
leadingIcon = {
|
|
||||||
Icon(Icons.Default.Label, null, Modifier.size(16.dp))
|
|
||||||
},
|
|
||||||
trailingIcon = {
|
|
||||||
Icon(Icons.Default.Close, null, Modifier.size(16.dp))
|
|
||||||
},
|
|
||||||
colors = FilterChipDefaults.filterChipColors(
|
|
||||||
selectedContainerColor = Color(0xFFF44336),
|
|
||||||
selectedLabelColor = Color.White
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Date range
|
|
||||||
if (dateRange != DateRange.ALL_TIME) {
|
|
||||||
FilterChip(
|
|
||||||
selected = true,
|
|
||||||
onClick = { searchViewModel.setDateRange(DateRange.ALL_TIME) },
|
|
||||||
label = { Text(dateRange.displayName) },
|
|
||||||
leadingIcon = {
|
|
||||||
Icon(Icons.Default.DateRange, null, Modifier.size(16.dp))
|
|
||||||
},
|
|
||||||
colors = FilterChipDefaults.filterChipColors(
|
|
||||||
selectedContainerColor = MaterialTheme.colorScheme.tertiaryContainer
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Results
|
// Results
|
||||||
if (images.isEmpty() && !searchViewModel.hasActiveFilters()) {
|
if (images.isEmpty() && searchQuery.isBlank() && activeTagFilters.isEmpty()) {
|
||||||
EmptyState()
|
EmptySearchState()
|
||||||
} else if (images.isEmpty()) {
|
} else if (images.isEmpty()) {
|
||||||
NoResultsState()
|
NoResultsState(
|
||||||
|
query = searchQuery,
|
||||||
|
hasFilters = activeTagFilters.isNotEmpty() || dateRange != DateRange.ALL_TIME
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
// Results count
|
Column {
|
||||||
|
// Results header
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "${images.size} photos • ${searchViewModel.getSearchSummary()}",
|
text = "${images.size} ${if (images.size == 1) "photo" else "photos"}",
|
||||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
style = MaterialTheme.typography.titleMedium,
|
||||||
style = MaterialTheme.typography.titleSmall,
|
fontWeight = FontWeight.Bold
|
||||||
fontWeight = FontWeight.SemiBold
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Image grid
|
// View Album button (if search results can be grouped)
|
||||||
|
if (activeTagFilters.size == 1 || searchQuery.isNotBlank()) {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
val albumTag = activeTagFilters.firstOrNull() ?: searchQuery
|
||||||
|
onAlbumClick(albumTag)
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Collections,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(16.dp)
|
||||||
|
)
|
||||||
|
Spacer(Modifier.width(4.dp))
|
||||||
|
Text("View Album")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Photo grid
|
||||||
LazyVerticalGrid(
|
LazyVerticalGrid(
|
||||||
columns = GridCells.Adaptive(minSize = 120.dp),
|
columns = GridCells.Adaptive(120.dp),
|
||||||
modifier = Modifier.fillMaxSize(),
|
contentPadding = PaddingValues(12.dp),
|
||||||
contentPadding = PaddingValues(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 16.dp),
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
modifier = Modifier.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
items(
|
items(
|
||||||
items = images,
|
items = images,
|
||||||
key = { it.image.imageUri }
|
key = { it.image.imageId }
|
||||||
) { imageWithTags ->
|
) { imageWithFaceTags ->
|
||||||
|
PhotoCard(
|
||||||
|
imageWithFaceTags = imageWithFaceTags,
|
||||||
|
displayMode = displayMode,
|
||||||
|
onImageClick = onImageClick
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Photo card with clean person display
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun PhotoCard(
|
||||||
|
imageWithFaceTags: ImageWithFaceTags,
|
||||||
|
displayMode: DisplayMode,
|
||||||
|
onImageClick: (String) -> Unit
|
||||||
|
) {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth(),
|
||||||
.aspectRatio(1f)
|
shape = RoundedCornerShape(12.dp),
|
||||||
.clickable { onImageClick(imageWithTags.image.imageUri) }
|
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
||||||
) {
|
) {
|
||||||
AsyncImage(
|
Column {
|
||||||
model = imageWithTags.image.imageUri,
|
// Image
|
||||||
|
ImageGridItem(
|
||||||
|
image = imageWithFaceTags.image,
|
||||||
|
onClick = { onImageClick(imageWithFaceTags.image.imageUri) }
|
||||||
|
)
|
||||||
|
|
||||||
|
// Person tags
|
||||||
|
if (imageWithFaceTags.persons.isNotEmpty()) {
|
||||||
|
when (displayMode) {
|
||||||
|
DisplayMode.SIMPLE -> {
|
||||||
|
// SIMPLE: Just names, no icons, no percentages
|
||||||
|
Surface(
|
||||||
|
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = imageWithFaceTags.persons
|
||||||
|
.take(3)
|
||||||
|
.joinToString(", ") { it.name },
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
modifier = Modifier.padding(8.dp),
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DisplayMode.VERBOSE -> {
|
||||||
|
// VERBOSE: Icons + names + confidence
|
||||||
|
Surface(
|
||||||
|
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(8.dp),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||||
|
) {
|
||||||
|
imageWithFaceTags.persons
|
||||||
|
.take(3)
|
||||||
|
.forEachIndexed { index, person ->
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Face,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.size(14.dp),
|
||||||
contentScale = androidx.compose.ui.layout.ContentScale.Crop
|
tint = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// People picker dialog
|
|
||||||
if (showPeoplePicker) {
|
|
||||||
PeoplePickerDialog(
|
|
||||||
people = availablePeople,
|
|
||||||
includedPeople = includedPeople,
|
|
||||||
excludedPeople = excludedPeople,
|
|
||||||
onInclude = { searchViewModel.includePerson(it) },
|
|
||||||
onExclude = { searchViewModel.excludePerson(it) },
|
|
||||||
onDismiss = { showPeoplePicker = false }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tag picker dialog
|
|
||||||
if (showTagPicker) {
|
|
||||||
TagPickerDialog(
|
|
||||||
tags = availableTags,
|
|
||||||
includedTags = includedTags,
|
|
||||||
excludedTags = excludedTags,
|
|
||||||
onInclude = { searchViewModel.includeTag(it) },
|
|
||||||
onExclude = { searchViewModel.excludeTag(it) },
|
|
||||||
onDismiss = { showTagPicker = false }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun FilterChip(
|
|
||||||
selected: Boolean,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
onLongClick: (() -> Unit)? = null,
|
|
||||||
label: @Composable () -> Unit,
|
|
||||||
leadingIcon: @Composable (() -> Unit)? = null,
|
|
||||||
trailingIcon: @Composable (() -> Unit)? = null,
|
|
||||||
colors: androidx.compose.material3.SelectableChipColors = FilterChipDefaults.filterChipColors()
|
|
||||||
) {
|
|
||||||
androidx.compose.material3.FilterChip(
|
|
||||||
selected = selected,
|
|
||||||
onClick = onClick,
|
|
||||||
label = label,
|
|
||||||
leadingIcon = leadingIcon,
|
|
||||||
trailingIcon = trailingIcon,
|
|
||||||
colors = colors
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun PeoplePickerDialog(
|
|
||||||
people: List<com.placeholder.sherpai2.data.local.entity.PersonEntity>,
|
|
||||||
includedPeople: Set<String>,
|
|
||||||
excludedPeople: Set<String>,
|
|
||||||
onInclude: (String) -> Unit,
|
|
||||||
onExclude: (String) -> Unit,
|
|
||||||
onDismiss: () -> Unit
|
|
||||||
) {
|
|
||||||
AlertDialog(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
title = { Text("Add People Filter") },
|
|
||||||
text = {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(400.dp)
|
|
||||||
.verticalScroll(rememberScrollState()),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
"Tap to INCLUDE (green) • Long press to EXCLUDE (red)",
|
text = person.name,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
modifier = Modifier.weight(1f),
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
)
|
)
|
||||||
|
if (index < imageWithFaceTags.faceTags.size) {
|
||||||
people.forEach { person ->
|
val confidence = (imageWithFaceTags.faceTags[index].confidence * 100).toInt()
|
||||||
val isIncluded = person.id in includedPeople
|
|
||||||
val isExcluded = person.id in excludedPeople
|
|
||||||
|
|
||||||
Card(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable { onInclude(person.id) },
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = when {
|
|
||||||
isIncluded -> Color(0xFF4CAF50).copy(alpha = 0.3f)
|
|
||||||
isExcluded -> Color(0xFFF44336).copy(alpha = 0.3f)
|
|
||||||
else -> MaterialTheme.colorScheme.surfaceVariant
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.padding(12.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(person.name, fontWeight = FontWeight.Medium)
|
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
|
||||||
IconButton(
|
|
||||||
onClick = { onInclude(person.id) },
|
|
||||||
colors = IconButtonDefaults.iconButtonColors(
|
|
||||||
containerColor = if (isIncluded) Color(0xFF4CAF50) else Color.Transparent
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Icon(Icons.Default.Check, "Include", tint = if (isIncluded) Color.White else MaterialTheme.colorScheme.onSurface)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
onClick = { onExclude(person.id) },
|
|
||||||
colors = IconButtonDefaults.iconButtonColors(
|
|
||||||
containerColor = if (isExcluded) Color(0xFFF44336) else Color.Transparent
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Icon(Icons.Default.Close, "Exclude", tint = if (isExcluded) Color.White else MaterialTheme.colorScheme.onSurface)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
confirmButton = {
|
|
||||||
TextButton(onClick = onDismiss) {
|
|
||||||
Text("Done")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun TagPickerDialog(
|
|
||||||
tags: List<String>,
|
|
||||||
includedTags: Set<String>,
|
|
||||||
excludedTags: Set<String>,
|
|
||||||
onInclude: (String) -> Unit,
|
|
||||||
onExclude: (String) -> Unit,
|
|
||||||
onDismiss: () -> Unit
|
|
||||||
) {
|
|
||||||
AlertDialog(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
title = { Text("Add Tag Filter") },
|
|
||||||
text = {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(400.dp)
|
|
||||||
.verticalScroll(rememberScrollState()),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
"Tap to INCLUDE (green) • Long press to EXCLUDE (red)",
|
text = "$confidence%",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.labelSmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tags.forEach { tagValue ->
|
if (imageWithFaceTags.persons.size > 3) {
|
||||||
val isIncluded = tagValue in includedTags
|
Text(
|
||||||
val isExcluded = tagValue in excludedTags
|
text = "+${imageWithFaceTags.persons.size - 3} more",
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
Card(
|
color = MaterialTheme.colorScheme.primary
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable { onInclude(tagValue) },
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = when {
|
|
||||||
isIncluded -> Color(0xFF4CAF50).copy(alpha = 0.3f)
|
|
||||||
isExcluded -> Color(0xFFF44336).copy(alpha = 0.3f)
|
|
||||||
else -> MaterialTheme.colorScheme.surfaceVariant
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.padding(12.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(tagValue, fontWeight = FontWeight.Medium)
|
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
|
||||||
IconButton(
|
|
||||||
onClick = { onInclude(tagValue) },
|
|
||||||
colors = IconButtonDefaults.iconButtonColors(
|
|
||||||
containerColor = if (isIncluded) Color(0xFF4CAF50) else Color.Transparent
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Icon(Icons.Default.Check, "Include", tint = if (isIncluded) Color.White else MaterialTheme.colorScheme.onSurface)
|
|
||||||
}
|
|
||||||
IconButton(
|
|
||||||
onClick = { onExclude(tagValue) },
|
|
||||||
colors = IconButtonDefaults.iconButtonColors(
|
|
||||||
containerColor = if (isExcluded) Color(0xFFF44336) else Color.Transparent
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Icon(Icons.Default.Close, "Exclude", tint = if (isExcluded) Color.White else MaterialTheme.colorScheme.onSurface)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
confirmButton = {
|
|
||||||
TextButton(onClick = onDismiss) {
|
|
||||||
Text("Done")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun EmptyState() {
|
private fun EmptySearchState() {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxSize(),
|
||||||
.fillMaxSize()
|
|
||||||
.padding(32.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
modifier = Modifier.padding(32.dp)
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Search,
|
Icons.Default.Search,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(64.dp),
|
modifier = Modifier.size(80.dp),
|
||||||
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f)
|
tint = MaterialTheme.colorScheme.primary.copy(alpha = 0.3f)
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"Advanced Search",
|
text = "Search or filter photos",
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"Add people and tags to build your search",
|
text = "Try searching or tapping quick filters",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
@@ -545,33 +412,67 @@ private fun EmptyState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun NoResultsState() {
|
private fun NoResultsState(query: String, hasFilters: Boolean) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxSize(),
|
||||||
.fillMaxSize()
|
|
||||||
.padding(32.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
|
modifier = Modifier.padding(32.dp)
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.SearchOff,
|
Icons.Default.SearchOff,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(64.dp),
|
modifier = Modifier.size(80.dp),
|
||||||
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f)
|
tint = MaterialTheme.colorScheme.error.copy(alpha = 0.5f)
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"No photos found",
|
text = "No results found",
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
|
if (query.isNotBlank()) {
|
||||||
Text(
|
Text(
|
||||||
"Try different filters",
|
text = "No matches for \"$query\"",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (hasFilters) {
|
||||||
|
Text(
|
||||||
|
text = "Try removing some filters",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get emoji for tag type
|
||||||
|
*/
|
||||||
|
private fun getTagEmoji(tagValue: String): String {
|
||||||
|
return when (tagValue) {
|
||||||
|
"night" -> "🌙"
|
||||||
|
"morning" -> "🌅"
|
||||||
|
"afternoon" -> "☀️"
|
||||||
|
"evening" -> "🌇"
|
||||||
|
"indoor" -> "🏠"
|
||||||
|
"outdoor" -> "🌲"
|
||||||
|
"group_photo" -> "👥"
|
||||||
|
"selfie" -> "🤳"
|
||||||
|
"couple" -> "💑"
|
||||||
|
"family" -> "👨👩👧"
|
||||||
|
"friend" -> "🤝"
|
||||||
|
"birthday" -> "🎂"
|
||||||
|
"high_res" -> "⭐"
|
||||||
|
"low_res" -> "📦"
|
||||||
|
"landscape" -> "🖼️"
|
||||||
|
"portrait" -> "📱"
|
||||||
|
"square" -> "⬜"
|
||||||
|
else -> "🏷️"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,13 +2,13 @@ package com.placeholder.sherpai2.ui.search
|
|||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.placeholder.sherpai2.data.local.dao.ImageAggregateDao
|
|
||||||
import com.placeholder.sherpai2.data.local.dao.PersonDao
|
|
||||||
import com.placeholder.sherpai2.data.local.dao.TagDao
|
import com.placeholder.sherpai2.data.local.dao.TagDao
|
||||||
import com.placeholder.sherpai2.data.local.entity.ImageEntity
|
import com.placeholder.sherpai2.data.local.entity.ImageEntity
|
||||||
import com.placeholder.sherpai2.data.local.entity.PersonEntity
|
import com.placeholder.sherpai2.data.local.entity.PersonEntity
|
||||||
import com.placeholder.sherpai2.data.local.entity.PhotoFaceTagEntity
|
import com.placeholder.sherpai2.data.local.entity.PhotoFaceTagEntity
|
||||||
|
import com.placeholder.sherpai2.data.local.entity.TagEntity
|
||||||
import com.placeholder.sherpai2.data.repository.FaceRecognitionRepository
|
import com.placeholder.sherpai2.data.repository.FaceRecognitionRepository
|
||||||
|
import com.placeholder.sherpai2.domain.repository.ImageRepository
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -16,241 +16,220 @@ import java.util.Calendar
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OPTIMIZED SearchViewModel with Boolean Logic
|
* SearchViewModel - COMPLETE REDESIGN
|
||||||
*
|
*
|
||||||
* PERFORMANCE: NO N+1 QUERIES!
|
* Features:
|
||||||
* ✅ ImageAggregateDao loads tags via @Relation (1 query for 100 images!)
|
* - Near-match search ("low" → "low_res", "gro" → "group_photo")
|
||||||
* ✅ Person cache for O(1) faceModelId lookups
|
* - Date range filtering
|
||||||
* ✅ All filtering in memory (FAST)
|
* - Quick tag filters
|
||||||
|
* - Clean person-only display
|
||||||
|
* - Simple/Verbose toggle
|
||||||
*/
|
*/
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class SearchViewModel @Inject constructor(
|
class SearchViewModel @Inject constructor(
|
||||||
private val imageAggregateDao: ImageAggregateDao,
|
private val imageRepository: ImageRepository,
|
||||||
private val faceRecognitionRepository: FaceRecognitionRepository,
|
private val faceRecognitionRepository: FaceRecognitionRepository,
|
||||||
private val personDao: PersonDao,
|
|
||||||
private val tagDao: TagDao
|
private val tagDao: TagDao
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
|
// Search query with near-match support
|
||||||
private val _searchQuery = MutableStateFlow("")
|
private val _searchQuery = MutableStateFlow("")
|
||||||
val searchQuery: StateFlow<String> = _searchQuery.asStateFlow()
|
val searchQuery: StateFlow<String> = _searchQuery.asStateFlow()
|
||||||
|
|
||||||
private val _includedPeople = MutableStateFlow<Set<String>>(emptySet())
|
// Active tag filters (quick chips)
|
||||||
val includedPeople: StateFlow<Set<String>> = _includedPeople.asStateFlow()
|
private val _activeTagFilters = MutableStateFlow<Set<String>>(emptySet())
|
||||||
|
val activeTagFilters: StateFlow<Set<String>> = _activeTagFilters.asStateFlow()
|
||||||
private val _excludedPeople = MutableStateFlow<Set<String>>(emptySet())
|
|
||||||
val excludedPeople: StateFlow<Set<String>> = _excludedPeople.asStateFlow()
|
|
||||||
|
|
||||||
private val _includedTags = MutableStateFlow<Set<String>>(emptySet())
|
|
||||||
val includedTags: StateFlow<Set<String>> = _includedTags.asStateFlow()
|
|
||||||
|
|
||||||
private val _excludedTags = MutableStateFlow<Set<String>>(emptySet())
|
|
||||||
val excludedTags: StateFlow<Set<String>> = _excludedTags.asStateFlow()
|
|
||||||
|
|
||||||
|
// Date range filter
|
||||||
private val _dateRange = MutableStateFlow(DateRange.ALL_TIME)
|
private val _dateRange = MutableStateFlow(DateRange.ALL_TIME)
|
||||||
val dateRange: StateFlow<DateRange> = _dateRange.asStateFlow()
|
val dateRange: StateFlow<DateRange> = _dateRange.asStateFlow()
|
||||||
|
|
||||||
private val _availablePeople = MutableStateFlow<List<PersonEntity>>(emptyList())
|
// Display mode (simple = names only, verbose = icons + percentages)
|
||||||
val availablePeople: StateFlow<List<PersonEntity>> = _availablePeople.asStateFlow()
|
private val _displayMode = MutableStateFlow(DisplayMode.SIMPLE)
|
||||||
|
val displayMode: StateFlow<DisplayMode> = _displayMode.asStateFlow()
|
||||||
|
|
||||||
private val _availableTags = MutableStateFlow<List<String>>(emptyList())
|
// Available system tags for quick filters
|
||||||
val availableTags: StateFlow<List<String>> = _availableTags.asStateFlow()
|
private val _systemTags = MutableStateFlow<List<TagEntity>>(emptyList())
|
||||||
|
val systemTags: StateFlow<List<TagEntity>> = _systemTags.asStateFlow()
|
||||||
private val personCache = mutableMapOf<String, String>()
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
loadAvailableFilters()
|
loadSystemTags()
|
||||||
buildPersonCache()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildPersonCache() {
|
|
||||||
viewModelScope.launch {
|
|
||||||
val people = personDao.getAllPersons()
|
|
||||||
people.forEach { person ->
|
|
||||||
val stats = faceRecognitionRepository.getPersonFaceStats(person.id)
|
|
||||||
if (stats != null) {
|
|
||||||
personCache[stats.faceModelId] = person.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main search flow - combines query, tag filters, and date range
|
||||||
|
*/
|
||||||
fun searchImages(): Flow<List<ImageWithFaceTags>> {
|
fun searchImages(): Flow<List<ImageWithFaceTags>> {
|
||||||
return combine(
|
return combine(
|
||||||
_searchQuery,
|
_searchQuery,
|
||||||
_includedPeople,
|
_activeTagFilters,
|
||||||
_excludedPeople,
|
|
||||||
_includedTags,
|
|
||||||
_excludedTags,
|
|
||||||
_dateRange
|
_dateRange
|
||||||
) { values: Array<*> ->
|
) { query, tagFilters, dateRange ->
|
||||||
SearchCriteria(
|
Triple(query, tagFilters, dateRange)
|
||||||
query = values[0] as String,
|
}.flatMapLatest { (query, tagFilters, dateRange) ->
|
||||||
includedPeople = values[1] as Set<String>,
|
|
||||||
excludedPeople = values[2] as Set<String>,
|
channelFlow {
|
||||||
includedTags = values[3] as Set<String>,
|
// Get matching tags FIRST (suspend call)
|
||||||
excludedTags = values[4] as Set<String>,
|
val matchingTags = if (query.isNotBlank()) {
|
||||||
dateRange = values[5] as DateRange
|
findMatchingTags(query)
|
||||||
)
|
} else {
|
||||||
}.flatMapLatest { criteria ->
|
emptyList()
|
||||||
imageAggregateDao.observeAllImagesWithEverything()
|
|
||||||
.map { imagesList ->
|
|
||||||
imagesList.mapNotNull { imageWithEverything ->
|
|
||||||
if (!isInDateRange(imageWithEverything.image.capturedAt, criteria.dateRange)) {
|
|
||||||
return@mapNotNull null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val personIds = imageWithEverything.faceTags
|
// Get base images
|
||||||
.mapNotNull { faceTag -> personCache[faceTag.faceModelId] }
|
val imagesFlow = when {
|
||||||
.toSet()
|
matchingTags.isNotEmpty() -> {
|
||||||
|
// Search by all matching tags
|
||||||
val imageTags = imageWithEverything.tags
|
combine(matchingTags.map { tag ->
|
||||||
.map { it.value }
|
imageRepository.findImagesByTag(tag.value)
|
||||||
.toSet()
|
}) { results ->
|
||||||
|
results.flatMap { it }.distinctBy { it.image.imageId }
|
||||||
val passesFilter = applyBooleanLogic(
|
|
||||||
personIds = personIds,
|
|
||||||
imageTags = imageTags,
|
|
||||||
criteria = criteria
|
|
||||||
)
|
|
||||||
|
|
||||||
if (passesFilter) {
|
|
||||||
val persons = personIds.mapNotNull { personId ->
|
|
||||||
_availablePeople.value.find { it.id == personId }
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
tagFilters.isNotEmpty() -> {
|
||||||
|
// Filter by active tags
|
||||||
|
combine(tagFilters.map { tagValue ->
|
||||||
|
imageRepository.findImagesByTag(tagValue)
|
||||||
|
}) { results ->
|
||||||
|
results.flatMap { it }.distinctBy { it.image.imageId }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> imageRepository.getAllImages()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply date filtering and add face data
|
||||||
|
imagesFlow.collect { imagesList ->
|
||||||
|
val filtered = imagesList
|
||||||
|
.filter { imageWithEverything ->
|
||||||
|
isInDateRange(imageWithEverything.image.capturedAt, dateRange)
|
||||||
|
}
|
||||||
|
.map { imageWithEverything ->
|
||||||
|
// Get face tags with person info
|
||||||
|
val tagsWithPersons = faceRecognitionRepository.getFaceTagsWithPersons(
|
||||||
|
imageWithEverything.image.imageId
|
||||||
|
)
|
||||||
|
|
||||||
ImageWithFaceTags(
|
ImageWithFaceTags(
|
||||||
image = imageWithEverything.image,
|
image = imageWithEverything.image,
|
||||||
faceTags = imageWithEverything.faceTags,
|
faceTags = tagsWithPersons.map { it.first },
|
||||||
persons = persons
|
persons = tagsWithPersons.map { it.second }
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
}
|
||||||
}.sortedByDescending { it.image.capturedAt }
|
.sortedByDescending { it.image.capturedAt }
|
||||||
|
|
||||||
|
send(filtered)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applyBooleanLogic(
|
/**
|
||||||
personIds: Set<String>,
|
* Near-match search: "low" matches "low_res", "gro" matches "group_photo"
|
||||||
imageTags: Set<String>,
|
*/
|
||||||
criteria: SearchCriteria
|
private suspend fun findMatchingTags(query: String): List<TagEntity> {
|
||||||
): Boolean {
|
val normalizedQuery = query.trim().lowercase()
|
||||||
val hasAllIncludedPeople = if (criteria.includedPeople.isNotEmpty()) {
|
|
||||||
criteria.includedPeople.all { it in personIds }
|
|
||||||
} else true
|
|
||||||
|
|
||||||
val hasNoExcludedPeople = if (criteria.excludedPeople.isNotEmpty()) {
|
// Get all system tags
|
||||||
criteria.excludedPeople.none { it in personIds }
|
val allTags = tagDao.getByType("SYSTEM")
|
||||||
} else true
|
|
||||||
|
|
||||||
val hasAllIncludedTags = if (criteria.includedTags.isNotEmpty()) {
|
// Find tags that contain the query or match it closely
|
||||||
criteria.includedTags.all { it in imageTags }
|
return allTags.filter { tag ->
|
||||||
} else true
|
val tagValue = tag.value.lowercase()
|
||||||
|
|
||||||
val hasNoExcludedTags = if (criteria.excludedTags.isNotEmpty()) {
|
// Exact match
|
||||||
criteria.excludedTags.none { it in imageTags }
|
tagValue == normalizedQuery ||
|
||||||
} else true
|
// Contains match
|
||||||
|
tagValue.contains(normalizedQuery) ||
|
||||||
val matchesTextSearch = if (criteria.query.isNotBlank()) {
|
// Starts with match
|
||||||
val normalizedQuery = criteria.query.trim().lowercase()
|
tagValue.startsWith(normalizedQuery) ||
|
||||||
imageTags.any { tag -> tag.lowercase().contains(normalizedQuery) }
|
// Fuzzy match (remove underscores and compare)
|
||||||
} else true
|
tagValue.replace("_", "").contains(normalizedQuery.replace("_", ""))
|
||||||
|
}.sortedBy { tag ->
|
||||||
return hasAllIncludedPeople && hasNoExcludedPeople &&
|
// Sort by relevance: exact > starts with > contains
|
||||||
hasAllIncludedTags && hasNoExcludedTags &&
|
when {
|
||||||
matchesTextSearch
|
tag.value.lowercase() == normalizedQuery -> 0
|
||||||
|
tag.value.lowercase().startsWith(normalizedQuery) -> 1
|
||||||
|
else -> 2
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadAvailableFilters() {
|
/**
|
||||||
|
* Load available system tags for quick filters
|
||||||
|
*/
|
||||||
|
private fun loadSystemTags() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val people = personDao.getAllPersons()
|
|
||||||
_availablePeople.value = people.sortedBy { it.name }
|
|
||||||
|
|
||||||
val tags = tagDao.getByType("SYSTEM")
|
val tags = tagDao.getByType("SYSTEM")
|
||||||
|
|
||||||
|
// Get usage counts for all tags
|
||||||
val tagsWithUsage = tags.map { tag ->
|
val tagsWithUsage = tags.map { tag ->
|
||||||
tag to tagDao.getTagUsageCount(tag.tagId)
|
tag to tagDao.getTagUsageCount(tag.tagId)
|
||||||
}
|
}
|
||||||
_availableTags.value = tagsWithUsage
|
|
||||||
|
// Sort by most commonly used
|
||||||
|
val sortedTags = tagsWithUsage
|
||||||
.sortedByDescending { (_, usageCount) -> usageCount }
|
.sortedByDescending { (_, usageCount) -> usageCount }
|
||||||
.take(30)
|
.take(12) // Show top 12 most used tags
|
||||||
.map { (tag, _) -> tag.value }
|
.map { (tag, _) -> tag }
|
||||||
|
|
||||||
|
_systemTags.value = sortedTags
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun includePerson(personId: String) {
|
/**
|
||||||
_includedPeople.value = _includedPeople.value + personId
|
* Update search query
|
||||||
_excludedPeople.value = _excludedPeople.value - personId
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
fun excludePerson(personId: String) {
|
|
||||||
_excludedPeople.value = _excludedPeople.value + personId
|
|
||||||
_includedPeople.value = _includedPeople.value - personId
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removePersonFilter(personId: String) {
|
|
||||||
_includedPeople.value = _includedPeople.value - personId
|
|
||||||
_excludedPeople.value = _excludedPeople.value - personId
|
|
||||||
}
|
|
||||||
|
|
||||||
fun includeTag(tagValue: String) {
|
|
||||||
_includedTags.value = _includedTags.value + tagValue
|
|
||||||
_excludedTags.value = _excludedTags.value - tagValue
|
|
||||||
}
|
|
||||||
|
|
||||||
fun excludeTag(tagValue: String) {
|
|
||||||
_excludedTags.value = _excludedTags.value + tagValue
|
|
||||||
_includedTags.value = _includedTags.value - tagValue
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeTagFilter(tagValue: String) {
|
|
||||||
_includedTags.value = _includedTags.value - tagValue
|
|
||||||
_excludedTags.value = _excludedTags.value - tagValue
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setSearchQuery(query: String) {
|
fun setSearchQuery(query: String) {
|
||||||
_searchQuery.value = query
|
_searchQuery.value = query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle a tag filter
|
||||||
|
*/
|
||||||
|
fun toggleTagFilter(tagValue: String) {
|
||||||
|
_activeTagFilters.value = if (tagValue in _activeTagFilters.value) {
|
||||||
|
_activeTagFilters.value - tagValue
|
||||||
|
} else {
|
||||||
|
_activeTagFilters.value + tagValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear all tag filters
|
||||||
|
*/
|
||||||
|
fun clearTagFilters() {
|
||||||
|
_activeTagFilters.value = emptySet()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set date range filter
|
||||||
|
*/
|
||||||
fun setDateRange(range: DateRange) {
|
fun setDateRange(range: DateRange) {
|
||||||
_dateRange.value = range
|
_dateRange.value = range
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearAllFilters() {
|
/**
|
||||||
_searchQuery.value = ""
|
* Toggle display mode (simple/verbose)
|
||||||
_includedPeople.value = emptySet()
|
*/
|
||||||
_excludedPeople.value = emptySet()
|
fun toggleDisplayMode() {
|
||||||
_includedTags.value = emptySet()
|
_displayMode.value = when (_displayMode.value) {
|
||||||
_excludedTags.value = emptySet()
|
DisplayMode.SIMPLE -> DisplayMode.VERBOSE
|
||||||
_dateRange.value = DateRange.ALL_TIME
|
DisplayMode.VERBOSE -> DisplayMode.SIMPLE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasActiveFilters(): Boolean {
|
/**
|
||||||
return _searchQuery.value.isNotBlank() ||
|
* Check if timestamp is in date range
|
||||||
_includedPeople.value.isNotEmpty() ||
|
*/
|
||||||
_excludedPeople.value.isNotEmpty() ||
|
private fun isInDateRange(timestamp: Long, range: DateRange): Boolean {
|
||||||
_includedTags.value.isNotEmpty() ||
|
return when (range) {
|
||||||
_excludedTags.value.isNotEmpty() ||
|
|
||||||
_dateRange.value != DateRange.ALL_TIME
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getSearchSummary(): String {
|
|
||||||
val parts = mutableListOf<String>()
|
|
||||||
if (_includedPeople.value.isNotEmpty()) parts.add("WITH: ${_includedPeople.value.size} people")
|
|
||||||
if (_excludedPeople.value.isNotEmpty()) parts.add("WITHOUT: ${_excludedPeople.value.size} people")
|
|
||||||
if (_includedTags.value.isNotEmpty()) parts.add("HAS: ${_includedTags.value.size} tags")
|
|
||||||
if (_excludedTags.value.isNotEmpty()) parts.add("NOT: ${_excludedTags.value.size} tags")
|
|
||||||
if (_dateRange.value != DateRange.ALL_TIME) parts.add(_dateRange.value.displayName)
|
|
||||||
return parts.joinToString(" • ")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isInDateRange(timestamp: Long, range: DateRange): Boolean = when (range) {
|
|
||||||
DateRange.ALL_TIME -> true
|
DateRange.ALL_TIME -> true
|
||||||
DateRange.TODAY -> isToday(timestamp)
|
DateRange.TODAY -> isToday(timestamp)
|
||||||
DateRange.THIS_WEEK -> isThisWeek(timestamp)
|
DateRange.THIS_WEEK -> isThisWeek(timestamp)
|
||||||
DateRange.THIS_MONTH -> isThisMonth(timestamp)
|
DateRange.THIS_MONTH -> isThisMonth(timestamp)
|
||||||
DateRange.THIS_YEAR -> isThisYear(timestamp)
|
DateRange.THIS_YEAR -> isThisYear(timestamp)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun isToday(timestamp: Long): Boolean {
|
private fun isToday(timestamp: Long): Boolean {
|
||||||
val today = Calendar.getInstance()
|
val today = Calendar.getInstance()
|
||||||
@@ -280,21 +259,18 @@ class SearchViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class SearchCriteria(
|
/**
|
||||||
val query: String,
|
* Data class containing image with face recognition data
|
||||||
val includedPeople: Set<String>,
|
*/
|
||||||
val excludedPeople: Set<String>,
|
|
||||||
val includedTags: Set<String>,
|
|
||||||
val excludedTags: Set<String>,
|
|
||||||
val dateRange: DateRange
|
|
||||||
)
|
|
||||||
|
|
||||||
data class ImageWithFaceTags(
|
data class ImageWithFaceTags(
|
||||||
val image: ImageEntity,
|
val image: ImageEntity,
|
||||||
val faceTags: List<PhotoFaceTagEntity>,
|
val faceTags: List<PhotoFaceTagEntity>,
|
||||||
val persons: List<PersonEntity>
|
val persons: List<PersonEntity>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date range filters
|
||||||
|
*/
|
||||||
enum class DateRange(val displayName: String) {
|
enum class DateRange(val displayName: String) {
|
||||||
ALL_TIME("All Time"),
|
ALL_TIME("All Time"),
|
||||||
TODAY("Today"),
|
TODAY("Today"),
|
||||||
@@ -303,5 +279,10 @@ enum class DateRange(val displayName: String) {
|
|||||||
THIS_YEAR("This Year")
|
THIS_YEAR("This Year")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("No longer used")
|
/**
|
||||||
enum class DisplayMode { SIMPLE, VERBOSE }
|
* Display modes for photo tags
|
||||||
|
*/
|
||||||
|
enum class DisplayMode {
|
||||||
|
SIMPLE, // Just person names
|
||||||
|
VERBOSE // Names + icons + confidence percentages
|
||||||
|
}
|
||||||
@@ -24,24 +24,9 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import com.placeholder.sherpai2.data.local.entity.TagWithUsage
|
import com.placeholder.sherpai2.data.local.entity.TagWithUsage
|
||||||
|
|
||||||
/**
|
|
||||||
* CLEANED TagManagementScreen - No Scaffold wrapper
|
|
||||||
*
|
|
||||||
* Removed:
|
|
||||||
* - Scaffold wrapper (line 38)
|
|
||||||
* - Moved FAB inline as part of content
|
|
||||||
*
|
|
||||||
* Features:
|
|
||||||
* - Tag list with usage counts
|
|
||||||
* - Search functionality
|
|
||||||
* - Scanning progress
|
|
||||||
* - Delete tags
|
|
||||||
* - System/User tag distinction
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TagManagementScreen(
|
fun TagManagementScreen(
|
||||||
viewModel: TagManagementViewModel = hiltViewModel(),
|
viewModel: TagManagementViewModel = hiltViewModel()
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
) {
|
||||||
val uiState by viewModel.uiState.collectAsState()
|
val uiState by viewModel.uiState.collectAsState()
|
||||||
val scanningState by viewModel.scanningState.collectAsState()
|
val scanningState by viewModel.scanningState.collectAsState()
|
||||||
@@ -50,8 +35,105 @@ fun TagManagementScreen(
|
|||||||
var showScanMenu by remember { mutableStateOf(false) }
|
var showScanMenu by remember { mutableStateOf(false) }
|
||||||
var searchQuery by remember { mutableStateOf("") }
|
var searchQuery by remember { mutableStateOf("") }
|
||||||
|
|
||||||
Box(modifier = modifier.fillMaxSize()) {
|
Scaffold(
|
||||||
Column(modifier = Modifier.fillMaxSize()) {
|
floatingActionButton = {
|
||||||
|
// Single extended FAB with dropdown menu
|
||||||
|
var showMenu by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.End,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
// Dropdown menu for scan options
|
||||||
|
if (showMenu) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.width(180.dp),
|
||||||
|
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
ListItem(
|
||||||
|
headlineContent = { Text("Scan All", style = MaterialTheme.typography.bodyMedium) },
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.AutoFixHigh,
|
||||||
|
null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(20.dp)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier.clickable {
|
||||||
|
viewModel.scanForAllTags()
|
||||||
|
showMenu = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
ListItem(
|
||||||
|
headlineContent = { Text("Base Tags", style = MaterialTheme.typography.bodyMedium) },
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.PhotoCamera,
|
||||||
|
null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(20.dp)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier.clickable {
|
||||||
|
viewModel.scanForBaseTags()
|
||||||
|
showMenu = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
ListItem(
|
||||||
|
headlineContent = { Text("Relationships", style = MaterialTheme.typography.bodyMedium) },
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.People,
|
||||||
|
null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(20.dp)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier.clickable {
|
||||||
|
viewModel.scanForRelationshipTags()
|
||||||
|
showMenu = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
ListItem(
|
||||||
|
headlineContent = { Text("Birthdays", style = MaterialTheme.typography.bodyMedium) },
|
||||||
|
leadingContent = {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Cake,
|
||||||
|
null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(20.dp)
|
||||||
|
)
|
||||||
|
},
|
||||||
|
modifier = Modifier.clickable {
|
||||||
|
viewModel.scanForBirthdayTags()
|
||||||
|
showMenu = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main FAB
|
||||||
|
ExtendedFloatingActionButton(
|
||||||
|
onClick = { showMenu = !showMenu },
|
||||||
|
icon = {
|
||||||
|
Icon(
|
||||||
|
if (showMenu) Icons.Default.Close else Icons.Default.AutoFixHigh,
|
||||||
|
"Scan"
|
||||||
|
)
|
||||||
|
},
|
||||||
|
text = { Text(if (showMenu) "Close" else "Scan Tags") }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) { paddingValues ->
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(paddingValues)
|
||||||
|
) {
|
||||||
// Stats Bar
|
// Stats Bar
|
||||||
StatsBar(uiState)
|
StatsBar(uiState)
|
||||||
|
|
||||||
@@ -84,30 +166,16 @@ fun TagManagementScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
is TagManagementViewModel.TagUiState.Success -> {
|
is TagManagementViewModel.TagUiState.Success -> {
|
||||||
if (state.tags.isEmpty()) {
|
|
||||||
EmptyTagsView()
|
|
||||||
} else {
|
|
||||||
TagList(
|
TagList(
|
||||||
tags = state.tags,
|
tags = state.tags,
|
||||||
onDeleteTag = { viewModel.deleteTag(it) }
|
onDeleteTag = { viewModel.deleteTag(it) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
is TagManagementViewModel.TagUiState.Error -> {
|
is TagManagementViewModel.TagUiState.Error -> {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Error,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(48.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
Text(
|
Text(
|
||||||
text = state.message,
|
text = state.message,
|
||||||
color = MaterialTheme.colorScheme.error
|
color = MaterialTheme.colorScheme.error
|
||||||
@@ -118,28 +186,6 @@ fun TagManagementScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FAB (inline, positioned over content)
|
|
||||||
ScanFAB(
|
|
||||||
showMenu = showScanMenu,
|
|
||||||
onToggleMenu = { showScanMenu = !showScanMenu },
|
|
||||||
onScanAll = {
|
|
||||||
viewModel.scanForAllTags()
|
|
||||||
showScanMenu = false
|
|
||||||
},
|
|
||||||
onScanBase = {
|
|
||||||
viewModel.scanForBaseTags()
|
|
||||||
showScanMenu = false
|
|
||||||
},
|
|
||||||
onScanRelationships = {
|
|
||||||
viewModel.scanForRelationshipTags()
|
|
||||||
showScanMenu = false
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.BottomEnd)
|
|
||||||
.padding(16.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add Tag Dialog
|
// Add Tag Dialog
|
||||||
if (showAddTagDialog) {
|
if (showAddTagDialog) {
|
||||||
AddTagDialog(
|
AddTagDialog(
|
||||||
@@ -150,77 +196,73 @@ fun TagManagementScreen(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scan Menu
|
||||||
|
if (showScanMenu) {
|
||||||
|
ScanMenuDialog(
|
||||||
|
onDismiss = { showScanMenu = false },
|
||||||
|
onScanSelected = { scanType ->
|
||||||
|
when (scanType) {
|
||||||
|
TagManagementViewModel.ScanType.BASE_TAGS -> viewModel.scanForBaseTags()
|
||||||
|
TagManagementViewModel.ScanType.RELATIONSHIP_TAGS -> viewModel.scanForRelationshipTags()
|
||||||
|
TagManagementViewModel.ScanType.BIRTHDAY_TAGS -> viewModel.scanForBirthdayTags()
|
||||||
|
TagManagementViewModel.ScanType.SCENE_TAGS -> viewModel.scanForSceneTags()
|
||||||
|
TagManagementViewModel.ScanType.ALL -> viewModel.scanForAllTags()
|
||||||
|
}
|
||||||
|
showScanMenu = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Stats bar at top
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun StatsBar(uiState: TagManagementViewModel.TagUiState) {
|
private fun StatsBar(uiState: TagManagementViewModel.TagUiState) {
|
||||||
val (totalTags, totalPhotos) = when (uiState) {
|
if (uiState is TagManagementViewModel.TagUiState.Success) {
|
||||||
is TagManagementViewModel.TagUiState.Success -> {
|
Card(
|
||||||
val photoCount: Int = uiState.tags.sumOf { it.usageCount }
|
modifier = Modifier
|
||||||
uiState.tags.size to photoCount
|
.fillMaxWidth()
|
||||||
}
|
.padding(16.dp),
|
||||||
else -> 0 to 0
|
colors = CardDefaults.cardColors(
|
||||||
}
|
containerColor = MaterialTheme.colorScheme.primaryContainer
|
||||||
|
)
|
||||||
Surface(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f)
|
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly
|
horizontalArrangement = Arrangement.SpaceAround
|
||||||
) {
|
) {
|
||||||
StatItem(
|
StatItem("Total", uiState.totalTags.toString(), Icons.Default.Label)
|
||||||
icon = Icons.Default.Label,
|
StatItem("System", uiState.systemTags.toString(), Icons.Default.AutoAwesome)
|
||||||
value = totalTags.toString(),
|
StatItem("User", uiState.userTags.toString(), Icons.Default.PersonOutline)
|
||||||
label = "Tags"
|
}
|
||||||
)
|
|
||||||
VerticalDivider(
|
|
||||||
modifier = Modifier.height(48.dp),
|
|
||||||
color = MaterialTheme.colorScheme.outline.copy(alpha = 0.3f)
|
|
||||||
)
|
|
||||||
StatItem(
|
|
||||||
icon = Icons.Default.Photo,
|
|
||||||
value = totalPhotos.toString(),
|
|
||||||
label = "Tagged Photos"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun StatItem(icon: ImageVector, value: String, label: String) {
|
private fun StatItem(label: String, value: String, icon: ImageVector) {
|
||||||
Column(
|
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
Icon(
|
||||||
icon,
|
imageVector = icon,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(24.dp),
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
tint = MaterialTheme.colorScheme.primary
|
modifier = Modifier.size(24.dp)
|
||||||
)
|
)
|
||||||
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
value,
|
text = value,
|
||||||
style = MaterialTheme.typography.headlineSmall,
|
style = MaterialTheme.typography.headlineSmall,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
label,
|
text = label,
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Search bar
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun SearchBar(
|
private fun SearchBar(
|
||||||
searchQuery: String,
|
searchQuery: String,
|
||||||
@@ -231,9 +273,9 @@ private fun SearchBar(
|
|||||||
onValueChange = onSearchChange,
|
onValueChange = onSearchChange,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(16.dp),
|
.padding(horizontal = 16.dp),
|
||||||
placeholder = { Text("Search tags...") },
|
placeholder = { Text("Search tags...") },
|
||||||
leadingIcon = { Icon(Icons.Default.Search, contentDescription = null) },
|
leadingIcon = { Icon(Icons.Default.Search, "Search") },
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
if (searchQuery.isNotEmpty()) {
|
if (searchQuery.isNotEmpty()) {
|
||||||
IconButton(onClick = { onSearchChange("") }) {
|
IconButton(onClick = { onSearchChange("") }) {
|
||||||
@@ -241,124 +283,96 @@ private fun SearchBar(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
singleLine = true,
|
singleLine = true
|
||||||
shape = RoundedCornerShape(16.dp)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Scanning progress indicator
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ScanningProgress(
|
private fun ScanningProgress(
|
||||||
scanningState: TagManagementViewModel.TagScanningState,
|
scanningState: TagManagementViewModel.TagScanningState,
|
||||||
viewModel: TagManagementViewModel
|
viewModel: TagManagementViewModel
|
||||||
) {
|
) {
|
||||||
when (scanningState) {
|
|
||||||
is TagManagementViewModel.TagScanningState.Scanning -> {
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
.padding(16.dp),
|
||||||
colors = CardDefaults.cardColors(
|
colors = CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f)
|
containerColor = MaterialTheme.colorScheme.secondaryContainer
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(16.dp),
|
modifier = Modifier
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp)
|
||||||
) {
|
) {
|
||||||
|
when (scanningState) {
|
||||||
|
is TagManagementViewModel.TagScanningState.Scanning -> {
|
||||||
|
Text(
|
||||||
|
text = "Scanning: ${scanningState.scanType.name.replace("_", " ")}",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
fontWeight = FontWeight.Bold
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
LinearProgressIndicator(
|
||||||
|
progress = { scanningState.progress.toFloat() / scanningState.total.toFloat() },
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
|
Text(
|
||||||
|
text = "${scanningState.progress} / ${scanningState.total} images",
|
||||||
|
style = MaterialTheme.typography.bodySmall
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "Tags applied: ${scanningState.tagsApplied}",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
}
|
||||||
|
is TagManagementViewModel.TagScanningState.Complete -> {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
Text(
|
||||||
|
text = "✓ Scan Complete",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "${scanningState.tagsApplied} tags applied to ${scanningState.imagesProcessed} images",
|
||||||
|
style = MaterialTheme.typography.bodySmall
|
||||||
|
)
|
||||||
|
}
|
||||||
|
IconButton(onClick = { viewModel.resetScanningState() }) {
|
||||||
|
Icon(Icons.Default.Close, "Close")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is TagManagementViewModel.TagScanningState.Error -> {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
"Scanning: ${scanningState.scanType}",
|
text = "Error: ${scanningState.message}",
|
||||||
style = MaterialTheme.typography.titleSmall,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
fontWeight = FontWeight.SemiBold
|
color = MaterialTheme.colorScheme.error
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"${scanningState.progress}/${scanningState.total}",
|
|
||||||
style = MaterialTheme.typography.bodySmall
|
|
||||||
)
|
|
||||||
}
|
|
||||||
LinearProgressIndicator(
|
|
||||||
progress = {
|
|
||||||
if (scanningState.total > 0) {
|
|
||||||
scanningState.progress.toFloat() / scanningState.total.toFloat()
|
|
||||||
} else {
|
|
||||||
0f
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"Tags applied: ${scanningState.tagsApplied}",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
if (scanningState.currentImage.isNotEmpty()) {
|
|
||||||
Text(
|
|
||||||
"Current: ${scanningState.currentImage}",
|
|
||||||
style = MaterialTheme.typography.labelSmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
)
|
||||||
|
IconButton(onClick = { viewModel.resetScanningState() }) {
|
||||||
|
Icon(Icons.Default.Close, "Close")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else -> { /* Idle - don't show */ }
|
||||||
is TagManagementViewModel.TagScanningState.Complete -> {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.padding(16.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.CheckCircle,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
Column {
|
|
||||||
Text(
|
|
||||||
"Scan Complete!",
|
|
||||||
style = MaterialTheme.typography.titleSmall,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"Processed: ${scanningState.imagesProcessed} images",
|
|
||||||
style = MaterialTheme.typography.bodySmall
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"Applied: ${scanningState.tagsApplied} tags",
|
|
||||||
style = MaterialTheme.typography.bodySmall
|
|
||||||
)
|
|
||||||
if (scanningState.newTagsCreated > 0) {
|
|
||||||
Text(
|
|
||||||
"Created: ${scanningState.newTagsCreated} new tags",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tag list
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun TagList(
|
private fun TagList(
|
||||||
tags: List<TagWithUsage>,
|
tags: List<TagWithUsage>,
|
||||||
@@ -369,238 +383,114 @@ private fun TagList(
|
|||||||
contentPadding = PaddingValues(16.dp),
|
contentPadding = PaddingValues(16.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
) {
|
) {
|
||||||
items(tags) { tagWithUsage ->
|
items(tags, key = { it.tagId }) { tag ->
|
||||||
TagCard(
|
TagListItem(tag, onDeleteTag)
|
||||||
tagWithUsage = tagWithUsage,
|
|
||||||
onDelete = { onDeleteTag(tagWithUsage.tagId) }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Individual tag card
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun TagCard(
|
private fun TagListItem(
|
||||||
tagWithUsage: TagWithUsage,
|
tag: TagWithUsage,
|
||||||
onDelete: () -> Unit
|
onDeleteTag: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val isSystemTag = tagWithUsage.type == "SYSTEM"
|
var showDeleteConfirm by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
onClick = { /* TODO: Navigate to images with this tag */ }
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.padding(16.dp),
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
// Tag icon
|
// Tag type icon
|
||||||
Surface(
|
|
||||||
modifier = Modifier.size(40.dp),
|
|
||||||
shape = RoundedCornerShape(8.dp),
|
|
||||||
color = if (isSystemTag)
|
|
||||||
MaterialTheme.colorScheme.primaryContainer
|
|
||||||
else
|
|
||||||
MaterialTheme.colorScheme.secondaryContainer
|
|
||||||
) {
|
|
||||||
Box(contentAlignment = Alignment.Center) {
|
|
||||||
Icon(
|
Icon(
|
||||||
if (isSystemTag) Icons.Default.AutoAwesome else Icons.Default.Label,
|
imageVector = if (tag.type == "SYSTEM") Icons.Default.AutoAwesome else Icons.Default.Label,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(20.dp),
|
tint = if (tag.type == "SYSTEM")
|
||||||
tint = if (isSystemTag)
|
MaterialTheme.colorScheme.secondary
|
||||||
MaterialTheme.colorScheme.onPrimaryContainer
|
|
||||||
else
|
else
|
||||||
MaterialTheme.colorScheme.onSecondaryContainer
|
MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tag info
|
|
||||||
Column {
|
Column {
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = tagWithUsage.value,
|
text = tag.value,
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.SemiBold
|
fontWeight = FontWeight.Medium
|
||||||
)
|
)
|
||||||
if (isSystemTag) {
|
|
||||||
Surface(
|
|
||||||
shape = RoundedCornerShape(4.dp),
|
|
||||||
color = MaterialTheme.colorScheme.primary.copy(alpha = 0.1f)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
"SYSTEM",
|
text = if (tag.type == "SYSTEM") "System tag" else "User tag",
|
||||||
modifier = Modifier.padding(horizontal = 6.dp, vertical = 2.dp),
|
|
||||||
style = MaterialTheme.typography.labelSmall,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
text = "${tagWithUsage.usageCount} ${if (tagWithUsage.usageCount == 1) "photo" else "photos"}",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
// Usage count badge
|
||||||
|
Surface(
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
color = MaterialTheme.colorScheme.primaryContainer
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = tag.usageCount.toString(),
|
||||||
|
modifier = Modifier.padding(horizontal = 12.dp, vertical = 6.dp),
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = MaterialTheme.colorScheme.onPrimaryContainer
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Delete button (only for user tags)
|
// Delete button (only for user tags)
|
||||||
if (!isSystemTag) {
|
if (tag.type == "GENERIC") {
|
||||||
IconButton(onClick = onDelete) {
|
IconButton(onClick = { showDeleteConfirm = true }) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Delete,
|
Icons.Default.Delete,
|
||||||
contentDescription = "Delete",
|
contentDescription = "Delete tag",
|
||||||
tint = MaterialTheme.colorScheme.error
|
tint = MaterialTheme.colorScheme.error
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Empty state
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
private fun EmptyTagsView() {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(32.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.LabelOff,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(64.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f)
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"No Tags Yet",
|
|
||||||
style = MaterialTheme.typography.titleLarge,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"Scan your photos to generate tags automatically",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Floating Action Button with scan menu
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
private fun ScanFAB(
|
|
||||||
showMenu: Boolean,
|
|
||||||
onToggleMenu: () -> Unit,
|
|
||||||
onScanAll: () -> Unit,
|
|
||||||
onScanBase: () -> Unit,
|
|
||||||
onScanRelationships: () -> Unit,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = modifier,
|
|
||||||
horizontalAlignment = Alignment.End,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
// Menu options
|
|
||||||
AnimatedVisibility(visible = showMenu) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.End,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
SmallFAB(
|
|
||||||
icon = Icons.Default.AutoFixHigh,
|
|
||||||
text = "Scan All",
|
|
||||||
onClick = onScanAll
|
|
||||||
)
|
|
||||||
SmallFAB(
|
|
||||||
icon = Icons.Default.PhotoCamera,
|
|
||||||
text = "Base Tags",
|
|
||||||
onClick = onScanBase
|
|
||||||
)
|
|
||||||
SmallFAB(
|
|
||||||
icon = Icons.Default.People,
|
|
||||||
text = "Relationships",
|
|
||||||
onClick = onScanRelationships
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main FAB
|
if (showDeleteConfirm) {
|
||||||
ExtendedFloatingActionButton(
|
AlertDialog(
|
||||||
onClick = onToggleMenu,
|
onDismissRequest = { showDeleteConfirm = false },
|
||||||
icon = {
|
title = { Text("Delete Tag?") },
|
||||||
Icon(
|
text = { Text("Are you sure you want to delete '${tag.value}'? This will remove it from ${tag.usageCount} images.") },
|
||||||
if (showMenu) Icons.Default.Close else Icons.Default.AutoFixHigh,
|
confirmButton = {
|
||||||
"Scan"
|
TextButton(
|
||||||
)
|
onClick = {
|
||||||
|
onDeleteTag(tag.tagId)
|
||||||
|
showDeleteConfirm = false
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text("Delete", color = MaterialTheme.colorScheme.error)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
text = { Text(if (showMenu) "Close" else "Scan Tags") },
|
dismissButton = {
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
TextButton(onClick = { showDeleteConfirm = false }) {
|
||||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun SmallFAB(
|
|
||||||
icon: ImageVector,
|
|
||||||
text: String,
|
|
||||||
onClick: () -> Unit
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
Surface(
|
|
||||||
shape = RoundedCornerShape(8.dp),
|
|
||||||
color = MaterialTheme.colorScheme.surface,
|
|
||||||
shadowElevation = 2.dp
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text,
|
|
||||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp),
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
fontWeight = FontWeight.Medium
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
FloatingActionButton(
|
|
||||||
onClick = onClick,
|
|
||||||
modifier = Modifier.size(48.dp),
|
|
||||||
containerColor = MaterialTheme.colorScheme.secondaryContainer,
|
|
||||||
contentColor = MaterialTheme.colorScheme.onSecondaryContainer
|
|
||||||
) {
|
|
||||||
Icon(icon, contentDescription = text, modifier = Modifier.size(20.dp))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add tag dialog
|
|
||||||
*/
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun AddTagDialog(
|
private fun AddTagDialog(
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
@@ -610,19 +500,18 @@ private fun AddTagDialog(
|
|||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
icon = { Icon(Icons.Default.Add, contentDescription = null) },
|
title = { Text("Add New Tag") },
|
||||||
title = { Text("Add Custom Tag") },
|
|
||||||
text = {
|
text = {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = tagName,
|
value = tagName,
|
||||||
onValueChange = { tagName = it },
|
onValueChange = { tagName = it },
|
||||||
label = { Text("Tag Name") },
|
label = { Text("Tag name") },
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
Button(
|
TextButton(
|
||||||
onClick = { onConfirm(tagName) },
|
onClick = { onConfirm(tagName) },
|
||||||
enabled = tagName.isNotBlank()
|
enabled = tagName.isNotBlank()
|
||||||
) {
|
) {
|
||||||
@@ -636,3 +525,100 @@ private fun AddTagDialog(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ScanMenuDialog(
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
onScanSelected: (TagManagementViewModel.ScanType) -> Unit
|
||||||
|
) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = { Text("Scan for Tags") },
|
||||||
|
text = {
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
ScanOption(
|
||||||
|
title = "Base Tags",
|
||||||
|
description = "Face count, orientation, time, quality",
|
||||||
|
icon = Icons.Default.PhotoCamera,
|
||||||
|
onClick = { onScanSelected(TagManagementViewModel.ScanType.BASE_TAGS) }
|
||||||
|
)
|
||||||
|
ScanOption(
|
||||||
|
title = "Relationship Tags",
|
||||||
|
description = "Family, friends, colleagues",
|
||||||
|
icon = Icons.Default.People,
|
||||||
|
onClick = { onScanSelected(TagManagementViewModel.ScanType.RELATIONSHIP_TAGS) }
|
||||||
|
)
|
||||||
|
ScanOption(
|
||||||
|
title = "Birthday Tags",
|
||||||
|
description = "Photos near birthdays",
|
||||||
|
icon = Icons.Default.Cake,
|
||||||
|
onClick = { onScanSelected(TagManagementViewModel.ScanType.BIRTHDAY_TAGS) }
|
||||||
|
)
|
||||||
|
ScanOption(
|
||||||
|
title = "Scene Tags",
|
||||||
|
description = "Indoor/outdoor detection",
|
||||||
|
icon = Icons.Default.Landscape,
|
||||||
|
onClick = { onScanSelected(TagManagementViewModel.ScanType.SCENE_TAGS) }
|
||||||
|
)
|
||||||
|
Divider()
|
||||||
|
ScanOption(
|
||||||
|
title = "Scan All",
|
||||||
|
description = "Run all scans",
|
||||||
|
icon = Icons.Default.AutoFixHigh,
|
||||||
|
onClick = { onScanSelected(TagManagementViewModel.ScanType.ALL) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ScanOption(
|
||||||
|
title: String,
|
||||||
|
description: String,
|
||||||
|
icon: ImageVector,
|
||||||
|
onClick: () -> Unit
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable(onClick = onClick),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = icon,
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(32.dp)
|
||||||
|
)
|
||||||
|
Column {
|
||||||
|
Text(
|
||||||
|
text = title,
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
fontWeight = FontWeight.Medium
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = description,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,373 +0,0 @@
|
|||||||
package com.placeholder.sherpai2.ui.trainingprep
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.foundation.rememberScrollState
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.foundation.verticalScroll
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.*
|
|
||||||
import androidx.compose.material3.*
|
|
||||||
import androidx.compose.runtime.*
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import androidx.compose.ui.window.DialogProperties
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
|
||||||
* BEAUTIFUL PersonInfoDialog - Modern, centered, spacious
|
|
||||||
*
|
|
||||||
* Improvements:
|
|
||||||
* - Full-screen dialog with proper centering
|
|
||||||
* - Better spacing and visual hierarchy
|
|
||||||
* - Larger touch targets
|
|
||||||
* - Scrollable content
|
|
||||||
* - Modern rounded design
|
|
||||||
*/
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun BeautifulPersonInfoDialog(
|
|
||||||
onDismiss: () -> Unit,
|
|
||||||
onConfirm: (name: String, dateOfBirth: Long?, relationship: String) -> Unit
|
|
||||||
) {
|
|
||||||
var name by remember { mutableStateOf("") }
|
|
||||||
var dateOfBirth by remember { mutableStateOf<Long?>(null) }
|
|
||||||
var selectedRelationship by remember { mutableStateOf("Other") }
|
|
||||||
var showDatePicker by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
val relationships = listOf(
|
|
||||||
"Family" to "👨👩👧👦",
|
|
||||||
"Friend" to "🤝",
|
|
||||||
"Partner" to "❤️",
|
|
||||||
"Parent" to "👪",
|
|
||||||
"Sibling" to "👫",
|
|
||||||
"Colleague" to "💼"
|
|
||||||
)
|
|
||||||
|
|
||||||
Dialog(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
properties = DialogProperties(usePlatformDefaultWidth = false)
|
|
||||||
) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(0.92f)
|
|
||||||
.fillMaxHeight(0.85f),
|
|
||||||
shape = RoundedCornerShape(28.dp),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surface
|
|
||||||
),
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 8.dp)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxSize()
|
|
||||||
) {
|
|
||||||
// Header with icon and close button
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(24.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Surface(
|
|
||||||
shape = RoundedCornerShape(16.dp),
|
|
||||||
color = MaterialTheme.colorScheme.primaryContainer,
|
|
||||||
modifier = Modifier.size(64.dp)
|
|
||||||
) {
|
|
||||||
Box(contentAlignment = Alignment.Center) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Person,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(36.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Column {
|
|
||||||
Text(
|
|
||||||
"Person Details",
|
|
||||||
style = MaterialTheme.typography.headlineMedium,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"Help us organize your photos",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IconButton(onClick = onDismiss) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Close,
|
|
||||||
contentDescription = "Close",
|
|
||||||
modifier = Modifier.size(24.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant)
|
|
||||||
|
|
||||||
// Scrollable content
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.verticalScroll(rememberScrollState())
|
|
||||||
.padding(24.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(24.dp)
|
|
||||||
) {
|
|
||||||
// Name field
|
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
||||||
Text(
|
|
||||||
"Name *",
|
|
||||||
style = MaterialTheme.typography.titleSmall,
|
|
||||||
fontWeight = FontWeight.SemiBold,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
OutlinedTextField(
|
|
||||||
value = name,
|
|
||||||
onValueChange = { name = it },
|
|
||||||
placeholder = { Text("e.g., John Doe") },
|
|
||||||
leadingIcon = {
|
|
||||||
Icon(Icons.Default.Face, contentDescription = null)
|
|
||||||
},
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
singleLine = true,
|
|
||||||
shape = RoundedCornerShape(16.dp),
|
|
||||||
keyboardOptions = androidx.compose.foundation.text.KeyboardOptions(
|
|
||||||
capitalization = KeyboardCapitalization.Words
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Birthday (Optional)
|
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
||||||
Text(
|
|
||||||
"Birthday (Optional)",
|
|
||||||
style = MaterialTheme.typography.titleSmall,
|
|
||||||
fontWeight = FontWeight.SemiBold
|
|
||||||
)
|
|
||||||
OutlinedButton(
|
|
||||||
onClick = { showDatePicker = true },
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(56.dp),
|
|
||||||
shape = RoundedCornerShape(16.dp),
|
|
||||||
colors = ButtonDefaults.outlinedButtonColors(
|
|
||||||
containerColor = if (dateOfBirth != null)
|
|
||||||
MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f)
|
|
||||||
else
|
|
||||||
MaterialTheme.colorScheme.surface
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Cake,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(24.dp)
|
|
||||||
)
|
|
||||||
Spacer(Modifier.width(12.dp))
|
|
||||||
Text(
|
|
||||||
if (dateOfBirth != null) {
|
|
||||||
formatDate(dateOfBirth!!)
|
|
||||||
} else {
|
|
||||||
"Select Birthday"
|
|
||||||
},
|
|
||||||
style = MaterialTheme.typography.bodyLarge
|
|
||||||
)
|
|
||||||
Spacer(Modifier.weight(1f))
|
|
||||||
if (dateOfBirth != null) {
|
|
||||||
IconButton(
|
|
||||||
onClick = { dateOfBirth = null },
|
|
||||||
modifier = Modifier.size(24.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Clear,
|
|
||||||
contentDescription = "Clear",
|
|
||||||
modifier = Modifier.size(18.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Relationship
|
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
|
||||||
Text(
|
|
||||||
"Relationship",
|
|
||||||
style = MaterialTheme.typography.titleSmall,
|
|
||||||
fontWeight = FontWeight.SemiBold
|
|
||||||
)
|
|
||||||
|
|
||||||
// 3 columns grid for relationship chips
|
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
||||||
relationships.chunked(3).forEach { rowChips ->
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
rowChips.forEach { (rel, emoji) ->
|
|
||||||
FilterChip(
|
|
||||||
selected = selectedRelationship == rel,
|
|
||||||
onClick = { selectedRelationship = rel },
|
|
||||||
label = {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(emoji, style = MaterialTheme.typography.titleMedium)
|
|
||||||
Text(rel)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
shape = RoundedCornerShape(12.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// Fill empty space if less than 3 chips
|
|
||||||
repeat(3 - rowChips.size) {
|
|
||||||
Spacer(Modifier.weight(1f))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// "Other" option
|
|
||||||
FilterChip(
|
|
||||||
selected = selectedRelationship == "Other",
|
|
||||||
onClick = { selectedRelationship = "Other" },
|
|
||||||
label = {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text("👤", style = MaterialTheme.typography.titleMedium)
|
|
||||||
Text("Other")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
shape = RoundedCornerShape(12.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Privacy note
|
|
||||||
Card(
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f)
|
|
||||||
),
|
|
||||||
shape = RoundedCornerShape(16.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Lock,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
Column {
|
|
||||||
Text(
|
|
||||||
"Privacy First",
|
|
||||||
style = MaterialTheme.typography.titleSmall,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"All data stays on your device",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant)
|
|
||||||
|
|
||||||
// Action buttons
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(24.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
OutlinedButton(
|
|
||||||
onClick = onDismiss,
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.height(56.dp),
|
|
||||||
shape = RoundedCornerShape(16.dp)
|
|
||||||
) {
|
|
||||||
Text("Cancel", style = MaterialTheme.typography.titleMedium)
|
|
||||||
}
|
|
||||||
|
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
if (name.isNotBlank()) {
|
|
||||||
onConfirm(name.trim(), dateOfBirth, selectedRelationship)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enabled = name.isNotBlank(),
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.height(56.dp),
|
|
||||||
shape = RoundedCornerShape(16.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.ArrowForward,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(20.dp)
|
|
||||||
)
|
|
||||||
Spacer(Modifier.width(8.dp))
|
|
||||||
Text("Continue", style = MaterialTheme.typography.titleMedium)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Date picker dialog
|
|
||||||
if (showDatePicker) {
|
|
||||||
DatePickerDialog(
|
|
||||||
onDismissRequest = { showDatePicker = false },
|
|
||||||
confirmButton = {
|
|
||||||
TextButton(
|
|
||||||
onClick = {
|
|
||||||
dateOfBirth = System.currentTimeMillis()
|
|
||||||
showDatePicker = false
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Text("OK")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
dismissButton = {
|
|
||||||
TextButton(onClick = { showDatePicker = false }) {
|
|
||||||
Text("Cancel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
DatePicker(
|
|
||||||
state = rememberDatePickerState(),
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun formatDate(timestamp: Long): String {
|
|
||||||
val formatter = SimpleDateFormat("MMMM dd, yyyy", Locale.getDefault())
|
|
||||||
return formatter.format(Date(timestamp))
|
|
||||||
}
|
|
||||||
@@ -5,105 +5,65 @@ import android.graphics.BitmapFactory
|
|||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Canvas
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.*
|
import androidx.compose.material.icons.filled.CheckCircle
|
||||||
|
import androidx.compose.material.icons.filled.Close
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
|
import androidx.compose.ui.geometry.Size
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.asImageBitmap
|
import androidx.compose.ui.graphics.asImageBitmap
|
||||||
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import com.google.mlkit.vision.common.InputImage
|
import coil.compose.AsyncImage
|
||||||
import com.google.mlkit.vision.face.FaceDetection
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import com.google.mlkit.vision.face.FaceDetectorOptions
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.tasks.await
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MINIMAL FacePickerDialog - Optimized for batch processing 30-50 photos
|
* Dialog for selecting a face from multiple detected faces
|
||||||
*
|
|
||||||
* REMOVED CLUTTER:
|
|
||||||
* - "Preview (tap to select)" header
|
|
||||||
* - "Face will be used for training" info box
|
|
||||||
* - "Face #" labels covering previews
|
|
||||||
* - Original image preview
|
|
||||||
*
|
|
||||||
* IMPROVED:
|
|
||||||
* - Larger face previews (1:1 aspect ratio)
|
|
||||||
* - Clean checkmark overlay only
|
|
||||||
* - Minimal text
|
|
||||||
* - Fast workflow
|
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun FacePickerDialog(
|
fun FacePickerDialog(
|
||||||
result: FaceDetectionHelper.FaceDetectionResult,
|
result: FaceDetectionHelper.FaceDetectionResult,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onFaceSelected: (Int, Bitmap) -> Unit
|
onFaceSelected: (Int, Bitmap) -> Unit // faceIndex, croppedFaceBitmap
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
var selectedFaceIndex by remember { mutableStateOf(0) }
|
var selectedFaceIndex by remember { mutableStateOf<Int?>(null) }
|
||||||
var croppedFaces by remember { mutableStateOf<List<Bitmap>>(emptyList()) }
|
var croppedFaces by remember { mutableStateOf<List<Bitmap>>(emptyList()) }
|
||||||
var isLoading by remember { mutableStateOf(true) }
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
var errorMessage by remember { mutableStateOf<String?>(null) }
|
|
||||||
|
|
||||||
// Load and crop all faces - RE-DETECT to get accurate bounds
|
// Load and crop all faces
|
||||||
LaunchedEffect(result) {
|
LaunchedEffect(result) {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
errorMessage = null
|
|
||||||
|
|
||||||
try {
|
|
||||||
croppedFaces = withContext(Dispatchers.IO) {
|
croppedFaces = withContext(Dispatchers.IO) {
|
||||||
// Load the FULL resolution bitmap (no downsampling)
|
val bitmap = loadBitmapFromUri(context, result.uri)
|
||||||
val fullBitmap = loadFullResolutionBitmap(context, result.uri)
|
bitmap?.let { bmp ->
|
||||||
|
result.faceBounds.map { bounds ->
|
||||||
if (fullBitmap == null) {
|
cropFaceFromBitmap(bmp, bounds)
|
||||||
errorMessage = "Failed to load image"
|
|
||||||
return@withContext emptyList()
|
|
||||||
}
|
}
|
||||||
|
} ?: emptyList()
|
||||||
// Re-detect faces on the full resolution bitmap to get accurate bounds
|
|
||||||
val accurateFaceBounds = detectFacesOnBitmap(fullBitmap)
|
|
||||||
|
|
||||||
if (accurateFaceBounds.isEmpty()) {
|
|
||||||
// Fallback: try to use the original bounds with scaling
|
|
||||||
val scaledBounds = result.faceBounds.map { originalBounds ->
|
|
||||||
cropFaceFromBitmap(fullBitmap, originalBounds)
|
|
||||||
}
|
}
|
||||||
fullBitmap.recycle()
|
|
||||||
return@withContext scaledBounds
|
|
||||||
}
|
|
||||||
|
|
||||||
// Crop faces using accurate bounds
|
|
||||||
val croppedList = accurateFaceBounds.map { bounds ->
|
|
||||||
cropFaceFromBitmap(fullBitmap, bounds)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CRITICAL: Recycle AFTER all cropping is done
|
|
||||||
fullBitmap.recycle()
|
|
||||||
|
|
||||||
croppedList
|
|
||||||
}
|
|
||||||
|
|
||||||
if (croppedFaces.isEmpty() && errorMessage == null) {
|
|
||||||
errorMessage = "No faces found in full resolution image"
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
errorMessage = "Error processing faces: ${e.message}"
|
|
||||||
} finally {
|
|
||||||
isLoading = false
|
isLoading = false
|
||||||
|
// Auto-select the first (largest) face
|
||||||
|
if (croppedFaces.isNotEmpty()) {
|
||||||
|
selectedFaceIndex = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,62 +73,96 @@ fun FacePickerDialog(
|
|||||||
) {
|
) {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth(0.92f)
|
.fillMaxWidth(0.95f)
|
||||||
.wrapContentHeight(),
|
.fillMaxHeight(0.9f),
|
||||||
shape = RoundedCornerShape(20.dp),
|
shape = RoundedCornerShape(16.dp)
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surface
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxSize()
|
||||||
.padding(20.dp),
|
.padding(20.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
// Minimal header - just close button
|
// Header
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
|
Column {
|
||||||
Text(
|
Text(
|
||||||
text = "${result.faceCount} faces",
|
text = "Pick a Face",
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.headlineSmall,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
|
Text(
|
||||||
|
text = "${result.faceCount} faces detected",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
IconButton(onClick = onDismiss) {
|
IconButton(onClick = onDismiss) {
|
||||||
Icon(Icons.Default.Close, contentDescription = "Close")
|
Icon(Icons.Default.Close, "Close")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instruction
|
||||||
|
Text(
|
||||||
|
text = "Tap a face below to select it for training:",
|
||||||
|
style = MaterialTheme.typography.bodyMedium
|
||||||
|
)
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
// Loading state - minimal
|
// Loading state
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(180.dp),
|
.weight(1f),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
CircularProgressIndicator()
|
CircularProgressIndicator()
|
||||||
}
|
}
|
||||||
} else if (errorMessage != null) {
|
|
||||||
// Error state - minimal
|
|
||||||
Text(
|
|
||||||
text = errorMessage!!,
|
|
||||||
color = MaterialTheme.colorScheme.error,
|
|
||||||
style = MaterialTheme.typography.bodyMedium
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
// CLEAN face grid - NO labels, NO text
|
// Original image with face boxes overlay
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.weight(1f),
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
FaceOverlayImage(
|
||||||
|
imageUri = result.uri,
|
||||||
|
faceBounds = result.faceBounds,
|
||||||
|
selectedFaceIndex = selectedFaceIndex,
|
||||||
|
onFaceClick = { index ->
|
||||||
|
selectedFaceIndex = index
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Face previews grid
|
||||||
|
Text(
|
||||||
|
text = "Preview (tap to select):",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
fontWeight = FontWeight.SemiBold
|
||||||
|
)
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.spacedBy(10.dp)
|
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
) {
|
) {
|
||||||
croppedFaces.forEachIndexed { index, faceBitmap ->
|
croppedFaces.forEachIndexed { index, faceBitmap ->
|
||||||
CleanFaceCard(
|
FacePreviewCard(
|
||||||
faceBitmap = faceBitmap,
|
faceBitmap = faceBitmap,
|
||||||
|
index = index,
|
||||||
isSelected = selectedFaceIndex == index,
|
isSelected = selectedFaceIndex == index,
|
||||||
onClick = { selectedFaceIndex = index },
|
onClick = { selectedFaceIndex = index },
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f)
|
||||||
@@ -177,34 +171,32 @@ fun FacePickerDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action buttons - minimal
|
// Action buttons
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.spacedBy(10.dp)
|
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
) {
|
) {
|
||||||
TextButton(
|
OutlinedButton(
|
||||||
onClick = onDismiss,
|
onClick = onDismiss,
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f)
|
||||||
) {
|
) {
|
||||||
Text("Skip")
|
Text("Cancel")
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
if (selectedFaceIndex < croppedFaces.size) {
|
selectedFaceIndex?.let { index ->
|
||||||
onFaceSelected(selectedFaceIndex, croppedFaces[selectedFaceIndex])
|
if (index < croppedFaces.size) {
|
||||||
|
onFaceSelected(index, croppedFaces[index])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enabled = !isLoading && croppedFaces.isNotEmpty(),
|
modifier = Modifier.weight(1f),
|
||||||
modifier = Modifier.weight(1f)
|
enabled = selectedFaceIndex != null && !isLoading
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(Icons.Default.CheckCircle, contentDescription = null)
|
||||||
Icons.Default.Check,
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
contentDescription = null,
|
Text("Use This Face")
|
||||||
modifier = Modifier.size(18.dp)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(6.dp))
|
|
||||||
Text("Use")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,75 +205,204 @@ fun FacePickerDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ULTRA-CLEAN face card - NO TEXT, just image + checkmark
|
* Image with interactive face boxes overlay
|
||||||
*
|
|
||||||
* CHANGES:
|
|
||||||
* - 1:1 aspect ratio (bigger!)
|
|
||||||
* - NO "Face #" label
|
|
||||||
* - Checkmark in corner only
|
|
||||||
* - Minimal border
|
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun CleanFaceCard(
|
private fun FaceOverlayImage(
|
||||||
|
imageUri: Uri,
|
||||||
|
faceBounds: List<Rect>,
|
||||||
|
selectedFaceIndex: Int?,
|
||||||
|
onFaceClick: (Int) -> Unit
|
||||||
|
) {
|
||||||
|
var imageSize by remember { mutableStateOf(Size.Zero) }
|
||||||
|
var imageBounds by remember { mutableStateOf(Rect()) }
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.fillMaxSize()
|
||||||
|
) {
|
||||||
|
// Original image
|
||||||
|
AsyncImage(
|
||||||
|
model = imageUri,
|
||||||
|
contentDescription = "Original image",
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(8.dp),
|
||||||
|
contentScale = ContentScale.Fit,
|
||||||
|
onSuccess = { state ->
|
||||||
|
val drawable = state.result.drawable
|
||||||
|
imageBounds = Rect(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Face boxes overlay
|
||||||
|
Canvas(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(8.dp)
|
||||||
|
) {
|
||||||
|
if (imageBounds.width() > 0 && imageBounds.height() > 0) {
|
||||||
|
// Calculate scale to fit image in canvas
|
||||||
|
val scaleX = size.width / imageBounds.width()
|
||||||
|
val scaleY = size.height / imageBounds.height()
|
||||||
|
val scale = minOf(scaleX, scaleY)
|
||||||
|
|
||||||
|
// Calculate offset to center image
|
||||||
|
val scaledWidth = imageBounds.width() * scale
|
||||||
|
val scaledHeight = imageBounds.height() * scale
|
||||||
|
val offsetX = (size.width - scaledWidth) / 2
|
||||||
|
val offsetY = (size.height - scaledHeight) / 2
|
||||||
|
|
||||||
|
faceBounds.forEachIndexed { index, bounds ->
|
||||||
|
val isSelected = selectedFaceIndex == index
|
||||||
|
|
||||||
|
// Scale and position the face box
|
||||||
|
val left = bounds.left * scale + offsetX
|
||||||
|
val top = bounds.top * scale + offsetY
|
||||||
|
val width = bounds.width() * scale
|
||||||
|
val height = bounds.height() * scale
|
||||||
|
|
||||||
|
// Draw box
|
||||||
|
drawRect(
|
||||||
|
color = if (isSelected) Color(0xFF4CAF50) else Color(0xFF2196F3),
|
||||||
|
topLeft = Offset(left, top),
|
||||||
|
size = Size(width, height),
|
||||||
|
style = Stroke(width = if (isSelected) 6f else 4f)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Draw semi-transparent fill for selected
|
||||||
|
if (isSelected) {
|
||||||
|
drawRect(
|
||||||
|
color = Color(0xFF4CAF50).copy(alpha = 0.2f),
|
||||||
|
topLeft = Offset(left, top),
|
||||||
|
size = Size(width, height)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw face number label
|
||||||
|
drawCircle(
|
||||||
|
color = if (isSelected) Color(0xFF4CAF50) else Color(0xFF2196F3),
|
||||||
|
radius = 20f * scale,
|
||||||
|
center = Offset(left + 20f * scale, top + 20f * scale)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clickable areas for each face
|
||||||
|
faceBounds.forEachIndexed { index, bounds ->
|
||||||
|
if (imageBounds.width() > 0 && imageBounds.height() > 0) {
|
||||||
|
val scaleX = imageSize.width / imageBounds.width()
|
||||||
|
val scaleY = imageSize.height / imageBounds.height()
|
||||||
|
val scale = minOf(scaleX, scaleY)
|
||||||
|
|
||||||
|
val scaledWidth = imageBounds.width() * scale
|
||||||
|
val scaledHeight = imageBounds.height() * scale
|
||||||
|
val offsetX = (imageSize.width - scaledWidth) / 2
|
||||||
|
val offsetY = (imageSize.height - scaledHeight) / 2
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.clickable { onFaceClick(index) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update image size
|
||||||
|
BoxWithConstraints {
|
||||||
|
LaunchedEffect(constraints) {
|
||||||
|
imageSize = Size(constraints.maxWidth.toFloat(), constraints.maxHeight.toFloat())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Individual face preview card
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
private fun FacePreviewCard(
|
||||||
faceBitmap: Bitmap,
|
faceBitmap: Bitmap,
|
||||||
|
index: Int,
|
||||||
isSelected: Boolean,
|
isSelected: Boolean,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
Card(
|
Card(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.aspectRatio(1f) // SQUARE = bigger previews!
|
.aspectRatio(1f)
|
||||||
.clickable(onClick = onClick),
|
.clickable(onClick = onClick),
|
||||||
colors = CardDefaults.cardColors(
|
colors = CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
containerColor = if (isSelected)
|
||||||
|
MaterialTheme.colorScheme.primaryContainer
|
||||||
|
else
|
||||||
|
MaterialTheme.colorScheme.surface
|
||||||
),
|
),
|
||||||
border = if (isSelected)
|
border = if (isSelected)
|
||||||
BorderStroke(3.dp, MaterialTheme.colorScheme.primary)
|
BorderStroke(3.dp, MaterialTheme.colorScheme.primary)
|
||||||
else
|
else
|
||||||
BorderStroke(1.dp, MaterialTheme.colorScheme.outline.copy(alpha = 0.3f)),
|
BorderStroke(1.dp, MaterialTheme.colorScheme.outline)
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
elevation = CardDefaults.cardElevation(
|
|
||||||
defaultElevation = if (isSelected) 4.dp else 1.dp
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
Box(
|
||||||
// Face image - FULL SIZE
|
modifier = Modifier.fillMaxSize()
|
||||||
Image(
|
) {
|
||||||
|
androidx.compose.foundation.Image(
|
||||||
bitmap = faceBitmap.asImageBitmap(),
|
bitmap = faceBitmap.asImageBitmap(),
|
||||||
contentDescription = null,
|
contentDescription = "Face ${index + 1}",
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
contentScale = ContentScale.Crop
|
contentScale = ContentScale.Crop
|
||||||
)
|
)
|
||||||
|
|
||||||
// Checkmark in corner - ONLY if selected
|
// Selected checkmark (only show when selected)
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.TopEnd)
|
.align(Alignment.Center),
|
||||||
.padding(6.dp)
|
|
||||||
.size(32.dp),
|
|
||||||
shape = CircleShape,
|
shape = CircleShape,
|
||||||
color = MaterialTheme.colorScheme.primary,
|
color = MaterialTheme.colorScheme.primary.copy(alpha = 0.9f)
|
||||||
shadowElevation = 4.dp
|
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.CheckCircle,
|
Icons.Default.CheckCircle,
|
||||||
contentDescription = "Selected",
|
contentDescription = "Selected",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(6.dp)
|
.padding(12.dp)
|
||||||
.size(20.dp),
|
.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.onPrimary
|
tint = MaterialTheme.colorScheme.onPrimary
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Face number badge (always in top-right, small)
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier
|
||||||
|
.align(Alignment.TopEnd)
|
||||||
|
.padding(4.dp),
|
||||||
|
shape = CircleShape,
|
||||||
|
color = if (isSelected)
|
||||||
|
MaterialTheme.colorScheme.primary
|
||||||
|
else
|
||||||
|
MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.9f),
|
||||||
|
shadowElevation = 2.dp
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "${index + 1}",
|
||||||
|
modifier = Modifier.padding(6.dp),
|
||||||
|
style = MaterialTheme.typography.labelSmall,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = if (isSelected)
|
||||||
|
MaterialTheme.colorScheme.onPrimary
|
||||||
|
else
|
||||||
|
MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load full resolution bitmap WITHOUT downsampling
|
* Helper function to load bitmap from URI
|
||||||
*/
|
*/
|
||||||
private suspend fun loadFullResolutionBitmap(
|
private suspend fun loadBitmapFromUri(
|
||||||
context: android.content.Context,
|
context: android.content.Context,
|
||||||
uri: Uri
|
uri: Uri
|
||||||
): Bitmap? = withContext(Dispatchers.IO) {
|
): Bitmap? = withContext(Dispatchers.IO) {
|
||||||
@@ -296,33 +417,7 @@ private suspend fun loadFullResolutionBitmap(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-detect faces on full resolution bitmap to get accurate bounds
|
* Helper function to crop face from bitmap
|
||||||
*/
|
|
||||||
private suspend fun detectFacesOnBitmap(bitmap: Bitmap): List<Rect> = withContext(Dispatchers.Default) {
|
|
||||||
try {
|
|
||||||
val options = FaceDetectorOptions.Builder()
|
|
||||||
.setPerformanceMode(FaceDetectorOptions.PERFORMANCE_MODE_ACCURATE)
|
|
||||||
.setLandmarkMode(FaceDetectorOptions.LANDMARK_MODE_NONE)
|
|
||||||
.setClassificationMode(FaceDetectorOptions.CLASSIFICATION_MODE_NONE)
|
|
||||||
.setMinFaceSize(0.10f)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
val detector = FaceDetection.getClient(options)
|
|
||||||
val image = InputImage.fromBitmap(bitmap, 0)
|
|
||||||
val faces = detector.process(image).await()
|
|
||||||
|
|
||||||
// Sort by size (largest first)
|
|
||||||
faces.sortedByDescending { face ->
|
|
||||||
face.boundingBox.width() * face.boundingBox.height()
|
|
||||||
}.map { it.boundingBox }
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crop face from bitmap with padding
|
|
||||||
*/
|
*/
|
||||||
private fun cropFaceFromBitmap(bitmap: Bitmap, faceBounds: Rect): Bitmap {
|
private fun cropFaceFromBitmap(bitmap: Bitmap, faceBounds: Rect): Bitmap {
|
||||||
// Add 20% padding around the face
|
// Add 20% padding around the face
|
||||||
|
|||||||
@@ -8,29 +8,19 @@ import android.net.Uri
|
|||||||
import com.google.mlkit.vision.common.InputImage
|
import com.google.mlkit.vision.common.InputImage
|
||||||
import com.google.mlkit.vision.face.FaceDetection
|
import com.google.mlkit.vision.face.FaceDetection
|
||||||
import com.google.mlkit.vision.face.FaceDetectorOptions
|
import com.google.mlkit.vision.face.FaceDetectorOptions
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.awaitAll
|
|
||||||
import kotlinx.coroutines.coroutineScope
|
|
||||||
import kotlinx.coroutines.tasks.await
|
import kotlinx.coroutines.tasks.await
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXED FaceDetectionHelper with parallel processing
|
* Helper class for detecting faces in images using ML Kit Face Detection
|
||||||
*
|
|
||||||
* FIXES:
|
|
||||||
* - Removed bitmap.recycle() that broke face cropping
|
|
||||||
* - Proper memory management with downsampling
|
|
||||||
* - Parallel processing for speed
|
|
||||||
*/
|
*/
|
||||||
class FaceDetectionHelper(private val context: Context) {
|
class FaceDetectionHelper(private val context: Context) {
|
||||||
|
|
||||||
private val faceDetectorOptions = FaceDetectorOptions.Builder()
|
private val faceDetectorOptions = FaceDetectorOptions.Builder()
|
||||||
.setPerformanceMode(FaceDetectorOptions.PERFORMANCE_MODE_ACCURATE) // ACCURATE for quality
|
.setPerformanceMode(FaceDetectorOptions.PERFORMANCE_MODE_ACCURATE)
|
||||||
.setLandmarkMode(FaceDetectorOptions.LANDMARK_MODE_ALL)
|
.setLandmarkMode(FaceDetectorOptions.LANDMARK_MODE_ALL)
|
||||||
.setClassificationMode(FaceDetectorOptions.CLASSIFICATION_MODE_ALL)
|
.setClassificationMode(FaceDetectorOptions.CLASSIFICATION_MODE_ALL)
|
||||||
.setMinFaceSize(0.15f)
|
.setMinFaceSize(0.15f) // Detect faces that are at least 15% of image
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
private val detector = FaceDetection.getClient(faceDetectorOptions)
|
private val detector = FaceDetection.getClient(faceDetectorOptions)
|
||||||
@@ -40,7 +30,7 @@ class FaceDetectionHelper(private val context: Context) {
|
|||||||
val hasFace: Boolean,
|
val hasFace: Boolean,
|
||||||
val faceCount: Int,
|
val faceCount: Int,
|
||||||
val faceBounds: List<Rect> = emptyList(),
|
val faceBounds: List<Rect> = emptyList(),
|
||||||
val croppedFaceBitmap: Bitmap? = null, // Only largest face
|
val croppedFaceBitmap: Bitmap? = null,
|
||||||
val errorMessage: String? = null
|
val errorMessage: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -48,12 +38,10 @@ class FaceDetectionHelper(private val context: Context) {
|
|||||||
* Detect faces in a single image
|
* Detect faces in a single image
|
||||||
*/
|
*/
|
||||||
suspend fun detectFacesInImage(uri: Uri): FaceDetectionResult {
|
suspend fun detectFacesInImage(uri: Uri): FaceDetectionResult {
|
||||||
return withContext(Dispatchers.IO) {
|
return try {
|
||||||
var bitmap: Bitmap? = null
|
val bitmap = loadBitmap(uri)
|
||||||
try {
|
|
||||||
bitmap = loadBitmap(uri)
|
|
||||||
if (bitmap == null) {
|
if (bitmap == null) {
|
||||||
return@withContext FaceDetectionResult(
|
return FaceDetectionResult(
|
||||||
uri = uri,
|
uri = uri,
|
||||||
hasFace = false,
|
hasFace = false,
|
||||||
faceCount = 0,
|
faceCount = 0,
|
||||||
@@ -64,14 +52,9 @@ class FaceDetectionHelper(private val context: Context) {
|
|||||||
val inputImage = InputImage.fromBitmap(bitmap, 0)
|
val inputImage = InputImage.fromBitmap(bitmap, 0)
|
||||||
val faces = detector.process(inputImage).await()
|
val faces = detector.process(inputImage).await()
|
||||||
|
|
||||||
// Sort by face size (area) to get the largest face
|
val croppedFace = if (faces.isNotEmpty()) {
|
||||||
val sortedFaces = faces.sortedByDescending { face ->
|
// Crop the first detected face with some padding
|
||||||
face.boundingBox.width() * face.boundingBox.height()
|
cropFaceFromBitmap(bitmap, faces[0].boundingBox)
|
||||||
}
|
|
||||||
|
|
||||||
val croppedFace = if (sortedFaces.isNotEmpty()) {
|
|
||||||
// Crop the LARGEST detected face (most likely the subject)
|
|
||||||
cropFaceFromBitmap(bitmap, sortedFaces[0].boundingBox)
|
|
||||||
} else null
|
} else null
|
||||||
|
|
||||||
FaceDetectionResult(
|
FaceDetectionResult(
|
||||||
@@ -88,37 +71,15 @@ class FaceDetectionHelper(private val context: Context) {
|
|||||||
faceCount = 0,
|
faceCount = 0,
|
||||||
errorMessage = e.message ?: "Unknown error"
|
errorMessage = e.message ?: "Unknown error"
|
||||||
)
|
)
|
||||||
} finally {
|
|
||||||
// NOW we can recycle after we're completely done
|
|
||||||
bitmap?.recycle()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PARALLEL face detection in multiple images - 10x FASTER!
|
* Detect faces in multiple images
|
||||||
*
|
|
||||||
* @param onProgress Callback with (current, total)
|
|
||||||
*/
|
*/
|
||||||
suspend fun detectFacesInImages(
|
suspend fun detectFacesInImages(uris: List<Uri>): List<FaceDetectionResult> {
|
||||||
uris: List<Uri>,
|
return uris.map { uri ->
|
||||||
onProgress: ((Int, Int) -> Unit)? = null
|
detectFacesInImage(uri)
|
||||||
): List<FaceDetectionResult> = coroutineScope {
|
|
||||||
val total = uris.size
|
|
||||||
var completed = 0
|
|
||||||
|
|
||||||
// Process in parallel batches of 5 to avoid overwhelming the system
|
|
||||||
uris.chunked(5).flatMap { batch ->
|
|
||||||
batch.map { uri ->
|
|
||||||
async(Dispatchers.IO) {
|
|
||||||
val result = detectFacesInImage(uri)
|
|
||||||
synchronized(this@FaceDetectionHelper) {
|
|
||||||
completed++
|
|
||||||
onProgress?.invoke(completed, total)
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}.awaitAll()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,35 +102,13 @@ class FaceDetectionHelper(private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load bitmap from URI with downsampling for memory efficiency
|
* Load bitmap from URI
|
||||||
*/
|
*/
|
||||||
private fun loadBitmap(uri: Uri): Bitmap? {
|
private fun loadBitmap(uri: Uri): Bitmap? {
|
||||||
return try {
|
return try {
|
||||||
val inputStream: InputStream? = context.contentResolver.openInputStream(uri)
|
val inputStream: InputStream? = context.contentResolver.openInputStream(uri)
|
||||||
|
BitmapFactory.decodeStream(inputStream)?.also {
|
||||||
// First decode with inJustDecodeBounds to get dimensions
|
|
||||||
val options = BitmapFactory.Options().apply {
|
|
||||||
inJustDecodeBounds = true
|
|
||||||
}
|
|
||||||
BitmapFactory.decodeStream(inputStream, null, options)
|
|
||||||
inputStream?.close()
|
inputStream?.close()
|
||||||
|
|
||||||
// Calculate sample size to limit max dimension to 1024px
|
|
||||||
val maxDimension = 1024
|
|
||||||
var sampleSize = 1
|
|
||||||
while (options.outWidth / sampleSize > maxDimension ||
|
|
||||||
options.outHeight / sampleSize > maxDimension) {
|
|
||||||
sampleSize *= 2
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now decode with sample size
|
|
||||||
val inputStream2 = context.contentResolver.openInputStream(uri)
|
|
||||||
val finalOptions = BitmapFactory.Options().apply {
|
|
||||||
inSampleSize = sampleSize
|
|
||||||
}
|
|
||||||
|
|
||||||
BitmapFactory.decodeStream(inputStream2, null, finalOptions)?.also {
|
|
||||||
inputStream2?.close()
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -4,28 +4,32 @@ import android.net.Uri
|
|||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.verticalScroll
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.*
|
import androidx.compose.material.icons.filled.*
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FIXED ImageSelectorScreen
|
* Enhanced ImageSelectorScreen
|
||||||
*
|
*
|
||||||
* Fixes:
|
* Changes:
|
||||||
* - Added verticalScroll to Column for proper scrolling
|
* - NO LIMIT on photo count (was 10)
|
||||||
* - Buttons are now always accessible via scroll
|
* - Recommends 20-30 photos
|
||||||
* - Better spacing and padding
|
* - Real-time progress feedback
|
||||||
* - Cleaner layout structure
|
* - Quality indicators
|
||||||
|
* - Training tips
|
||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -33,7 +37,6 @@ fun ImageSelectorScreen(
|
|||||||
onImagesSelected: (List<Uri>) -> Unit
|
onImagesSelected: (List<Uri>) -> Unit
|
||||||
) {
|
) {
|
||||||
var selectedImages by remember { mutableStateOf<List<Uri>>(emptyList()) }
|
var selectedImages by remember { mutableStateOf<List<Uri>>(emptyList()) }
|
||||||
val scrollState = rememberScrollState()
|
|
||||||
|
|
||||||
val photoPicker = rememberLauncherForActivityResult(
|
val photoPicker = rememberLauncherForActivityResult(
|
||||||
contract = ActivityResultContracts.GetMultipleContents()
|
contract = ActivityResultContracts.GetMultipleContents()
|
||||||
@@ -57,7 +60,6 @@ fun ImageSelectorScreen(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(paddingValues)
|
.padding(paddingValues)
|
||||||
.verticalScroll(scrollState) // FIXED: Added scrolling
|
|
||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
@@ -122,6 +124,8 @@ fun ImageSelectorScreen(
|
|||||||
ProgressCard(selectedImages.size)
|
ProgressCard(selectedImages.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer(Modifier.weight(1f))
|
||||||
|
|
||||||
// Select photos button
|
// Select photos button
|
||||||
Button(
|
Button(
|
||||||
onClick = { photoPicker.launch("image/*") },
|
onClick = { photoPicker.launch("image/*") },
|
||||||
@@ -143,7 +147,7 @@ fun ImageSelectorScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue button - FIXED: Always visible via scroll
|
// Continue button
|
||||||
AnimatedVisibility(selectedImages.size >= 15) {
|
AnimatedVisibility(selectedImages.size >= 15) {
|
||||||
Button(
|
Button(
|
||||||
onClick = { onImagesSelected(selectedImages) },
|
onClick = { onImagesSelected(selectedImages) },
|
||||||
@@ -196,9 +200,6 @@ fun ImageSelectorScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bottom spacing to ensure last item is visible
|
|
||||||
Spacer(Modifier.height(32.dp))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,231 +0,0 @@
|
|||||||
package com.placeholder.sherpai2.ui.trainingprep
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.*
|
|
||||||
import androidx.compose.material3.*
|
|
||||||
import androidx.compose.runtime.*
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
|
||||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
|
|
||||||
/**
|
|
||||||
* IMPROVED NameInputDialog - Better centered, cleaner layout
|
|
||||||
*
|
|
||||||
* Fixes:
|
|
||||||
* - Centered dialog with proper constraints
|
|
||||||
* - Better spacing and padding
|
|
||||||
* - Clearer visual hierarchy
|
|
||||||
* - Improved error state handling
|
|
||||||
*/
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun ImprovedNameInputDialog(
|
|
||||||
onDismiss: () -> Unit,
|
|
||||||
onConfirm: (String) -> Unit,
|
|
||||||
trainingState: TrainingState
|
|
||||||
) {
|
|
||||||
var personName by remember { mutableStateOf("") }
|
|
||||||
val isError = trainingState is TrainingState.Error
|
|
||||||
val isProcessing = trainingState is TrainingState.Processing
|
|
||||||
|
|
||||||
Dialog(
|
|
||||||
onDismissRequest = {
|
|
||||||
if (!isProcessing) {
|
|
||||||
onDismiss()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(0.9f) // 90% of screen width
|
|
||||||
.wrapContentHeight(),
|
|
||||||
shape = RoundedCornerShape(24.dp),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surface
|
|
||||||
),
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 8.dp)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(24.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(20.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
// Icon
|
|
||||||
Surface(
|
|
||||||
shape = RoundedCornerShape(16.dp),
|
|
||||||
color = if (isError) {
|
|
||||||
MaterialTheme.colorScheme.errorContainer
|
|
||||||
} else {
|
|
||||||
MaterialTheme.colorScheme.primaryContainer
|
|
||||||
},
|
|
||||||
modifier = Modifier.size(72.dp)
|
|
||||||
) {
|
|
||||||
Box(contentAlignment = Alignment.Center) {
|
|
||||||
Icon(
|
|
||||||
if (isError) Icons.Default.Warning else Icons.Default.Face,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(40.dp),
|
|
||||||
tint = if (isError) {
|
|
||||||
MaterialTheme.colorScheme.error
|
|
||||||
} else {
|
|
||||||
MaterialTheme.colorScheme.primary
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Title
|
|
||||||
Text(
|
|
||||||
text = if (isError) "Training Error" else "Who is this?",
|
|
||||||
style = MaterialTheme.typography.headlineSmall,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
|
||||||
)
|
|
||||||
|
|
||||||
// Error message or description
|
|
||||||
if (isError) {
|
|
||||||
val error = trainingState as TrainingState.Error
|
|
||||||
Card(
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.errorContainer
|
|
||||||
),
|
|
||||||
shape = RoundedCornerShape(12.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Error,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = error.message,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onErrorContainer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Text(
|
|
||||||
text = "Enter the name of the person in these training images. This will help you find their photos later.",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Name input field
|
|
||||||
OutlinedTextField(
|
|
||||||
value = personName,
|
|
||||||
onValueChange = { personName = it },
|
|
||||||
label = { Text("Person's Name") },
|
|
||||||
placeholder = { Text("e.g., John Doe") },
|
|
||||||
singleLine = true,
|
|
||||||
enabled = !isProcessing,
|
|
||||||
keyboardOptions = KeyboardOptions(
|
|
||||||
capitalization = KeyboardCapitalization.Words,
|
|
||||||
imeAction = ImeAction.Done
|
|
||||||
),
|
|
||||||
keyboardActions = KeyboardActions(
|
|
||||||
onDone = {
|
|
||||||
if (personName.isNotBlank() && !isProcessing) {
|
|
||||||
onConfirm(personName.trim())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
),
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
colors = OutlinedTextFieldDefaults.colors(
|
|
||||||
focusedBorderColor = MaterialTheme.colorScheme.primary,
|
|
||||||
unfocusedBorderColor = MaterialTheme.colorScheme.outline
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Action buttons
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
// Cancel button
|
|
||||||
if (!isProcessing) {
|
|
||||||
OutlinedButton(
|
|
||||||
onClick = onDismiss,
|
|
||||||
modifier = Modifier.weight(1f),
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
contentPadding = PaddingValues(vertical = 14.dp)
|
|
||||||
) {
|
|
||||||
Text("Cancel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Confirm button
|
|
||||||
Button(
|
|
||||||
onClick = { onConfirm(personName.trim()) },
|
|
||||||
enabled = personName.isNotBlank() && !isProcessing,
|
|
||||||
modifier = Modifier.weight(if (isProcessing) 1f else 1f),
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
contentPadding = PaddingValues(vertical = 14.dp),
|
|
||||||
colors = ButtonDefaults.buttonColors(
|
|
||||||
containerColor = if (isError) {
|
|
||||||
MaterialTheme.colorScheme.error
|
|
||||||
} else {
|
|
||||||
MaterialTheme.colorScheme.primary
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
if (isProcessing) {
|
|
||||||
CircularProgressIndicator(
|
|
||||||
modifier = Modifier.size(20.dp),
|
|
||||||
strokeWidth = 2.dp,
|
|
||||||
color = MaterialTheme.colorScheme.onPrimary
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
|
||||||
Text("Training...")
|
|
||||||
} else {
|
|
||||||
Icon(
|
|
||||||
if (isError) Icons.Default.Refresh else Icons.Default.Check,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(20.dp)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
Text(if (isError) "Try Again" else "Start Training")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Alternative: Use this version in ScanResultsScreen.kt
|
|
||||||
*
|
|
||||||
* Replace the existing NameInputDialog function (lines 154-257) with:
|
|
||||||
*
|
|
||||||
* @Composable
|
|
||||||
* private fun NameInputDialog(
|
|
||||||
* onDismiss: () -> Unit,
|
|
||||||
* onConfirm: (String) -> Unit,
|
|
||||||
* trainingState: TrainingState
|
|
||||||
* ) {
|
|
||||||
* ImprovedNameInputDialog(
|
|
||||||
* onDismiss = onDismiss,
|
|
||||||
* onConfirm = onConfirm,
|
|
||||||
* trainingState = trainingState
|
|
||||||
* )
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
@@ -32,9 +32,6 @@ import androidx.compose.ui.text.style.TextAlign
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import com.placeholder.sherpai2.ui.trainingprep.BeautifulPersonInfoDialog
|
|
||||||
import com.placeholder.sherpai2.ui.trainingprep.FaceDetectionHelper
|
|
||||||
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -98,6 +95,7 @@ fun ScanResultsScreen(
|
|||||||
ImprovedResultsView(
|
ImprovedResultsView(
|
||||||
result = state.sanityCheckResult,
|
result = state.sanityCheckResult,
|
||||||
onContinue = {
|
onContinue = {
|
||||||
|
// Show name input dialog instead of immediately finishing
|
||||||
showNameInputDialog = true
|
showNameInputDialog = true
|
||||||
},
|
},
|
||||||
onRetry = onFinish,
|
onRetry = onFinish,
|
||||||
@@ -106,8 +104,7 @@ fun ScanResultsScreen(
|
|||||||
},
|
},
|
||||||
onSelectFaceFromMultiple = { result ->
|
onSelectFaceFromMultiple = { result ->
|
||||||
showFacePickerDialog = result
|
showFacePickerDialog = result
|
||||||
},
|
}
|
||||||
trainViewModel = trainViewModel
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +125,7 @@ fun ScanResultsScreen(
|
|||||||
|
|
||||||
// Face Picker Dialog
|
// Face Picker Dialog
|
||||||
showFacePickerDialog?.let { result ->
|
showFacePickerDialog?.let { result ->
|
||||||
FacePickerDialog ( // CHANGED
|
FacePickerDialog(
|
||||||
result = result,
|
result = result,
|
||||||
onDismiss = { showFacePickerDialog = null },
|
onDismiss = { showFacePickerDialog = null },
|
||||||
onFaceSelected = { faceIndex, croppedFaceBitmap ->
|
onFaceSelected = { faceIndex, croppedFaceBitmap ->
|
||||||
@@ -360,8 +357,7 @@ private fun ImprovedResultsView(
|
|||||||
onContinue: () -> Unit,
|
onContinue: () -> Unit,
|
||||||
onRetry: () -> Unit,
|
onRetry: () -> Unit,
|
||||||
onReplaceImage: (Uri, Uri) -> Unit,
|
onReplaceImage: (Uri, Uri) -> Unit,
|
||||||
onSelectFaceFromMultiple: (FaceDetectionHelper.FaceDetectionResult) -> Unit,
|
onSelectFaceFromMultiple: (FaceDetectionHelper.FaceDetectionResult) -> Unit
|
||||||
trainViewModel: TrainViewModel
|
|
||||||
) {
|
) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
@@ -423,9 +419,7 @@ private fun ImprovedResultsView(
|
|||||||
},
|
},
|
||||||
onSelectFace = if (imageResult.faceCount > 1) {
|
onSelectFace = if (imageResult.faceCount > 1) {
|
||||||
{ onSelectFaceFromMultiple(imageResult) }
|
{ onSelectFaceFromMultiple(imageResult) }
|
||||||
} else null,
|
} else null
|
||||||
trainViewModel = trainViewModel,
|
|
||||||
isExcluded = trainViewModel.isImageExcluded(imageResult.uri)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,9 +588,7 @@ private fun ImageResultCard(
|
|||||||
index: Int,
|
index: Int,
|
||||||
result: FaceDetectionHelper.FaceDetectionResult,
|
result: FaceDetectionHelper.FaceDetectionResult,
|
||||||
onReplace: (Uri) -> Unit,
|
onReplace: (Uri) -> Unit,
|
||||||
onSelectFace: (() -> Unit)?,
|
onSelectFace: (() -> Unit)?
|
||||||
trainViewModel: TrainViewModel,
|
|
||||||
isExcluded: Boolean
|
|
||||||
) {
|
) {
|
||||||
val photoPickerLauncher = rememberLauncherForActivityResult(
|
val photoPickerLauncher = rememberLauncherForActivityResult(
|
||||||
contract = ActivityResultContracts.PickVisualMedia()
|
contract = ActivityResultContracts.PickVisualMedia()
|
||||||
@@ -605,7 +597,6 @@ private fun ImageResultCard(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val status = when {
|
val status = when {
|
||||||
isExcluded -> ImageStatus.EXCLUDED
|
|
||||||
result.errorMessage != null -> ImageStatus.ERROR
|
result.errorMessage != null -> ImageStatus.ERROR
|
||||||
!result.hasFace -> ImageStatus.NO_FACE
|
!result.hasFace -> ImageStatus.NO_FACE
|
||||||
result.faceCount > 1 -> ImageStatus.MULTIPLE_FACES
|
result.faceCount > 1 -> ImageStatus.MULTIPLE_FACES
|
||||||
@@ -619,7 +610,6 @@ private fun ImageResultCard(
|
|||||||
containerColor = when (status) {
|
containerColor = when (status) {
|
||||||
ImageStatus.VALID -> MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f)
|
ImageStatus.VALID -> MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f)
|
||||||
ImageStatus.MULTIPLE_FACES -> MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.4f)
|
ImageStatus.MULTIPLE_FACES -> MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.4f)
|
||||||
ImageStatus.EXCLUDED -> MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f)
|
|
||||||
else -> MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.3f)
|
else -> MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.3f)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -639,7 +629,6 @@ private fun ImageResultCard(
|
|||||||
color = when (status) {
|
color = when (status) {
|
||||||
ImageStatus.VALID -> MaterialTheme.colorScheme.primary
|
ImageStatus.VALID -> MaterialTheme.colorScheme.primary
|
||||||
ImageStatus.MULTIPLE_FACES -> MaterialTheme.colorScheme.tertiary
|
ImageStatus.MULTIPLE_FACES -> MaterialTheme.colorScheme.tertiary
|
||||||
ImageStatus.EXCLUDED -> MaterialTheme.colorScheme.outline
|
|
||||||
else -> MaterialTheme.colorScheme.error
|
else -> MaterialTheme.colorScheme.error
|
||||||
},
|
},
|
||||||
shape = CircleShape
|
shape = CircleShape
|
||||||
@@ -668,7 +657,6 @@ private fun ImageResultCard(
|
|||||||
when (status) {
|
when (status) {
|
||||||
ImageStatus.VALID -> MaterialTheme.colorScheme.primary
|
ImageStatus.VALID -> MaterialTheme.colorScheme.primary
|
||||||
ImageStatus.MULTIPLE_FACES -> MaterialTheme.colorScheme.tertiary
|
ImageStatus.MULTIPLE_FACES -> MaterialTheme.colorScheme.tertiary
|
||||||
ImageStatus.EXCLUDED -> MaterialTheme.colorScheme.outline
|
|
||||||
else -> MaterialTheme.colorScheme.error
|
else -> MaterialTheme.colorScheme.error
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
@@ -696,14 +684,12 @@ private fun ImageResultCard(
|
|||||||
imageVector = when (status) {
|
imageVector = when (status) {
|
||||||
ImageStatus.VALID -> Icons.Default.CheckCircle
|
ImageStatus.VALID -> Icons.Default.CheckCircle
|
||||||
ImageStatus.MULTIPLE_FACES -> Icons.Default.Info
|
ImageStatus.MULTIPLE_FACES -> Icons.Default.Info
|
||||||
ImageStatus.EXCLUDED -> Icons.Default.RemoveCircle
|
|
||||||
else -> Icons.Default.Warning
|
else -> Icons.Default.Warning
|
||||||
},
|
},
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = when (status) {
|
tint = when (status) {
|
||||||
ImageStatus.VALID -> MaterialTheme.colorScheme.primary
|
ImageStatus.VALID -> MaterialTheme.colorScheme.primary
|
||||||
ImageStatus.MULTIPLE_FACES -> MaterialTheme.colorScheme.tertiary
|
ImageStatus.MULTIPLE_FACES -> MaterialTheme.colorScheme.tertiary
|
||||||
ImageStatus.EXCLUDED -> MaterialTheme.colorScheme.outline
|
|
||||||
else -> MaterialTheme.colorScheme.error
|
else -> MaterialTheme.colorScheme.error
|
||||||
},
|
},
|
||||||
modifier = Modifier.size(20.dp)
|
modifier = Modifier.size(20.dp)
|
||||||
@@ -714,7 +700,6 @@ private fun ImageResultCard(
|
|||||||
ImageStatus.VALID -> "Face Detected"
|
ImageStatus.VALID -> "Face Detected"
|
||||||
ImageStatus.MULTIPLE_FACES -> "Multiple Faces (${result.faceCount})"
|
ImageStatus.MULTIPLE_FACES -> "Multiple Faces (${result.faceCount})"
|
||||||
ImageStatus.NO_FACE -> "No Face Detected"
|
ImageStatus.NO_FACE -> "No Face Detected"
|
||||||
ImageStatus.EXCLUDED -> "Excluded"
|
|
||||||
ImageStatus.ERROR -> "Error"
|
ImageStatus.ERROR -> "Error"
|
||||||
},
|
},
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
@@ -735,8 +720,8 @@ private fun ImageResultCard(
|
|||||||
horizontalAlignment = Alignment.End,
|
horizontalAlignment = Alignment.End,
|
||||||
verticalArrangement = Arrangement.spacedBy(4.dp)
|
verticalArrangement = Arrangement.spacedBy(4.dp)
|
||||||
) {
|
) {
|
||||||
// Select Face button (for multiple faces, not excluded)
|
// Select Face button (for multiple faces)
|
||||||
if (onSelectFace != null && !isExcluded) {
|
if (onSelectFace != null) {
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
onClick = onSelectFace,
|
onClick = onSelectFace,
|
||||||
modifier = Modifier.height(32.dp),
|
modifier = Modifier.height(32.dp),
|
||||||
@@ -756,8 +741,7 @@ private fun ImageResultCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace button (not for excluded)
|
// Replace button
|
||||||
if (!isExcluded) {
|
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
photoPickerLauncher.launch(
|
photoPickerLauncher.launch(
|
||||||
@@ -776,44 +760,6 @@ private fun ImageResultCard(
|
|||||||
Text("Replace", style = MaterialTheme.typography.bodySmall)
|
Text("Replace", style = MaterialTheme.typography.bodySmall)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exclude/Include button
|
|
||||||
OutlinedButton(
|
|
||||||
onClick = {
|
|
||||||
if (isExcluded) {
|
|
||||||
trainViewModel.includeImage(result.uri)
|
|
||||||
} else {
|
|
||||||
trainViewModel.excludeImage(result.uri)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.height(32.dp),
|
|
||||||
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 0.dp),
|
|
||||||
colors = ButtonDefaults.outlinedButtonColors(
|
|
||||||
contentColor = if (isExcluded)
|
|
||||||
MaterialTheme.colorScheme.primary
|
|
||||||
else
|
|
||||||
MaterialTheme.colorScheme.error
|
|
||||||
),
|
|
||||||
border = BorderStroke(
|
|
||||||
1.dp,
|
|
||||||
if (isExcluded)
|
|
||||||
MaterialTheme.colorScheme.primary
|
|
||||||
else
|
|
||||||
MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
if (isExcluded) Icons.Default.Add else Icons.Default.Close,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(16.dp)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
|
||||||
Text(
|
|
||||||
if (isExcluded) "Include" else "Exclude",
|
|
||||||
style = MaterialTheme.typography.bodySmall
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -929,6 +875,5 @@ private enum class ImageStatus {
|
|||||||
VALID,
|
VALID,
|
||||||
MULTIPLE_FACES,
|
MULTIPLE_FACES,
|
||||||
NO_FACE,
|
NO_FACE,
|
||||||
ERROR,
|
ERROR
|
||||||
EXCLUDED
|
|
||||||
}
|
}
|
||||||
@@ -44,9 +44,6 @@ data class PersonInfo(
|
|||||||
val relationship: String
|
val relationship: String
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* FIXED TrainViewModel with proper exclude functionality and efficient replace
|
|
||||||
*/
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class TrainViewModel @Inject constructor(
|
class TrainViewModel @Inject constructor(
|
||||||
application: Application,
|
application: Application,
|
||||||
@@ -69,9 +66,6 @@ class TrainViewModel @Inject constructor(
|
|||||||
private var currentImageUris: List<Uri> = emptyList()
|
private var currentImageUris: List<Uri> = emptyList()
|
||||||
private val manualFaceSelections = mutableMapOf<Uri, ManualFaceSelection>()
|
private val manualFaceSelections = mutableMapOf<Uri, ManualFaceSelection>()
|
||||||
|
|
||||||
// Track excluded images
|
|
||||||
private val excludedImages = mutableSetOf<Uri>()
|
|
||||||
|
|
||||||
data class ManualFaceSelection(
|
data class ManualFaceSelection(
|
||||||
val faceIndex: Int,
|
val faceIndex: Int,
|
||||||
val croppedFaceBitmap: Bitmap
|
val croppedFaceBitmap: Bitmap
|
||||||
@@ -84,39 +78,6 @@ class TrainViewModel @Inject constructor(
|
|||||||
personInfo = PersonInfo(name, dateOfBirth, relationship)
|
personInfo = PersonInfo(name, dateOfBirth, relationship)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Exclude an image from training
|
|
||||||
*/
|
|
||||||
fun excludeImage(uri: Uri) {
|
|
||||||
excludedImages.add(uri)
|
|
||||||
|
|
||||||
val currentState = _uiState.value
|
|
||||||
if (currentState is ScanningState.Success) {
|
|
||||||
val updatedResult = applyManualSelections(currentState.sanityCheckResult)
|
|
||||||
_uiState.value = ScanningState.Success(updatedResult)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Include a previously excluded image
|
|
||||||
*/
|
|
||||||
fun includeImage(uri: Uri) {
|
|
||||||
excludedImages.remove(uri)
|
|
||||||
|
|
||||||
val currentState = _uiState.value
|
|
||||||
if (currentState is ScanningState.Success) {
|
|
||||||
val updatedResult = applyManualSelections(currentState.sanityCheckResult)
|
|
||||||
_uiState.value = ScanningState.Success(updatedResult)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if an image is excluded
|
|
||||||
*/
|
|
||||||
fun isImageExcluded(uri: Uri): Boolean {
|
|
||||||
return uri in excludedImages
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create face model with captured person info
|
* Create face model with captured person info
|
||||||
*/
|
*/
|
||||||
@@ -128,7 +89,7 @@ class TrainViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val validImages = currentState.sanityCheckResult.validImagesWithFaces
|
val validImages = currentState.sanityCheckResult.validImagesWithFaces
|
||||||
if (validImages.size < 15) {
|
if (validImages.size < 15) { // Updated minimum
|
||||||
_trainingState.value = TrainingState.Error(
|
_trainingState.value = TrainingState.Error(
|
||||||
"Need at least 15 valid images, have ${validImages.size}"
|
"Need at least 15 valid images, have ${validImages.size}"
|
||||||
)
|
)
|
||||||
@@ -143,14 +104,16 @@ class TrainViewModel @Inject constructor(
|
|||||||
total = validImages.size
|
total = validImages.size
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Create person with captured info
|
||||||
val person = PersonEntity.create(
|
val person = PersonEntity.create(
|
||||||
name = personName,
|
name = personName,
|
||||||
dateOfBirth = personInfo?.dateOfBirth,
|
dateOfBirth = personInfo?.dateOfBirth,
|
||||||
relationship = personInfo?.relationship
|
relationship = personInfo?.relationship
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Create person with face model
|
||||||
val personId = faceRecognitionRepository.createPersonWithFaceModel(
|
val personId = faceRecognitionRepository.createPersonWithFaceModel(
|
||||||
person = person,
|
person = person, // Pass full PersonEntity now
|
||||||
validImages = validImages,
|
validImages = validImages,
|
||||||
onProgress = { current, total ->
|
onProgress = { current, total ->
|
||||||
_trainingState.value = TrainingState.Processing(
|
_trainingState.value = TrainingState.Processing(
|
||||||
@@ -182,61 +145,25 @@ class TrainViewModel @Inject constructor(
|
|||||||
fun scanAndTagFaces(imageUris: List<Uri>) {
|
fun scanAndTagFaces(imageUris: List<Uri>) {
|
||||||
currentImageUris = imageUris
|
currentImageUris = imageUris
|
||||||
manualFaceSelections.clear()
|
manualFaceSelections.clear()
|
||||||
excludedImages.clear()
|
|
||||||
performScan(imageUris)
|
performScan(imageUris)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* FIXED: Replace image - only rescan the ONE new image, not all images!
|
|
||||||
*/
|
|
||||||
fun replaceImage(oldUri: Uri, newUri: Uri) {
|
fun replaceImage(oldUri: Uri, newUri: Uri) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
|
||||||
val currentState = _uiState.value
|
|
||||||
if (currentState !is ScanningState.Success) return@launch
|
|
||||||
|
|
||||||
// Update the URI list
|
|
||||||
val updatedUris = currentImageUris.toMutableList()
|
val updatedUris = currentImageUris.toMutableList()
|
||||||
val index = updatedUris.indexOf(oldUri)
|
val index = updatedUris.indexOf(oldUri)
|
||||||
if (index == -1) return@launch
|
|
||||||
|
|
||||||
|
if (index != -1) {
|
||||||
updatedUris[index] = newUri
|
updatedUris[index] = newUri
|
||||||
currentImageUris = updatedUris
|
currentImageUris = updatedUris
|
||||||
|
|
||||||
// Clean up old selections/exclusions
|
|
||||||
manualFaceSelections.remove(oldUri)
|
manualFaceSelections.remove(oldUri)
|
||||||
excludedImages.remove(oldUri)
|
performScan(currentImageUris)
|
||||||
|
|
||||||
// Only scan the NEW image
|
|
||||||
val newResult = faceDetectionHelper.detectFacesInImage(newUri)
|
|
||||||
|
|
||||||
// Update the results list
|
|
||||||
val updatedFaceResults = currentState.sanityCheckResult.faceDetectionResults.toMutableList()
|
|
||||||
updatedFaceResults[index] = newResult
|
|
||||||
|
|
||||||
// Create updated SanityCheckResult
|
|
||||||
val updatedSanityResult = currentState.sanityCheckResult.copy(
|
|
||||||
faceDetectionResults = updatedFaceResults
|
|
||||||
)
|
|
||||||
|
|
||||||
// Apply manual selections and exclusions
|
|
||||||
val finalResult = applyManualSelections(updatedSanityResult)
|
|
||||||
_uiState.value = ScanningState.Success(finalResult)
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
_uiState.value = ScanningState.Error(
|
|
||||||
e.message ?: "Failed to replace image"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Select face and auto-include the image
|
|
||||||
*/
|
|
||||||
fun selectFaceFromImage(imageUri: Uri, faceIndex: Int, croppedFaceBitmap: Bitmap) {
|
fun selectFaceFromImage(imageUri: Uri, faceIndex: Int, croppedFaceBitmap: Bitmap) {
|
||||||
manualFaceSelections[imageUri] = ManualFaceSelection(faceIndex, croppedFaceBitmap)
|
manualFaceSelections[imageUri] = ManualFaceSelection(faceIndex, croppedFaceBitmap)
|
||||||
excludedImages.remove(imageUri) // Auto-include
|
|
||||||
|
|
||||||
val currentState = _uiState.value
|
val currentState = _uiState.value
|
||||||
if (currentState is ScanningState.Success) {
|
if (currentState is ScanningState.Success) {
|
||||||
@@ -245,9 +172,6 @@ class TrainViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform full scan with exclusions and progress tracking
|
|
||||||
*/
|
|
||||||
private fun performScan(imageUris: List<Uri>) {
|
private fun performScan(imageUris: List<Uri>) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
@@ -255,13 +179,9 @@ class TrainViewModel @Inject constructor(
|
|||||||
|
|
||||||
val result = sanityChecker.performSanityChecks(
|
val result = sanityChecker.performSanityChecks(
|
||||||
imageUris = imageUris,
|
imageUris = imageUris,
|
||||||
minImagesRequired = 15,
|
minImagesRequired = 15, // Updated minimum
|
||||||
allowMultipleFaces = true,
|
allowMultipleFaces = true,
|
||||||
duplicateSimilarityThreshold = 0.95,
|
duplicateSimilarityThreshold = 0.95
|
||||||
excludedImages = excludedImages,
|
|
||||||
onProgress = { stage, current, total ->
|
|
||||||
_uiState.value = ScanningState.Processing(current, total)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val finalResult = applyManualSelections(result)
|
val finalResult = applyManualSelections(result)
|
||||||
@@ -275,14 +195,11 @@ class TrainViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply manual selections with exclusion filtering
|
|
||||||
*/
|
|
||||||
private fun applyManualSelections(
|
private fun applyManualSelections(
|
||||||
result: TrainingSanityChecker.SanityCheckResult
|
result: TrainingSanityChecker.SanityCheckResult
|
||||||
): TrainingSanityChecker.SanityCheckResult {
|
): TrainingSanityChecker.SanityCheckResult {
|
||||||
|
|
||||||
if (manualFaceSelections.isEmpty() && excludedImages.isEmpty()) {
|
if (manualFaceSelections.isEmpty()) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,36 +216,26 @@ class TrainViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val updatedValidImages = updatedFaceResults
|
val updatedValidImages = updatedFaceResults
|
||||||
.filter { it.uri !in excludedImages } // Filter excluded
|
|
||||||
.filter { it.hasFace }
|
.filter { it.hasFace }
|
||||||
.filter { it.croppedFaceBitmap != null }
|
.filter { it.croppedFaceBitmap != null }
|
||||||
.filter { it.errorMessage == null }
|
.filter { it.errorMessage == null }
|
||||||
.filter { it.faceCount >= 1 }
|
.filter { it.faceCount >= 1 }
|
||||||
.map { faceResult ->
|
.map { result ->
|
||||||
TrainingSanityChecker.ValidTrainingImage(
|
TrainingSanityChecker.ValidTrainingImage(
|
||||||
uri = faceResult.uri,
|
uri = result.uri,
|
||||||
croppedFaceBitmap = faceResult.croppedFaceBitmap!!,
|
croppedFaceBitmap = result.croppedFaceBitmap!!,
|
||||||
faceCount = faceResult.faceCount
|
faceCount = result.faceCount
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val updatedErrors = result.validationErrors.toMutableList()
|
val updatedErrors = result.validationErrors.toMutableList()
|
||||||
|
|
||||||
// Remove errors for manually selected faces or excluded images
|
|
||||||
updatedErrors.removeAll { error ->
|
updatedErrors.removeAll { error ->
|
||||||
when (error) {
|
error is TrainingSanityChecker.ValidationError.MultipleFacesDetected &&
|
||||||
is TrainingSanityChecker.ValidationError.MultipleFacesDetected ->
|
manualFaceSelections.containsKey(error.uri)
|
||||||
manualFaceSelections.containsKey(error.uri) || excludedImages.contains(error.uri)
|
|
||||||
is TrainingSanityChecker.ValidationError.NoFaceDetected ->
|
|
||||||
error.uris.any { excludedImages.contains(it) }
|
|
||||||
is TrainingSanityChecker.ValidationError.ImageLoadError ->
|
|
||||||
excludedImages.contains(error.uri)
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update insufficient images error
|
if (updatedValidImages.size < 15) { // Updated minimum
|
||||||
if (updatedValidImages.size < 15) {
|
|
||||||
if (updatedErrors.none { it is TrainingSanityChecker.ValidationError.InsufficientImages }) {
|
if (updatedErrors.none { it is TrainingSanityChecker.ValidationError.InsufficientImages }) {
|
||||||
updatedErrors.add(
|
updatedErrors.add(
|
||||||
TrainingSanityChecker.ValidationError.InsufficientImages(
|
TrainingSanityChecker.ValidationError.InsufficientImages(
|
||||||
@@ -347,8 +254,7 @@ class TrainViewModel @Inject constructor(
|
|||||||
isValid = isValid,
|
isValid = isValid,
|
||||||
faceDetectionResults = updatedFaceResults,
|
faceDetectionResults = updatedFaceResults,
|
||||||
validationErrors = updatedErrors,
|
validationErrors = updatedErrors,
|
||||||
validImagesWithFaces = updatedValidImages,
|
validImagesWithFaces = updatedValidImages
|
||||||
excludedImages = excludedImages
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,7 +267,6 @@ class TrainViewModel @Inject constructor(
|
|||||||
_trainingState.value = TrainingState.Idle
|
_trainingState.value = TrainingState.Idle
|
||||||
currentImageUris = emptyList()
|
currentImageUris = emptyList()
|
||||||
manualFaceSelections.clear()
|
manualFaceSelections.clear()
|
||||||
excludedImages.clear()
|
|
||||||
personInfo = null
|
personInfo = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,8 +303,7 @@ private fun TrainingSanityChecker.SanityCheckResult.copy(
|
|||||||
duplicateCheckResult: DuplicateImageDetector.DuplicateCheckResult = this.duplicateCheckResult,
|
duplicateCheckResult: DuplicateImageDetector.DuplicateCheckResult = this.duplicateCheckResult,
|
||||||
validationErrors: List<TrainingSanityChecker.ValidationError> = this.validationErrors,
|
validationErrors: List<TrainingSanityChecker.ValidationError> = this.validationErrors,
|
||||||
warnings: List<String> = this.warnings,
|
warnings: List<String> = this.warnings,
|
||||||
validImagesWithFaces: List<TrainingSanityChecker.ValidTrainingImage> = this.validImagesWithFaces,
|
validImagesWithFaces: List<TrainingSanityChecker.ValidTrainingImage> = this.validImagesWithFaces
|
||||||
excludedImages: Set<Uri> = this.excludedImages
|
|
||||||
): TrainingSanityChecker.SanityCheckResult {
|
): TrainingSanityChecker.SanityCheckResult {
|
||||||
return TrainingSanityChecker.SanityCheckResult(
|
return TrainingSanityChecker.SanityCheckResult(
|
||||||
isValid = isValid,
|
isValid = isValid,
|
||||||
@@ -407,7 +311,6 @@ private fun TrainingSanityChecker.SanityCheckResult.copy(
|
|||||||
duplicateCheckResult = duplicateCheckResult,
|
duplicateCheckResult = duplicateCheckResult,
|
||||||
validationErrors = validationErrors,
|
validationErrors = validationErrors,
|
||||||
warnings = warnings,
|
warnings = warnings,
|
||||||
validImagesWithFaces = validImagesWithFaces,
|
validImagesWithFaces = validImagesWithFaces
|
||||||
excludedImages = excludedImages
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -13,38 +13,45 @@ import androidx.compose.runtime.*
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Brush
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CLEANED TrainingScreen - No duplicate header
|
* Beautiful TrainingScreen with person info capture
|
||||||
*
|
|
||||||
* Removed:
|
|
||||||
* - Scaffold wrapper (lines 46-55)
|
|
||||||
* - TopAppBar (was creating banner)
|
|
||||||
* - "Train New Person" title (MainScreen shows it)
|
|
||||||
*
|
*
|
||||||
* Features:
|
* Features:
|
||||||
* - Person info capture (name, DOB, relationship)
|
* - Name input
|
||||||
|
* - Date of birth picker
|
||||||
|
* - Relationship selector
|
||||||
* - Onboarding cards
|
* - Onboarding cards
|
||||||
* - Beautiful gradient design
|
* - Beautiful gradient design
|
||||||
* - Clear call to action
|
* - Clear call to action
|
||||||
* - Scrollable on small screens
|
|
||||||
*/
|
*/
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun TrainingScreen(
|
fun TrainingScreen(
|
||||||
onSelectImages: () -> Unit,
|
onSelectImages: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier
|
||||||
trainViewModel: TrainViewModel = hiltViewModel()
|
|
||||||
) {
|
) {
|
||||||
var showInfoDialog by remember { mutableStateOf(false) }
|
var showInfoDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
Scaffold(
|
||||||
|
topBar = {
|
||||||
|
TopAppBar(
|
||||||
|
title = { Text("Train New Person") },
|
||||||
|
colors = TopAppBarDefaults.topAppBarColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.primaryContainer
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
) { paddingValues ->
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
.padding(paddingValues)
|
||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
.padding(20.dp),
|
.padding(20.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(20.dp)
|
verticalArrangement = Arrangement.spacedBy(20.dp)
|
||||||
@@ -87,15 +94,16 @@ fun TrainingScreen(
|
|||||||
|
|
||||||
Spacer(Modifier.height(8.dp))
|
Spacer(Modifier.height(8.dp))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Person info dialog
|
// Person info dialog
|
||||||
if (showInfoDialog) {
|
if (showInfoDialog) {
|
||||||
BeautifulPersonInfoDialog(
|
PersonInfoDialog(
|
||||||
onDismiss = { showInfoDialog = false },
|
onDismiss = { showInfoDialog = false },
|
||||||
onConfirm = { name, dob, relationship ->
|
onConfirm = { name, dob, relationship ->
|
||||||
showInfoDialog = false
|
showInfoDialog = false
|
||||||
// Store person info in ViewModel
|
// TODO: Store this info before photo selection
|
||||||
trainViewModel.setPersonInfo(name, dob, relationship)
|
// For now, just proceed to photo selection
|
||||||
onSelectImages()
|
onSelectImages()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -187,16 +195,16 @@ private fun HowItWorksSection() {
|
|||||||
|
|
||||||
StepCard(
|
StepCard(
|
||||||
number = 3,
|
number = 3,
|
||||||
icon = Icons.Default.SmartToy,
|
icon = Icons.Default.ModelTraining,
|
||||||
title = "AI Training",
|
title = "AI Learns Their Face",
|
||||||
description = "We'll create a recognition model"
|
description = "Takes ~30 seconds to train"
|
||||||
)
|
)
|
||||||
|
|
||||||
StepCard(
|
StepCard(
|
||||||
number = 4,
|
number = 4,
|
||||||
icon = Icons.Default.AutoFixHigh,
|
icon = Icons.Default.Search,
|
||||||
title = "Auto-Tag Photos",
|
title = "Auto-Tag Your Library",
|
||||||
description = "Find this person across your library"
|
description = "Find them in all your photos"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,31 +212,31 @@ private fun HowItWorksSection() {
|
|||||||
@Composable
|
@Composable
|
||||||
private fun StepCard(
|
private fun StepCard(
|
||||||
number: Int,
|
number: Int,
|
||||||
icon: ImageVector,
|
icon: androidx.compose.ui.graphics.vector.ImageVector,
|
||||||
title: String,
|
title: String,
|
||||||
description: String
|
description: String
|
||||||
) {
|
) {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
colors = CardDefaults.cardColors(
|
colors = CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f)
|
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
||||||
),
|
),
|
||||||
shape = RoundedCornerShape(16.dp)
|
shape = RoundedCornerShape(12.dp)
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.padding(16.dp),
|
modifier = Modifier.padding(16.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
// Number circle
|
// Number badge
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.size(48.dp),
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
shape = RoundedCornerShape(12.dp),
|
||||||
color = MaterialTheme.colorScheme.primary
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
modifier = Modifier.size(48.dp)
|
||||||
) {
|
) {
|
||||||
Box(contentAlignment = Alignment.Center) {
|
Box(contentAlignment = Alignment.Center) {
|
||||||
Text(
|
Text(
|
||||||
"$number",
|
text = number.toString(),
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = MaterialTheme.colorScheme.onPrimary
|
color = MaterialTheme.colorScheme.onPrimary
|
||||||
@@ -236,7 +244,6 @@ private fun StepCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Content
|
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
@@ -254,6 +261,7 @@ private fun StepCard(
|
|||||||
fontWeight = FontWeight.SemiBold
|
fontWeight = FontWeight.SemiBold
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Spacer(Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
description,
|
description,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
@@ -269,7 +277,7 @@ private fun RequirementsCard() {
|
|||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
colors = CardDefaults.cardColors(
|
colors = CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.3f)
|
containerColor = MaterialTheme.colorScheme.secondaryContainer
|
||||||
),
|
),
|
||||||
shape = RoundedCornerShape(16.dp)
|
shape = RoundedCornerShape(16.dp)
|
||||||
) {
|
) {
|
||||||
@@ -284,59 +292,225 @@ private fun RequirementsCard() {
|
|||||||
Icon(
|
Icon(
|
||||||
Icons.Default.CheckCircle,
|
Icons.Default.CheckCircle,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = MaterialTheme.colorScheme.primary,
|
tint = MaterialTheme.colorScheme.primary
|
||||||
modifier = Modifier.size(24.dp)
|
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"Best Results",
|
"What You'll Need",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
RequirementItem(
|
RequirementItem("20-30 photos of the person", true)
|
||||||
icon = Icons.Default.PhotoCamera,
|
RequirementItem("Different angles and lighting", true)
|
||||||
text = "20-30 photos minimum"
|
RequirementItem("Clear face visibility", true)
|
||||||
)
|
RequirementItem("Mix of expressions", true)
|
||||||
|
RequirementItem("2-3 minutes of your time", true)
|
||||||
RequirementItem(
|
|
||||||
icon = Icons.Default.Face,
|
|
||||||
text = "Clear, well-lit face photos"
|
|
||||||
)
|
|
||||||
|
|
||||||
RequirementItem(
|
|
||||||
icon = Icons.Default.Diversity1,
|
|
||||||
text = "Variety of angles & expressions"
|
|
||||||
)
|
|
||||||
|
|
||||||
RequirementItem(
|
|
||||||
icon = Icons.Default.HighQuality,
|
|
||||||
text = "Good quality images"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun RequirementItem(
|
private fun RequirementItem(text: String, isMet: Boolean) {
|
||||||
icon: ImageVector,
|
|
||||||
text: String
|
|
||||||
) {
|
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically
|
||||||
modifier = Modifier.padding(vertical = 4.dp)
|
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
icon,
|
if (isMet) Icons.Default.Check else Icons.Default.Close,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(20.dp),
|
modifier = Modifier.size(18.dp),
|
||||||
tint = MaterialTheme.colorScheme.onSecondaryContainer
|
tint = if (isMet) {
|
||||||
|
MaterialTheme.colorScheme.primary
|
||||||
|
} else {
|
||||||
|
MaterialTheme.colorScheme.error
|
||||||
|
}
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text,
|
text = text,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium
|
||||||
color = MaterialTheme.colorScheme.onSecondaryContainer
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
private fun PersonInfoDialog(
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
onConfirm: (name: String, dateOfBirth: Long?, relationship: String) -> Unit
|
||||||
|
) {
|
||||||
|
var name by remember { mutableStateOf("") }
|
||||||
|
var dateOfBirth by remember { mutableStateOf<Long?>(null) }
|
||||||
|
var selectedRelationship by remember { mutableStateOf("Other") }
|
||||||
|
var showDatePicker by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val relationships = listOf(
|
||||||
|
"Family" to "👨👩👧👦",
|
||||||
|
"Friend" to "🤝",
|
||||||
|
"Partner" to "❤️",
|
||||||
|
"Child" to "👶",
|
||||||
|
"Parent" to "👪",
|
||||||
|
"Sibling" to "👫",
|
||||||
|
"Colleague" to "💼",
|
||||||
|
"Other" to "👤"
|
||||||
|
)
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
title = {
|
||||||
|
Column {
|
||||||
|
Text("Person Details")
|
||||||
|
Text(
|
||||||
|
"Help us organize your photos",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
|
) {
|
||||||
|
// Name field
|
||||||
|
OutlinedTextField(
|
||||||
|
value = name,
|
||||||
|
onValueChange = { name = it },
|
||||||
|
label = { Text("Name *") },
|
||||||
|
placeholder = { Text("e.g., John Doe") },
|
||||||
|
leadingIcon = {
|
||||||
|
Icon(Icons.Default.Person, contentDescription = null)
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
singleLine = true
|
||||||
|
)
|
||||||
|
|
||||||
|
// Date of birth
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = { showDatePicker = true },
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Icon(Icons.Default.Cake, contentDescription = null)
|
||||||
|
Spacer(Modifier.width(8.dp))
|
||||||
|
Text(
|
||||||
|
if (dateOfBirth != null) {
|
||||||
|
"Birthday: ${formatDate(dateOfBirth!!)}"
|
||||||
|
} else {
|
||||||
|
"Add Birthday (Optional)"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Relationship selector
|
||||||
|
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
Text(
|
||||||
|
"Relationship",
|
||||||
|
style = MaterialTheme.typography.labelMedium
|
||||||
|
)
|
||||||
|
|
||||||
|
// Relationship chips
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
relationships.take(4).forEach { (rel, emoji) ->
|
||||||
|
FilterChip(
|
||||||
|
selected = selectedRelationship == rel,
|
||||||
|
onClick = { selectedRelationship = rel },
|
||||||
|
label = { Text("$emoji $rel") }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
relationships.drop(4).forEach { (rel, emoji) ->
|
||||||
|
FilterChip(
|
||||||
|
selected = selectedRelationship == rel,
|
||||||
|
onClick = { selectedRelationship = rel },
|
||||||
|
label = { Text("$emoji $rel") }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Privacy note
|
||||||
|
Card(
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.padding(12.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Lock,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(16.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
"All data stays on your device",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
if (name.isNotBlank()) {
|
||||||
|
onConfirm(name, dateOfBirth, selectedRelationship)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enabled = name.isNotBlank()
|
||||||
|
) {
|
||||||
|
Text("Continue")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Date picker dialog
|
||||||
|
if (showDatePicker) {
|
||||||
|
DatePickerDialog(
|
||||||
|
onDismissRequest = { showDatePicker = false },
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
// Get selected date from date picker
|
||||||
|
// For now, set to current date as placeholder
|
||||||
|
dateOfBirth = System.currentTimeMillis()
|
||||||
|
showDatePicker = false
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Text("OK")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { showDatePicker = false }) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
// Material3 DatePicker
|
||||||
|
DatePicker(
|
||||||
|
state = rememberDatePickerState(),
|
||||||
|
modifier = Modifier.padding(16.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun formatDate(timestamp: Long): String {
|
||||||
|
val formatter = SimpleDateFormat("MMM dd, yyyy", Locale.getDefault())
|
||||||
|
return formatter.format(Date(timestamp))
|
||||||
|
}
|
||||||
@@ -5,12 +5,7 @@ import android.graphics.Bitmap
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ENHANCED TrainingSanityChecker
|
* Coordinates sanity checks for training images
|
||||||
*
|
|
||||||
* New features:
|
|
||||||
* - Progress callbacks
|
|
||||||
* - Exclude functionality
|
|
||||||
* - Faster processing
|
|
||||||
*/
|
*/
|
||||||
class TrainingSanityChecker(private val context: Context) {
|
class TrainingSanityChecker(private val context: Context) {
|
||||||
|
|
||||||
@@ -23,8 +18,7 @@ class TrainingSanityChecker(private val context: Context) {
|
|||||||
val duplicateCheckResult: DuplicateImageDetector.DuplicateCheckResult,
|
val duplicateCheckResult: DuplicateImageDetector.DuplicateCheckResult,
|
||||||
val validationErrors: List<ValidationError>,
|
val validationErrors: List<ValidationError>,
|
||||||
val warnings: List<String>,
|
val warnings: List<String>,
|
||||||
val validImagesWithFaces: List<ValidTrainingImage>,
|
val validImagesWithFaces: List<ValidTrainingImage>
|
||||||
val excludedImages: Set<Uri> = emptySet() // NEW: Track excluded images
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ValidTrainingImage(
|
data class ValidTrainingImage(
|
||||||
@@ -42,42 +36,30 @@ class TrainingSanityChecker(private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform comprehensive sanity checks with PROGRESS tracking
|
* Perform comprehensive sanity checks on training images
|
||||||
*/
|
*/
|
||||||
suspend fun performSanityChecks(
|
suspend fun performSanityChecks(
|
||||||
imageUris: List<Uri>,
|
imageUris: List<Uri>,
|
||||||
minImagesRequired: Int = 15,
|
minImagesRequired: Int = 10,
|
||||||
allowMultipleFaces: Boolean = false,
|
allowMultipleFaces: Boolean = false,
|
||||||
duplicateSimilarityThreshold: Double = 0.95,
|
duplicateSimilarityThreshold: Double = 0.95
|
||||||
excludedImages: Set<Uri> = emptySet(), // NEW: Allow excluding images
|
|
||||||
onProgress: ((String, Int, Int) -> Unit)? = null // NEW: Progress callback
|
|
||||||
): SanityCheckResult {
|
): SanityCheckResult {
|
||||||
|
|
||||||
val validationErrors = mutableListOf<ValidationError>()
|
val validationErrors = mutableListOf<ValidationError>()
|
||||||
val warnings = mutableListOf<String>()
|
val warnings = mutableListOf<String>()
|
||||||
|
|
||||||
// Filter out excluded images
|
// Check minimum image count
|
||||||
val activeImages = imageUris.filter { it !in excludedImages }
|
if (imageUris.size < minImagesRequired) {
|
||||||
|
|
||||||
// Check minimum image count (AFTER exclusions)
|
|
||||||
if (activeImages.size < minImagesRequired) {
|
|
||||||
validationErrors.add(
|
validationErrors.add(
|
||||||
ValidationError.InsufficientImages(
|
ValidationError.InsufficientImages(
|
||||||
required = minImagesRequired,
|
required = minImagesRequired,
|
||||||
available = activeImages.size
|
available = imageUris.size
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 1: Detect faces in all images (WITH PROGRESS)
|
// Step 1: Detect faces in all images
|
||||||
onProgress?.invoke("Detecting faces...", 0, activeImages.size)
|
val faceDetectionResults = faceDetectionHelper.detectFacesInImages(imageUris)
|
||||||
|
|
||||||
val faceDetectionResults = faceDetectionHelper.detectFacesInImages(
|
|
||||||
uris = activeImages,
|
|
||||||
onProgress = { current, total ->
|
|
||||||
onProgress?.invoke("Detecting faces...", current, total)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Check for images without faces
|
// Check for images without faces
|
||||||
val imagesWithoutFaces = faceDetectionResults.filter { !it.hasFace }
|
val imagesWithoutFaces = faceDetectionResults.filter { !it.hasFace }
|
||||||
@@ -116,10 +98,8 @@ class TrainingSanityChecker(private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Step 2: Check for duplicate images
|
// Step 2: Check for duplicate images
|
||||||
onProgress?.invoke("Checking for duplicates...", activeImages.size, activeImages.size)
|
|
||||||
|
|
||||||
val duplicateCheckResult = duplicateDetector.checkForDuplicates(
|
val duplicateCheckResult = duplicateDetector.checkForDuplicates(
|
||||||
uris = activeImages,
|
uris = imageUris,
|
||||||
similarityThreshold = duplicateSimilarityThreshold
|
similarityThreshold = duplicateSimilarityThreshold
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -158,16 +138,13 @@ class TrainingSanityChecker(private val context: Context) {
|
|||||||
|
|
||||||
val isValid = validationErrors.isEmpty() && validImagesWithFaces.size >= minImagesRequired
|
val isValid = validationErrors.isEmpty() && validImagesWithFaces.size >= minImagesRequired
|
||||||
|
|
||||||
onProgress?.invoke("Analysis complete", activeImages.size, activeImages.size)
|
|
||||||
|
|
||||||
return SanityCheckResult(
|
return SanityCheckResult(
|
||||||
isValid = isValid,
|
isValid = isValid,
|
||||||
faceDetectionResults = faceDetectionResults,
|
faceDetectionResults = faceDetectionResults,
|
||||||
duplicateCheckResult = duplicateCheckResult,
|
duplicateCheckResult = duplicateCheckResult,
|
||||||
validationErrors = validationErrors,
|
validationErrors = validationErrors,
|
||||||
warnings = warnings,
|
warnings = warnings,
|
||||||
validImagesWithFaces = validImagesWithFaces,
|
validImagesWithFaces = validImagesWithFaces
|
||||||
excludedImages = excludedImages
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,20 +156,24 @@ class TrainingSanityChecker(private val context: Context) {
|
|||||||
when (error) {
|
when (error) {
|
||||||
is ValidationError.NoFaceDetected -> {
|
is ValidationError.NoFaceDetected -> {
|
||||||
val count = error.uris.size
|
val count = error.uris.size
|
||||||
"No face detected in $count image(s)"
|
val images = error.uris.joinToString(", ") { it.lastPathSegment ?: "Unknown" }
|
||||||
|
"No face detected in $count image(s): $images"
|
||||||
}
|
}
|
||||||
is ValidationError.MultipleFacesDetected -> {
|
is ValidationError.MultipleFacesDetected -> {
|
||||||
"Multiple faces (${error.faceCount}) detected in: ${error.uri.lastPathSegment}"
|
"Multiple faces (${error.faceCount}) detected in: ${error.uri.lastPathSegment}"
|
||||||
}
|
}
|
||||||
is ValidationError.DuplicateImages -> {
|
is ValidationError.DuplicateImages -> {
|
||||||
val count = error.groups.size
|
val count = error.groups.size
|
||||||
"Found $count duplicate group(s)"
|
val details = error.groups.joinToString("\n") { group ->
|
||||||
|
" - ${group.images.size} duplicates: ${group.images.joinToString(", ") { it.lastPathSegment ?: "Unknown" }}"
|
||||||
|
}
|
||||||
|
"Found $count duplicate group(s):\n$details"
|
||||||
}
|
}
|
||||||
is ValidationError.InsufficientImages -> {
|
is ValidationError.InsufficientImages -> {
|
||||||
"Need ${error.required} images, have ${error.available}"
|
"Insufficient images: need ${error.required}, but only ${error.available} valid images available"
|
||||||
}
|
}
|
||||||
is ValidationError.ImageLoadError -> {
|
is ValidationError.ImageLoadError -> {
|
||||||
"Failed to load image: ${error.uri.lastPathSegment}"
|
"Failed to load image ${error.uri.lastPathSegment}: ${error.error}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,430 +0,0 @@
|
|||||||
package com.placeholder.sherpai2.ui.utilities
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.*
|
|
||||||
import androidx.compose.material3.*
|
|
||||||
import androidx.compose.runtime.*
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|
||||||
import com.placeholder.sherpai2.ui.utilities.stats.StatsScreen
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CLEANED PhotoUtilitiesScreen - No duplicate header
|
|
||||||
*
|
|
||||||
* Removed:
|
|
||||||
* - Scaffold wrapper (lines 36-74)
|
|
||||||
* - TopAppBar (was creating banner)
|
|
||||||
* - "Photo Utilities" title (MainScreen shows it)
|
|
||||||
*
|
|
||||||
* Features:
|
|
||||||
* - Stats tab (photo statistics and analytics)
|
|
||||||
* - Tools tab (scan, duplicates, bursts, quality)
|
|
||||||
* - Clean TabRow navigation
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun PhotoUtilitiesScreen(
|
|
||||||
viewModel: PhotoUtilitiesViewModel = hiltViewModel(),
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
|
||||||
val scanProgress by viewModel.scanProgress.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
var selectedTab by remember { mutableStateOf(0) }
|
|
||||||
|
|
||||||
Column(modifier = modifier.fillMaxSize()) {
|
|
||||||
// TabRow for Stats/Tools
|
|
||||||
TabRow(
|
|
||||||
selectedTabIndex = selectedTab,
|
|
||||||
containerColor = MaterialTheme.colorScheme.surface,
|
|
||||||
contentColor = MaterialTheme.colorScheme.primary
|
|
||||||
) {
|
|
||||||
Tab(
|
|
||||||
selected = selectedTab == 0,
|
|
||||||
onClick = { selectedTab = 0 },
|
|
||||||
text = { Text("Stats") },
|
|
||||||
icon = { Icon(Icons.Default.BarChart, "Statistics") }
|
|
||||||
)
|
|
||||||
Tab(
|
|
||||||
selected = selectedTab == 1,
|
|
||||||
onClick = { selectedTab = 1 },
|
|
||||||
text = { Text("Tools") },
|
|
||||||
icon = { Icon(Icons.Default.Build, "Tools") }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tab content
|
|
||||||
when (selectedTab) {
|
|
||||||
0 -> {
|
|
||||||
// Stats tab
|
|
||||||
StatsScreen()
|
|
||||||
}
|
|
||||||
1 -> {
|
|
||||||
// Tools tab
|
|
||||||
ToolsTabContent(
|
|
||||||
uiState = uiState,
|
|
||||||
scanProgress = scanProgress,
|
|
||||||
onScanPhotos = { viewModel.scanForPhotos() },
|
|
||||||
onDetectDuplicates = { viewModel.detectDuplicates() },
|
|
||||||
onDetectBursts = { viewModel.detectBursts() },
|
|
||||||
onAnalyzeQuality = { viewModel.analyzeQuality() }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun ToolsTabContent(
|
|
||||||
uiState: UtilitiesUiState,
|
|
||||||
scanProgress: ScanProgress?,
|
|
||||||
onScanPhotos: () -> Unit,
|
|
||||||
onDetectDuplicates: () -> Unit,
|
|
||||||
onDetectBursts: () -> Unit,
|
|
||||||
onAnalyzeQuality: () -> Unit,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
LazyColumn(
|
|
||||||
modifier = modifier.fillMaxSize(),
|
|
||||||
contentPadding = PaddingValues(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
|
||||||
// Section: Scan & Import
|
|
||||||
item {
|
|
||||||
SectionHeader(
|
|
||||||
title = "Scan & Import",
|
|
||||||
icon = Icons.Default.Scanner
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
UtilityCard(
|
|
||||||
title = "Scan for Photos",
|
|
||||||
description = "Search your device for new photos",
|
|
||||||
icon = Icons.Default.PhotoLibrary,
|
|
||||||
buttonText = "Scan Now",
|
|
||||||
enabled = uiState !is UtilitiesUiState.Scanning,
|
|
||||||
onClick = onScanPhotos
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Section: Organization
|
|
||||||
item {
|
|
||||||
Spacer(Modifier.height(8.dp))
|
|
||||||
SectionHeader(
|
|
||||||
title = "Organization",
|
|
||||||
icon = Icons.Default.Folder
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
UtilityCard(
|
|
||||||
title = "Detect Duplicates",
|
|
||||||
description = "Find and tag duplicate photos",
|
|
||||||
icon = Icons.Default.FileCopy,
|
|
||||||
buttonText = "Find Duplicates",
|
|
||||||
enabled = uiState !is UtilitiesUiState.Scanning,
|
|
||||||
onClick = onDetectDuplicates
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
UtilityCard(
|
|
||||||
title = "Detect Bursts",
|
|
||||||
description = "Group photos taken in rapid succession (3+ in 2 seconds)",
|
|
||||||
icon = Icons.Default.BurstMode,
|
|
||||||
buttonText = "Find Bursts",
|
|
||||||
enabled = uiState !is UtilitiesUiState.Scanning,
|
|
||||||
onClick = onDetectBursts
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Section: Quality
|
|
||||||
item {
|
|
||||||
Spacer(Modifier.height(8.dp))
|
|
||||||
SectionHeader(
|
|
||||||
title = "Quality Analysis",
|
|
||||||
icon = Icons.Default.HighQuality
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
UtilityCard(
|
|
||||||
title = "Find Screenshots & Blurry",
|
|
||||||
description = "Identify screenshots and low-quality photos",
|
|
||||||
icon = Icons.Default.PhoneAndroid,
|
|
||||||
buttonText = "Analyze",
|
|
||||||
enabled = uiState !is UtilitiesUiState.Scanning,
|
|
||||||
onClick = onAnalyzeQuality
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Progress indicator
|
|
||||||
if (scanProgress != null) {
|
|
||||||
item {
|
|
||||||
ProgressCard(scanProgress)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Results
|
|
||||||
when (val state = uiState) {
|
|
||||||
is UtilitiesUiState.ScanComplete -> {
|
|
||||||
item {
|
|
||||||
ResultCard(
|
|
||||||
title = "Scan Complete",
|
|
||||||
message = state.message,
|
|
||||||
icon = Icons.Default.CheckCircle,
|
|
||||||
iconTint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is UtilitiesUiState.DuplicatesFound -> {
|
|
||||||
item {
|
|
||||||
ResultCard(
|
|
||||||
title = "Duplicates Found",
|
|
||||||
message = "Found ${state.groups.size} groups of duplicates (${state.groups.sumOf { it.images.size - 1 }} duplicate photos)",
|
|
||||||
icon = Icons.Default.Info,
|
|
||||||
iconTint = MaterialTheme.colorScheme.tertiary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is UtilitiesUiState.BurstsFound -> {
|
|
||||||
item {
|
|
||||||
ResultCard(
|
|
||||||
title = "Bursts Found",
|
|
||||||
message = "Found ${state.groups.size} burst sequences (${state.groups.sumOf { it.images.size }} photos total)",
|
|
||||||
icon = Icons.Default.Info,
|
|
||||||
iconTint = MaterialTheme.colorScheme.tertiary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is UtilitiesUiState.QualityAnalysisComplete -> {
|
|
||||||
item {
|
|
||||||
ResultCard(
|
|
||||||
title = "Analysis Complete",
|
|
||||||
message = "Screenshots: ${state.screenshots}\nBlurry: ${state.blurry}",
|
|
||||||
icon = Icons.Default.CheckCircle,
|
|
||||||
iconTint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is UtilitiesUiState.Error -> {
|
|
||||||
item {
|
|
||||||
ResultCard(
|
|
||||||
title = "Error",
|
|
||||||
message = state.message,
|
|
||||||
icon = Icons.Default.Error,
|
|
||||||
iconTint = MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info card
|
|
||||||
item {
|
|
||||||
Spacer(Modifier.height(8.dp))
|
|
||||||
InfoCard()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun SectionHeader(
|
|
||||||
title: String,
|
|
||||||
icon: ImageVector
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
||||||
modifier = Modifier.padding(vertical = 4.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.primary,
|
|
||||||
modifier = Modifier.size(20.dp)
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = title,
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun UtilityCard(
|
|
||||||
title: String,
|
|
||||||
description: String,
|
|
||||||
icon: ImageVector,
|
|
||||||
buttonText: String,
|
|
||||||
enabled: Boolean,
|
|
||||||
onClick: () -> Unit
|
|
||||||
) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Surface(
|
|
||||||
modifier = Modifier.size(48.dp),
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
color = MaterialTheme.colorScheme.primaryContainer
|
|
||||||
) {
|
|
||||||
Box(contentAlignment = Alignment.Center) {
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
||||||
modifier = Modifier.size(24.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
|
||||||
Text(
|
|
||||||
text = title,
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.SemiBold
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = description,
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Button(
|
|
||||||
onClick = onClick,
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
enabled = enabled,
|
|
||||||
shape = RoundedCornerShape(12.dp)
|
|
||||||
) {
|
|
||||||
Text(buttonText)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun ProgressCard(progress: ScanProgress) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.3f)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = progress.message,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
fontWeight = FontWeight.Medium
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = "${progress.current}/${progress.total}",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
LinearProgressIndicator(
|
|
||||||
progress = { progress.current.toFloat() / progress.total.toFloat() },
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun ResultCard(
|
|
||||||
title: String,
|
|
||||||
message: String,
|
|
||||||
icon: ImageVector,
|
|
||||||
iconTint: androidx.compose.ui.graphics.Color
|
|
||||||
) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.padding(16.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = iconTint,
|
|
||||||
modifier = Modifier.size(32.dp)
|
|
||||||
)
|
|
||||||
Column {
|
|
||||||
Text(
|
|
||||||
text = title,
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = message,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun InfoCard() {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.3f)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.padding(12.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Info,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.onSecondaryContainer,
|
|
||||||
modifier = Modifier.size(20.dp)
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = "These tools help you organize and maintain your photo collection",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSecondaryContainer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,384 +0,0 @@
|
|||||||
package com.placeholder.sherpai2.ui.utilities
|
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import com.placeholder.sherpai2.data.local.dao.ImageDao
|
|
||||||
import com.placeholder.sherpai2.data.local.dao.ImageTagDao
|
|
||||||
import com.placeholder.sherpai2.data.local.dao.TagDao
|
|
||||||
import com.placeholder.sherpai2.data.local.entity.ImageEntity
|
|
||||||
import com.placeholder.sherpai2.data.local.entity.ImageTagEntity
|
|
||||||
import com.placeholder.sherpai2.data.local.entity.TagEntity
|
|
||||||
import com.placeholder.sherpai2.domain.repository.ImageRepository
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import java.util.UUID
|
|
||||||
import javax.inject.Inject
|
|
||||||
import kotlin.math.abs
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PhotoUtilitiesViewModel - Photo collection management
|
|
||||||
*
|
|
||||||
* Features:
|
|
||||||
* 1. Manual photo scan/rescan
|
|
||||||
* 2. Duplicate detection (SHA256 + perceptual hash)
|
|
||||||
* 3. Burst detection (photos within 2 seconds)
|
|
||||||
* 4. Quality analysis (blurry, screenshots)
|
|
||||||
*/
|
|
||||||
@HiltViewModel
|
|
||||||
class PhotoUtilitiesViewModel @Inject constructor(
|
|
||||||
private val imageRepository: ImageRepository,
|
|
||||||
private val imageDao: ImageDao,
|
|
||||||
private val tagDao: TagDao,
|
|
||||||
private val imageTagDao: ImageTagDao
|
|
||||||
) : ViewModel() {
|
|
||||||
|
|
||||||
private val _uiState = MutableStateFlow<UtilitiesUiState>(UtilitiesUiState.Idle)
|
|
||||||
val uiState: StateFlow<UtilitiesUiState> = _uiState.asStateFlow()
|
|
||||||
|
|
||||||
private val _scanProgress = MutableStateFlow<ScanProgress?>(null)
|
|
||||||
val scanProgress: StateFlow<ScanProgress?> = _scanProgress.asStateFlow()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manual scan for new photos
|
|
||||||
*/
|
|
||||||
fun scanForPhotos() {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
try {
|
|
||||||
_uiState.value = UtilitiesUiState.Scanning("photos")
|
|
||||||
_scanProgress.value = ScanProgress("Scanning device...", 0, 0)
|
|
||||||
|
|
||||||
val beforeCount = imageDao.getImageCount()
|
|
||||||
|
|
||||||
imageRepository.ingestImagesWithProgress { current, total ->
|
|
||||||
_scanProgress.value = ScanProgress(
|
|
||||||
"Found $current photos...",
|
|
||||||
current,
|
|
||||||
total
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val afterCount = imageDao.getImageCount()
|
|
||||||
val newPhotos = afterCount - beforeCount
|
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
_uiState.value = UtilitiesUiState.ScanComplete(
|
|
||||||
"Found $newPhotos new photos",
|
|
||||||
newPhotos
|
|
||||||
)
|
|
||||||
_scanProgress.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
_uiState.value = UtilitiesUiState.Error(
|
|
||||||
e.message ?: "Failed to scan photos"
|
|
||||||
)
|
|
||||||
_scanProgress.value = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detect duplicate photos
|
|
||||||
*/
|
|
||||||
fun detectDuplicates() {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
try {
|
|
||||||
_uiState.value = UtilitiesUiState.Scanning("duplicates")
|
|
||||||
_scanProgress.value = ScanProgress("Analyzing photos...", 0, 0)
|
|
||||||
|
|
||||||
val allImages = imageDao.getAllImages()
|
|
||||||
val duplicateGroups = mutableListOf<DuplicateGroup>()
|
|
||||||
|
|
||||||
// Group by SHA256
|
|
||||||
val sha256Groups = allImages.groupBy { it.sha256 }
|
|
||||||
|
|
||||||
var processed = 0
|
|
||||||
sha256Groups.forEach { (sha256, images) ->
|
|
||||||
if (images.size > 1) {
|
|
||||||
// Found duplicates!
|
|
||||||
duplicateGroups.add(
|
|
||||||
DuplicateGroup(
|
|
||||||
images = images,
|
|
||||||
reason = "Exact duplicate (same file content)",
|
|
||||||
confidence = 1.0f
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
processed++
|
|
||||||
|
|
||||||
if (processed % 100 == 0) {
|
|
||||||
_scanProgress.value = ScanProgress(
|
|
||||||
"Checked $processed photos...",
|
|
||||||
processed,
|
|
||||||
sha256Groups.size
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tag duplicates
|
|
||||||
val duplicateTag = getOrCreateTag("duplicate", "SYSTEM")
|
|
||||||
duplicateGroups.forEach { group ->
|
|
||||||
// Tag all but the first image (keep one, mark rest as dupes)
|
|
||||||
group.images.drop(1).forEach { image ->
|
|
||||||
tagImage(image.imageId, duplicateTag.tagId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
_uiState.value = UtilitiesUiState.DuplicatesFound(duplicateGroups)
|
|
||||||
_scanProgress.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
_uiState.value = UtilitiesUiState.Error(
|
|
||||||
e.message ?: "Failed to detect duplicates"
|
|
||||||
)
|
|
||||||
_scanProgress.value = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detect burst photos (rapid succession)
|
|
||||||
*/
|
|
||||||
fun detectBursts() {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
try {
|
|
||||||
_uiState.value = UtilitiesUiState.Scanning("bursts")
|
|
||||||
_scanProgress.value = ScanProgress("Analyzing timestamps...", 0, 0)
|
|
||||||
|
|
||||||
val allImages = imageDao.getAllImagesSortedByTime()
|
|
||||||
val burstGroups = mutableListOf<BurstGroup>()
|
|
||||||
|
|
||||||
// Group photos taken within 2 seconds of each other
|
|
||||||
val burstThresholdMs = 2000L
|
|
||||||
var currentBurst = mutableListOf<ImageEntity>()
|
|
||||||
|
|
||||||
allImages.forEachIndexed { index, image ->
|
|
||||||
if (currentBurst.isEmpty()) {
|
|
||||||
currentBurst.add(image)
|
|
||||||
} else {
|
|
||||||
val lastImage = currentBurst.last()
|
|
||||||
val timeDiff = abs(image.capturedAt - lastImage.capturedAt)
|
|
||||||
|
|
||||||
if (timeDiff <= burstThresholdMs) {
|
|
||||||
// Part of current burst
|
|
||||||
currentBurst.add(image)
|
|
||||||
} else {
|
|
||||||
// End of burst
|
|
||||||
if (currentBurst.size >= 3) {
|
|
||||||
// Only consider bursts with 3+ photos
|
|
||||||
burstGroups.add(
|
|
||||||
BurstGroup(
|
|
||||||
images = currentBurst.toList(),
|
|
||||||
burstId = UUID.randomUUID().toString(),
|
|
||||||
representativeIndex = currentBurst.size / 2 // Middle photo
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
currentBurst = mutableListOf(image)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index % 100 == 0) {
|
|
||||||
_scanProgress.value = ScanProgress(
|
|
||||||
"Checked $index photos...",
|
|
||||||
index,
|
|
||||||
allImages.size
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check last burst
|
|
||||||
if (currentBurst.size >= 3) {
|
|
||||||
burstGroups.add(
|
|
||||||
BurstGroup(
|
|
||||||
images = currentBurst,
|
|
||||||
burstId = UUID.randomUUID().toString(),
|
|
||||||
representativeIndex = currentBurst.size / 2
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tag bursts
|
|
||||||
val burstTag = getOrCreateTag("burst", "SYSTEM")
|
|
||||||
burstGroups.forEach { group ->
|
|
||||||
group.images.forEach { image ->
|
|
||||||
tagImage(image.imageId, burstTag.tagId)
|
|
||||||
|
|
||||||
// Tag the representative photo specially
|
|
||||||
if (image == group.images[group.representativeIndex]) {
|
|
||||||
val burstRepTag = getOrCreateTag("burst_representative", "SYSTEM")
|
|
||||||
tagImage(image.imageId, burstRepTag.tagId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
_uiState.value = UtilitiesUiState.BurstsFound(burstGroups)
|
|
||||||
_scanProgress.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
_uiState.value = UtilitiesUiState.Error(
|
|
||||||
e.message ?: "Failed to detect bursts"
|
|
||||||
)
|
|
||||||
_scanProgress.value = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detect screenshots and low quality photos
|
|
||||||
*/
|
|
||||||
fun analyzeQuality() {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
try {
|
|
||||||
_uiState.value = UtilitiesUiState.Scanning("quality")
|
|
||||||
_scanProgress.value = ScanProgress("Analyzing quality...", 0, 0)
|
|
||||||
|
|
||||||
val allImages = imageDao.getAllImages()
|
|
||||||
val screenshotTag = getOrCreateTag("screenshot", "SYSTEM")
|
|
||||||
val blurryTag = getOrCreateTag("blurry", "SYSTEM")
|
|
||||||
|
|
||||||
var screenshotCount = 0
|
|
||||||
var blurryCount = 0
|
|
||||||
|
|
||||||
allImages.forEachIndexed { index, image ->
|
|
||||||
// Detect screenshots by dimensions (screen-sized)
|
|
||||||
val isScreenshot = isLikelyScreenshot(image.width, image.height)
|
|
||||||
if (isScreenshot) {
|
|
||||||
tagImage(image.imageId, screenshotTag.tagId)
|
|
||||||
screenshotCount++
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Detect blurry photos (requires bitmap analysis)
|
|
||||||
// For now, skip blur detection
|
|
||||||
|
|
||||||
if (index % 50 == 0) {
|
|
||||||
_scanProgress.value = ScanProgress(
|
|
||||||
"Analyzed $index photos...",
|
|
||||||
index,
|
|
||||||
allImages.size
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
_uiState.value = UtilitiesUiState.QualityAnalysisComplete(
|
|
||||||
screenshots = screenshotCount,
|
|
||||||
blurry = blurryCount
|
|
||||||
)
|
|
||||||
_scanProgress.value = null
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
_uiState.value = UtilitiesUiState.Error(
|
|
||||||
e.message ?: "Failed to analyze quality"
|
|
||||||
)
|
|
||||||
_scanProgress.value = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detect screenshots by common screen dimensions
|
|
||||||
*/
|
|
||||||
private fun isLikelyScreenshot(width: Int, height: Int): Boolean {
|
|
||||||
val commonScreenRatios = listOf(
|
|
||||||
16.0 / 9.0, // 1080x1920, 1440x2560
|
|
||||||
19.5 / 9.0, // 1080x2340 (iPhone X)
|
|
||||||
20.0 / 9.0, // 1080x2400
|
|
||||||
18.5 / 9.0, // 1080x2220
|
|
||||||
19.0 / 9.0 // 1080x2280
|
|
||||||
)
|
|
||||||
|
|
||||||
val imageRatio = if (width > height) {
|
|
||||||
width.toDouble() / height.toDouble()
|
|
||||||
} else {
|
|
||||||
height.toDouble() / width.toDouble()
|
|
||||||
}
|
|
||||||
|
|
||||||
return commonScreenRatios.any { screenRatio ->
|
|
||||||
abs(imageRatio - screenRatio) < 0.1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun getOrCreateTag(value: String, type: String): TagEntity {
|
|
||||||
return tagDao.getByValue(value) ?: run {
|
|
||||||
val tag = TagEntity(
|
|
||||||
tagId = UUID.randomUUID().toString(),
|
|
||||||
type = type,
|
|
||||||
value = value,
|
|
||||||
createdAt = System.currentTimeMillis()
|
|
||||||
)
|
|
||||||
tagDao.insert(tag)
|
|
||||||
tag
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun tagImage(imageId: String, tagId: String) {
|
|
||||||
val imageTag = ImageTagEntity(
|
|
||||||
imageId = imageId,
|
|
||||||
tagId = tagId,
|
|
||||||
source = "AUTO",
|
|
||||||
confidence = 1.0f,
|
|
||||||
visibility = "PUBLIC",
|
|
||||||
createdAt = System.currentTimeMillis()
|
|
||||||
)
|
|
||||||
imageTagDao.insert(imageTag)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun resetState() {
|
|
||||||
_uiState.value = UtilitiesUiState.Idle
|
|
||||||
_scanProgress.value = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* UI State
|
|
||||||
*/
|
|
||||||
sealed class UtilitiesUiState {
|
|
||||||
object Idle : UtilitiesUiState()
|
|
||||||
data class Scanning(val type: String) : UtilitiesUiState()
|
|
||||||
data class ScanComplete(val message: String, val count: Int) : UtilitiesUiState()
|
|
||||||
data class DuplicatesFound(val groups: List<DuplicateGroup>) : UtilitiesUiState()
|
|
||||||
data class BurstsFound(val groups: List<BurstGroup>) : UtilitiesUiState()
|
|
||||||
data class QualityAnalysisComplete(
|
|
||||||
val screenshots: Int,
|
|
||||||
val blurry: Int
|
|
||||||
) : UtilitiesUiState()
|
|
||||||
data class Error(val message: String) : UtilitiesUiState()
|
|
||||||
}
|
|
||||||
|
|
||||||
data class ScanProgress(
|
|
||||||
val message: String,
|
|
||||||
val current: Int,
|
|
||||||
val total: Int
|
|
||||||
)
|
|
||||||
|
|
||||||
data class DuplicateGroup(
|
|
||||||
val images: List<ImageEntity>,
|
|
||||||
val reason: String,
|
|
||||||
val confidence: Float
|
|
||||||
)
|
|
||||||
|
|
||||||
data class BurstGroup(
|
|
||||||
val images: List<ImageEntity>,
|
|
||||||
val burstId: String,
|
|
||||||
val representativeIndex: Int // Which photo to show in albums
|
|
||||||
)
|
|
||||||
@@ -1,635 +0,0 @@
|
|||||||
package com.placeholder.sherpai2.ui.utilities.stats
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.lazy.items
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.*
|
|
||||||
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.graphics.vector.ImageVector
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|
||||||
import com.patrykandpatrick.vico.compose.cartesian.CartesianChartHost
|
|
||||||
import com.patrykandpatrick.vico.compose.cartesian.axis.rememberBottomAxis
|
|
||||||
import com.patrykandpatrick.vico.compose.cartesian.axis.rememberStartAxis
|
|
||||||
import com.patrykandpatrick.vico.compose.cartesian.layer.rememberColumnCartesianLayer
|
|
||||||
import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLayer
|
|
||||||
import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart
|
|
||||||
import com.patrykandpatrick.vico.compose.common.component.rememberLineComponent
|
|
||||||
import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent
|
|
||||||
import com.patrykandpatrick.vico.compose.common.component.rememberTextComponent
|
|
||||||
import com.patrykandpatrick.vico.compose.common.of
|
|
||||||
import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer
|
|
||||||
import com.patrykandpatrick.vico.core.cartesian.data.columnSeries
|
|
||||||
import com.patrykandpatrick.vico.core.cartesian.data.lineSeries
|
|
||||||
import com.patrykandpatrick.vico.core.common.shape.Shape
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
|
||||||
* StatsScreen - Beautiful statistics dashboard
|
|
||||||
*
|
|
||||||
* Features:
|
|
||||||
* - Photo count timeline (with granularity toggle)
|
|
||||||
* - Year-by-year breakdown
|
|
||||||
* - System tag statistics
|
|
||||||
* - Burst detection stats
|
|
||||||
* - Usage patterns (day of week, time of day)
|
|
||||||
* - Face recognition stats
|
|
||||||
*/
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun StatsScreen(
|
|
||||||
viewModel: StatsViewModel = hiltViewModel()
|
|
||||||
) {
|
|
||||||
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
|
||||||
val granularity by viewModel.timelineGranularity.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
Scaffold(
|
|
||||||
topBar = {
|
|
||||||
TopAppBar(
|
|
||||||
title = {
|
|
||||||
Column {
|
|
||||||
Text(
|
|
||||||
"Photo Statistics",
|
|
||||||
style = MaterialTheme.typography.titleLarge,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"Your collection insights",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
actions = {
|
|
||||||
IconButton(onClick = { viewModel.refresh() }) {
|
|
||||||
Icon(Icons.Default.Refresh, "Refresh")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
colors = TopAppBarDefaults.topAppBarColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
) { paddingValues ->
|
|
||||||
when (val state = uiState) {
|
|
||||||
is StatsUiState.Loading -> {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(paddingValues),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
CircularProgressIndicator()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is StatsUiState.Error -> {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(paddingValues),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.Error,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(64.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
state.message,
|
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
|
||||||
color = MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
Button(onClick = { viewModel.refresh() }) {
|
|
||||||
Text("Retry")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is StatsUiState.Success -> {
|
|
||||||
StatsContent(
|
|
||||||
state = state,
|
|
||||||
granularity = granularity,
|
|
||||||
onGranularityChange = { viewModel.setTimelineGranularity(it) },
|
|
||||||
modifier = Modifier.padding(paddingValues)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun StatsContent(
|
|
||||||
state: StatsUiState.Success,
|
|
||||||
granularity: TimelineGranularity,
|
|
||||||
onGranularityChange: (TimelineGranularity) -> Unit,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
LazyColumn(
|
|
||||||
modifier = modifier.fillMaxSize(),
|
|
||||||
contentPadding = PaddingValues(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
|
||||||
// Overview stats cards
|
|
||||||
item {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
StatCard(
|
|
||||||
title = "Total Photos",
|
|
||||||
value = state.totalPhotos.toString(),
|
|
||||||
icon = Icons.Default.Photo,
|
|
||||||
color = MaterialTheme.colorScheme.primary,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
)
|
|
||||||
StatCard(
|
|
||||||
title = "Per Day",
|
|
||||||
value = String.format("%.1f", state.averagePerDay),
|
|
||||||
icon = Icons.Default.CalendarToday,
|
|
||||||
color = MaterialTheme.colorScheme.tertiary,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
StatCard(
|
|
||||||
title = "People",
|
|
||||||
value = state.personCount.toString(),
|
|
||||||
icon = Icons.Default.Face,
|
|
||||||
color = MaterialTheme.colorScheme.secondary,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
)
|
|
||||||
state.burstStats?.let { burst ->
|
|
||||||
StatCard(
|
|
||||||
title = "Burst Groups",
|
|
||||||
value = burst.estimatedBurstGroups.toString(),
|
|
||||||
icon = Icons.Default.BurstMode,
|
|
||||||
color = MaterialTheme.colorScheme.error,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Timeline chart
|
|
||||||
item {
|
|
||||||
SectionHeader("Photo Timeline")
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
TimelineChart(
|
|
||||||
state = state,
|
|
||||||
granularity = granularity,
|
|
||||||
onGranularityChange = onGranularityChange
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Year breakdown
|
|
||||||
item {
|
|
||||||
Spacer(Modifier.height(8.dp))
|
|
||||||
SectionHeader("Photos by Year")
|
|
||||||
}
|
|
||||||
|
|
||||||
items(state.yearCounts) { yearCount ->
|
|
||||||
YearStatRow(
|
|
||||||
year = yearCount.year,
|
|
||||||
count = yearCount.count,
|
|
||||||
totalPhotos = state.totalPhotos
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// System tags
|
|
||||||
if (state.systemTagStats.isNotEmpty()) {
|
|
||||||
item {
|
|
||||||
Spacer(Modifier.height(8.dp))
|
|
||||||
SectionHeader("System Tags")
|
|
||||||
}
|
|
||||||
|
|
||||||
items(state.systemTagStats) { tagStat ->
|
|
||||||
TagStatRow(tagStat)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Usage patterns
|
|
||||||
if (state.dayOfWeekCounts.isNotEmpty()) {
|
|
||||||
item {
|
|
||||||
Spacer(Modifier.height(8.dp))
|
|
||||||
SectionHeader("When You Shoot")
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
DayOfWeekChart(state.dayOfWeekCounts)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Date range info
|
|
||||||
state.dateRange?.let { range ->
|
|
||||||
item {
|
|
||||||
Spacer(Modifier.height(8.dp))
|
|
||||||
DateRangeCard(range)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun SectionHeader(title: String) {
|
|
||||||
Text(
|
|
||||||
text = title,
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = MaterialTheme.colorScheme.primary,
|
|
||||||
modifier = Modifier.padding(vertical = 8.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun StatCard(
|
|
||||||
title: String,
|
|
||||||
value: String,
|
|
||||||
icon: ImageVector,
|
|
||||||
color: Color,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
Card(
|
|
||||||
modifier = modifier,
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = color.copy(alpha = 0.1f)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
icon,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(32.dp),
|
|
||||||
tint = color
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
value,
|
|
||||||
style = MaterialTheme.typography.headlineMedium,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = color
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
title,
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun TimelineChart(
|
|
||||||
state: StatsUiState.Success,
|
|
||||||
granularity: TimelineGranularity,
|
|
||||||
onGranularityChange: (TimelineGranularity) -> Unit
|
|
||||||
) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
|
||||||
// Granularity selector
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
TimelineGranularity.entries.forEach { g ->
|
|
||||||
FilterChip(
|
|
||||||
selected = granularity == g,
|
|
||||||
onClick = { onGranularityChange(g) },
|
|
||||||
label = {
|
|
||||||
Text(
|
|
||||||
when (g) {
|
|
||||||
TimelineGranularity.DAILY -> "Daily"
|
|
||||||
TimelineGranularity.MONTHLY -> "Monthly"
|
|
||||||
TimelineGranularity.YEARLY -> "Yearly"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Chart
|
|
||||||
val modelProducer = remember { CartesianChartModelProducer.build() }
|
|
||||||
|
|
||||||
LaunchedEffect(granularity, state) {
|
|
||||||
val data = when (granularity) {
|
|
||||||
TimelineGranularity.DAILY -> state.dailyCounts.map { it.count.toFloat() }
|
|
||||||
TimelineGranularity.MONTHLY -> state.monthlyCounts.map { it.count.toFloat() }
|
|
||||||
TimelineGranularity.YEARLY -> state.yearCounts.reversed().map { it.count.toFloat() }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.isNotEmpty()) {
|
|
||||||
modelProducer.tryRunTransaction {
|
|
||||||
lineSeries { series(data) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.dailyCounts.isNotEmpty()) {
|
|
||||||
CartesianChartHost(
|
|
||||||
chart = rememberCartesianChart(
|
|
||||||
rememberLineCartesianLayer(),
|
|
||||||
startAxis = rememberStartAxis(),
|
|
||||||
bottomAxis = rememberBottomAxis()
|
|
||||||
),
|
|
||||||
modelProducer = modelProducer,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(200.dp)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Text(
|
|
||||||
"No data available",
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(32.dp),
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun YearStatRow(
|
|
||||||
year: String,
|
|
||||||
count: Int,
|
|
||||||
totalPhotos: Int
|
|
||||||
) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 1.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
|
||||||
Text(
|
|
||||||
year,
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
val percentage = if (totalPhotos > 0) {
|
|
||||||
(count.toFloat() / totalPhotos * 100).toInt()
|
|
||||||
} else 0
|
|
||||||
Text(
|
|
||||||
"$percentage% of collection",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Surface(
|
|
||||||
shape = RoundedCornerShape(8.dp),
|
|
||||||
color = MaterialTheme.colorScheme.primaryContainer
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
count.toString(),
|
|
||||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun TagStatRow(tagStat: com.placeholder.sherpai2.data.local.dao.TagStat) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 1.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
getTagIcon(tagStat.tagValue),
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.primary,
|
|
||||||
modifier = Modifier.size(24.dp)
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
tagStat.tagValue.replace("_", " ").capitalize(),
|
|
||||||
style = MaterialTheme.typography.bodyLarge
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Surface(
|
|
||||||
shape = RoundedCornerShape(8.dp),
|
|
||||||
color = MaterialTheme.colorScheme.secondaryContainer
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
tagStat.imageCount.toString(),
|
|
||||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 6.dp),
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = MaterialTheme.colorScheme.secondary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun DayOfWeekChart(counts: List<com.placeholder.sherpai2.data.local.dao.DayOfWeekCount>) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
val days = listOf("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
|
|
||||||
val maxCount = counts.maxOfOrNull { it.count } ?: 1
|
|
||||||
|
|
||||||
counts.forEach { dayCount ->
|
|
||||||
val dayName = days.getOrNull(dayCount.dayOfWeek) ?: "?"
|
|
||||||
val percentage = (dayCount.count.toFloat() / maxCount)
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
dayName,
|
|
||||||
modifier = Modifier.width(50.dp),
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
fontWeight = FontWeight.Medium
|
|
||||||
)
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.height(32.dp)
|
|
||||||
.background(
|
|
||||||
MaterialTheme.colorScheme.surfaceVariant,
|
|
||||||
RoundedCornerShape(4.dp)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxHeight()
|
|
||||||
.fillMaxWidth(percentage)
|
|
||||||
.background(
|
|
||||||
MaterialTheme.colorScheme.primary,
|
|
||||||
RoundedCornerShape(4.dp)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
dayCount.count.toString(),
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.CenterEnd)
|
|
||||||
.padding(end = 8.dp),
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun DateRangeCard(range: com.placeholder.sherpai2.data.local.dao.PhotoDateRange) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
colors = CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Default.DateRange,
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
"Collection Date Range",
|
|
||||||
style = MaterialTheme.typography.titleSmall,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val dateFormat = SimpleDateFormat("MMM dd, yyyy", Locale.getDefault())
|
|
||||||
val earliest = dateFormat.format(Date(range.earliest))
|
|
||||||
val latest = dateFormat.format(Date(range.latest))
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Column {
|
|
||||||
Text(
|
|
||||||
"Earliest",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
earliest,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
fontWeight = FontWeight.Medium
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Column(horizontalAlignment = Alignment.End) {
|
|
||||||
Text(
|
|
||||||
"Latest",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
latest,
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
fontWeight = FontWeight.Medium
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getTagIcon(tagValue: String): ImageVector {
|
|
||||||
return when (tagValue) {
|
|
||||||
"burst" -> Icons.Default.BurstMode
|
|
||||||
"duplicate" -> Icons.Default.FileCopy
|
|
||||||
"screenshot" -> Icons.Default.Screenshot
|
|
||||||
"blurry" -> Icons.Default.BlurOn
|
|
||||||
"low_quality" -> Icons.Default.LowPriority
|
|
||||||
else -> Icons.Default.LocalOffer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun String.capitalize(): String {
|
|
||||||
return this.split("_").joinToString(" ") { word ->
|
|
||||||
word.replaceFirstChar { it.uppercase() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
package com.placeholder.sherpai2.ui.utilities.stats
|
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import com.placeholder.sherpai2.data.local.dao.*
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
/**
|
|
||||||
* StatsViewModel - Photo collection statistics
|
|
||||||
*
|
|
||||||
* Features:
|
|
||||||
* 1. Photo count timeline (daily/monthly/yearly)
|
|
||||||
* 2. Year-by-year breakdown
|
|
||||||
* 3. System tag statistics
|
|
||||||
* 4. Burst detection stats
|
|
||||||
* 5. Usage patterns (day of week, hour of day)
|
|
||||||
*/
|
|
||||||
@HiltViewModel
|
|
||||||
class StatsViewModel @Inject constructor(
|
|
||||||
private val imageDao: ImageDao,
|
|
||||||
private val tagDao: TagDao,
|
|
||||||
private val imageTagDao: ImageTagDao,
|
|
||||||
private val personDao: PersonDao,
|
|
||||||
private val photoFaceTagDao: PhotoFaceTagDao
|
|
||||||
) : ViewModel() {
|
|
||||||
|
|
||||||
private val _uiState = MutableStateFlow<StatsUiState>(StatsUiState.Loading)
|
|
||||||
val uiState: StateFlow<StatsUiState> = _uiState.asStateFlow()
|
|
||||||
|
|
||||||
private val _timelineGranularity = MutableStateFlow(TimelineGranularity.MONTHLY)
|
|
||||||
val timelineGranularity: StateFlow<TimelineGranularity> = _timelineGranularity.asStateFlow()
|
|
||||||
|
|
||||||
init {
|
|
||||||
loadStats()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun loadStats() {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
|
||||||
try {
|
|
||||||
_uiState.value = StatsUiState.Loading
|
|
||||||
|
|
||||||
// Load all stats in parallel
|
|
||||||
val totalCount = imageDao.getImageCount()
|
|
||||||
val yearCounts = imageDao.getPhotoCountsByYear()
|
|
||||||
val monthlyCounts = imageDao.getPhotoCountsByMonth()
|
|
||||||
val dailyCounts = imageDao.getPhotoCountsByDate()
|
|
||||||
val systemTagStats = tagDao.getSystemTagStats()
|
|
||||||
val burstStats = imageTagDao.getBurstStats()
|
|
||||||
val dateRange = imageDao.getPhotoDateRange()
|
|
||||||
val avgPerDay = imageDao.getAveragePhotosPerDay()
|
|
||||||
val dayOfWeekCounts = imageDao.getPhotoCountsByDayOfWeek()
|
|
||||||
val hourCounts = imageDao.getPhotoCountsByHour()
|
|
||||||
|
|
||||||
// Face recognition stats
|
|
||||||
val personCount = personDao.getPersonCount()
|
|
||||||
val taggedFaceCount = photoFaceTagDao.getUnverifiedTagCount()
|
|
||||||
|
|
||||||
_uiState.value = StatsUiState.Success(
|
|
||||||
totalPhotos = totalCount,
|
|
||||||
yearCounts = yearCounts,
|
|
||||||
monthlyCounts = monthlyCounts,
|
|
||||||
dailyCounts = dailyCounts,
|
|
||||||
systemTagStats = systemTagStats,
|
|
||||||
burstStats = burstStats,
|
|
||||||
dateRange = dateRange,
|
|
||||||
averagePerDay = avgPerDay ?: 0f,
|
|
||||||
dayOfWeekCounts = dayOfWeekCounts,
|
|
||||||
hourCounts = hourCounts,
|
|
||||||
personCount = personCount,
|
|
||||||
taggedFaceCount = taggedFaceCount
|
|
||||||
)
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
_uiState.value = StatsUiState.Error(
|
|
||||||
e.message ?: "Failed to load statistics"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setTimelineGranularity(granularity: TimelineGranularity) {
|
|
||||||
_timelineGranularity.value = granularity
|
|
||||||
}
|
|
||||||
|
|
||||||
fun refresh() {
|
|
||||||
loadStats()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* UI State for stats screen
|
|
||||||
*/
|
|
||||||
sealed class StatsUiState {
|
|
||||||
object Loading : StatsUiState()
|
|
||||||
|
|
||||||
data class Success(
|
|
||||||
val totalPhotos: Int,
|
|
||||||
val yearCounts: List<YearCount>,
|
|
||||||
val monthlyCounts: List<MonthCount>,
|
|
||||||
val dailyCounts: List<DateCount>,
|
|
||||||
val systemTagStats: List<TagStat>,
|
|
||||||
val burstStats: BurstStats?,
|
|
||||||
val dateRange: PhotoDateRange?,
|
|
||||||
val averagePerDay: Float,
|
|
||||||
val dayOfWeekCounts: List<DayOfWeekCount>,
|
|
||||||
val hourCounts: List<HourCount>,
|
|
||||||
val personCount: Int,
|
|
||||||
val taggedFaceCount: Int
|
|
||||||
) : StatsUiState()
|
|
||||||
|
|
||||||
data class Error(val message: String) : StatsUiState()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Timeline granularity options
|
|
||||||
*/
|
|
||||||
enum class TimelineGranularity {
|
|
||||||
DAILY,
|
|
||||||
MONTHLY,
|
|
||||||
YEARLY
|
|
||||||
}
|
|
||||||
@@ -28,13 +28,6 @@ tensorflow-lite = "2.14.0"
|
|||||||
tensorflow-lite-support = "0.4.4"
|
tensorflow-lite-support = "0.4.4"
|
||||||
gson = "2.10.1"
|
gson = "2.10.1"
|
||||||
|
|
||||||
#Album/Image View Tools
|
|
||||||
zoomable = "1.6.1"
|
|
||||||
|
|
||||||
#Charting Lib
|
|
||||||
vico = "2.0.0-alpha.28"
|
|
||||||
|
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle" }
|
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle" }
|
||||||
@@ -75,16 +68,6 @@ tensorflow-lite-gpu = { group = "org.tensorflow", name = "tensorflow-lite-gpu",
|
|||||||
|
|
||||||
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
|
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
|
||||||
|
|
||||||
|
|
||||||
#Album/Image View Tools
|
|
||||||
zoomable = { group = "net.engawapg.lib", name = "zoomable", version.ref = "zoomable" }
|
|
||||||
|
|
||||||
vico-compose = { module = "com.patrykandpatrick.vico:compose", version.ref = "vico" }
|
|
||||||
vico-compose-m3 = { module = "com.patrykandpatrick.vico:compose-m3", version.ref = "vico" }
|
|
||||||
vico-core = { module = "com.patrykandpatrick.vico:core", version.ref = "vico" }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||||
|
|||||||
Reference in New Issue
Block a user