properly pick either the dark or light dialog theme

This commit is contained in:
tibbi 2017-01-03 22:31:45 +01:00
parent dbd662d0c2
commit 566646a1b9
4 changed files with 40 additions and 26 deletions

View File

@ -11,6 +11,7 @@ import android.view.WindowManager
import android.widget.AdapterView
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.beVisibleIf
import com.simplemobiletools.calendar.extensions.getAppropriateTheme
import com.simplemobiletools.calendar.extensions.scheduleNotification
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.models.Event
@ -35,7 +36,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
setContentView(R.layout.activity_event)
val intent = intent ?: return
mDialogTheme = if (config.backgroundColor.getContrastColor() == Color.WHITE) R.style.DialogTheme_Dark else R.style.DialogTheme
mDialogTheme = getAppropriateTheme()
mWasReminderInit = false
val eventId = intent.getIntExtra(EVENT_ID, 0)

View File

@ -6,12 +6,14 @@ import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Build
import android.os.SystemClock
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.receivers.NotificationReceiver
import com.simplemobiletools.commons.extensions.getContrastColor
fun Context.updateWidgets() {
val widgetsCnt = AppWidgetManager.getInstance(this).getAppWidgetIds(ComponentName(this, MyWidgetMonthlyProvider::class.java))
@ -91,3 +93,7 @@ private fun getNotificationIntent(context: Context, eventId: Int): PendingIntent
intent.putExtra(EVENT_ID, eventId)
return PendingIntent.getBroadcast(context, eventId, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
fun Context.getAppropriateTheme(): Int {
return if (Config.newInstance(this).backgroundColor.getContrastColor() == Color.WHITE) R.style.DialogTheme_Dark else R.style.DialogTheme
}

View File

@ -15,14 +15,17 @@ import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.adapters.DayEventsAdapter
import com.simplemobiletools.calendar.extensions.getAppropriateTheme
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.extensions.adjustAlpha
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.views.RecyclerViewDivider
import kotlinx.android.synthetic.main.fragment_day.view.*
import kotlinx.android.synthetic.main.top_navigation.view.*
import org.joda.time.DateTime
import java.util.*
import kotlin.comparisons.compareBy
@ -85,28 +88,29 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
}
fun pickDay() {
val alertDialog = AlertDialog.Builder(context)
activity.setTheme(context.getAppropriateTheme())
val view = getLayoutInflater(arguments).inflate(R.layout.date_picker, null)
val datePicker = view.findViewById(R.id.date_picker) as DatePicker
val dateTime = Formatter.getDateTimeFromCode(mDayCode)
datePicker.init(dateTime.year, dateTime.monthOfYear - 1, dateTime.dayOfMonth, null)
alertDialog.apply {
setView(view)
setNegativeButton(R.string.cancel, null)
setPositiveButton(R.string.ok) { dialog, id ->
val month = datePicker.month + 1
val year = datePicker.year
val day = datePicker.dayOfMonth
val newDateTime = dateTime.withDate(year, month, day)
mListener?.goToDateTime(newDateTime)
}
show()
AlertDialog.Builder(context)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.ok) { dialog, which -> positivePressed(dateTime, datePicker) }
.create().apply {
context.setupDialogStuff(view, this)
}
}
private fun positivePressed(dateTime: DateTime, datePicker: DatePicker) {
val month = datePicker.month + 1
val year = datePicker.year
val day = datePicker.dayOfMonth
val newDateTime = dateTime.withDate(year, month, day)
mListener?.goToDateTime(newDateTime)
}
private fun checkEvents() {
val startTS = Formatter.getDayStartTS(mDayCode)
val endTS = Formatter.getDayEndTS(mDayCode)

View File

@ -16,11 +16,13 @@ import com.simplemobiletools.calendar.MonthlyCalendarImpl
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.DayActivity
import com.simplemobiletools.calendar.extensions.beVisibleIf
import com.simplemobiletools.calendar.extensions.getAppropriateTheme
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.interfaces.MonthlyCalendar
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.Day
import com.simplemobiletools.commons.extensions.adjustAlpha
import com.simplemobiletools.commons.extensions.setupDialogStuff
import kotlinx.android.synthetic.main.first_row.*
import kotlinx.android.synthetic.main.fragment_month.view.*
import kotlinx.android.synthetic.main.top_navigation.view.*
@ -120,7 +122,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
}
fun showMonthDialog() {
val alertDialog = AlertDialog.Builder(context)
activity.setTheme(context.getAppropriateTheme())
val view = getLayoutInflater(arguments).inflate(R.layout.date_picker, null)
val datePicker = view.findViewById(R.id.date_picker) as DatePicker
datePicker.findViewById(Resources.getSystem().getIdentifier("day", "id", "android")).visibility = View.GONE
@ -128,20 +130,21 @@ class MonthFragment : Fragment(), MonthlyCalendar {
val dateTime = DateTime(mCalendar.mTargetDate.toString())
datePicker.init(dateTime.year, dateTime.monthOfYear - 1, 1, null)
alertDialog.apply {
setView(view)
setNegativeButton(R.string.cancel, null)
setPositiveButton(R.string.ok) { dialog, id ->
val month = datePicker.month + 1
val year = datePicker.year
val newDateTime = dateTime.withDate(year, month, 1)
mListener?.goToDateTime(newDateTime)
}
show()
AlertDialog.Builder(context)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.ok) { dialog, which -> positivePressed(dateTime, datePicker) }
.create().apply {
context.setupDialogStuff(view, this)
}
}
private fun positivePressed(dateTime: DateTime, datePicker: DatePicker) {
val month = datePicker.month + 1
val year = datePicker.year
val newDateTime = dateTime.withDate(year, month, 1)
mListener?.goToDateTime(newDateTime)
}
private fun setupLabels() {
val letters = letterIDs