use proper time and date at new tasks

This commit is contained in:
tibbi 2022-02-23 09:49:02 +01:00
parent b6d21c1b4a
commit fc66698acf
3 changed files with 23 additions and 5 deletions

View File

@ -113,10 +113,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
fab_task_icon.setOnClickListener {
hideKeyboard()
Intent(this, TaskActivity::class.java).apply {
startActivity(this)
}
openNewTask()
Handler().postDelayed({
hideExtendedFab()
@ -930,6 +927,13 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
launchNewEventIntent(lastFragment.getNewEventDayCode(), allowChangingDay)
}
private fun openNewTask() {
hideKeyboard()
val lastFragment = currentFragments.last()
val allowChangingDay = lastFragment !is DayFragmentsHolder && lastFragment !is MonthDayFragmentsHolder
launchNewTaskIntent(lastFragment.getNewEventDayCode(), allowChangingDay)
}
fun openMonthFromYearly(dateTime: DateTime) {
if (currentFragments.last() is MonthFragmentsHolder) {
return

View File

@ -8,6 +8,7 @@ import android.view.WindowManager
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.helpers.NEW_EVENT_START_TS
import com.simplemobiletools.calendar.pro.helpers.TASK_ID
import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.activity_task.*
@ -29,7 +30,6 @@ class TaskActivity : SimpleActivity() {
val intent = intent ?: return
mDialogTheme = getDialogTheme()
val taskId = intent.getLongExtra(TASK_ID, 0L)
mTaskDateTime = DateTime.now()
updateColors()
gotTask()
}
@ -54,6 +54,10 @@ class TaskActivity : SimpleActivity() {
}
private fun setupNewTask() {
val startTS = intent.getLongExtra(NEW_EVENT_START_TS, 0L)
val dateTime = Formatter.getDateTimeFromTS(startTS)
mTaskDateTime = dateTime
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
task_title.requestFocus()
updateActionBarTitle(getString(R.string.new_task))

View File

@ -27,6 +27,7 @@ import androidx.print.PrintHelper
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.EventActivity
import com.simplemobiletools.calendar.pro.activities.SnoozeReminderActivity
import com.simplemobiletools.calendar.pro.activities.TaskActivity
import com.simplemobiletools.calendar.pro.databases.EventsDatabase
import com.simplemobiletools.calendar.pro.helpers.*
import com.simplemobiletools.calendar.pro.helpers.Formatter
@ -368,6 +369,15 @@ fun Context.launchNewEventIntent(dayCode: String = Formatter.getTodayCode(), all
}
}
// if the default start time is set to "Next full hour" and the task is created before midnight, it could change the day
fun Context.launchNewTaskIntent(dayCode: String = Formatter.getTodayCode(), allowChangingDay: Boolean = false) {
Intent(applicationContext, TaskActivity::class.java).apply {
putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(dayCode, allowChangingDay))
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(this)
}
}
fun Context.getNewEventTimestampFromCode(dayCode: String, allowChangingDay: Boolean = false): Long {
val calendar = Calendar.getInstance()
val defaultStartTime = config.defaultStartTime