diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index de5d465a..27c4b1bc 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -116,6 +116,9 @@
android:name=".ui.modules.webpush.WebPushConfigActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@style/AppTheme.Dark" />
+
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt
index 788e19d5..d05c5e18 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt
@@ -576,52 +576,65 @@ operator fun StringBuilder.plusAssign(str: String?) {
this.append(str)
}
-fun Context.timeTill(time: Int, delimiter: String = " "): String {
+fun Context.timeTill(time: Int, delimiter: String = " ", countInSeconds: Boolean = false): String {
val parts = mutableListOf>()
val hours = time / 3600
val minutes = (time - hours*3600) / 60
val seconds = time - minutes*60 - hours*3600
- var prefixAdded = false
- if (hours > 0) {
- if (!prefixAdded) parts += R.plurals.time_till_text to hours; prefixAdded = true
- parts += R.plurals.time_till_hours to hours
- }
- if (minutes > 0) {
- if (!prefixAdded) parts += R.plurals.time_till_text to minutes; prefixAdded = true
- parts += R.plurals.time_till_minutes to minutes
- }
- if (hours == 0 && minutes < 10) {
- if (!prefixAdded) parts += R.plurals.time_till_text to seconds; prefixAdded = true
- parts += R.plurals.time_till_seconds to seconds
+ if (!countInSeconds) {
+ var prefixAdded = false
+ if (hours > 0) {
+ if (!prefixAdded) parts += R.plurals.time_till_text to hours
+ prefixAdded = true
+ parts += R.plurals.time_till_hours to hours
+ }
+ if (minutes > 0) {
+ if (!prefixAdded) parts += R.plurals.time_till_text to minutes
+ prefixAdded = true
+ parts += R.plurals.time_till_minutes to minutes
+ }
+ if (hours == 0 && minutes < 10) {
+ if (!prefixAdded) parts += R.plurals.time_till_text to seconds
+ prefixAdded = true
+ parts += R.plurals.time_till_seconds to seconds
+ }
+ } else {
+ parts += R.plurals.time_till_text to time
+ parts += R.plurals.time_till_seconds to time
}
return parts.joinToString(delimiter) { resources.getQuantityString(it.first, it.second, it.second) }
}
-fun Context.timeLeft(time: Int, delimiter: String = " "): String {
+fun Context.timeLeft(time: Int, delimiter: String = " ", countInSeconds: Boolean = false): String {
val parts = mutableListOf>()
val hours = time / 3600
val minutes = (time - hours*3600) / 60
val seconds = time - minutes*60 - hours*3600
- var prefixAdded = false
- if (hours > 0) {
- if (!prefixAdded) parts += R.plurals.time_left_text to hours
- prefixAdded = true
- parts += R.plurals.time_left_hours to hours
- }
- if (minutes > 0) {
- if (!prefixAdded) parts += R.plurals.time_left_text to minutes
- prefixAdded = true
- parts += R.plurals.time_left_minutes to minutes
- }
- if (hours == 0 && minutes < 10) {
- if (!prefixAdded) parts += R.plurals.time_left_text to seconds
- prefixAdded = true
- parts += R.plurals.time_left_seconds to seconds
+ if (!countInSeconds) {
+ var prefixAdded = false
+ if (hours > 0) {
+ if (!prefixAdded) parts += R.plurals.time_left_text to hours
+ prefixAdded = true
+ parts += R.plurals.time_left_hours to hours
+ }
+ if (minutes > 0) {
+ if (!prefixAdded) parts += R.plurals.time_left_text to minutes
+ prefixAdded = true
+ parts += R.plurals.time_left_minutes to minutes
+ }
+ if (hours == 0 && minutes < 10) {
+ if (!prefixAdded) parts += R.plurals.time_left_text to seconds
+ prefixAdded = true
+ parts += R.plurals.time_left_seconds to seconds
+ }
+ } else {
+ parts += R.plurals.time_left_text to time
+ parts += R.plurals.time_left_seconds to time
}
return parts.joinToString(delimiter) { resources.getQuantityString(it.first, it.second, it.second) }
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/bell/BellSyncTimeChooseDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/bell/BellSyncTimeChooseDialog.kt
index 3934d8e0..f806b7b5 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/bell/BellSyncTimeChooseDialog.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/bell/BellSyncTimeChooseDialog.kt
@@ -11,6 +11,7 @@ import kotlinx.coroutines.*
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.MainActivity
import pl.szczodrzynski.edziennik.R
+import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
import pl.szczodrzynski.edziennik.databinding.DialogBellSyncTimeChooseBinding
import pl.szczodrzynski.edziennik.utils.TextInputDropDown
import pl.szczodrzynski.edziennik.utils.models.Date
@@ -103,17 +104,22 @@ class BellSyncTimeChooseDialog(
val items = mutableListOf()
lessons.forEach {
- items += TextInputDropDown.Item(
- it.startTime?.value?.toLong() ?: return@forEach,
- app.getString(R.string.bell_sync_lesson_item, it.displaySubjectName, it.startTime?.stringHM),
- tag = it.startTime
- )
+ if (it.type != Lesson.TYPE_NO_LESSONS &&
+ it.type != Lesson.TYPE_CANCELLED &&
+ it.type != Lesson.TYPE_SHIFTED_SOURCE) {
- items += TextInputDropDown.Item(
- it.endTime?.value?.toLong() ?: return@forEach,
- app.getString(R.string.bell_sync_break_item, it.endTime?.stringHM),
- tag = it.endTime
- )
+ items += TextInputDropDown.Item(
+ it.displayStartTime?.value?.toLong() ?: return@forEach,
+ app.getString(R.string.bell_sync_lesson_item, it.displaySubjectName, it.displayStartTime?.stringHM),
+ tag = it.displayStartTime
+ )
+
+ items += TextInputDropDown.Item(
+ it.displayEndTime?.value?.toLong() ?: return@forEach,
+ app.getString(R.string.bell_sync_break_item, it.displayEndTime?.stringHM),
+ tag = it.displayEndTime
+ )
+ }
}
items
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CardItemTouchHelperCallback.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CardItemTouchHelperCallback.kt
index 62c6b1ee..0103e934 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CardItemTouchHelperCallback.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CardItemTouchHelperCallback.kt
@@ -46,4 +46,4 @@ class CardItemTouchHelperCallback(private val cardAdapter: HomeCardAdapter, priv
dragCardView = null
}
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivity.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivity.kt
new file mode 100644
index 00000000..e75d7658
--- /dev/null
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivity.kt
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) Kacper Ziubryniewicz 2019-12-21
+ */
+
+package pl.szczodrzynski.edziennik.ui.modules.home
+
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import kotlinx.coroutines.*
+import pl.szczodrzynski.edziennik.*
+import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
+import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
+import pl.szczodrzynski.edziennik.databinding.ActivityCounterBinding
+import pl.szczodrzynski.edziennik.utils.models.Date
+import pl.szczodrzynski.edziennik.utils.models.Time
+import kotlin.coroutines.CoroutineContext
+
+class CounterActivity : AppCompatActivity(), CoroutineScope {
+
+ private var job = Job()
+ override val coroutineContext: CoroutineContext
+ get() = job + Dispatchers.Main
+
+ private var counterJob: Job? = null
+
+ private val app by lazy { application as App }
+ private lateinit var b: ActivityCounterBinding
+
+ private val lessonList = mutableListOf()
+
+ private var bellSyncDiffMillis = 0L
+ private val syncedNow: Time
+ get() = Time.fromMillis(Time.getNow().inMillis - bellSyncDiffMillis)
+
+ private val countInSeconts: Boolean
+ get() = app.config.timetable.countInSeconds
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ b = ActivityCounterBinding.inflate(layoutInflater)
+ setContentView(b.root)
+ initView()
+ }
+
+ private fun initView() { launch {
+ withContext(Dispatchers.Default) {
+ lessonList.apply {
+ clear()
+ addAll(app.db.timetableDao().getForDateNow(App.profileId, Date.getToday())
+ .filter {
+ it.type != Lesson.TYPE_NO_LESSONS && it.type != Lesson.TYPE_CANCELLED &&
+ it.type != Lesson.TYPE_SHIFTED_SOURCE
+ })
+ }
+ }
+
+ app.config.timetable.bellSyncDiff?.let {
+ bellSyncDiffMillis = (it.hour * 60 * 60 * 1000 + it.minute * 60 * 1000 + it.second * 1000).toLong()
+ bellSyncDiffMillis *= app.config.timetable.bellSyncMultiplier.toLong()
+ }
+
+ counterJob = startCoroutineTimer(repeatMillis = 1000) {
+ update()
+ }
+ }}
+
+ private fun update() {
+ if (lessonList.isEmpty()) {
+ b.lessonName.text = app.getString(R.string.no_lessons_today)
+ b.timeLeft.text = ""
+ } else {
+ val now = syncedNow
+
+ val next = lessonList.firstOrNull {
+ it.displayStartTime != null && it.displayStartTime!! > now
+ }
+
+ val actual = lessonList.firstOrNull {
+ it.displayStartTime != null && it.displayEndTime != null &&
+ it.displayStartTime!! <= now && now <= it.displayEndTime!!
+ }
+
+ when {
+ actual != null -> {
+ b.lessonName.text = actual.displaySubjectName
+
+ val left = actual.displayEndTime!! - now
+ b.timeLeft.text = timeLeft(left.toInt(), "\n", countInSeconts)
+ }
+ next != null -> {
+ b.lessonName.text = next.displaySubjectName
+
+ val till = next.displayStartTime!! - now
+ b.timeLeft.text = timeTill(till.toInt(), "\n", countInSeconts)
+ }
+ else -> {
+ b.lessonName.text = app.getString(R.string.lessons_finished)
+ b.timeLeft.text = ""
+ }
+ }
+ }
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ counterJob?.cancel()
+ }
+}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivity.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivityOld.java
similarity index 98%
rename from app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivity.java
rename to app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivityOld.java
index 43751d28..2aacd054 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivity.java
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/CounterActivityOld.java
@@ -22,9 +22,9 @@ import pl.szczodrzynski.edziennik.utils.models.Time;
import static pl.szczodrzynski.edziennik.ui.modules.home.HomeFragmentOld.updateInterval;
-public class CounterActivity extends AppCompatActivity {
+public class CounterActivityOld extends AppCompatActivity {
- private static final String TAG = "CounterActivity";
+ private static final String TAG = "CounterActivityOld";
private App app;
private ActivityCounterBinding b;
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeTimetableCardOld.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeTimetableCardOld.java
index 6560fe88..dbebf84e 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeTimetableCardOld.java
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeTimetableCardOld.java
@@ -61,7 +61,7 @@ public class HomeTimetableCardOld {
insertPoint.addView(b.getRoot(), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
b.cardTimetableFullscreenCounter.setOnClickListener((v -> {
- Intent intent = new Intent(a, CounterActivity.class);
+ Intent intent = new Intent(a, CounterActivityOld.class);
a.startActivity(intent);
}));
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeLuckyNumberCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeLuckyNumberCard.kt
index 13d5580b..c5094535 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeLuckyNumberCard.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeLuckyNumberCard.kt
@@ -104,4 +104,4 @@ class HomeLuckyNumberCard(
}}
override fun unbind(position: Int, holder: HomeCardAdapter.ViewHolder) = Unit
-}
\ No newline at end of file
+}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt
index 1c266e30..bdb99029 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/cards/HomeTimetableCard.kt
@@ -4,6 +4,7 @@
package pl.szczodrzynski.edziennik.ui.modules.home.cards
+import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@@ -30,6 +31,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
import pl.szczodrzynski.edziennik.databinding.CardHomeTimetableBinding
import pl.szczodrzynski.edziennik.ui.dialogs.bell.BellSyncTimeChooseDialog
+import pl.szczodrzynski.edziennik.ui.modules.home.CounterActivity
import pl.szczodrzynski.edziennik.ui.modules.home.HomeCard
import pl.szczodrzynski.edziennik.ui.modules.home.HomeCardAdapter
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment
@@ -66,7 +68,7 @@ class HomeTimetableCard(
private var bellSyncDiffMillis = 0L
private val syncedNow: Time
- get() = Time.fromMillis(Time.getNow().inMillis + bellSyncDiffMillis)
+ get() = Time.fromMillis(Time.getNow().inMillis - bellSyncDiffMillis)
private var counterJob: Job? = null
private var counterStart: Time? = null
@@ -91,12 +93,20 @@ class HomeTimetableCard(
.colorAttr(activity, R.attr.colorIcon)
.sizeDp(20))
+ b.showCounter.setImageDrawable(IconicsDrawable(activity, CommunityMaterial.Icon.cmd_fullscreen)
+ .colorAttr(activity, R.attr.colorIcon)
+ .sizeDp(20))
+
b.bellSync.setOnClickListener {
BellSyncTimeChooseDialog(
activity
)
}
+ b.showCounter.setOnClickListener {
+ activity.startActivity(Intent(activity, CounterActivity::class.java))
+ }
+
b.root.onClick {
activity.loadTarget(MainActivity.DRAWER_ITEM_TIMETABLE, Bundle().apply {
putString("timetableDate", timetableDate.stringY_m_d)
@@ -113,7 +123,6 @@ class HomeTimetableCard(
app.config.timetable.bellSyncDiff?.let {
bellSyncDiffMillis = (it.hour * 60 * 60 * 1000 + it.minute * 60 * 1000 + it.second * 1000).toLong()
bellSyncDiffMillis *= app.config.timetable.bellSyncMultiplier.toLong()
- bellSyncDiffMillis *= -1
}
// get all lessons within the search bounds
diff --git a/app/src/main/res/layout/card_home_timetable.xml b/app/src/main/res/layout/card_home_timetable.xml
index 415c8390..d2659c2b 100644
--- a/app/src/main/res/layout/card_home_timetable.xml
+++ b/app/src/main/res/layout/card_home_timetable.xml
@@ -183,6 +183,14 @@
android:padding="10dp"
android:background="?selectableItemBackgroundBorderless"
tools:src="@sample/settings" />
+
+
Brak lekcji przez następne 7 dni.
Nie pobrano planu lekcji.
Brak lekcji przez nast. 7 dni.
+ Nie ma dzisiaj żadnych lekcji!
+ Nie ma dzisiaj więcej lekcji!