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
@@ -44,7 +44,6 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
private var mContext = WeakReference(context)
private var mApplication = application
private var mView = WeakReference(parentView)
private var priority = 200
private var notificationText = ""
private var informational = ""
private val prefs = PreferenceManager.getDefaultSharedPreferences(mContext.get())
@@ -120,7 +119,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
}
indices.add(foodElements.size)
for ((priority, l) in (0 until indices.size - 1).withIndex()) {
for (l in 0 until indices.size - 1) {
var s = ""
for (i2 in indices[l] until indices[l + 1]) {
if (s.isEmpty()) {
@@ -129,7 +128,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
s += "\n${foodElements[i2].text()}"
}
}
foodRepository.insert(Food(s, priority))
foodRepository.insert(Food(s, l))
}
edit.putString("newFoodTime", currentFoodTime).apply()
}
@@ -171,13 +170,13 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
additional = cols[5].text(),
teacher = cols[6].text(),
type = cols[7].text(),
priority = priority
priority = i
)
substArray.add(subst)
substRepo.insert(subst)
priority--
}
var countOfNotificationItems = 0
var countOfMoreNotificationItems = 0
if (jobService && prefs.getBoolean("notif", true)) {
substArray.filter { substitution ->
HelperFunctions.checkPersonalSubstitutions(
@@ -187,7 +186,15 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
false
)
}.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
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>>
@Insert
@@ -39,7 +39,7 @@ internal class PersonalPlanFragment : PlanFragment() {
}
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()
mAdapter.setSubst(planCardList)
+5
View File
@@ -145,4 +145,9 @@
<string name="noSPlan">\' 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>
+5
View File
@@ -158,4 +158,9 @@
<string name="noSPlan">\' 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>