forked from github/szkolny
[UI/Timetable] Handle no timetable or no lessons in Home card.
This commit is contained in:
parent
1f5927eec0
commit
b399a3f5ad
@ -14,9 +14,16 @@ import androidx.core.view.setMargins
|
|||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import com.mikepenz.iconics.IconicsDrawable
|
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.typeface.library.szkolny.font.SzkolnyFont
|
||||||
import com.mikepenz.iconics.utils.sizeDp
|
import com.mikepenz.iconics.utils.sizeDp
|
||||||
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.LOGIN_TYPE_LIBRUS
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.events.ApiTaskAllFinishedEvent
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.task.EdziennikTask
|
||||||
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.profiles.Profile
|
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
|
||||||
@ -80,7 +87,7 @@ class HomeTimetableCard(
|
|||||||
.colorAttr(activity, R.attr.colorIcon)
|
.colorAttr(activity, R.attr.colorIcon)
|
||||||
.sizeDp(20))
|
.sizeDp(20))
|
||||||
|
|
||||||
b.bellSync.setImageDrawable(IconicsDrawable(activity, CommunityMaterial.Icon.cmd_alarm_bell)
|
b.bellSync.setImageDrawable(IconicsDrawable(activity, SzkolnyFont.Icon.szf_alarm_bell_outline)
|
||||||
.colorAttr(activity, R.attr.colorIcon)
|
.colorAttr(activity, R.attr.colorIcon)
|
||||||
.sizeDp(20))
|
.sizeDp(20))
|
||||||
|
|
||||||
@ -90,6 +97,18 @@ class HomeTimetableCard(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.root.onClick {
|
||||||
|
activity.loadTarget(MainActivity.DRAWER_ITEM_TIMETABLE, Bundle().apply {
|
||||||
|
putString("timetableDate", timetableDate.stringY_m_d)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app.profile.loginStoreType == LOGIN_TYPE_LIBRUS && app.profile.getLoginData("timetableNotPublic", false)) {
|
||||||
|
b.timetableLayout.visibility = View.GONE
|
||||||
|
b.notPublicLayout.visibility = View.VISIBLE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// get current bell-sync params
|
// get current bell-sync params
|
||||||
app.config.timetable.bellSyncDiff?.let {
|
app.config.timetable.bellSyncDiff?.let {
|
||||||
bellSyncDiffMillis = (it.hour * 60 * 60 * 1000 + it.minute * 60 * 1000 + it.second * 1000).toLong()
|
bellSyncDiffMillis = (it.hour * 60 * 60 * 1000 + it.minute * 60 * 1000 + it.second * 1000).toLong()
|
||||||
@ -103,11 +122,7 @@ class HomeTimetableCard(
|
|||||||
update()
|
update()
|
||||||
})
|
})
|
||||||
|
|
||||||
b.root.setOnClickListener {
|
EventBus.getDefault().register(this)
|
||||||
activity.loadTarget(MainActivity.DRAWER_ITEM_TIMETABLE, Bundle().apply {
|
|
||||||
putString("timetableDate", timetableDate.stringY_m_d)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun update() { launch {
|
private fun update() { launch {
|
||||||
@ -144,6 +159,42 @@ class HomeTimetableCard(
|
|||||||
|
|
||||||
timetableDate = deferred.await()
|
timetableDate = deferred.await()
|
||||||
|
|
||||||
|
if (lessons.isEmpty()) {
|
||||||
|
// timetable is not downloaded yet
|
||||||
|
b.timetableLayout.visibility = View.GONE
|
||||||
|
b.noTimetableLayout.visibility = View.VISIBLE
|
||||||
|
b.noLessonsLayout.visibility = View.GONE
|
||||||
|
val weekStart = timetableDate.clone().weekStart
|
||||||
|
b.noTimetableText.setText(
|
||||||
|
R.string.home_timetable_no_timetable_text,
|
||||||
|
weekStart.stringY_m_d
|
||||||
|
)
|
||||||
|
b.noTimetableSync.onClick {
|
||||||
|
it.isEnabled = false
|
||||||
|
EdziennikTask.syncProfile(
|
||||||
|
profileId = App.profileId,
|
||||||
|
viewIds = listOf(
|
||||||
|
MainActivity.DRAWER_ITEM_TIMETABLE to 0
|
||||||
|
),
|
||||||
|
arguments = JsonObject(
|
||||||
|
"weekStart" to weekStart
|
||||||
|
)
|
||||||
|
).enqueue(activity)
|
||||||
|
}
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
if (lessons.size == 1 && lessons[0].type == Lesson.TYPE_NO_LESSONS) {
|
||||||
|
// in next 7 days only NO_LESSONS is found
|
||||||
|
b.timetableLayout.visibility = View.GONE
|
||||||
|
b.noTimetableLayout.visibility = View.GONE
|
||||||
|
b.noLessonsLayout.visibility = View.VISIBLE
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
|
b.timetableLayout.visibility = View.VISIBLE
|
||||||
|
b.noTimetableLayout.visibility = View.GONE
|
||||||
|
b.noLessonsLayout.visibility = View.GONE
|
||||||
|
|
||||||
val isToday = today == timetableDate
|
val isToday = today == timetableDate
|
||||||
|
|
||||||
b.progress.visibility = View.GONE
|
b.progress.visibility = View.GONE
|
||||||
@ -290,5 +341,10 @@ class HomeTimetableCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
fun onSyncFinishedEvent(event: ApiTaskAllFinishedEvent) {
|
||||||
|
b.noTimetableSync.isEnabled = true
|
||||||
|
}
|
||||||
|
|
||||||
override fun unbind(position: Int, holder: HomeCardAdapter.ViewHolder) = Unit
|
override fun unbind(position: Int, holder: HomeCardAdapter.ViewHolder) = Unit
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,140 @@
|
|||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:layout_margin="8dp">
|
tools:layout_margin="8dp">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/noTimetableLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="64dp"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:background="@drawable/ic_sync"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="@style/NavView.TextView.Title"
|
||||||
|
android:text="@string/home_timetable_no_timetable" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/noTimetableText"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:text="@string/home_timetable_no_timetable_text"/>
|
||||||
|
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/noTimetableSync"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="end"
|
||||||
|
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||||
|
android:text="@string/home_timetable_no_timetable_sync" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/noLessonsLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:layout_marginTop="150dp"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="64dp"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:background="@drawable/ic_timetable"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="@style/NavView.TextView.Title"
|
||||||
|
android:text="@string/home_timetable_no_lessons" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:text="@string/home_timetable_no_lessons_text"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/notPublicLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:layout_marginTop="220dp"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="64dp"
|
||||||
|
android:layout_height="64dp"
|
||||||
|
android:background="@drawable/ic_no_timetable"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="@style/NavView.TextView.Title"
|
||||||
|
android:text="@string/home_timetable_not_public" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:text="@string/home_timetable_not_public_text"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/timetableLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:layout_marginTop="350dp">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -96,8 +224,10 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="4dp"
|
android:layout_marginLeft="4dp"
|
||||||
android:layout_marginRight="4dp"
|
android:layout_marginRight="4dp"
|
||||||
android:max="2700"
|
android:visibility="gone"
|
||||||
android:progress="780" />
|
tools:visibility="visible"
|
||||||
|
tools:max="2700"
|
||||||
|
tools:progress="780" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
@ -126,4 +256,6 @@
|
|||||||
tools:text="Póżniej:\n9:05 informatyka\n10:00 urządzenia techniki komputerowej\n11:00 projektowanie lokalnych sieci komputerowych\n11:55 zajęcia z wychowawcą\n13:00 język polski\n14:05 język niemiecki" />
|
tools:text="Póżniej:\n9:05 informatyka\n10:00 urządzenia techniki komputerowej\n11:00 projektowanie lokalnych sieci komputerowych\n11:55 zajęcia z wychowawcą\n13:00 język polski\n14:05 język niemiecki" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
</layout>
|
</layout>
|
||||||
|
@ -1113,4 +1113,11 @@
|
|||||||
<string name="qr_scanner_dialog_title">Skanuj kod QR</string>
|
<string name="qr_scanner_dialog_title">Skanuj kod QR</string>
|
||||||
<string name="web_push_unpair_button">Odłącz</string>
|
<string name="web_push_unpair_button">Odłącz</string>
|
||||||
<string name="web_push_date_paired_format">Połączono %s</string>
|
<string name="web_push_date_paired_format">Połączono %s</string>
|
||||||
|
<string name="home_timetable_no_timetable">Nie pobrano planu lekcji</string>
|
||||||
|
<string name="home_timetable_no_timetable_text">Plan lekcji na tydzień %s nie został jeszcze pobrany.</string>
|
||||||
|
<string name="home_timetable_no_timetable_sync">Pobierz</string>
|
||||||
|
<string name="home_timetable_no_lessons">Nie ma żadnych lekcji</string>
|
||||||
|
<string name="home_timetable_no_lessons_text">Przez następne 7 dni nie ma żadnych lekcji.</string>
|
||||||
|
<string name="home_timetable_not_public">Brak planu lekcji</string>
|
||||||
|
<string name="home_timetable_not_public_text">Plan lekcji nie został opublikowany przez szkołę.\n\nSkontaktuj się z wychowawcą.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user