make widget variables non static

This commit is contained in:
tibbi 2017-06-23 23:18:01 +02:00
parent fbaf5b6f1e
commit 4884a4ce39
3 changed files with 36 additions and 31 deletions

View File

@ -36,12 +36,8 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
}
}
fun getPrevMonth() {
updateMonthlyCalendar(mTargetDate.minusMonths(1))
}
fun getNextMonth() {
updateMonthlyCalendar(mTargetDate.plusMonths(1))
fun getMonth(targetDate: DateTime) {
updateMonthlyCalendar(targetDate)
}
fun getDays() {

View File

@ -22,15 +22,13 @@ class MyWidgetListProvider : AppWidgetProvider() {
private val NEW_EVENT = "new_event"
private val LAUNCH_TODAY = "launch_today"
companion object {
private var mTextColor = 0
private var mTextColor = 0
lateinit var mRemoteViews: RemoteViews
lateinit var mRes: Resources
lateinit var mWidgetManager: AppWidgetManager
lateinit var mIntent: Intent
lateinit var mContext: Context
}
lateinit var mRemoteViews: RemoteViews
lateinit var mRes: Resources
lateinit var mWidgetManager: AppWidgetManager
lateinit var mIntent: Intent
lateinit var mContext: Context
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
initVariables(context)

View File

@ -23,20 +23,22 @@ import com.simplemobiletools.commons.extensions.adjustAlpha
import org.joda.time.DateTime
class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
private val PREV = "prev"
private val NEXT = "next"
private val NEW_EVENT = "new_event"
private var mTextColor = 0
private var mWeakTextColor = 0
private var mCalendar: MonthlyCalendarImpl? = null
private var mRemoteViews: RemoteViews? = null
lateinit var mRes: Resources
lateinit var mContext: Context
lateinit var mWidgetManager: AppWidgetManager
lateinit var mIntent: Intent
companion object {
private val PREV = "prev"
private val NEXT = "next"
private val NEW_EVENT = "new_event"
private var mTextColor = 0
private var mWeakTextColor = 0
private var mCalendar: MonthlyCalendarImpl? = null
private var mRemoteViews: RemoteViews? = null
lateinit var mRes: Resources
lateinit var mContext: Context
lateinit var mWidgetManager: AppWidgetManager
lateinit var mIntent: Intent
private var mTargetDate = DateTime()
}
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
@ -63,8 +65,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
updateTopViews()
mRemoteViews?.setInt(R.id.calendar_holder, "setBackgroundColor", config.widgetBgColor)
mCalendar?.updateMonthlyCalendar(DateTime(), false)
mCalendar?.updateMonthlyCalendar(mTargetDate, false)
}
private fun updateWidget() {
@ -107,13 +108,23 @@ class MyWidgetMonthlyProvider : AppWidgetProvider(), MonthlyCalendar {
val action = intent.action
when (action) {
PREV -> mCalendar?.getPrevMonth()
NEXT -> mCalendar?.getNextMonth()
PREV -> getPrevMonth()
NEXT -> getNextMonth()
NEW_EVENT -> mContext.launchNewEventIntent(true)
else -> super.onReceive(context, intent)
}
}
private fun getPrevMonth() {
mTargetDate = mTargetDate.minusMonths(1)
mCalendar?.getMonth(mTargetDate)
}
private fun getNextMonth() {
mTargetDate = mTargetDate.plusMonths(1)
mCalendar?.getMonth(mTargetDate)
}
fun updateDays(days: List<Day>) {
val displayWeekNumbers = mContext.config.displayWeekNumbers
val len = days.size