forked from github/szkolny
[API/Events] Update Event Manual dialog sharing.
This commit is contained in:
parent
2cf204ff79
commit
f242c30476
@ -641,3 +641,8 @@ fun Drawable.setTintColor(color: Int): Drawable {
|
|||||||
)
|
)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun <T> List<T>.ifNotEmpty(block: (List<T>) -> Unit) {
|
||||||
|
if (!isEmpty())
|
||||||
|
block(this)
|
||||||
|
}
|
||||||
|
@ -36,7 +36,7 @@ class Szkolny(val app: App, val callback: EdziennikCallback) {
|
|||||||
completed()
|
completed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shareEvent(event: EventFull) {
|
/*fun shareEvent(event: EventFull) {
|
||||||
api.shareEvent(event)
|
api.shareEvent(event)
|
||||||
completed()
|
completed()
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ class Szkolny(val app: App, val callback: EdziennikCallback) {
|
|||||||
fun unshareEvent(event: EventFull) {
|
fun unshareEvent(event: EventFull) {
|
||||||
api.unshareEvent(event)
|
api.unshareEvent(event)
|
||||||
completed()
|
completed()
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private fun completed() {
|
private fun completed() {
|
||||||
callback.onCompleted()
|
callback.onCompleted()
|
||||||
|
@ -15,7 +15,9 @@ import pl.szczodrzynski.edziennik.data.api.szkolny.interceptor.SignatureIntercep
|
|||||||
import pl.szczodrzynski.edziennik.data.api.szkolny.request.EventShareRequest
|
import pl.szczodrzynski.edziennik.data.api.szkolny.request.EventShareRequest
|
||||||
import pl.szczodrzynski.edziennik.data.api.szkolny.request.ServerSyncRequest
|
import pl.szczodrzynski.edziennik.data.api.szkolny.request.ServerSyncRequest
|
||||||
import pl.szczodrzynski.edziennik.data.api.szkolny.request.WebPushRequest
|
import pl.szczodrzynski.edziennik.data.api.szkolny.request.WebPushRequest
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.szkolny.response.ApiResponse
|
||||||
import pl.szczodrzynski.edziennik.data.api.szkolny.response.WebPushResponse
|
import pl.szczodrzynski.edziennik.data.api.szkolny.response.WebPushResponse
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.ProfileFull
|
import pl.szczodrzynski.edziennik.data.db.modules.profiles.ProfileFull
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
@ -102,29 +104,33 @@ class SzkolnyApi(val app: App) {
|
|||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shareEvent(event: EventFull) {
|
fun shareEvent(event: EventFull): ApiResponse<Nothing>? {
|
||||||
val team = app.db.teamDao().getByIdNow(event.profileId, event.teamId)
|
val team = app.db.teamDao().getByIdNow(event.profileId, event.teamId)
|
||||||
|
|
||||||
api.shareEvent(EventShareRequest(
|
return api.shareEvent(EventShareRequest(
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
sharedByName = event.sharedByName,
|
sharedByName = event.sharedByName,
|
||||||
shareTeamCode = team.code,
|
shareTeamCode = team.code,
|
||||||
event = event
|
event = event
|
||||||
)).execute()
|
)).execute().body()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unshareEvent(event: EventFull) {
|
fun unshareEvent(event: Event): ApiResponse<Nothing>? {
|
||||||
val team = app.db.teamDao().getByIdNow(event.profileId, event.teamId)
|
val team = app.db.teamDao().getByIdNow(event.profileId, event.teamId)
|
||||||
|
|
||||||
api.shareEvent(EventShareRequest(
|
return api.shareEvent(EventShareRequest(
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
sharedByName = event.sharedByName,
|
sharedByName = event.sharedByName,
|
||||||
unshareTeamCode = team.code,
|
unshareTeamCode = team.code,
|
||||||
eventId = event.id
|
eventId = event.id
|
||||||
)).execute()
|
)).execute().body()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pairBrowser(browserId: String?, pairToken: String?): List<WebPushResponse.Browser> {
|
/*fun eventEditRequest(requesterName: String, event: Event): ApiResponse<Nothing>? {
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
|
fun pairBrowser(browserId: String?, pairToken: String?, onError: ((List<ApiResponse.Error>) -> Unit)? = null): List<WebPushResponse.Browser> {
|
||||||
val response = api.webPush(WebPushRequest(
|
val response = api.webPush(WebPushRequest(
|
||||||
action = "pairBrowser",
|
action = "pairBrowser",
|
||||||
deviceId = app.deviceId,
|
deviceId = app.deviceId,
|
||||||
@ -132,10 +138,15 @@ class SzkolnyApi(val app: App) {
|
|||||||
pairToken = pairToken
|
pairToken = pairToken
|
||||||
)).execute().body()
|
)).execute().body()
|
||||||
|
|
||||||
|
response?.errors?.let {
|
||||||
|
onError?.invoke(it)
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
return response?.data?.browsers ?: emptyList()
|
return response?.data?.browsers ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun listBrowsers(): List<WebPushResponse.Browser> {
|
fun listBrowsers(onError: ((List<ApiResponse.Error>) -> Unit)? = null): List<WebPushResponse.Browser> {
|
||||||
val response = api.webPush(WebPushRequest(
|
val response = api.webPush(WebPushRequest(
|
||||||
action = "listBrowsers",
|
action = "listBrowsers",
|
||||||
deviceId = app.deviceId
|
deviceId = app.deviceId
|
||||||
|
@ -14,6 +14,7 @@ data class EventShareRequest (
|
|||||||
val sharedByName: String,
|
val sharedByName: String,
|
||||||
val shareTeamCode: String? = null,
|
val shareTeamCode: String? = null,
|
||||||
val unshareTeamCode: String? = null,
|
val unshareTeamCode: String? = null,
|
||||||
|
val requesterName: String? = null,
|
||||||
|
|
||||||
val eventId: Long? = null,
|
val eventId: Long? = null,
|
||||||
val event: EventFull? = null
|
val event: EventFull? = null
|
||||||
|
@ -16,8 +16,8 @@ class SzkolnyTask(val request: Any) : IApiTask(-1) {
|
|||||||
private const val TAG = "SzkolnyTask"
|
private const val TAG = "SzkolnyTask"
|
||||||
|
|
||||||
fun sync(profiles: List<ProfileFull>) = SzkolnyTask(SyncRequest(profiles))
|
fun sync(profiles: List<ProfileFull>) = SzkolnyTask(SyncRequest(profiles))
|
||||||
fun shareEvent(event: EventFull) = SzkolnyTask(ShareEventRequest(event))
|
/*fun shareEvent(event: EventFull) = SzkolnyTask(ShareEventRequest(event))
|
||||||
fun unshareEvent(event: EventFull) = SzkolnyTask(UnshareEventRequest(event))
|
fun unshareEvent(event: EventFull) = SzkolnyTask(UnshareEventRequest(event))*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var szkolny: Szkolny
|
private lateinit var szkolny: Szkolny
|
||||||
@ -35,12 +35,12 @@ class SzkolnyTask(val request: Any) : IApiTask(-1) {
|
|||||||
|
|
||||||
when (request) {
|
when (request) {
|
||||||
is SyncRequest -> szkolny.sync(request.profiles)
|
is SyncRequest -> szkolny.sync(request.profiles)
|
||||||
is ShareEventRequest -> szkolny.shareEvent(request.event)
|
/*is ShareEventRequest -> szkolny.shareEvent(request.event)
|
||||||
is UnshareEventRequest -> szkolny.unshareEvent(request.event)
|
is UnshareEventRequest -> szkolny.unshareEvent(request.event)*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class SyncRequest(val profiles: List<ProfileFull>)
|
data class SyncRequest(val profiles: List<ProfileFull>)
|
||||||
data class ShareEventRequest(val event: EventFull)
|
/*data class ShareEventRequest(val event: EventFull)
|
||||||
data class UnshareEventRequest(val event: EventFull)
|
data class UnshareEventRequest(val event: EventFull)*/
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||||
import pl.szczodrzynski.edziennik.data.api.task.SzkolnyTask
|
import pl.szczodrzynski.edziennik.data.api.task.SzkolnyTask
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
||||||
import pl.szczodrzynski.edziennik.databinding.DialogEventDetailsBinding
|
import pl.szczodrzynski.edziennik.databinding.DialogEventDetailsBinding
|
||||||
@ -39,6 +40,10 @@ class EventDetailsDialog(
|
|||||||
|
|
||||||
private lateinit var adapter: EventListAdapter
|
private lateinit var adapter: EventListAdapter
|
||||||
|
|
||||||
|
private val api by lazy {
|
||||||
|
SzkolnyApi(app)
|
||||||
|
}
|
||||||
|
|
||||||
init { run {
|
init { run {
|
||||||
if (activity.isFinishing)
|
if (activity.isFinishing)
|
||||||
return@run
|
return@run
|
||||||
@ -126,21 +131,29 @@ class EventDetailsDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun removeEvent() {
|
private fun removeEvent() {
|
||||||
|
launch {
|
||||||
if (eventShared && eventOwn) {
|
if (eventShared && eventOwn) {
|
||||||
Toast.makeText(activity, "Unshare + remove own event", Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, "Unshare + remove own event", Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
SzkolnyTask.unshareEvent(event).enqueue(activity)
|
val response = withContext(Dispatchers.Default) {
|
||||||
finishRemoving()
|
api.unshareEvent(event!!)
|
||||||
}
|
}
|
||||||
else if (eventShared && !eventOwn) {
|
|
||||||
|
response?.errors?.ifNotEmpty {
|
||||||
|
Toast.makeText(activity, "Error: "+it[0].reason, Toast.LENGTH_SHORT).show()
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
|
finishRemoving()
|
||||||
|
} else if (eventShared && !eventOwn) {
|
||||||
Toast.makeText(activity, "Remove + blacklist somebody's event", Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, "Remove + blacklist somebody's event", Toast.LENGTH_SHORT).show()
|
||||||
// TODO
|
// TODO
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Toast.makeText(activity, "Remove event", Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, "Remove event", Toast.LENGTH_SHORT).show()
|
||||||
finishRemoving()
|
finishRemoving()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun finishRemoving() {
|
private fun finishRemoving() {
|
||||||
launch {
|
launch {
|
||||||
|
@ -20,6 +20,7 @@ import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
|
|||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_AGENDA
|
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_AGENDA
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||||
import pl.szczodrzynski.edziennik.data.api.task.SzkolnyTask
|
import pl.szczodrzynski.edziennik.data.api.task.SzkolnyTask
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
|
||||||
@ -60,13 +61,17 @@ class EventManualDialog(
|
|||||||
private val app by lazy { activity.application as App }
|
private val app by lazy { activity.application as App }
|
||||||
private lateinit var b: DialogEventManualV2Binding
|
private lateinit var b: DialogEventManualV2Binding
|
||||||
private lateinit var dialog: AlertDialog
|
private lateinit var dialog: AlertDialog
|
||||||
private var removeEventDialog: AlertDialog? = null
|
|
||||||
private var defaultLoaded = false
|
|
||||||
|
|
||||||
private lateinit var event: Event
|
private lateinit var event: Event
|
||||||
private var customColor: Int? = null
|
private var customColor: Int? = null
|
||||||
private val editingShared = editingEvent?.sharedBy != null
|
private val editingShared = editingEvent?.sharedBy != null
|
||||||
private val editingOwn = editingEvent?.sharedBy == "self"
|
private val editingOwn = editingEvent?.sharedBy == "self"
|
||||||
|
private var removeEventDialog: AlertDialog? = null
|
||||||
|
private var defaultLoaded = false
|
||||||
|
|
||||||
|
private val api by lazy {
|
||||||
|
SzkolnyApi(app)
|
||||||
|
}
|
||||||
|
|
||||||
init { run {
|
init { run {
|
||||||
if (activity.isFinishing)
|
if (activity.isFinishing)
|
||||||
@ -617,7 +622,21 @@ class EventManualDialog(
|
|||||||
else if (!share && editingShared) {
|
else if (!share && editingShared) {
|
||||||
Toast.makeText(activity, "Unshare own event", Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, "Unshare own event", Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
SzkolnyTask.unshareEvent(eventObject.withMetadata(metadataObject)).enqueue(activity)
|
eventObject.apply {
|
||||||
|
sharedBy = null
|
||||||
|
sharedByName = profile?.studentNameLong
|
||||||
|
}
|
||||||
|
|
||||||
|
val response = withContext(Dispatchers.Default) {
|
||||||
|
api.unshareEvent(eventObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
response?.errors?.ifNotEmpty {
|
||||||
|
Toast.makeText(activity, "Error: "+it[0].reason, Toast.LENGTH_SHORT).show()
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
|
eventObject.sharedByName = null
|
||||||
finishAdding(eventObject, metadataObject)
|
finishAdding(eventObject, metadataObject)
|
||||||
}
|
}
|
||||||
else if (share) {
|
else if (share) {
|
||||||
@ -630,7 +649,14 @@ class EventManualDialog(
|
|||||||
|
|
||||||
metadataObject.addedDate = System.currentTimeMillis()
|
metadataObject.addedDate = System.currentTimeMillis()
|
||||||
|
|
||||||
SzkolnyTask.shareEvent(eventObject.withMetadata(metadataObject)).enqueue(activity)
|
val response = withContext(Dispatchers.Default) {
|
||||||
|
api.shareEvent(eventObject.withMetadata(metadataObject))
|
||||||
|
}
|
||||||
|
|
||||||
|
response?.errors?.ifNotEmpty {
|
||||||
|
Toast.makeText(activity, "Error: "+it[0].reason, Toast.LENGTH_SHORT).show()
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
eventObject.sharedBy = "self"
|
eventObject.sharedBy = "self"
|
||||||
finishAdding(eventObject, metadataObject)
|
finishAdding(eventObject, metadataObject)
|
||||||
@ -642,21 +668,29 @@ class EventManualDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun removeEvent() {
|
private fun removeEvent() {
|
||||||
|
launch {
|
||||||
if (editingShared && editingOwn) {
|
if (editingShared && editingOwn) {
|
||||||
Toast.makeText(activity, "Unshare + remove own event", Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, "Unshare + remove own event", Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
editingEvent?.let { SzkolnyTask.unshareEvent(it).enqueue(activity) }
|
val response = withContext(Dispatchers.Default) {
|
||||||
finishRemoving()
|
api.unshareEvent(editingEvent!!)
|
||||||
}
|
}
|
||||||
else if (editingShared && !editingOwn) {
|
|
||||||
|
response?.errors?.ifNotEmpty {
|
||||||
|
Toast.makeText(activity, "Error: "+it[0].reason, Toast.LENGTH_SHORT).show()
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
|
finishRemoving()
|
||||||
|
} else if (editingShared && !editingOwn) {
|
||||||
Toast.makeText(activity, "Remove + blacklist somebody's event", Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, "Remove + blacklist somebody's event", Toast.LENGTH_SHORT).show()
|
||||||
// TODO
|
// TODO
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Toast.makeText(activity, "Remove event", Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, "Remove event", Toast.LENGTH_SHORT).show()
|
||||||
finishRemoving()
|
finishRemoving()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun finishAdding(eventObject: Event, metadataObject: Metadata) {
|
private fun finishAdding(eventObject: Event, metadataObject: Metadata) {
|
||||||
launch {
|
launch {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user