delete events from date resolved

This commit is contained in:
MariemMARZOUGUI 2023-12-02 16:39:01 +01:00
parent cf884d8cf3
commit 75ab6fac7e
4 changed files with 20 additions and 42 deletions

View File

@ -1,5 +1,6 @@
package com.simplemobiletools.calendar.pro.activities
import android.annotation.SuppressLint
import android.app.Activity
import android.app.DatePickerDialog
import android.app.TimePickerDialog
@ -11,8 +12,10 @@ import android.media.RingtoneManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.widget.RelativeLayout
import android.widget.Button
import android.widget.DatePicker
import android.widget.ImageButton
import android.widget.Toast
import androidx.annotation.RequiresApi
import com.google.android.material.timepicker.MaterialTimePicker
@ -42,15 +45,11 @@ class SettingsActivity : SimpleActivity() {
private val PICK_SETTINGS_IMPORT_SOURCE_INTENT = 2
private val PICK_EVENTS_IMPORT_SOURCE_INTENT = 3
private val PICK_EVENTS_EXPORT_FILE_INTENT = 4
private var mStoredPrimaryColor = 0
private var eventTypesToExport = listOf<Long>()
private val binding by viewBinding(ActivitySettingsBinding::inflate)
public var chosenDateTimestamp = 0L
@SuppressLint("WrongViewCast")
@RequiresApi(Build.VERSION_CODES.N)
override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true
@ -60,12 +59,10 @@ class SettingsActivity : SimpleActivity() {
updateMaterialActivityViews(binding.settingsCoordinator, binding.settingsHolder, useTransparentNavigation = true, useTopSearchMenu = false)
setupMaterialScrollListener(binding.settingsNestedScrollview, binding.settingsToolbar)
val selectDateButton: Button = findViewById(R.id.selectDateButton)
val settingsDeleteEventsFromDateHolder: RelativeLayout = findViewById(R.id.settings_delete_events_from_date_holder)
selectDateButton.setOnClickListener {
settingsDeleteEventsFromDateHolder.setOnClickListener {
showDatePickerDialog()
}
@ -77,28 +74,20 @@ class SettingsActivity : SimpleActivity() {
val year = currentDate.get(Calendar.YEAR)
val month = currentDate.get(Calendar.MONTH)
val day = currentDate.get(Calendar.DAY_OF_MONTH)
val datePickerDialog = DatePickerDialog(
this,
{ _, year, month, day ->
val selectedDate = Calendar.getInstance()
selectedDate.set(year, month, day)
chosenDateTimestamp = selectedDate.timeInMillis
val chosenDateTimestamp = selectedDate.timeInMillis
setupDeleteEventsFromDate(chosenDateTimestamp)
// You can display the selected date if needed
Toast.makeText(this, selectedDate.toString(), Toast.LENGTH_SHORT).show()
Log.d("MyApp", "Toast displayed: ${selectedDate.toString()}")
},
year,
month,
day
)
datePickerDialog.show()
// Now, you can use chosenDateTimestamp in other parts of your code if needed.
setupDeleteEventsFromDate(chosenDateTimestamp)
}
@ -123,7 +112,6 @@ class SettingsActivity : SimpleActivity() {
setupHighlightWeekends()
setupHighlightWeekendsColor()
setupDeleteAllEvents()
setupDeleteEventsFromDate(chosenDateTimestamp)
setupDisplayDescription()
setupReplaceDescription()
setupWeekNumbers()
@ -164,6 +152,7 @@ class SettingsActivity : SimpleActivity() {
setupExportSettings()
setupImportSettings()
arrayOf(
binding.settingsColorCustomizationSectionLabel,
binding.settingsGeneralSettingsLabel,
@ -461,8 +450,9 @@ class SettingsActivity : SimpleActivity() {
}
@RequiresApi(Build.VERSION_CODES.N)
private fun setupDeleteEventsFromDate(choosendateTimestamp: Long) = binding.apply {
eventsHelper.deleteEventsFromDate(choosendateTimestamp)
private fun setupDeleteEventsFromDate(chosenDateTimestamp: Long) = binding.apply {
Log.d("MyApp", "Deleting events after timestamp: $chosenDateTimestamp")
eventsHelper.deleteEventsFromDate(chosenDateTimestamp)
}
private fun setupDisplayDescription() = binding.apply {

View File

@ -259,9 +259,9 @@ class EventsHelper(val context: Context) {
}
}
fun deleteEventsFromDate(choosendateTimestamp: Long) {
fun deleteEventsFromDate(chosenDateTimestamp: Long) {
ensureBackgroundThread {
val eventIds = eventsDB.getEventIdsWhereDate(choosendateTimestamp).toMutableList()
val eventIds = eventsDB.getEventIdsWhereDate(chosenDateTimestamp).toMutableList()
deleteEvents(eventIds, true)
}
}

View File

@ -137,6 +137,6 @@ interface EventsDao {
@Query("DELETE FROM events WHERE source = :source AND import_id = :importId")
fun deleteBirthdayAnniversary(source: String, importId: String): Int
@Query("SELECT id FROM events WHERE start_ts > :chosenDateTimestamp")
fun getEventIdsWhereDate( chosenDateTimestamp : Long) :List<Long>
@Query("SELECT id FROM events WHERE start_ts*1000 > :chosenDateTimestamp")
fun getEventIdsWhereDate(chosenDateTimestamp: Long): List<Long>
}

View File

@ -884,35 +884,23 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_delete_events_from_date_holder"
style="@style/SettingsHolderTextViewOneLinerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:clickable="true">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_delete_events_from_date"
style="@style/SettingsTextLabelStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete events and tasks from date" />
<Button
android:id="@+id/selectDateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Date"
android:layout_below="@id/settings_delete_events_from_date"
android:layout_marginTop="8dp"
android:layout_alignBaseline="@id/settings_delete_events_from_date"
android:layout_alignParentEnd="true"
android:layout_marginEnd="8dp"
android:onClick="onSelectDateButtonClick" />
android:text="Delete events and tasks after a specific date" />
</RelativeLayout>
<include
android:id="@+id/settings_events_divider"
layout="@layout/divider" />