forked from github/szkolny
[App] Share Lesson and Event notes to specific team only.
This commit is contained in:
parent
742bd03e9e
commit
9fde97bef0
@ -324,11 +324,14 @@ class SzkolnyApi(val app: App) : CoroutineScope {
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun shareNote(note: Note) {
|
||||
fun shareNote(note: Note, teamId: Long? = null) {
|
||||
val profile = app.db.profileDao().getByIdNow(note.profileId)
|
||||
?: throw NullPointerException("Profile is not found")
|
||||
val team = app.db.teamDao().getClassNow(note.profileId)
|
||||
?: throw NullPointerException("TeamClass is not found")
|
||||
val team = if (teamId == null)
|
||||
app.db.teamDao().getClassNow(note.profileId)
|
||||
else
|
||||
app.db.teamDao().getByIdNow(note.profileId, teamId)
|
||||
team ?: throw NullPointerException("TeamClass is not found")
|
||||
|
||||
val response = api.shareNote(NoteShareRequest(
|
||||
deviceId = app.deviceId,
|
||||
|
@ -9,6 +9,7 @@ interface Noteable {
|
||||
fun getNoteType(): Note.OwnerType
|
||||
fun getNoteOwnerProfileId(): Int
|
||||
fun getNoteOwnerId(): Long
|
||||
fun getNoteShareTeamId(): Long? = null
|
||||
|
||||
var notes: MutableList<Note>
|
||||
|
||||
|
@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Note
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Noteable
|
||||
import pl.szczodrzynski.edziennik.ext.takePositive
|
||||
import pl.szczodrzynski.edziennik.ui.search.Searchable
|
||||
import pl.szczodrzynski.edziennik.utils.html.BetterHtml
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
@ -118,4 +119,5 @@ class EventFull(
|
||||
override fun getNoteType() = Note.OwnerType.EVENT
|
||||
override fun getNoteOwnerProfileId() = profileId
|
||||
override fun getNoteOwnerId() = id
|
||||
override fun getNoteShareTeamId() = teamId.takePositive()
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Lesson
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Note
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Noteable
|
||||
import pl.szczodrzynski.edziennik.ext.takePositive
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
class LessonFull(
|
||||
@ -142,4 +143,5 @@ class LessonFull(
|
||||
override fun getNoteType() = Note.OwnerType.LESSON
|
||||
override fun getNoteOwnerProfileId() = profileId
|
||||
override fun getNoteOwnerId() = ownerId
|
||||
override fun getNoteShareTeamId() = teamId.takePositive()
|
||||
}
|
||||
|
@ -76,6 +76,9 @@ fun pendingIntentFlag(): Int {
|
||||
fun Int?.takeValue() = if (this == -1) null else this
|
||||
fun Int?.takePositive() = if (this == -1 || this == 0) null else this
|
||||
|
||||
fun Long?.takeValue() = if (this == -1L) null else this
|
||||
fun Long?.takePositive() = if (this == -1L || this == 0L) null else this
|
||||
|
||||
fun String?.takeValue() = if (this.isNullOrBlank()) null else this
|
||||
|
||||
fun Any?.ignore() = Unit
|
||||
|
@ -87,7 +87,12 @@ class NoteEditorDialog(
|
||||
.show()
|
||||
}
|
||||
|
||||
val success = manager.saveNote(activity, note, wasShared = editingNote?.isShared ?: false)
|
||||
val success = manager.saveNote(
|
||||
activity = activity,
|
||||
note = note,
|
||||
teamId = owner?.getNoteShareTeamId(),
|
||||
wasShared = editingNote?.isShared ?: false,
|
||||
)
|
||||
progressDialog?.dismiss()
|
||||
return success
|
||||
}
|
||||
|
@ -93,10 +93,15 @@ class NoteManager(private val app: App) {
|
||||
return getOwner(note) != null
|
||||
}
|
||||
|
||||
suspend fun saveNote(activity: AppCompatActivity, note: Note, wasShared: Boolean): Boolean {
|
||||
suspend fun saveNote(
|
||||
activity: AppCompatActivity,
|
||||
note: Note,
|
||||
teamId: Long?,
|
||||
wasShared: Boolean,
|
||||
): Boolean {
|
||||
val success = when {
|
||||
!note.isShared && wasShared -> unshareNote(activity, note)
|
||||
note.isShared -> shareNote(activity, note)
|
||||
note.isShared -> shareNote(activity, note, teamId)
|
||||
else -> true
|
||||
}
|
||||
|
||||
@ -124,9 +129,9 @@ class NoteManager(private val app: App) {
|
||||
return true
|
||||
}
|
||||
|
||||
private suspend fun shareNote(activity: AppCompatActivity, note: Note): Boolean {
|
||||
private suspend fun shareNote(activity: AppCompatActivity, note: Note, teamId: Long?): Boolean {
|
||||
return app.api.runCatching(activity) {
|
||||
shareNote(note)
|
||||
shareNote(note, teamId)
|
||||
} != null
|
||||
}
|
||||
|
||||
|
@ -426,4 +426,10 @@ public class Date implements Comparable<Date>, Noteable {
|
||||
public boolean hasReplacingNotes() {
|
||||
return Noteable.DefaultImpls.hasReplacingNotes(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Long getNoteShareTeamId() {
|
||||
return Noteable.DefaultImpls.getNoteShareTeamId(this);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user