Allow creating tasks as well via the monthly widget

This commit is contained in:
Naveen 2022-06-21 00:55:27 +05:30
parent 40b070bc57
commit 4e4740ecdb
3 changed files with 16 additions and 16 deletions

View File

@ -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

View File

@ -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()))

View File

@ -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)
}
}