create a context extension for updating the widget
This commit is contained in:
parent
ee508de5d1
commit
3119013ec4
|
@ -0,0 +1,15 @@
|
|||
package com.simplemobiletools.calendar.extensions
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.calendar.MyWidgetProvider
|
||||
import com.simplemobiletools.calendar.R
|
||||
|
||||
fun Context.updateWidget() {
|
||||
val intent = Intent(this, MyWidgetProvider::class.java)
|
||||
intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||
val ids = intArrayOf(R.xml.widget_info)
|
||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
|
||||
sendBroadcast(intent)
|
||||
}
|
|
@ -17,6 +17,7 @@ import com.simplemobiletools.calendar.*
|
|||
import com.simplemobiletools.calendar.Formatter
|
||||
import com.simplemobiletools.calendar.activities.EventActivity
|
||||
import com.simplemobiletools.calendar.adapters.EventsAdapter
|
||||
import com.simplemobiletools.calendar.extensions.updateWidget
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
import kotlinx.android.synthetic.main.day_fragment.view.*
|
||||
import kotlinx.android.synthetic.main.top_navigation.view.*
|
||||
|
@ -224,13 +225,16 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
|||
}
|
||||
|
||||
override fun eventInserted(event: Event) {
|
||||
context.updateWidget()
|
||||
}
|
||||
|
||||
override fun eventUpdated(event: Event) {
|
||||
context.updateWidget()
|
||||
}
|
||||
|
||||
override fun eventsDeleted(cnt: Int) {
|
||||
checkEvents()
|
||||
context.updateWidget()
|
||||
}
|
||||
|
||||
override fun gotEvents(events: MutableList<Event>) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.view.ViewGroup
|
|||
import android.widget.*
|
||||
import com.simplemobiletools.calendar.*
|
||||
import com.simplemobiletools.calendar.activities.DayActivity
|
||||
import com.simplemobiletools.calendar.extensions.updateWidget
|
||||
import com.simplemobiletools.calendar.models.Day
|
||||
import kotlinx.android.synthetic.main.month_fragment.view.*
|
||||
import kotlinx.android.synthetic.main.top_navigation.view.*
|
||||
|
@ -73,6 +74,7 @@ class MonthFragment : Fragment(), Calendar {
|
|||
activity?.runOnUiThread {
|
||||
mHolder.top_value.text = month
|
||||
updateDays(days)
|
||||
context.updateWidget()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue