mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-06 03:50:23 +02:00
Show the category names in the usage history
This commit is contained in:
parent
871d482a40
commit
c3759f6651
4 changed files with 13 additions and 4 deletions
|
@ -64,10 +64,10 @@ abstract class UsedTimeDao {
|
||||||
abstract fun getAllUsedTimeItemsSync(): List<UsedTimeItem>
|
abstract fun getAllUsedTimeItemsSync(): List<UsedTimeItem>
|
||||||
|
|
||||||
// breaking it into multiple lines causes issues during compilation ...
|
// breaking it into multiple lines causes issues during compilation ...
|
||||||
@Query("SELECT 2 AS type, start_time_of_day AS startMinuteOfDay, end_time_of_day AS endMinuteOfDay, used_time AS duration, day_of_epoch AS day, NULL AS lastUsage, NULL AS maxSessionDuration, NULL AS pauseDuration FROM used_time WHERE category_id = :categoryId UNION ALL SELECT 1 AS type, start_minute_of_day AS startMinuteOfDay, end_minute_of_day AS endMinuteOfDay, last_session_duration AS duration, NULL AS day, last_usage AS lastUsage, max_session_duration AS maxSessionDuration, session_pause_duration AS pauseDuration FROM session_duration WHERE category_id = :categoryId ORDER BY type, day DESC, lastUsage DESC, startMinuteOfDay, endMinuteOfDay")
|
@Query("SELECT 2 AS type, start_time_of_day AS startMinuteOfDay, end_time_of_day AS endMinuteOfDay, used_time AS duration, day_of_epoch AS day, NULL AS lastUsage, NULL AS maxSessionDuration, NULL AS pauseDuration, category.id AS categoryId, category.title AS categoryTitle FROM used_time JOIN category ON (used_time.category_id = category.id) WHERE category.id = :categoryId UNION ALL SELECT 1 AS type, start_minute_of_day AS startMinuteOfDay, end_minute_of_day AS endMinuteOfDay, last_session_duration AS duration, NULL AS day, last_usage AS lastUsage, max_session_duration AS maxSessionDuration, session_pause_duration AS pauseDuration, category.id AS categoryId, category.title AS categoryTitle FROM session_duration JOIN category ON (session_duration.category_id = category.id) WHERE category.id = :categoryId ORDER BY type, day DESC, lastUsage DESC, startMinuteOfDay, endMinuteOfDay, categoryId")
|
||||||
abstract fun getUsedTimeListItemsByCategoryId(categoryId: String): DataSource.Factory<Int, UsedTimeListItem>
|
abstract fun getUsedTimeListItemsByCategoryId(categoryId: String): DataSource.Factory<Int, UsedTimeListItem>
|
||||||
|
|
||||||
// breaking it into multiple lines causes issues during compilation ...
|
// breaking it into multiple lines causes issues during compilation ...
|
||||||
@Query("SELECT 2 AS type, start_time_of_day AS startMinuteOfDay, end_time_of_day AS endMinuteOfDay, used_time AS duration, day_of_epoch AS day, NULL AS lastUsage, NULL AS maxSessionDuration, NULL AS pauseDuration FROM used_time WHERE category_id IN (SELECT category_id FROM category WHERE child_id = :userId) UNION ALL SELECT 1 AS type, start_minute_of_day AS startMinuteOfDay, end_minute_of_day AS endMinuteOfDay, last_session_duration AS duration, NULL AS day, last_usage AS lastUsage, max_session_duration AS maxSessionDuration, session_pause_duration AS pauseDuration FROM session_duration WHERE category_id IN (SELECT category_id FROM category WHERE child_id = :userId) ORDER BY type, day DESC, lastUsage DESC, startMinuteOfDay, endMinuteOfDay")
|
@Query("SELECT 2 AS type, start_time_of_day AS startMinuteOfDay, end_time_of_day AS endMinuteOfDay, used_time AS duration, day_of_epoch AS day, NULL AS lastUsage, NULL AS maxSessionDuration, NULL AS pauseDuration, category.id AS categoryId, category.title AS categoryTitle FROM used_time JOIN category ON (used_time.category_id = category.id) WHERE category.child_id = :userId UNION ALL SELECT 1 AS type, start_minute_of_day AS startMinuteOfDay, end_minute_of_day AS endMinuteOfDay, last_session_duration AS duration, NULL AS day, last_usage AS lastUsage, max_session_duration AS maxSessionDuration, session_pause_duration AS pauseDuration, category.id AS categoryId, category.title AS categoryTitle FROM session_duration JOIN category ON (session_duration.category_id = category.id) WHERE category.child_id = :userId ORDER BY type, day DESC, lastUsage DESC, startMinuteOfDay, endMinuteOfDay, categoryId")
|
||||||
abstract fun getUsedTimeListItemsByUserId(userId: String): DataSource.Factory<Int, UsedTimeListItem>
|
abstract fun getUsedTimeListItemsByUserId(userId: String): DataSource.Factory<Int, UsedTimeListItem>
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
package io.timelimit.android.data.model
|
package io.timelimit.android.data.model
|
||||||
|
|
||||||
data class UsedTimeListItem(
|
data class UsedTimeListItem(
|
||||||
|
val categoryId: String,
|
||||||
|
val categoryTitle: String,
|
||||||
val startMinuteOfDay: Int,
|
val startMinuteOfDay: Int,
|
||||||
val endMinuteOfDay: Int,
|
val endMinuteOfDay: Int,
|
||||||
val duration: Long,
|
val duration: Long,
|
||||||
|
|
|
@ -30,6 +30,7 @@ import io.timelimit.android.util.TimeTextUtil
|
||||||
import org.threeten.bp.LocalDate
|
import org.threeten.bp.LocalDate
|
||||||
import org.threeten.bp.ZoneOffset
|
import org.threeten.bp.ZoneOffset
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
class UsageHistoryAdapter: PagedListAdapter<UsedTimeListItem, UsageHistoryViewHolder>(diffCallback) {
|
class UsageHistoryAdapter: PagedListAdapter<UsedTimeListItem, UsageHistoryViewHolder>(diffCallback) {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -41,6 +42,8 @@ class UsageHistoryAdapter: PagedListAdapter<UsedTimeListItem, UsageHistoryViewHo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var showCategoryTitle: Boolean by Delegates.observable(false) { _, _, _ -> notifyDataSetChanged() }
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = UsageHistoryViewHolder(
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = UsageHistoryViewHolder(
|
||||||
FragmentUsageHistoryItemBinding.inflate(
|
FragmentUsageHistoryItemBinding.inflate(
|
||||||
LayoutInflater.from(parent.context),
|
LayoutInflater.from(parent.context),
|
||||||
|
@ -59,17 +62,19 @@ class UsageHistoryAdapter: PagedListAdapter<UsedTimeListItem, UsageHistoryViewHo
|
||||||
else
|
else
|
||||||
context.getString(R.string.usage_history_time_area, MinuteOfDay.format(item.startMinuteOfDay), MinuteOfDay.format(item.endMinuteOfDay))
|
context.getString(R.string.usage_history_time_area, MinuteOfDay.format(item.startMinuteOfDay), MinuteOfDay.format(item.endMinuteOfDay))
|
||||||
|
|
||||||
|
val dateStringPrefix = if (showCategoryTitle) item?.categoryTitle + " - " else ""
|
||||||
|
|
||||||
if (item?.day != null) {
|
if (item?.day != null) {
|
||||||
val dateObject = LocalDate.ofEpochDay(item.day)
|
val dateObject = LocalDate.ofEpochDay(item.day)
|
||||||
val dateString = DateFormat.getDateFormat(context).apply {
|
val dateString = DateFormat.getDateFormat(context).apply {
|
||||||
timeZone = TimeZone.getTimeZone("UTC")
|
timeZone = TimeZone.getTimeZone("UTC")
|
||||||
}.format(Date(dateObject.atStartOfDay().toEpochSecond(ZoneOffset.UTC) * 1000L))
|
}.format(Date(dateObject.atStartOfDay().toEpochSecond(ZoneOffset.UTC) * 1000L))
|
||||||
|
|
||||||
binding.date = dateString
|
binding.date = dateStringPrefix + dateString
|
||||||
binding.timeArea = timeAreaString
|
binding.timeArea = timeAreaString
|
||||||
binding.usedTime = TimeTextUtil.used(item.duration.toInt(), context)
|
binding.usedTime = TimeTextUtil.used(item.duration.toInt(), context)
|
||||||
} else if (item?.lastUsage != null && item.maxSessionDuration != null && item.pauseDuration != null) {
|
} else if (item?.lastUsage != null && item.maxSessionDuration != null && item.pauseDuration != null) {
|
||||||
binding.date = context.getString(
|
binding.date = dateStringPrefix + context.getString(
|
||||||
R.string.usage_history_item_session_duration_limit,
|
R.string.usage_history_item_session_duration_limit,
|
||||||
TimeTextUtil.time(item.maxSessionDuration.toInt(), context),
|
TimeTextUtil.time(item.maxSessionDuration.toInt(), context),
|
||||||
TimeTextUtil.time(item.pauseDuration.toInt(), context)
|
TimeTextUtil.time(item.pauseDuration.toInt(), context)
|
||||||
|
|
|
@ -47,6 +47,8 @@ class UsageHistoryFragment : Fragment() {
|
||||||
val userId = requireArguments().getString(USER_ID)!!
|
val userId = requireArguments().getString(USER_ID)!!
|
||||||
val categoryId = requireArguments().getString(CATEGORY_ID)
|
val categoryId = requireArguments().getString(CATEGORY_ID)
|
||||||
|
|
||||||
|
adapter.showCategoryTitle = categoryId == null
|
||||||
|
|
||||||
LivePagedListBuilder(
|
LivePagedListBuilder(
|
||||||
categoryId?.let { database.usedTimes().getUsedTimeListItemsByCategoryId(it) }
|
categoryId?.let { database.usedTimes().getUsedTimeListItemsByCategoryId(it) }
|
||||||
?: database.usedTimes().getUsedTimeListItemsByUserId(userId),
|
?: database.usedTimes().getUsedTimeListItemsByUserId(userId),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue