forked from github/szkolny
[API] Fix task cancelling with the notification. [UI] Add event downloading progress bar.
This commit is contained in:
parent
a6c4053896
commit
14d267a95a
@ -743,6 +743,7 @@ inline fun <T : CompoundButton> T.onChange(crossinline onChangeListener: (v: T,
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <T : MaterialButton> T.onChange(crossinline onChangeListener: (v: T, isChecked: Boolean) -> Unit) {
|
||||
clearOnCheckedChangeListeners()
|
||||
addOnCheckedChangeListener { buttonView, isChecked ->
|
||||
onChangeListener(buttonView as T, isChecked)
|
||||
}
|
||||
|
@ -38,6 +38,9 @@ class ApiService : Service() {
|
||||
context.startService(Intent(context, ApiService::class.java))
|
||||
EventBus.getDefault().postSticky(request)
|
||||
}
|
||||
|
||||
var lastEventTime = System.currentTimeMillis()
|
||||
var taskCancelTries = 0
|
||||
}
|
||||
|
||||
private val app by lazy { applicationContext as App }
|
||||
@ -64,9 +67,6 @@ class ApiService : Service() {
|
||||
|
||||
private val notification by lazy { EdziennikNotification(app) }
|
||||
|
||||
private var lastEventTime = System.currentTimeMillis()
|
||||
private var taskCancelTries = 0
|
||||
|
||||
/* ______ _ _ _ _ _____ _ _ _ _
|
||||
| ____| | | (_) (_) | / ____| | | | | | |
|
||||
| |__ __| |_____ ___ _ __ _ __ _| | __ | | __ _| | | |__ __ _ ___| | __
|
||||
|
@ -8,11 +8,12 @@ import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationCompat.PRIORITY_MIN
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.Bundle
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.receivers.SzkolnyReceiver
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
@ -35,16 +36,18 @@ class EdziennikNotification(val app: App) {
|
||||
var serviceClosed = false
|
||||
|
||||
private fun cancelPendingIntent(taskId: Int): PendingIntent {
|
||||
val intent = Intent("pl.szczodrzynski.edziennik.SZKOLNY_MAIN")
|
||||
intent.putExtra("task", "TaskCancelRequest")
|
||||
intent.putExtra("taskId", taskId)
|
||||
return PendingIntent.getBroadcast(app, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT) as PendingIntent
|
||||
val intent = SzkolnyReceiver.getIntent(app, Bundle(
|
||||
"task" to "TaskCancelRequest",
|
||||
"taskId" to taskId
|
||||
))
|
||||
return PendingIntent.getBroadcast(app, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) as PendingIntent
|
||||
}
|
||||
private val closePendingIntent: PendingIntent
|
||||
get() {
|
||||
val intent = Intent("pl.szczodrzynski.edziennik.SZKOLNY_MAIN")
|
||||
intent.putExtra("task", "ServiceCloseRequest")
|
||||
return PendingIntent.getBroadcast(app, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT) as PendingIntent
|
||||
val intent = SzkolnyReceiver.getIntent(app, Bundle(
|
||||
"task" to "ServiceCloseRequest"
|
||||
))
|
||||
return PendingIntent.getBroadcast(app, 0, intent, 0) as PendingIntent
|
||||
}
|
||||
|
||||
private fun errorCountText(): String? {
|
||||
|
@ -103,6 +103,7 @@ class Edudziennik(val app: App, val profile: Profile?, val loginStore: LoginStor
|
||||
override fun cancel() {
|
||||
d(TAG, "Cancelled")
|
||||
data.cancel()
|
||||
callback.onCompleted()
|
||||
}
|
||||
|
||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
||||
|
@ -126,6 +126,7 @@ class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
||||
override fun cancel() {
|
||||
d(TAG, "Cancelled")
|
||||
data.cancel()
|
||||
callback.onCompleted()
|
||||
}
|
||||
|
||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
||||
|
@ -141,6 +141,7 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
override fun cancel() {
|
||||
d(TAG, "Cancelled")
|
||||
data.cancel()
|
||||
callback.onCompleted()
|
||||
}
|
||||
|
||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
||||
|
@ -128,6 +128,7 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
||||
override fun cancel() {
|
||||
d(TAG, "Cancelled")
|
||||
data.cancel()
|
||||
callback.onCompleted()
|
||||
}
|
||||
|
||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
||||
|
@ -101,6 +101,7 @@ class Template(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
||||
override fun cancel() {
|
||||
d(TAG, "Cancelled")
|
||||
data.cancel()
|
||||
callback.onCompleted()
|
||||
}
|
||||
|
||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
||||
|
@ -112,6 +112,7 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
||||
override fun cancel() {
|
||||
d(TAG, "Cancelled")
|
||||
data.cancel()
|
||||
callback.onCompleted()
|
||||
}
|
||||
|
||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
||||
|
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2020-3-31.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.events
|
||||
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
|
||||
data class EventGetEvent(val message: EventFull)
|
@ -86,6 +86,7 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
|
||||
val gradeCategories = LongSparseArray<GradeCategory>()
|
||||
|
||||
var teacherOnConflictStrategy = OnConflictStrategy.IGNORE
|
||||
var eventListReplace = false
|
||||
|
||||
val classrooms = LongSparseArray<Classroom>()
|
||||
val attendanceTypes = LongSparseArray<AttendanceType>()
|
||||
@ -284,7 +285,10 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
|
||||
db.gradeDao().addAll(gradeList)
|
||||
}
|
||||
if (eventList.isNotEmpty()) {
|
||||
db.eventDao().upsertAll(eventList, removeNotKept = true)
|
||||
if (eventListReplace)
|
||||
db.eventDao().replaceAll(eventList)
|
||||
else
|
||||
db.eventDao().upsertAll(eventList, removeNotKept = true)
|
||||
}
|
||||
if (noticeList.isNotEmpty()) {
|
||||
db.noticeDao().clear(profile.id)
|
||||
|
@ -7,6 +7,7 @@ package pl.szczodrzynski.edziennik.receivers
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import pl.szczodrzynski.edziennik.data.api.ApiService
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
||||
import pl.szczodrzynski.edziennik.data.api.events.requests.ServiceCloseRequest
|
||||
@ -15,6 +16,11 @@ import pl.szczodrzynski.edziennik.data.api.events.requests.TaskCancelRequest
|
||||
class SzkolnyReceiver : BroadcastReceiver() {
|
||||
companion object {
|
||||
const val ACTION = "pl.szczodrzynski.edziennik.SZKOLNY_MAIN"
|
||||
fun getIntent(context: Context, extras: Bundle): Intent {
|
||||
val intent = Intent(context, SzkolnyReceiver::class.java)
|
||||
intent.putExtras(extras)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
|
@ -12,10 +12,17 @@ import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
||||
import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||
import pl.szczodrzynski.edziennik.databinding.DialogEventDetailsBinding
|
||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
||||
@ -188,6 +195,26 @@ class EventDetailsDialog(
|
||||
BetterLink.attach(b.topic) {
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
if (event.homeworkBody == null && !event.addedManually && event.type == Event.TYPE_HOMEWORK) {
|
||||
b.bodyProgressBar.isVisible = true
|
||||
b.body.isVisible = false
|
||||
EdziennikTask.eventGet(event.profileId, event).enqueue(activity)
|
||||
}
|
||||
else {
|
||||
b.bodyProgressBar.isVisible = false
|
||||
b.body.isVisible = true
|
||||
b.body.text = event.homeworkBody
|
||||
BetterLink.attach(b.body) {
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
||||
fun onEventGetEvent(event: EventGetEvent) {
|
||||
EventBus.getDefault().removeStickyEvent(event)
|
||||
update()
|
||||
}
|
||||
|
||||
private fun showRemovingProgressDialog() {
|
||||
|
@ -17,10 +17,7 @@ import com.mikepenz.iconics.IconicsDrawable
|
||||
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
|
||||
import com.mikepenz.iconics.utils.colorInt
|
||||
import com.mikepenz.iconics.utils.sizeDp
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.MainActivity
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.receivers.SzkolnyReceiver
|
||||
import pl.szczodrzynski.edziennik.ui.widgets.WidgetConfig
|
||||
|
||||
@ -43,8 +40,9 @@ class WidgetNotificationsProvider : AppWidgetProvider() {
|
||||
RemoteViews(app.packageName, if (config.darkTheme) R.layout.widget_notifications_dark else R.layout.widget_notifications)
|
||||
}
|
||||
|
||||
val syncIntent = Intent(SzkolnyReceiver.ACTION)
|
||||
syncIntent.putExtra("task", "SyncRequest")
|
||||
val syncIntent = SzkolnyReceiver.getIntent(context, Bundle(
|
||||
"task" to "SyncRequest"
|
||||
))
|
||||
val syncPendingIntent = PendingIntent.getBroadcast(context, 0, syncIntent, 0)
|
||||
views.setOnClickPendingIntent(R.id.widgetNotificationsSync, syncPendingIntent)
|
||||
|
||||
|
@ -151,6 +151,33 @@
|
||||
android:textIsSelectable="true"
|
||||
tools:text="Rozdział II: Panowanie Piastów i Jagiellonów.Przeniesiony z 11 grudnia." />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:textAppearance="@style/NavView.TextView.Helper"
|
||||
android:text="@string/dialog_event_details_body"
|
||||
android:visibility="@{event.homeworkBody != null ? View.VISIBLE : View.GONE}"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/bodyProgressBar"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/body"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{event.homeworkBody}"
|
||||
android:textAppearance="@style/NavView.TextView.Medium"
|
||||
android:textIsSelectable="true"
|
||||
android:visibility="@{event.homeworkBody != null ? View.VISIBLE : View.GONE}"
|
||||
tools:text="Rozdział II: Panowanie Piastów i Jagiellonów.Przeniesiony z 11 grudnia." />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -1283,4 +1283,5 @@
|
||||
<string name="hint_mark_as_done">Oznacz jako wykonane</string>
|
||||
<string name="event_mark_as_done_title">Oznacz jako wykonane</string>
|
||||
<string name="event_mark_as_done_text">Czy chcesz oznaczyć to zadanie jako wykonane?\n\nNie będzie ono się wyświetlać na stronie głównej oraz w aktualnych zadaniach domowych. Będzie wciąż dostępne w Terminarzu.</string>
|
||||
<string name="dialog_event_details_body">Treść</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user