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")
|
@Suppress("UNCHECKED_CAST")
|
||||||
inline fun <T : MaterialButton> T.onChange(crossinline onChangeListener: (v: T, isChecked: Boolean) -> Unit) {
|
inline fun <T : MaterialButton> T.onChange(crossinline onChangeListener: (v: T, isChecked: Boolean) -> Unit) {
|
||||||
|
clearOnCheckedChangeListeners()
|
||||||
addOnCheckedChangeListener { buttonView, isChecked ->
|
addOnCheckedChangeListener { buttonView, isChecked ->
|
||||||
onChangeListener(buttonView as T, isChecked)
|
onChangeListener(buttonView as T, isChecked)
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,9 @@ class ApiService : Service() {
|
|||||||
context.startService(Intent(context, ApiService::class.java))
|
context.startService(Intent(context, ApiService::class.java))
|
||||||
EventBus.getDefault().postSticky(request)
|
EventBus.getDefault().postSticky(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lastEventTime = System.currentTimeMillis()
|
||||||
|
var taskCancelTries = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private val app by lazy { applicationContext as App }
|
private val app by lazy { applicationContext as App }
|
||||||
@ -64,9 +67,6 @@ class ApiService : Service() {
|
|||||||
|
|
||||||
private val notification by lazy { EdziennikNotification(app) }
|
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.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.NotificationCompat.PRIORITY_MIN
|
import androidx.core.app.NotificationCompat.PRIORITY_MIN
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
|
import pl.szczodrzynski.edziennik.Bundle
|
||||||
import pl.szczodrzynski.edziennik.R
|
import pl.szczodrzynski.edziennik.R
|
||||||
|
import pl.szczodrzynski.edziennik.receivers.SzkolnyReceiver
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
|
||||||
@ -35,16 +36,18 @@ class EdziennikNotification(val app: App) {
|
|||||||
var serviceClosed = false
|
var serviceClosed = false
|
||||||
|
|
||||||
private fun cancelPendingIntent(taskId: Int): PendingIntent {
|
private fun cancelPendingIntent(taskId: Int): PendingIntent {
|
||||||
val intent = Intent("pl.szczodrzynski.edziennik.SZKOLNY_MAIN")
|
val intent = SzkolnyReceiver.getIntent(app, Bundle(
|
||||||
intent.putExtra("task", "TaskCancelRequest")
|
"task" to "TaskCancelRequest",
|
||||||
intent.putExtra("taskId", taskId)
|
"taskId" to taskId
|
||||||
return PendingIntent.getBroadcast(app, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT) as PendingIntent
|
))
|
||||||
|
return PendingIntent.getBroadcast(app, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) as PendingIntent
|
||||||
}
|
}
|
||||||
private val closePendingIntent: PendingIntent
|
private val closePendingIntent: PendingIntent
|
||||||
get() {
|
get() {
|
||||||
val intent = Intent("pl.szczodrzynski.edziennik.SZKOLNY_MAIN")
|
val intent = SzkolnyReceiver.getIntent(app, Bundle(
|
||||||
intent.putExtra("task", "ServiceCloseRequest")
|
"task" to "ServiceCloseRequest"
|
||||||
return PendingIntent.getBroadcast(app, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT) as PendingIntent
|
))
|
||||||
|
return PendingIntent.getBroadcast(app, 0, intent, 0) as PendingIntent
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun errorCountText(): String? {
|
private fun errorCountText(): String? {
|
||||||
|
@ -103,6 +103,7 @@ class Edudziennik(val app: App, val profile: Profile?, val loginStore: LoginStor
|
|||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
d(TAG, "Cancelled")
|
d(TAG, "Cancelled")
|
||||||
data.cancel()
|
data.cancel()
|
||||||
|
callback.onCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
||||||
|
@ -126,6 +126,7 @@ class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
|||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
d(TAG, "Cancelled")
|
d(TAG, "Cancelled")
|
||||||
data.cancel()
|
data.cancel()
|
||||||
|
callback.onCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
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() {
|
override fun cancel() {
|
||||||
d(TAG, "Cancelled")
|
d(TAG, "Cancelled")
|
||||||
data.cancel()
|
data.cancel()
|
||||||
|
callback.onCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
||||||
|
@ -128,6 +128,7 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
|||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
d(TAG, "Cancelled")
|
d(TAG, "Cancelled")
|
||||||
data.cancel()
|
data.cancel()
|
||||||
|
callback.onCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
||||||
|
@ -101,6 +101,7 @@ class Template(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
|||||||
override fun cancel() {
|
override fun cancel() {
|
||||||
d(TAG, "Cancelled")
|
d(TAG, "Cancelled")
|
||||||
data.cancel()
|
data.cancel()
|
||||||
|
callback.onCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
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() {
|
override fun cancel() {
|
||||||
d(TAG, "Cancelled")
|
d(TAG, "Cancelled")
|
||||||
data.cancel()
|
data.cancel()
|
||||||
|
callback.onCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun wrapCallback(callback: EdziennikCallback): EdziennikCallback {
|
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>()
|
val gradeCategories = LongSparseArray<GradeCategory>()
|
||||||
|
|
||||||
var teacherOnConflictStrategy = OnConflictStrategy.IGNORE
|
var teacherOnConflictStrategy = OnConflictStrategy.IGNORE
|
||||||
|
var eventListReplace = false
|
||||||
|
|
||||||
val classrooms = LongSparseArray<Classroom>()
|
val classrooms = LongSparseArray<Classroom>()
|
||||||
val attendanceTypes = LongSparseArray<AttendanceType>()
|
val attendanceTypes = LongSparseArray<AttendanceType>()
|
||||||
@ -284,7 +285,10 @@ abstract class Data(val app: App, val profile: Profile?, val loginStore: LoginSt
|
|||||||
db.gradeDao().addAll(gradeList)
|
db.gradeDao().addAll(gradeList)
|
||||||
}
|
}
|
||||||
if (eventList.isNotEmpty()) {
|
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()) {
|
if (noticeList.isNotEmpty()) {
|
||||||
db.noticeDao().clear(profile.id)
|
db.noticeDao().clear(profile.id)
|
||||||
|
@ -7,6 +7,7 @@ package pl.szczodrzynski.edziennik.receivers
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
import pl.szczodrzynski.edziennik.data.api.ApiService
|
import pl.szczodrzynski.edziennik.data.api.ApiService
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.requests.ServiceCloseRequest
|
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() {
|
class SzkolnyReceiver : BroadcastReceiver() {
|
||||||
companion object {
|
companion object {
|
||||||
const val ACTION = "pl.szczodrzynski.edziennik.SZKOLNY_MAIN"
|
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?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
|
@ -12,10 +12,17 @@ import android.view.View
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import kotlinx.coroutines.*
|
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.*
|
||||||
|
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.api.szkolny.SzkolnyApi
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
import pl.szczodrzynski.edziennik.databinding.DialogEventDetailsBinding
|
import pl.szczodrzynski.edziennik.databinding.DialogEventDetailsBinding
|
||||||
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
import pl.szczodrzynski.edziennik.ui.modules.timetable.TimetableFragment
|
||||||
@ -188,6 +195,26 @@ class EventDetailsDialog(
|
|||||||
BetterLink.attach(b.topic) {
|
BetterLink.attach(b.topic) {
|
||||||
dialog.dismiss()
|
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() {
|
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.typeface.library.community.material.CommunityMaterial
|
||||||
import com.mikepenz.iconics.utils.colorInt
|
import com.mikepenz.iconics.utils.colorInt
|
||||||
import com.mikepenz.iconics.utils.sizeDp
|
import com.mikepenz.iconics.utils.sizeDp
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.MainActivity
|
|
||||||
import pl.szczodrzynski.edziennik.R
|
|
||||||
import pl.szczodrzynski.edziennik.getJsonObject
|
|
||||||
import pl.szczodrzynski.edziennik.receivers.SzkolnyReceiver
|
import pl.szczodrzynski.edziennik.receivers.SzkolnyReceiver
|
||||||
import pl.szczodrzynski.edziennik.ui.widgets.WidgetConfig
|
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)
|
RemoteViews(app.packageName, if (config.darkTheme) R.layout.widget_notifications_dark else R.layout.widget_notifications)
|
||||||
}
|
}
|
||||||
|
|
||||||
val syncIntent = Intent(SzkolnyReceiver.ACTION)
|
val syncIntent = SzkolnyReceiver.getIntent(context, Bundle(
|
||||||
syncIntent.putExtra("task", "SyncRequest")
|
"task" to "SyncRequest"
|
||||||
|
))
|
||||||
val syncPendingIntent = PendingIntent.getBroadcast(context, 0, syncIntent, 0)
|
val syncPendingIntent = PendingIntent.getBroadcast(context, 0, syncIntent, 0)
|
||||||
views.setOnClickPendingIntent(R.id.widgetNotificationsSync, syncPendingIntent)
|
views.setOnClickPendingIntent(R.id.widgetNotificationsSync, syncPendingIntent)
|
||||||
|
|
||||||
|
@ -151,6 +151,33 @@
|
|||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
tools:text="Rozdział II: Panowanie Piastów i Jagiellonów.Przeniesiony z 11 grudnia." />
|
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
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -1283,4 +1283,5 @@
|
|||||||
<string name="hint_mark_as_done">Oznacz jako wykonane</string>
|
<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_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="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>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user