Notifications now show up to four items and are then abbreviated to "and x more messages", removed redundant priority variables in DataFetcher.kt

This commit is contained in:
Deniz Düzgören
2019-09-15 14:59:04 +02:00
parent 8f4c604eed
commit b891a48b30
6 changed files with 28 additions and 11 deletions
+2 -2
View File
@@ -10,8 +10,8 @@ android {
applicationId "com.denizd.substitutionplan" applicationId "com.denizd.substitutionplan"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 28 targetSdkVersion 28
versionCode 35 versionCode 36
versionName "2.2.12" versionName "2.2.13"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
@@ -44,7 +44,6 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
private var mContext = WeakReference(context) private var mContext = WeakReference(context)
private var mApplication = application private var mApplication = application
private var mView = WeakReference(parentView) private var mView = WeakReference(parentView)
private var priority = 200
private var notificationText = "" private var notificationText = ""
private var informational = "" private var informational = ""
private val prefs = PreferenceManager.getDefaultSharedPreferences(mContext.get()) private val prefs = PreferenceManager.getDefaultSharedPreferences(mContext.get())
@@ -120,7 +119,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
} }
indices.add(foodElements.size) indices.add(foodElements.size)
for ((priority, l) in (0 until indices.size - 1).withIndex()) { for (l in 0 until indices.size - 1) {
var s = "" var s = ""
for (i2 in indices[l] until indices[l + 1]) { for (i2 in indices[l] until indices[l + 1]) {
if (s.isEmpty()) { if (s.isEmpty()) {
@@ -129,7 +128,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
s += "\n${foodElements[i2].text()}" s += "\n${foodElements[i2].text()}"
} }
} }
foodRepository.insert(Food(s, priority)) foodRepository.insert(Food(s, l))
} }
edit.putString("newFoodTime", currentFoodTime).apply() edit.putString("newFoodTime", currentFoodTime).apply()
} }
@@ -171,13 +170,13 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
additional = cols[5].text(), additional = cols[5].text(),
teacher = cols[6].text(), teacher = cols[6].text(),
type = cols[7].text(), type = cols[7].text(),
priority = priority priority = i
) )
substArray.add(subst) substArray.add(subst)
substRepo.insert(subst) substRepo.insert(subst)
priority--
} }
var countOfNotificationItems = 0
var countOfMoreNotificationItems = 0
if (jobService && prefs.getBoolean("notif", true)) { if (jobService && prefs.getBoolean("notif", true)) {
substArray.filter { substitution -> substArray.filter { substitution ->
HelperFunctions.checkPersonalSubstitutions( HelperFunctions.checkPersonalSubstitutions(
@@ -187,7 +186,15 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
false false
) )
}.forEach { substItem -> }.forEach { substItem ->
notificationText += "${if (notificationText.isNotEmpty()) ",\n" else ""}${substItem.course}: ${if (substItem.additional.isNotEmpty()) substItem.additional else "---"}" if (countOfNotificationItems < 4) {
notificationText += ("${if (notificationText.isNotEmpty()) ",\n" else ""}${substItem.course}: ${if (substItem.additional.isNotEmpty()) substItem.additional else "---"}")
countOfNotificationItems += 1
} else {
countOfMoreNotificationItems += 1
}
}
if (countOfMoreNotificationItems > 0) {
notificationText += mContext.get()?.resources?.getQuantityString(R.plurals.moreMessages, countOfMoreNotificationItems, countOfMoreNotificationItems)
} }
} }
@@ -8,7 +8,7 @@ import com.denizd.substitutionplan.models.Subst
@Dao @Dao
internal interface SubstDao { internal interface SubstDao {
@get:Query("SELECT * FROM subst_table ORDER BY priority DESC") @get:Query("SELECT * FROM subst_table ORDER BY priority ASC")
val allSubst: LiveData<List<Subst>> val allSubst: LiveData<List<Subst>>
@Insert @Insert
@@ -39,7 +39,7 @@ internal class PersonalPlanFragment : PlanFragment() {
} }
persPlanEmpty = (planCardList.size == 1 && planCardList[0].date.substring(0, 3) == "psa") || planCardList.isEmpty() persPlanEmpty = (planCardList.size == 1 && planCardList[0].date.substring(0, 3) == "psa") || planCardList.isEmpty()
planCardList.sortWith(Comparator { lhs, rhs -> rhs.priority.compareTo(lhs.priority) }) planCardList.sortWith(Comparator { rhs, lhs -> rhs.priority.compareTo(lhs.priority) })
recyclerView.scheduleLayoutAnimation() recyclerView.scheduleLayoutAnimation()
mAdapter.setSubst(planCardList) mAdapter.setSubst(planCardList)
+5
View File
@@ -145,4 +145,9 @@
<string name="noSPlan">\' Plan</string> <string name="noSPlan">\' Plan</string>
<string name="SPlan">s Plan</string> <string name="SPlan">s Plan</string>
<plurals name="moreMessages">
<item quantity="one">,\nund %d weitere Nachricht</item>
<item quantity="other">,\nund %d weitere Nachrichten</item>
</plurals>
</resources> </resources>
+5
View File
@@ -158,4 +158,9 @@
<string name="noSPlan">\' Plan</string> <string name="noSPlan">\' Plan</string>
<string name="SPlan">\'s Plan</string> <string name="SPlan">\'s Plan</string>
<plurals name="moreMessages">
<item quantity="one">,\nand %d more message</item>
<item quantity="other">,\nand %d more messages</item>
</plurals>
</resources> </resources>