adding some top menu items at the tasks activity

This commit is contained in:
tibbi 2022-02-23 10:44:58 +01:00
parent fc66698acf
commit e19145d13f
2 changed files with 53 additions and 3 deletions

View file

@ -4,12 +4,14 @@ import android.app.DatePickerDialog
import android.app.TimePickerDialog import android.app.TimePickerDialog
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager import android.view.WindowManager
import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.helpers.NEW_EVENT_START_TS import com.simplemobiletools.calendar.pro.helpers.NEW_EVENT_START_TS
import com.simplemobiletools.calendar.pro.helpers.TASK_ID import com.simplemobiletools.calendar.pro.helpers.TASK_ID
import com.simplemobiletools.calendar.pro.models.Task
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import kotlinx.android.synthetic.main.activity_task.* import kotlinx.android.synthetic.main.activity_task.*
import org.joda.time.DateTime import org.joda.time.DateTime
@ -18,6 +20,7 @@ import java.util.*
class TaskActivity : SimpleActivity() { class TaskActivity : SimpleActivity() {
private var mDialogTheme = 0 private var mDialogTheme = 0
private lateinit var mTaskDateTime: DateTime private lateinit var mTaskDateTime: DateTime
private lateinit var mTask: Task
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -29,17 +32,39 @@ class TaskActivity : SimpleActivity() {
val intent = intent ?: return val intent = intent ?: return
mDialogTheme = getDialogTheme() mDialogTheme = getDialogTheme()
val taskId = intent.getLongExtra(TASK_ID, 0L)
updateColors() updateColors()
gotTask() val taskId = intent.getLongExtra(TASK_ID, 0L)
gotTask(null)
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_task, menu)
if (::mTask.isInitialized) {
menu.findItem(R.id.delete).isVisible = mTask.id != null
menu.findItem(R.id.duplicate).isVisible = mTask.id != null
}
updateMenuItemColors(menu, true) updateMenuItemColors(menu, true)
return true return true
} }
private fun gotTask() { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.save -> saveCurrentTask()
R.id.delete -> deleteTask()
R.id.duplicate -> duplicateTask()
else -> return super.onOptionsItemSelected(item)
}
return true
}
private fun gotTask(task: Task?) {
if (task != null) {
mTask = task
} else {
mTask = Task(null)
}
task_all_day.setOnCheckedChangeListener { compoundButton, isChecked -> toggleAllDay(isChecked) } task_all_day.setOnCheckedChangeListener { compoundButton, isChecked -> toggleAllDay(isChecked) }
task_all_day_holder.setOnClickListener { task_all_day_holder.setOnClickListener {
task_all_day.toggle() task_all_day.toggle()
@ -63,6 +88,12 @@ class TaskActivity : SimpleActivity() {
updateActionBarTitle(getString(R.string.new_task)) updateActionBarTitle(getString(R.string.new_task))
} }
private fun saveCurrentTask() {}
private fun deleteTask() {}
private fun duplicateTask() {}
private fun setupDate() { private fun setupDate() {
hideKeyboard() hideKeyboard()
val datepicker = DatePickerDialog( val datepicker = DatePickerDialog(

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/save"
android:icon="@drawable/ic_check_vector"
android:title="@string/save"
app:showAsAction="always" />
<item
android:id="@+id/delete"
android:icon="@drawable/ic_delete_vector"
android:title="@string/delete"
app:showAsAction="always" />
<item
android:id="@+id/duplicate"
android:icon="@drawable/ic_copy_vector"
android:title="@string/duplicate_event"
app:showAsAction="always" />
</menu>