parent
ec1c25cb4c
commit
770040ad93
@ -145,6 +145,11 @@
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".services.UpdateCalendarJob"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE"
|
||||
android:exported="true"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,57 @@
|
||||
package com.tommasoberlose.anotherwidget.components
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
|
||||
import kotlinx.android.synthetic.main.bottom_sheet_menu.view.*
|
||||
import kotlinx.android.synthetic.main.bottom_sheet_menu.view.header
|
||||
import kotlinx.android.synthetic.main.fragment_weather_settings.*
|
||||
import kotlinx.android.synthetic.main.icon_pack_menu_item.view.*
|
||||
|
||||
class IconPackSelector(context: Context, private val header: String? = null) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
|
||||
|
||||
override fun show() {
|
||||
val view = View.inflate(context, R.layout.bottom_sheet_menu, null)
|
||||
|
||||
// Header
|
||||
view.header.isVisible = header != null
|
||||
view.header_text.text = header ?: ""
|
||||
|
||||
view.warning_text.isVisible = false
|
||||
|
||||
// Menu
|
||||
for (item in Constants.WeatherIconPack.values()) {
|
||||
val itemView = View.inflate(context, R.layout.icon_pack_menu_item, null)
|
||||
itemView.label.text = context.getString(R.string.settings_weather_icon_pack_default).format(item.value + 1)
|
||||
itemView.isSelected = item.value == Preferences.weatherIconPack
|
||||
|
||||
itemView.icon_1.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource("01d", item.value)))
|
||||
itemView.icon_2.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource("01n", item.value)))
|
||||
itemView.icon_3.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource("10d", item.value)))
|
||||
itemView.icon_4.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource("09n", item.value)))
|
||||
|
||||
listOf<ImageView>(itemView.icon_1, itemView.icon_2, itemView.icon_3, itemView.icon_4).forEach {
|
||||
if (item == Constants.WeatherIconPack.MINIMAL) {
|
||||
it.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryText))
|
||||
} else {
|
||||
it.setColorFilter(ContextCompat.getColor(context, android.R.color.transparent))
|
||||
}
|
||||
}
|
||||
|
||||
itemView.setOnClickListener {
|
||||
Preferences.weatherIconPack = item.value
|
||||
this.dismiss()
|
||||
}
|
||||
view.menu.addView(itemView)
|
||||
}
|
||||
setContentView(view)
|
||||
super.show()
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.tommasoberlose.anotherwidget.db
|
||||
|
||||
import android.content.Context
|
||||
import android.provider.CalendarContract
|
||||
import android.util.Log
|
||||
import com.chibatching.kotpref.bulk
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
@ -122,13 +123,18 @@ class EventRepository(val context: Context) {
|
||||
MainWidget.updateWidget(context)
|
||||
}
|
||||
|
||||
fun getFutureEvents(): RealmResults<Event> {
|
||||
fun getFutureEvents(): List<Event> {
|
||||
val now = Calendar.getInstance().timeInMillis
|
||||
realm.refresh()
|
||||
return realm.where(Event::class.java).greaterThan("endDate", now).findAll()
|
||||
return realm
|
||||
.where(Event::class.java)
|
||||
.greaterThan("endDate", now)
|
||||
.findAll()
|
||||
.filter { (Preferences.showDeclinedEvents || it.selfAttendeeStatus != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED) }
|
||||
.filter { (Preferences.calendarAllDay || !it.allDay) }
|
||||
}
|
||||
|
||||
private fun getEvents(): RealmResults<Event> {
|
||||
private fun getEvents(): List<Event> {
|
||||
val now = Calendar.getInstance().timeInMillis
|
||||
val limit = Calendar.getInstance().apply {
|
||||
timeInMillis = now
|
||||
@ -145,7 +151,13 @@ class EventRepository(val context: Context) {
|
||||
}
|
||||
}
|
||||
realm.refresh()
|
||||
return realm.where(Event::class.java).greaterThan("endDate", now).lessThanOrEqualTo("startDate", limit.timeInMillis).findAll()
|
||||
return realm
|
||||
.where(Event::class.java)
|
||||
.greaterThan("endDate", now)
|
||||
.lessThanOrEqualTo("startDate", limit.timeInMillis)
|
||||
.findAll()
|
||||
.filter { (Preferences.showDeclinedEvents || it.selfAttendeeStatus != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED) }
|
||||
.filter { (Preferences.calendarAllDay || !it.allDay) }
|
||||
}
|
||||
|
||||
fun getEventsCount(): Int = getEvents().size
|
||||
|
@ -1,8 +1,14 @@
|
||||
package com.tommasoberlose.anotherwidget.helpers
|
||||
|
||||
import android.Manifest
|
||||
import android.app.job.JobInfo
|
||||
import android.app.job.JobParameters
|
||||
import android.app.job.JobScheduler
|
||||
import android.app.job.JobService
|
||||
import android.content.ComponentName
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.provider.CalendarContract
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.services.EventListenerJob
|
||||
@ -10,6 +16,7 @@ import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.models.Event
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||
import com.tommasoberlose.anotherwidget.services.UpdateCalendarJob
|
||||
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
@ -25,104 +32,7 @@ import kotlin.collections.ArrayList
|
||||
|
||||
object CalendarHelper {
|
||||
fun updateEventList(context: Context) {
|
||||
val eventRepository = EventRepository(context)
|
||||
if (Preferences.showEvents) {
|
||||
val eventList = ArrayList<Event>()
|
||||
|
||||
val now = Calendar.getInstance()
|
||||
val begin = Calendar.getInstance().apply {
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MINUTE, 0)
|
||||
set(Calendar.HOUR_OF_DAY, 0)
|
||||
}
|
||||
val limit = Calendar.getInstance().apply {
|
||||
timeInMillis = begin.timeInMillis
|
||||
add(Calendar.DAY_OF_YEAR, 2)
|
||||
}
|
||||
|
||||
if (!context.checkGrantedPermission(
|
||||
Manifest.permission.READ_CALENDAR
|
||||
)
|
||||
) {
|
||||
eventRepository.resetNextEventData()
|
||||
} else {
|
||||
try {
|
||||
val provider = CalendarProvider(context)
|
||||
val data = provider.getInstances(begin.timeInMillis, limit.timeInMillis)
|
||||
if (data != null) {
|
||||
val instances = data.list
|
||||
for (instance in instances) {
|
||||
try {
|
||||
val e = provider.getEvent(instance.eventId)
|
||||
if (e != null && !e.deleted && instance.begin <= limit.timeInMillis && now.timeInMillis < instance.end && (Preferences.calendarAllDay || !e.allDay) && !getFilteredCalendarIdList().contains(
|
||||
e.calendarId
|
||||
) && (Preferences.showDeclinedEvents || e.selfAttendeeStatus.toInt() != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED)
|
||||
) {
|
||||
if (e.allDay) {
|
||||
val start = Calendar.getInstance()
|
||||
start.timeInMillis = instance.begin
|
||||
val end = Calendar.getInstance()
|
||||
end.timeInMillis = instance.end
|
||||
instance.begin =
|
||||
start.timeInMillis - start.timeZone.getOffset(start.timeInMillis)
|
||||
instance.end =
|
||||
end.timeInMillis - end.timeZone.getOffset(end.timeInMillis)
|
||||
}
|
||||
eventList.add(
|
||||
Event(
|
||||
instance.id,
|
||||
e.id,
|
||||
e.title ?: "",
|
||||
instance.begin,
|
||||
instance.end,
|
||||
e.calendarId.toInt(),
|
||||
e.allDay,
|
||||
e.eventLocation ?: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventList.isEmpty()) {
|
||||
eventRepository.resetNextEventData()
|
||||
eventRepository.clearEvents()
|
||||
} else {
|
||||
eventList.sortWith(Comparator { event: Event, event1: Event ->
|
||||
if (event.allDay && event1.allDay) {
|
||||
event.startDate.compareTo(event1.startDate)
|
||||
} else if (event.allDay) {
|
||||
1
|
||||
} else if (event1.allDay) {
|
||||
-1
|
||||
} else {
|
||||
event1.startDate.compareTo(event.startDate)
|
||||
}
|
||||
})
|
||||
eventList.reverse()
|
||||
eventRepository.saveEvents(
|
||||
eventList
|
||||
)
|
||||
eventRepository.saveNextEventData(
|
||||
eventList[0]
|
||||
)
|
||||
}
|
||||
} catch (ignored: java.lang.Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eventRepository.resetNextEventData()
|
||||
}
|
||||
|
||||
UpdatesReceiver.setUpdates(context)
|
||||
MainWidget.updateWidget(context)
|
||||
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
eventRepository.close()
|
||||
UpdateCalendarJob.enqueueWork(context, Intent())
|
||||
}
|
||||
|
||||
fun getCalendarList(context: Context): List<me.everything.providers.android.calendar.Calendar> {
|
||||
@ -144,7 +54,8 @@ object CalendarHelper {
|
||||
}
|
||||
|
||||
fun getFilteredCalendarIdList(): List<Long> {
|
||||
return Preferences.calendarFilter.split(",").map { it.replace(" ", "") }.filter { it != "" }.map { it.toLong() }
|
||||
return Preferences.calendarFilter.split(",").map { it.replace(" ", "") }
|
||||
.filter { it != "" }.map { it.toLong() }
|
||||
}
|
||||
|
||||
fun filterCalendar(list: List<Long>) {
|
||||
|
@ -11,9 +11,11 @@ import android.provider.AlarmClock
|
||||
import android.provider.CalendarContract
|
||||
import android.provider.CalendarContract.Events
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.models.Event
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.toast
|
||||
import java.util.*
|
||||
|
||||
|
||||
@ -64,12 +66,8 @@ object IntentHelper {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
addCategory(Intent.CATEGORY_DEFAULT)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
data = Uri.parse("dynact://velour/weather/ProxyActivity")
|
||||
component = ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velour.DynamicActivityTrampoline")
|
||||
}
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -98,10 +96,8 @@ object IntentHelper {
|
||||
data = calendarUri
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
data = calendarUri
|
||||
}
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,8 +128,9 @@ object IntentHelper {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getCalendarIntent(context).apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
val calendarIntent = getCalendarIntent(context)
|
||||
if (calendarIntent.action == Intent.ACTION_VIEW) {
|
||||
calendarIntent.apply {
|
||||
data = uri
|
||||
if (!e.allDay) {
|
||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
||||
@ -145,11 +142,20 @@ object IntentHelper {
|
||||
val end = Calendar.getInstance().apply {
|
||||
timeInMillis = e.endDate
|
||||
}
|
||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start.timeInMillis + start.timeZone.getOffset(start.timeInMillis))
|
||||
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end.timeInMillis + end.timeZone.getOffset(end.timeInMillis))
|
||||
putExtra(
|
||||
CalendarContract.EXTRA_EVENT_BEGIN_TIME,
|
||||
start.timeInMillis + start.timeZone.getOffset(start.timeInMillis)
|
||||
)
|
||||
putExtra(
|
||||
CalendarContract.EXTRA_EVENT_END_TIME,
|
||||
end.timeInMillis + end.timeZone.getOffset(end.timeInMillis)
|
||||
)
|
||||
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, 1)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
}
|
||||
false -> {
|
||||
@ -175,9 +181,8 @@ object IntentHelper {
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Intent(AlarmClock.ACTION_SHOW_ALARMS).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -199,6 +204,7 @@ object IntentHelper {
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
@ -212,6 +218,7 @@ object IntentHelper {
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
|
@ -46,10 +46,10 @@ object WeatherHelper {
|
||||
MainWidget.updateWidget(context)
|
||||
}
|
||||
|
||||
fun getWeatherIconResource(icon: String): Int {
|
||||
fun getWeatherIconResource(icon: String, style: Int = Preferences.weatherIconPack): Int {
|
||||
return when (icon) {
|
||||
"01d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.clear_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.clear_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.clear_day_4
|
||||
@ -57,7 +57,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"02d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.partly_cloudy_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.partly_cloudy_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.partly_cloudy_4
|
||||
@ -65,7 +65,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"03d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.mostly_cloudy_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.mostly_cloudy_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.mostly_cloudy_4
|
||||
@ -73,7 +73,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"04d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.cloudy_weather_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.cloudy_weather_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.cloudy_weather_4
|
||||
@ -81,7 +81,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"09d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.storm_weather_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.storm_weather_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.storm_weather_day_4
|
||||
@ -89,7 +89,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"10d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.rainy_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.rainy_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.rainy_day_4
|
||||
@ -97,7 +97,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"11d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.thunder_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.thunder_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.thunder_day_4
|
||||
@ -105,7 +105,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"13d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.snow_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.snow_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.snow_day_4
|
||||
@ -113,7 +113,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"50d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.haze_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.haze_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.haze_day_4
|
||||
@ -121,7 +121,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"80d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.windy_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.windy_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.windy_day_4
|
||||
@ -129,7 +129,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"81d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.rain_snow_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.rain_snow_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.rain_snow_day_4
|
||||
@ -137,7 +137,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"82d" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.haze_weather_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.haze_weather_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.haze_weather_4
|
||||
@ -148,7 +148,7 @@ object WeatherHelper {
|
||||
|
||||
|
||||
"01n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.clear_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.clear_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.clear_night_4
|
||||
@ -156,7 +156,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"02n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.partly_cloudy_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.partly_cloudy_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.partly_cloudy_night_4
|
||||
@ -164,7 +164,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"03n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.mostly_cloudy_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.mostly_cloudy_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.mostly_cloudy_night_4
|
||||
@ -172,7 +172,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"04n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.cloudy_weather_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.cloudy_weather_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.cloudy_weather_4
|
||||
@ -180,7 +180,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"09n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.storm_weather_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.storm_weather_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.storm_weather_night_4
|
||||
@ -188,7 +188,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"10n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.rainy_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.rainy_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.rainy_night_4
|
||||
@ -196,7 +196,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"11n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.thunder_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.thunder_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.thunder_night_4
|
||||
@ -204,7 +204,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"13n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.snow_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.snow_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.snow_night_4
|
||||
@ -212,7 +212,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"50n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.haze_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.haze_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.haze_night_4
|
||||
@ -220,7 +220,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"80n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.windy_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.windy_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.windy_night_4
|
||||
@ -228,7 +228,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"81n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.rain_snow_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.rain_snow_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.rain_snow_night_4
|
||||
@ -236,7 +236,7 @@ object WeatherHelper {
|
||||
}
|
||||
}
|
||||
"82n" -> {
|
||||
when (Preferences.weatherIconPack) {
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.haze_weather_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.haze_weather_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.haze_weather_4
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.tommasoberlose.anotherwidget.models
|
||||
|
||||
import android.provider.CalendarContract
|
||||
import io.realm.RealmObject
|
||||
import java.util.Date
|
||||
|
||||
@ -7,14 +8,17 @@ import java.util.Date
|
||||
* Created by tommaso on 05/10/17.
|
||||
*/
|
||||
|
||||
open class Event(var id: Long = 0,
|
||||
open class Event(
|
||||
var id: Long = 0,
|
||||
var eventID: Long = 0,
|
||||
var title: String = "",
|
||||
var startDate: Long = 0,
|
||||
var endDate: Long = 0,
|
||||
var calendarID: Int = 0,
|
||||
var allDay: Boolean = false,
|
||||
var address: String = "") : RealmObject() {
|
||||
var address: String = "",
|
||||
var selfAttendeeStatus: Int = CalendarContract.Attendees.ATTENDEE_STATUS_NONE
|
||||
) : RealmObject() {
|
||||
override fun toString(): String {
|
||||
return "Event:\nEVENT ID: " + eventID + "\nTITLE: " + title + "\nSTART DATE: " + Date(startDate) + "\nEND DATE: " + Date(endDate) + "\nCAL ID: " + calendarID + "\nADDRESS: " + address
|
||||
}
|
||||
|
@ -0,0 +1,134 @@
|
||||
package com.tommasoberlose.anotherwidget.services
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import androidx.core.app.JobIntentService
|
||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||
import com.tommasoberlose.anotherwidget.models.Event
|
||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import me.everything.providers.android.calendar.CalendarProvider
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.util.*
|
||||
import kotlin.Comparator
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class UpdateCalendarJob : JobIntentService() {
|
||||
|
||||
companion object {
|
||||
val jobId = 1200
|
||||
|
||||
fun enqueueWork(context: Context, work: Intent) {
|
||||
enqueueWork(context, UpdateCalendarJob::class.java, jobId, work)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onHandleWork(intent: Intent) {
|
||||
val eventRepository = EventRepository(this)
|
||||
if (Preferences.showEvents) {
|
||||
val eventList = ArrayList<Event>()
|
||||
|
||||
val now = Calendar.getInstance()
|
||||
val begin = Calendar.getInstance().apply {
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MINUTE, 0)
|
||||
set(Calendar.HOUR_OF_DAY, 0)
|
||||
}
|
||||
val limit = Calendar.getInstance().apply {
|
||||
timeInMillis = begin.timeInMillis
|
||||
add(Calendar.DAY_OF_YEAR, 2)
|
||||
}
|
||||
|
||||
if (!checkGrantedPermission(
|
||||
Manifest.permission.READ_CALENDAR
|
||||
)
|
||||
) {
|
||||
eventRepository.resetNextEventData()
|
||||
} else {
|
||||
try {
|
||||
val provider = CalendarProvider(this)
|
||||
val data = provider.getInstances(begin.timeInMillis, limit.timeInMillis)
|
||||
if (data != null) {
|
||||
val instances = data.list
|
||||
for (instance in instances) {
|
||||
try {
|
||||
val e = provider.getEvent(instance.eventId)
|
||||
if (e != null && !e.deleted && instance.begin <= limit.timeInMillis && now.timeInMillis < instance.end && !CalendarHelper.getFilteredCalendarIdList()
|
||||
.contains(e.calendarId)
|
||||
) {
|
||||
if (e.allDay) {
|
||||
val start = Calendar.getInstance()
|
||||
start.timeInMillis = instance.begin
|
||||
val end = Calendar.getInstance()
|
||||
end.timeInMillis = instance.end
|
||||
instance.begin =
|
||||
start.timeInMillis - start.timeZone.getOffset(start.timeInMillis)
|
||||
instance.end =
|
||||
end.timeInMillis - end.timeZone.getOffset(end.timeInMillis)
|
||||
}
|
||||
eventList.add(
|
||||
Event(
|
||||
id = instance.id,
|
||||
eventID = e.id,
|
||||
title = e.title ?: "",
|
||||
startDate = instance.begin,
|
||||
endDate = instance.end,
|
||||
calendarID = e.calendarId.toInt(),
|
||||
allDay = e.allDay,
|
||||
address = e.eventLocation ?: "",
|
||||
selfAttendeeStatus = e.selfAttendeeStatus.toInt()
|
||||
)
|
||||
)
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventList.isEmpty()) {
|
||||
eventRepository.resetNextEventData()
|
||||
eventRepository.clearEvents()
|
||||
} else {
|
||||
eventList.sortWith(Comparator { event: Event, event1: Event ->
|
||||
if (event.allDay && event1.allDay) {
|
||||
event.startDate.compareTo(event1.startDate)
|
||||
} else if (event.allDay) {
|
||||
1
|
||||
} else if (event1.allDay) {
|
||||
-1
|
||||
} else {
|
||||
event1.startDate.compareTo(event.startDate)
|
||||
}
|
||||
})
|
||||
eventList.reverse()
|
||||
eventRepository.saveEvents(
|
||||
eventList
|
||||
)
|
||||
eventRepository.saveNextEventData(
|
||||
eventList[0]
|
||||
)
|
||||
}
|
||||
} catch (ignored: java.lang.Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eventRepository.resetNextEventData()
|
||||
}
|
||||
|
||||
UpdatesReceiver.setUpdates(this)
|
||||
MainWidget.updateWidget(this)
|
||||
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
eventRepository.close()
|
||||
|
||||
Log.d("ciao", "aggiornati")
|
||||
}
|
||||
}
|
@ -109,14 +109,12 @@ class CalendarTabFragment : Fragment() {
|
||||
all_day_label?.text =
|
||||
if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
}
|
||||
updateCalendar()
|
||||
})
|
||||
|
||||
viewModel.showDeclinedEvents.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
show_declined_events_label?.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
}
|
||||
updateCalendar()
|
||||
})
|
||||
|
||||
viewModel.secondRowInformation.observe(viewLifecycleOwner, Observer {
|
||||
|
@ -8,6 +8,7 @@ import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.text.format.DateFormat
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -49,6 +50,7 @@ class ClockTabFragment : Fragment() {
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var colors: IntArray
|
||||
private lateinit var binding: FragmentClockSettingsBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -60,7 +62,7 @@ class ClockTabFragment : Fragment() {
|
||||
): View {
|
||||
|
||||
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
|
||||
val binding = DataBindingUtil.inflate<FragmentClockSettingsBinding>(inflater, R.layout.fragment_clock_settings, container, false)
|
||||
binding = DataBindingUtil.inflate<FragmentClockSettingsBinding>(inflater, R.layout.fragment_clock_settings, container, false)
|
||||
|
||||
subscribeUi(binding, viewModel)
|
||||
|
||||
@ -89,6 +91,7 @@ class ClockTabFragment : Fragment() {
|
||||
viewModel: MainViewModel
|
||||
) {
|
||||
binding.isClockVisible = Preferences.showClock
|
||||
binding.is24Format = DateFormat.is24HourFormat(requireContext())
|
||||
|
||||
viewModel.showBigClockWarning.observe(viewLifecycleOwner, Observer {
|
||||
large_clock_warning?.isVisible = it
|
||||
@ -266,6 +269,11 @@ class ClockTabFragment : Fragment() {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
binding.is24Format = DateFormat.is24HourFormat(requireContext())
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
private fun maintainScrollPosition(callback: () -> Unit) {
|
||||
scrollView.isScrollable = false
|
||||
callback.invoke()
|
||||
|
@ -25,6 +25,7 @@ import com.karumi.dexter.listener.PermissionRequest
|
||||
import com.karumi.dexter.listener.multi.MultiplePermissionsListener
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||
import com.tommasoberlose.anotherwidget.components.IconPackSelector
|
||||
import com.tommasoberlose.anotherwidget.databinding.FragmentWeatherSettingsBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
@ -133,12 +134,12 @@ class WeatherTabFragment : Fragment() {
|
||||
viewModel.weatherIconPack.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
label_weather_icon_pack?.text = getString(R.string.settings_weather_icon_pack_default).format((it + 1))
|
||||
weather_icon_pack.setImageDrawable(ContextCompat.getDrawable(requireContext(), WeatherHelper.getWeatherIconResource("02d")))
|
||||
if (it == Constants.WeatherIconPack.MINIMAL.value) {
|
||||
weather_icon_pack.setColorFilter(ContextCompat.getColor(requireContext(), R.color.colorPrimaryText))
|
||||
} else {
|
||||
weather_icon_pack.setColorFilter(ContextCompat.getColor(requireContext(), android.R.color.transparent))
|
||||
}
|
||||
// weather_icon_pack.setImageDrawable(ContextCompat.getDrawable(requireContext(), WeatherHelper.getWeatherIconResource("02d")))
|
||||
// if (it == Constants.WeatherIconPack.MINIMAL.value) {
|
||||
// weather_icon_pack.setColorFilter(ContextCompat.getColor(requireContext(), R.color.colorPrimaryText))
|
||||
// } else {
|
||||
// weather_icon_pack.setColorFilter(ContextCompat.getColor(requireContext(), android.R.color.transparent))
|
||||
// }
|
||||
}
|
||||
checkLocationPermission()
|
||||
})
|
||||
@ -236,13 +237,7 @@ class WeatherTabFragment : Fragment() {
|
||||
|
||||
action_weather_icon_pack.setOnClickListener {
|
||||
if (Preferences.showWeather) {
|
||||
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_weather_icon_pack_title)).setSelectedValue(Preferences.weatherIconPack)
|
||||
Constants.WeatherIconPack.values().forEach {
|
||||
dialog.addItem(getString(R.string.settings_weather_icon_pack_default).format(it.value + 1), it.value)
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
Preferences.weatherIconPack = value
|
||||
}.show()
|
||||
IconPackSelector(requireContext(), header = getString(R.string.settings_weather_icon_pack_title)).show()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,7 @@
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="12dp"
|
||||
android:src="@drawable/round_today"
|
||||
android:tint="@color/colorPrimaryText"/>
|
||||
android:src="@drawable/calendar"/>
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
|
@ -7,6 +7,10 @@
|
||||
<variable
|
||||
name="isClockVisible"
|
||||
type="Boolean" />
|
||||
<variable
|
||||
name="is24Format"
|
||||
type="Boolean" />
|
||||
<import type="android.view.View" />
|
||||
</data>
|
||||
<com.tommasoberlose.anotherwidget.components.FixedFocusScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
@ -77,7 +81,7 @@
|
||||
<ImageView
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="12dp"
|
||||
android:padding="10dp"
|
||||
android:src="@drawable/alarm"/>
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
@ -218,6 +222,7 @@
|
||||
android:paddingRight="8dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:visibility="@{is24Format ? View.GONE : View.VISIBLE, default=visible}"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/action_ampm_indicator_size"
|
||||
|
@ -76,10 +76,9 @@
|
||||
<ImageView
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="12dp"
|
||||
android:padding="10dp"
|
||||
android:id="@+id/weather_icon_pack"
|
||||
android:src="@drawable/round_brightness_5"
|
||||
android:tint="@color/colorPrimaryText"/>
|
||||
android:src="@drawable/clear_day_3"/>
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
|
59
app/src/main/res/layout/icon_pack_menu_item.xml
Normal file
59
app/src/main/res/layout/icon_pack_menu_item.xml
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:cardElevation="0dp"
|
||||
app:cardBackgroundColor="@drawable/menu_background"
|
||||
app:cardCornerRadius="8dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:duplicateParentState="true"
|
||||
android:id="@+id/label"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:text="Icon Pack 1"
|
||||
android:textColor="@drawable/menu_text_color"
|
||||
android:textAppearance="@style/AnotherWidget.Settings.Subtitle"
|
||||
app:textAllCaps="false" />
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:padding="4dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:id="@+id/icon_1" />
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:padding="4dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:id="@+id/icon_2" />
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:padding="4dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:id="@+id/icon_3" />
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:padding="4dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:id="@+id/icon_4" />
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
Loading…
x
Reference in New Issue
Block a user