[UI/Timetable] Handle no timetable or no lessons in Home card.

This commit is contained in:
Kuba Szczodrzyński 2019-12-21 17:39:17 +01:00
parent 1f5927eec0
commit b399a3f5ad
3 changed files with 275 additions and 80 deletions

View File

@ -14,9 +14,16 @@ import androidx.core.view.setMargins
import androidx.lifecycle.Observer
import com.mikepenz.iconics.IconicsDrawable
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 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.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.profiles.Profile
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
@ -80,7 +87,7 @@ class HomeTimetableCard(
.colorAttr(activity, R.attr.colorIcon)
.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)
.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
app.config.timetable.bellSyncDiff?.let {
bellSyncDiffMillis = (it.hour * 60 * 60 * 1000 + it.minute * 60 * 1000 + it.second * 1000).toLong()
@ -103,11 +122,7 @@ class HomeTimetableCard(
update()
})
b.root.setOnClickListener {
activity.loadTarget(MainActivity.DRAWER_ITEM_TIMETABLE, Bundle().apply {
putString("timetableDate", timetableDate.stringY_m_d)
})
}
EventBus.getDefault().register(this)
}
private fun update() { launch {
@ -144,6 +159,42 @@ class HomeTimetableCard(
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
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
}

View File

@ -6,124 +6,256 @@
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:layout_margin="8dp">
<LinearLayout
android:id="@+id/noTimetableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
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="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/dayInfo"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Title"
tools:text="Jutro" />
android:text="@string/home_timetable_no_timetable" />
<TextView
android:id="@+id/lessonInfo"
android:layout_width="match_parent"
android:id="@+id/noTimetableText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Helper"
tools:text="7 lekcji - 8:10 do 14:45" />
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>
<ImageView
android:id="@+id/settings"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="10dp"
android:background="?selectableItemBackgroundBorderless"
android:visibility="gone"
tools:src="@sample/settings" />
<ImageView
android:id="@+id/bellSync"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="10dp"
android:background="?selectableItemBackgroundBorderless"
tools:src="@sample/settings" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@color/dividerColor" />
<LinearLayout
android:id="@+id/noLessonsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
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="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/lessonBig"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Subtitle"
tools:text="Pierwsza: informatyka" />
android:textAppearance="@style/NavView.TextView.Title"
android:text="@string/home_timetable_no_lessons" />
<TextView
android:id="@+id/classroom"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Small"
tools:text="09a komputerowa" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:max="2700"
android:progress="780" />
android:textSize="16sp"
android:text="@string/home_timetable_no_lessons_text"/>
</LinearLayout>
<TextView
android:id="@+id/counter"
android:layout_width="wrap_content"
</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_gravity="center_vertical"
android:gravity="center"
tools:text="zostały\n2 minuty\n35 sekund" />
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>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@color/dividerColor" />
<TextView
android:id="@+id/nextLessons"
<LinearLayout
android:id="@+id/timetableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Helper"
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" />
android:orientation="vertical"
tools:layout_marginTop="350dp">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/dayInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Title"
tools:text="Jutro" />
<TextView
android:id="@+id/lessonInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Helper"
tools:text="7 lekcji - 8:10 do 14:45" />
</LinearLayout>
<ImageView
android:id="@+id/settings"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="10dp"
android:background="?selectableItemBackgroundBorderless"
android:visibility="gone"
tools:src="@sample/settings" />
<ImageView
android:id="@+id/bellSync"
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="10dp"
android:background="?selectableItemBackgroundBorderless"
tools:src="@sample/settings" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@color/dividerColor" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/lessonBig"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Subtitle"
tools:text="Pierwsza: informatyka" />
<TextView
android:id="@+id/classroom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Small"
tools:text="09a komputerowa" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:visibility="gone"
tools:visibility="visible"
tools:max="2700"
tools:progress="780" />
</LinearLayout>
<TextView
android:id="@+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
tools:text="zostały\n2 minuty\n35 sekund" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@color/dividerColor" />
<TextView
android:id="@+id/nextLessons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/NavView.TextView.Helper"
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>
</FrameLayout>
</layout>

View File

@ -1113,4 +1113,11 @@
<string name="qr_scanner_dialog_title">Skanuj kod QR</string>
<string name="web_push_unpair_button">Odłącz</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>