From 40b070bc57ad99352fa11ba5a86b6dac5e46f6ab Mon Sep 17 00:00:00 2001 From: Naveen Date: Sun, 19 Jun 2022 19:49:37 +0530 Subject: [PATCH 1/3] Allow creating tasks as well using the event list widget btn https://github.com/SimpleMobileTools/Simple-Calendar/issues/1665 --- app/src/main/AndroidManifest.xml | 5 +++ .../pro/activities/EventTypePickerActivity.kt | 35 +++++++++++++++++++ .../pro/helpers/MyWidgetListProvider.kt | 14 +++++++- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventTypePickerActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e2a042c0f..57f5202f9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -194,6 +194,11 @@ android:exported="false" android:theme="@style/Theme.Transparent" /> + + context.launchNewEventIntent() + NEW_EVENT -> launchNewEventActivity(context) LAUNCH_CAL -> launchCalenderInDefaultView(context) GO_TO_TODAY -> goToToday(context) else -> super.onReceive(context, intent) @@ -102,6 +103,17 @@ class MyWidgetListProvider : AppWidgetProvider() { } } + private fun launchNewEventActivity(context: Context) { + if (context.config.allowCreatingTasks) { + Intent(context, EventTypePickerActivity::class.java).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + context.startActivity(this) + } + } else { + context.launchNewEventIntent() + } + } + private fun launchCalenderInDefaultView(context: Context) { (context.getLaunchIntent() ?: Intent(context, SplashActivity::class.java)).apply { putExtra(DAY_CODE, Formatter.getDayCodeFromDateTime(DateTime())) From 4e4740ecdb47463be18956213d6f2dd170572d14 Mon Sep 17 00:00:00 2001 From: Naveen Date: Tue, 21 Jun 2022 00:55:27 +0530 Subject: [PATCH 2/3] Allow creating tasks as well via the monthly widget --- .../calendar/pro/extensions/Context.kt | 12 ++++++++++++ .../calendar/pro/helpers/MyWidgetListProvider.kt | 16 ++-------------- .../pro/helpers/MyWidgetMonthlyProvider.kt | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index 49144d7e2..2ab3c99da 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -25,6 +25,7 @@ import androidx.core.app.NotificationCompat import androidx.print.PrintHelper import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.EventActivity +import com.simplemobiletools.calendar.pro.activities.EventTypePickerActivity import com.simplemobiletools.calendar.pro.activities.SnoozeReminderActivity import com.simplemobiletools.calendar.pro.activities.TaskActivity import com.simplemobiletools.calendar.pro.databases.EventsDatabase @@ -376,6 +377,17 @@ fun Context.launchNewTaskIntent(dayCode: String = Formatter.getTodayCode(), allo } } +fun Context.launchNewEventActivity() { + if (config.allowCreatingTasks) { + Intent(this, EventTypePickerActivity::class.java).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + startActivity(this) + } + } else { + launchNewEventIntent() + } +} + fun Context.getNewEventTimestampFromCode(dayCode: String, allowChangingDay: Boolean = false): Long { val calendar = Calendar.getInstance() val defaultStartTime = config.defaultStartTime diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt index c46fb913f..fbeca895f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt @@ -9,11 +9,10 @@ import android.content.Intent import android.net.Uri import android.widget.RemoteViews import com.simplemobiletools.calendar.pro.R -import com.simplemobiletools.calendar.pro.activities.EventTypePickerActivity import com.simplemobiletools.calendar.pro.activities.SplashActivity import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.extensions.getWidgetFontSize -import com.simplemobiletools.calendar.pro.extensions.launchNewEventIntent +import com.simplemobiletools.calendar.pro.extensions.launchNewEventActivity import com.simplemobiletools.calendar.pro.extensions.widgetsDB import com.simplemobiletools.calendar.pro.services.WidgetService import com.simplemobiletools.calendar.pro.services.WidgetServiceEmpty @@ -87,7 +86,7 @@ class MyWidgetListProvider : AppWidgetProvider() { override fun onReceive(context: Context, intent: Intent) { when (intent.action) { - NEW_EVENT -> launchNewEventActivity(context) + NEW_EVENT -> context.launchNewEventActivity() LAUNCH_CAL -> launchCalenderInDefaultView(context) GO_TO_TODAY -> goToToday(context) else -> super.onReceive(context, intent) @@ -103,17 +102,6 @@ class MyWidgetListProvider : AppWidgetProvider() { } } - private fun launchNewEventActivity(context: Context) { - if (context.config.allowCreatingTasks) { - Intent(context, EventTypePickerActivity::class.java).apply { - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(this) - } - } else { - context.launchNewEventIntent() - } - } - private fun launchCalenderInDefaultView(context: Context) { (context.getLaunchIntent() ?: Intent(context, SplashActivity::class.java)).apply { putExtra(DAY_CODE, Formatter.getDayCodeFromDateTime(DateTime())) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt index cde88b056..b70a129d7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt @@ -14,7 +14,7 @@ import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SplashActivity import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.extensions.getWidgetFontSize -import com.simplemobiletools.calendar.pro.extensions.launchNewEventIntent +import com.simplemobiletools.calendar.pro.extensions.launchNewEventActivity import com.simplemobiletools.calendar.pro.interfaces.MonthlyCalendar import com.simplemobiletools.calendar.pro.models.DayMonthly import com.simplemobiletools.calendar.pro.models.Event @@ -73,7 +73,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { PREV -> getPrevMonth(context) NEXT -> getNextMonth(context) GO_TO_TODAY -> goToToday(context) - NEW_EVENT -> context.launchNewEventIntent() + NEW_EVENT -> context.launchNewEventActivity() else -> super.onReceive(context, intent) } } From 86f1b3743c33e960bbdde488962f8fc0c40178ee Mon Sep 17 00:00:00 2001 From: Naveen Date: Tue, 21 Jun 2022 01:11:03 +0530 Subject: [PATCH 3/3] Rename extension to `launchNewEventOrTaskActivity()` --- .../com/simplemobiletools/calendar/pro/extensions/Context.kt | 2 +- .../calendar/pro/helpers/MyWidgetListProvider.kt | 4 ++-- .../calendar/pro/helpers/MyWidgetMonthlyProvider.kt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index 2ab3c99da..035fd41ac 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -377,7 +377,7 @@ fun Context.launchNewTaskIntent(dayCode: String = Formatter.getTodayCode(), allo } } -fun Context.launchNewEventActivity() { +fun Context.launchNewEventOrTaskActivity() { if (config.allowCreatingTasks) { Intent(this, EventTypePickerActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt index fbeca895f..a617cc763 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt @@ -12,7 +12,7 @@ import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SplashActivity import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.extensions.getWidgetFontSize -import com.simplemobiletools.calendar.pro.extensions.launchNewEventActivity +import com.simplemobiletools.calendar.pro.extensions.launchNewEventOrTaskActivity import com.simplemobiletools.calendar.pro.extensions.widgetsDB import com.simplemobiletools.calendar.pro.services.WidgetService import com.simplemobiletools.calendar.pro.services.WidgetServiceEmpty @@ -86,7 +86,7 @@ class MyWidgetListProvider : AppWidgetProvider() { override fun onReceive(context: Context, intent: Intent) { when (intent.action) { - NEW_EVENT -> context.launchNewEventActivity() + NEW_EVENT -> context.launchNewEventOrTaskActivity() LAUNCH_CAL -> launchCalenderInDefaultView(context) GO_TO_TODAY -> goToToday(context) else -> super.onReceive(context, intent) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt index b70a129d7..83560c790 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt @@ -14,7 +14,7 @@ import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SplashActivity import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.extensions.getWidgetFontSize -import com.simplemobiletools.calendar.pro.extensions.launchNewEventActivity +import com.simplemobiletools.calendar.pro.extensions.launchNewEventOrTaskActivity import com.simplemobiletools.calendar.pro.interfaces.MonthlyCalendar import com.simplemobiletools.calendar.pro.models.DayMonthly import com.simplemobiletools.calendar.pro.models.Event @@ -73,7 +73,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { PREV -> getPrevMonth(context) NEXT -> getNextMonth(context) GO_TO_TODAY -> goToToday(context) - NEW_EVENT -> context.launchNewEventActivity() + NEW_EVENT -> context.launchNewEventOrTaskActivity() else -> super.onReceive(context, intent) } }