Fix the events order
This commit is contained in:
parent
6150dd7e22
commit
6ea97e7724
@ -18,7 +18,7 @@ import kotlin.collections.ArrayList
|
|||||||
class EventRepository(val context: Context) {
|
class EventRepository(val context: Context) {
|
||||||
private val realm by lazy { Realm.getDefaultInstance() }
|
private val realm by lazy { Realm.getDefaultInstance() }
|
||||||
|
|
||||||
fun saveEvents(eventList: ArrayList<Event>) {
|
fun saveEvents(eventList: List<Event>) {
|
||||||
realm.executeTransaction { realm ->
|
realm.executeTransaction { realm ->
|
||||||
realm.where(Event::class.java).findAll().deleteAllFromRealm()
|
realm.where(Event::class.java).findAll().deleteAllFromRealm()
|
||||||
realm.copyToRealm(eventList)
|
realm.copyToRealm(eventList)
|
||||||
|
@ -80,4 +80,27 @@ object CalendarHelper {
|
|||||||
.filter { (!Preferences.showOnlyBusyEvents || it.availability != CalendarContract.EventsEntity.AVAILABILITY_FREE) }
|
.filter { (!Preferences.showOnlyBusyEvents || it.availability != CalendarContract.EventsEntity.AVAILABILITY_FREE) }
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun List<Event>.sortEvents(): List<Event> {
|
||||||
|
return sortedWith { event: Event, event1: Event ->
|
||||||
|
val date = Calendar.getInstance().apply { timeInMillis = event.startDate }
|
||||||
|
val date1 = Calendar.getInstance().apply { timeInMillis = event1.startDate }
|
||||||
|
|
||||||
|
if (date.get(Calendar.DAY_OF_YEAR) == date1.get(Calendar.DAY_OF_YEAR) && date.get(
|
||||||
|
Calendar.YEAR) == date1.get(Calendar.YEAR)
|
||||||
|
) {
|
||||||
|
if (event.allDay && event1.allDay) {
|
||||||
|
event.startDate.compareTo(event1.startDate)
|
||||||
|
} else if (event.allDay) {
|
||||||
|
1
|
||||||
|
} else if (event1.allDay) {
|
||||||
|
-1
|
||||||
|
} else {
|
||||||
|
event.startDate.compareTo(event1.startDate)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
event.startDate.compareTo(event1.startDate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -37,9 +37,6 @@ object GlanceProviderHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Log.d("ciao", providers.toList().toString())
|
|
||||||
|
|
||||||
return ArrayList(providers.toList())
|
return ArrayList(providers.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import com.tommasoberlose.anotherwidget.db.EventRepository
|
|||||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.applyFilters
|
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.applyFilters
|
||||||
|
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.sortEvents
|
||||||
import com.tommasoberlose.anotherwidget.models.Event
|
import com.tommasoberlose.anotherwidget.models.Event
|
||||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||||
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
||||||
@ -44,8 +45,17 @@ class UpdateCalendarJob : JobIntentService() {
|
|||||||
set(Calendar.HOUR_OF_DAY, 0)
|
set(Calendar.HOUR_OF_DAY, 0)
|
||||||
}
|
}
|
||||||
val limit = Calendar.getInstance().apply {
|
val limit = Calendar.getInstance().apply {
|
||||||
timeInMillis = begin.timeInMillis
|
when (Preferences.showUntil) {
|
||||||
add(Calendar.DAY_OF_YEAR, 2)
|
0 -> add(Calendar.HOUR, 3)
|
||||||
|
1 -> add(Calendar.HOUR, 6)
|
||||||
|
2 -> add(Calendar.HOUR, 12)
|
||||||
|
3 -> add(Calendar.DAY_OF_MONTH, 1)
|
||||||
|
4 -> add(Calendar.DAY_OF_MONTH, 3)
|
||||||
|
5 -> add(Calendar.DAY_OF_MONTH, 7)
|
||||||
|
6 -> add(Calendar.MINUTE, 30)
|
||||||
|
7 -> add(Calendar.HOUR, 1)
|
||||||
|
else -> add(Calendar.HOUR, 6)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkGrantedPermission(
|
if (!checkGrantedPermission(
|
||||||
@ -95,34 +105,16 @@ class UpdateCalendarJob : JobIntentService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val filteredEventList = eventList
|
val sortedEvents = eventList.sortEvents()
|
||||||
|
val filteredEventList = sortedEvents
|
||||||
.applyFilters()
|
.applyFilters()
|
||||||
|
|
||||||
if (filteredEventList.isEmpty()) {
|
if (filteredEventList.isEmpty()) {
|
||||||
eventRepository.resetNextEventData()
|
eventRepository.resetNextEventData()
|
||||||
eventRepository.clearEvents()
|
eventRepository.clearEvents()
|
||||||
} else {
|
} else {
|
||||||
eventList.sortWith(Comparator { event: Event, event1: Event ->
|
|
||||||
val date = Calendar.getInstance().apply { timeInMillis = event.startDate }
|
|
||||||
val date1 = Calendar.getInstance().apply { timeInMillis = event1.startDate }
|
|
||||||
|
|
||||||
if (date.get(Calendar.DAY_OF_YEAR) == date1.get(Calendar.DAY_OF_YEAR) && date.get(Calendar.YEAR) == date1.get(Calendar.YEAR)) {
|
|
||||||
if (event.allDay && event1.allDay) {
|
|
||||||
event.startDate.compareTo(event1.startDate)
|
|
||||||
} else if (event.allDay) {
|
|
||||||
1
|
|
||||||
} else if (event1.allDay) {
|
|
||||||
-1
|
|
||||||
} else {
|
|
||||||
event.startDate.compareTo(event1.startDate)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
event.startDate.compareTo(event1.startDate)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
eventRepository.saveEvents(
|
eventRepository.saveEvents(
|
||||||
eventList
|
sortedEvents
|
||||||
)
|
)
|
||||||
eventRepository.saveNextEventData(filteredEventList.first())
|
eventRepository.saveNextEventData(filteredEventList.first())
|
||||||
}
|
}
|
||||||
|
@ -350,8 +350,12 @@ class MainWidget : AppWidgetProvider() {
|
|||||||
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
||||||
if (Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) {
|
if (Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) {
|
||||||
try {
|
try {
|
||||||
|
if (Preferences.lastNotificationIcon != 0) {
|
||||||
val remotePackageContext = context.createPackageContext(Preferences.lastNotificationPackage, 0)
|
val remotePackageContext = context.createPackageContext(Preferences.lastNotificationPackage, 0)
|
||||||
val icon = ContextCompat.getDrawable(remotePackageContext, Preferences.lastNotificationIcon)
|
ContextCompat.getDrawable(
|
||||||
|
remotePackageContext,
|
||||||
|
Preferences.lastNotificationIcon)
|
||||||
|
}
|
||||||
val notificationIntent = PendingIntent.getActivity(
|
val notificationIntent = PendingIntent.getActivity(
|
||||||
context,
|
context,
|
||||||
widgetID,
|
widgetID,
|
||||||
@ -606,7 +610,7 @@ class MainWidget : AppWidgetProvider() {
|
|||||||
dayDiff++
|
dayDiff++
|
||||||
} else if (startCal.get(Calendar.HOUR_OF_DAY) == endCal.get(Calendar.HOUR_OF_DAY) && startCal.get(
|
} else if (startCal.get(Calendar.HOUR_OF_DAY) == endCal.get(Calendar.HOUR_OF_DAY) && startCal.get(
|
||||||
Calendar.MINUTE
|
Calendar.MINUTE
|
||||||
) >= endCal.get(Calendar.MINUTE)
|
) > endCal.get(Calendar.MINUTE)
|
||||||
) {
|
) {
|
||||||
dayDiff++
|
dayDiff++
|
||||||
}
|
}
|
||||||
@ -618,8 +622,14 @@ class MainWidget : AppWidgetProvider() {
|
|||||||
context.getString(R.string.day_char)
|
context.getString(R.string.day_char)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nextEvent.startDate != nextEvent.endDate) {
|
||||||
v.next_event_date.text =
|
v.next_event_date.text =
|
||||||
String.format("%s - %s%s", startHour, endHour, multipleDay)
|
String.format("%s - %s%s", startHour, endHour, multipleDay)
|
||||||
|
} else {
|
||||||
|
v.next_event_date.text =
|
||||||
|
String.format("%s", startHour)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
val flags: Int =
|
val flags: Int =
|
||||||
@ -724,8 +734,8 @@ class MainWidget : AppWidgetProvider() {
|
|||||||
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
||||||
if (Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) {
|
if (Preferences.showNotifications && ActiveNotificationsHelper.showLastNotification()) {
|
||||||
try {
|
try {
|
||||||
val remotePackageContext = context.createPackageContext(Preferences.lastNotificationPackage, 0)
|
|
||||||
if (Preferences.lastNotificationIcon != 0) {
|
if (Preferences.lastNotificationIcon != 0) {
|
||||||
|
val remotePackageContext = context.createPackageContext(Preferences.lastNotificationPackage, 0)
|
||||||
val icon = ContextCompat.getDrawable(remotePackageContext,
|
val icon = ContextCompat.getDrawable(remotePackageContext,
|
||||||
Preferences.lastNotificationIcon)
|
Preferences.lastNotificationIcon)
|
||||||
v.second_row_icon.isVisible = true
|
v.second_row_icon.isVisible = true
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
android:id="@+id/empty_layout">
|
android:id="@+id/empty_layout">
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/empty_date"
|
android:id="@+id/empty_date"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:lines="1"
|
android:lines="1"
|
||||||
android:textColor="@color/colorPrimary"
|
android:textColor="@color/colorPrimary"
|
||||||
@ -36,7 +37,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:layout_marginStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:id="@+id/weather">
|
android:id="@+id/weather">
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -118,7 +119,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:layout_marginStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:id="@+id/special_weather">
|
android:id="@+id/special_weather">
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -205,7 +205,7 @@
|
|||||||
<string name="battery_low_warning">Low battery level</string>
|
<string name="battery_low_warning">Low battery level</string>
|
||||||
<string name="daily_steps_counter">%d steps so far</string>
|
<string name="daily_steps_counter">%d steps so far</string>
|
||||||
<string name="charging">Charging</string>
|
<string name="charging">Charging</string>
|
||||||
<string name="charged">Charged</string>
|
<string name="charged">Fully charged</string>
|
||||||
<string name="providers">Providers</string>
|
<string name="providers">Providers</string>
|
||||||
<string name="glance_info">Glance info will show up only when there are no events displayed and only when a few conditions are verified.</string>
|
<string name="glance_info">Glance info will show up only when there are no events displayed and only when a few conditions are verified.</string>
|
||||||
<string name="settings_music_players_filter_title">Music Players</string>
|
<string name="settings_music_players_filter_title">Music Players</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user