[UI] Mark Firebase-received events as manual. Update legend icons.

This commit is contained in:
Kuba Szczodrzyński 2022-10-24 22:41:15 +02:00
parent 26ad6373e6
commit 2c34924052
No known key found for this signature in database
GPG Key ID: 70CB8A85BA1633CB
5 changed files with 43 additions and 13 deletions

View File

@ -258,12 +258,10 @@ class SzkolnyApi(val app: App) : CoroutineScope {
seen = profile.empty
notified = profile.empty
if (profile.userCode == event.sharedBy) {
sharedBy = "self"
addedManually = true
} else {
sharedBy = eventSharedBy
}
sharedBy = if (profile.userCode == event.sharedBy)
"self"
else
eventSharedBy
}
}
}

View File

@ -73,13 +73,22 @@ open class Event(
const val COLOR_INFORMATION = 0xff039be5.toInt()
}
/**
* Added manually - added by self, shared by self, or shared by someone else.
*/
@ColumnInfo(name = "eventAddedManually")
var addedManually: Boolean = false
get() = field || sharedBy == "self"
get() = field || isShared
/**
* Shared by - user code who shared the event. Null if not shared.
* "Self" if shared by this app user.
*/
@ColumnInfo(name = "eventSharedBy")
var sharedBy: String? = null
@ColumnInfo(name = "eventSharedByName")
var sharedByName: String? = null
@ColumnInfo(name = "eventBlacklisted")
var blacklisted: Boolean = false
@ColumnInfo(name = "eventIsDone")
@ -104,6 +113,27 @@ open class Event(
var attachmentIds: MutableList<Long>? = null
var attachmentNames: MutableList<String>? = null
val isHomework
get() = type == TYPE_HOMEWORK
/**
* Whether the event is shared by anyone. Note that this implies [addedManually].
*/
val isShared
get() = sharedBy != null
/**
* Whether the event is shared by "self" (this app user).
*/
val isSharedSent
get() = sharedBy == "self"
/**
* Whether the event is shared by someone else from the class group.
*/
val isSharedReceived
get() = sharedBy != null && sharedBy != "self"
/**
* Add an attachment
* @param id attachment ID
@ -134,9 +164,6 @@ open class Event(
it.timeInMillis += 45 * MINUTE * 1000
}
val isHomework
get() = type == TYPE_HOMEWORK
@Ignore
fun withMetadata(metadata: Metadata) = EventFull(this, metadata)
}

View File

@ -160,11 +160,11 @@ class SzkolnyAppFirebase(val app: App, val profiles: List<Profile>, val message:
if (event.color == -1)
event.color = null
event.addedManually = true
event.sharedBy = json.getString("sharedBy")
event.sharedByName = json.getString("sharedByName")
if (profile.userCode == event.sharedBy) {
event.sharedBy = "self"
event.addedManually = true
}
val metadata = Metadata(

View File

@ -55,7 +55,8 @@ class EventManager(val app: App) : CoroutineScope {
val hasReplacingNotes = event.hasReplacingNotes()
title.text = listOfNotNull(
if (event.addedManually) "{cmd-clipboard-edit-outline} " else null,
if (event.addedManually && !event.isSharedReceived) "{cmd-calendar-edit} " else null,
if (event.isSharedReceived) "{cmd-share-variant} " else null,
if (event.hasNotes() && hasReplacingNotes && showNotes) "{cmd-swap-horizontal} " else null,
if (event.hasNotes() && !hasReplacingNotes && showNotes) "{cmd-playlist-edit} " else null,
if (showType) "${event.typeName ?: "wydarzenie"} - " else null,
@ -77,6 +78,8 @@ class EventManager(val app: App) : CoroutineScope {
fun setLegendText(legend: IconicsTextView, event: EventFull, showNotes: Boolean = true) {
legend.text = listOfNotNull(
if (event.addedManually) R.string.legend_event_added_manually else null,
if (event.isSharedSent) R.string.legend_event_shared_sent else null,
if (event.isSharedReceived) R.string.legend_event_shared_received else null,
if (event.isDone) R.string.legend_event_is_done else null,
if (showNotes) NoteManager.getLegendText(event) else null,
).map { legend.context.getString(it) }.join("\n")

View File

@ -1437,7 +1437,7 @@
<string name="agenda_config_elearning_mark">Ustaw wydarzenia jako lekcje on-line</string>
<string name="agenda_config_elearning_type">Wybierz rodzaj wydarzeń</string>
<string name="agenda_config_elearning_group">Grupuj lekcje on-line na liście</string>
<string name="legend_event_added_manually">{cmd-clipboard-edit-outline} wydarzenie dodane ręcznie</string>
<string name="legend_event_added_manually">{cmd-calendar-edit} wydarzenie dodane ręcznie</string>
<string name="legend_event_is_done">{cmd-check} oznaczono jako wykonane</string>
<string name="agenda_config_not_available_yet">Funkcja jeszcze nie jest dostępna.</string>
<string name="messages_config_compose">Tworzenie wiadomości</string>
@ -1549,4 +1549,6 @@
<string name="notification_user_action_required_oauth_usos">USOS - wymagane logowanie z użyciem przeglądarki</string>
<string name="oauth_dialog_title">Zaloguj się</string>
<string name="app_cannot_load_data">Nie można załadować danych aplikacji</string>
<string name="legend_event_shared_received">{cmd-share-variant} udostępnione w klasie</string>
<string name="legend_event_shared_sent">{cmd-share-variant} udostępnione przez Ciebie</string>
</resources>