Fix event tap ui

This commit is contained in:
Tommaso Berlose
2020-05-04 19:28:06 +02:00
parent 6279846cea
commit dd450443c8
18 changed files with 102 additions and 105 deletions

View File

@ -40,6 +40,7 @@ object Preferences : KotprefModel() {
var weatherProviderApi by stringPref(key = "PREF_WEATHER_PROVIDER_API_KEY", default = "")
var eventAppName by stringPref(key = "PREF_EVENT_APP_NAME", default = "")
var eventAppPackage by stringPref(key = "PREF_EVENT_APP_PACKAGE", default = "")
var openEventDetails by booleanPref(default = true)
var showEventLocation by stringPref(key = "PREF_SHOW_EVENT_LOCATION", default = "")
var textGlobalColor by stringPref(key = "PREF_TEXT_COLOR", default = "#FFFFFF")
var textMainSize by floatPref(key = "PREF_TEXT_MAIN_SIZE", default = 26f)
@ -49,7 +50,7 @@ object Preferences : KotprefModel() {
var showClock by booleanPref(key = "PREF_SHOW_CLOCK", default = false)
var clockAppName by stringPref(key = "PREF_CLOCK_APP_NAME", default = "")
var clockAppPackage by stringPref(key = "PREF_CLOCK_APP_PACKAGE", default = "")
var showNextAlarm by booleanPref(default = true)
var showNextAlarm by booleanPref(default = false)
var textShadow by intPref(key = "PREF_TEXT_SHADOW", default = 1)
var showDiffTime by booleanPref(key = "PREF_SHOW_DIFF_TIME")
var showDeclinedEvents by booleanPref(key = "PREF_SHOW_DECLINED_EVENTS", default = true)

View File

@ -11,7 +11,7 @@ object AlarmHelper {
val alarm = nextAlarmClock
return if (
alarm != null
&& alarm.triggerTime - Calendar.getInstance().timeInMillis > 2 * 60 * 1000
&& alarm.triggerTime - Calendar.getInstance().timeInMillis > 10 * 60 * 1000
&& alarm.triggerTime - Calendar.getInstance().timeInMillis < 12 * 60 * 60 * 1000
) {
"%s %s".format(

View File

@ -30,35 +30,6 @@ object IntentHelper {
}
}
fun getCalendarIntent(context: Context): Intent {
return when (Preferences.calendarAppPackage) {
"" -> {
Intent(Intent.ACTION_MAIN).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addCategory(Intent.CATEGORY_APP_CALENDAR)
}
}
"_" -> {
Intent()
}
else -> {
val pm: PackageManager = context.packageManager
try {
pm.getLaunchIntentForPackage(Preferences.calendarAppPackage)!!.apply {
addCategory(Intent.CATEGORY_LAUNCHER)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
} catch (e: Exception) {
e.printStackTrace()
Intent(Intent.ACTION_MAIN).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addCategory(Intent.CATEGORY_APP_CALENDAR)
}
}
}
}
}
fun getWeatherIntent(context: Context): Intent {
return when (Preferences.weatherAppPackage) {
"" -> {
@ -91,15 +62,12 @@ object IntentHelper {
}
}
fun getEventIntent(context: Context, e: Event): Intent {
return when (Preferences.eventAppPackage) {
fun getCalendarIntent(context: Context): Intent {
return when (Preferences.calendarAppPackage) {
"" -> {
val uri = ContentUris.withAppendedId(Events.CONTENT_URI, e.eventID)
Intent(Intent.ACTION_VIEW).apply {
data = uri
Intent(Intent.ACTION_MAIN).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
addCategory(Intent.CATEGORY_APP_CALENDAR)
}
}
"_" -> {
@ -107,25 +75,46 @@ object IntentHelper {
}
else -> {
val pm: PackageManager = context.packageManager
val uri = ContentUris.withAppendedId(Events.CONTENT_URI, e.eventID)
try {
pm.getLaunchIntentForPackage(Preferences.eventAppPackage)!!.apply {
action = Intent.ACTION_VIEW
data = uri
pm.getLaunchIntentForPackage(Preferences.calendarAppPackage)!!.apply {
addCategory(Intent.CATEGORY_LAUNCHER)
// addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
// putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
} catch (ex: Exception) {
} catch (e: Exception) {
e.printStackTrace()
Intent(Intent.ACTION_MAIN).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
addCategory(Intent.CATEGORY_APP_CALENDAR)
}
}
}
}
}
fun getEventIntent(context: Context, e: Event, forceEventDetails: Boolean = false): Intent {
return when (Preferences.openEventDetails || forceEventDetails) {
true -> {
val uri = ContentUris.withAppendedId(Events.CONTENT_URI, e.eventID)
if (Preferences.calendarAppPackage == "") {
Intent(Intent.ACTION_VIEW).apply {
data = uri
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
}
} else {
getCalendarIntent(context).apply {
action = Intent.ACTION_VIEW
data = uri
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
}
}
}
false -> {
getCalendarIntent(context)
}
}
}

View File

@ -147,9 +147,9 @@ class CalendarSettingsFragment : Fragment() {
}
})
viewModel.eventAppName.observe(viewLifecycleOwner, Observer {
viewModel.openEventDetails.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
event_app_label.text = if (it != "") it else getString(R.string.default_calendar_app)
open_event_details_label.text = if (it) getString(R.string.default_event_app) else getString(R.string.default_calendar_app)
}
})
@ -301,8 +301,15 @@ class CalendarSettingsFragment : Fragment() {
}
}
action_event_app.setOnClickListener {
startActivityForResult(Intent(requireContext(), ChooseApplicationActivity::class.java), RequestCode.EVENT_APP_REQUEST_CODE.code)
action_open_event_details.setOnClickListener {
if (Preferences.showEvents) {
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_event_app_title)).setSelectedValue(Preferences.openEventDetails)
.addItem(getString(R.string.default_event_app), true)
.addItem(getString(R.string.default_calendar_app), false)
.addOnSelectItemListener { value ->
Preferences.openEventDetails = value
}.show()
}
}
action_calendar_app.setOnClickListener {

View File

@ -21,10 +21,9 @@ class MainViewModel : ViewModel() {
val showDiffTime = Preferences.asLiveData(Preferences::showDiffTime)
val showDeclinedEvents = Preferences.asLiveData(Preferences::showDeclinedEvents)
val showNextEvent = Preferences.asLiveData(Preferences::showNextEvent)
val openEventDetails = Preferences.asLiveData(Preferences::openEventDetails)
val calendarAppName = Preferences.asLiveData(Preferences::calendarAppName)
val eventAppName = Preferences.asLiveData(Preferences::eventAppName)
// Clock Settings
val showClock = Preferences.asLiveData(Preferences::showClock)

View File

@ -156,7 +156,8 @@ class MainWidget : AppWidgetProvider() {
val mapIntent = PendingIntent.getActivity(context, widgetID, IntentHelper.getGoogleMapsIntentFromAddress(context, nextEvent.address), 0)
views.setOnClickPendingIntent(R.id.second_row_rect, mapIntent)
} else {
views.setOnClickPendingIntent(R.id.second_row_rect, pIntent)
val pIntentDetail = PendingIntent.getActivity(context, widgetID, IntentHelper.getEventIntent(context, nextEvent, forceEventDetails = true), 0)
views.setOnClickPendingIntent(R.id.second_row_rect, pIntentDetail)
}
views.setImageViewBitmap(R.id.next_event_rect, BitmapHelper.getBitmapFromView(v.next_event, draw = false))