diff --git a/app/src/androidTest/java/com/example/util/simpletimetracker/DataEditTest.kt b/app/src/androidTest/java/com/example/util/simpletimetracker/DataEditTest.kt index 0ea422668..38527d807 100644 --- a/app/src/androidTest/java/com/example/util/simpletimetracker/DataEditTest.kt +++ b/app/src/androidTest/java/com/example/util/simpletimetracker/DataEditTest.kt @@ -3,6 +3,7 @@ package com.example.util.simpletimetracker import androidx.test.espresso.Espresso.onView import androidx.test.espresso.Espresso.pressBack import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.action.ViewActions.swipeUp import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers.hasDescendant import androidx.test.espresso.matcher.ViewMatchers.isChecked @@ -25,6 +26,7 @@ import com.example.util.simpletimetracker.utils.clickOnViewWithText import com.example.util.simpletimetracker.utils.nestedScrollTo import com.example.util.simpletimetracker.utils.nthChildOf import com.example.util.simpletimetracker.utils.recyclerItemCount +import com.example.util.simpletimetracker.utils.tryAction import com.example.util.simpletimetracker.utils.typeTextIntoView import com.example.util.simpletimetracker.utils.withCardColor import com.example.util.simpletimetracker.utils.withTag @@ -55,25 +57,34 @@ class DataEditTest : BaseUiTest() { // Check NavUtils.openSettingsScreen() NavUtils.openDataEditScreen() - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) - onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo(), click()) + onView(withId(dataEditR.id.checkboxDataEditChangeActivity)) + .perform(nestedScrollTo(), click()) clickOnViewWithText(name2) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) - clickOnViewWithText(coreR.string.data_edit_select_records) + onView(withText(coreR.string.data_edit_select_records)) + .perform(nestedScrollTo(), click()) clickOnViewWithText(coreR.string.activity_hint) clickOnView(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText(name2))) pressBack() - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) - clickOnViewWithText(coreR.string.data_edit_select_records) + onView(withText(coreR.string.data_edit_select_records)) + .perform(nestedScrollTo(), click()) clickOnView(allOf(isDescendantOfA(withId(R.id.viewRecordTypeItem)), withText(name1))) pressBack() - onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isEnabled())) - onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo(), click()) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) + onView(withId(dataEditR.id.checkboxDataEditChangeActivity)) + .perform(nestedScrollTo(), click()) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) } @Test @@ -129,23 +140,32 @@ class DataEditTest : BaseUiTest() { checkViewIsDisplayed( allOf(withId(dataEditR.id.tvDataEditSelectedRecords), withSubstring("2")), ) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) - onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).check(matches(isNotChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) + onView(withId(dataEditR.id.checkboxDataEditChangeActivity)) + .perform(nestedScrollTo()).check(matches(isNotChecked())) clickOnViewWithId(dataEditR.id.checkboxDataEditChangeActivity) pressBack() - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) - onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).check(matches(isNotChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) + onView(withId(dataEditR.id.checkboxDataEditChangeActivity)) + .perform(nestedScrollTo()).check(matches(isNotChecked())) // Change - onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo(), click()) + onView(withId(dataEditR.id.checkboxDataEditChangeActivity)) + .perform(nestedScrollTo(), click()) clickOnViewWithText(name2) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) - onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).check(matches(isChecked())) - clickOnViewWithText(coreR.string.data_edit_button_change) - clickOnViewWithText(coreR.string.data_edit_button_change) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isEnabled())) + onView(withId(dataEditR.id.checkboxDataEditChangeActivity)) + .perform(nestedScrollTo()).check(matches(isChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()) + onView(withId(dataEditR.id.nsvDataEdit)) + .perform(swipeUp()) + onView(withText(coreR.string.data_edit_button_change)) + .perform(click()) + clickOnViewWithText(coreR.string.ok) Thread.sleep(1000) // Check @@ -226,18 +246,22 @@ class DataEditTest : BaseUiTest() { checkViewIsDisplayed( allOf(withId(dataEditR.id.tvDataEditSelectedRecords), withSubstring("2")), ) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) - onView(withId(dataEditR.id.checkboxDataEditChangeComment)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditChangeComment)).check(matches(isNotChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) + onView(withId(dataEditR.id.checkboxDataEditChangeComment)) + .perform(nestedScrollTo()).check(matches(isNotChecked())) // Change - onView(withId(dataEditR.id.checkboxDataEditChangeComment)).perform(nestedScrollTo(), click()) + onView(withId(dataEditR.id.checkboxDataEditChangeComment)) + .perform(nestedScrollTo(), click()) typeTextIntoView(dataEditR.id.etDataEditChangeComment, comment3) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) - onView(withId(dataEditR.id.checkboxDataEditChangeComment)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditChangeComment)).check(matches(isChecked())) - clickOnViewWithText(coreR.string.data_edit_button_change) - clickOnViewWithText(coreR.string.data_edit_button_change) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isEnabled())) + onView(withId(dataEditR.id.checkboxDataEditChangeComment)) + .perform(nestedScrollTo()).check(matches(isChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo(), click()) + clickOnViewWithText(coreR.string.ok) Thread.sleep(1000) // Check @@ -317,25 +341,30 @@ class DataEditTest : BaseUiTest() { checkViewIsDisplayed( allOf(withId(dataEditR.id.tvDataEditSelectedRecords), withSubstring("2")), ) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) - onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditAddTag)).check(matches(isNotChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) + onView(withId(dataEditR.id.checkboxDataEditAddTag)) + .perform(nestedScrollTo()).check(matches(isNotChecked())) clickOnViewWithId(dataEditR.id.checkboxDataEditAddTag) pressBack() - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) - onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditAddTag)).check(matches(isNotChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) + onView(withId(dataEditR.id.checkboxDataEditAddTag)) + .perform(nestedScrollTo()).check(matches(isNotChecked())) // Change - onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo(), click()) + onView(withId(dataEditR.id.checkboxDataEditAddTag)) + .perform(nestedScrollTo(), click()) clickOnViewWithText(tag1) clickOnViewWithText(tag3) clickOnViewWithText(coreR.string.records_filter_select) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) - onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditAddTag)).check(matches(isChecked())) - clickOnViewWithText(coreR.string.data_edit_button_change) - clickOnViewWithText(coreR.string.data_edit_button_change) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isEnabled())) + onView(withId(dataEditR.id.checkboxDataEditAddTag)) + .perform(nestedScrollTo()).check(matches(isChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo(), click()) + clickOnViewWithText(coreR.string.ok) Thread.sleep(1000) // Check @@ -415,25 +444,30 @@ class DataEditTest : BaseUiTest() { checkViewIsDisplayed( allOf(withId(dataEditR.id.tvDataEditSelectedRecords), withSubstring("2")), ) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) - onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).check(matches(isNotChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) + onView(withId(dataEditR.id.checkboxDataEditRemoveTag)) + .perform(nestedScrollTo()).check(matches(isNotChecked())) clickOnViewWithId(dataEditR.id.checkboxDataEditRemoveTag) pressBack() - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) - onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).check(matches(isNotChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) + onView(withId(dataEditR.id.checkboxDataEditRemoveTag)) + .perform(nestedScrollTo()).check(matches(isNotChecked())) // Change - onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo(), click()) + onView(withId(dataEditR.id.checkboxDataEditRemoveTag)) + .perform(nestedScrollTo(), click()) clickOnViewWithText(tag1) clickOnViewWithText(tag3) clickOnViewWithText(coreR.string.records_filter_select) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) - onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo()) - onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).check(matches(isChecked())) - clickOnViewWithText(coreR.string.data_edit_button_change) - clickOnViewWithText(coreR.string.data_edit_button_change) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isEnabled())) + onView(withId(dataEditR.id.checkboxDataEditRemoveTag)) + .perform(nestedScrollTo()).check(matches(isChecked())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo(), click()) + clickOnViewWithText(coreR.string.ok) Thread.sleep(1000) // Check @@ -513,29 +547,40 @@ class DataEditTest : BaseUiTest() { checkViewIsDisplayed( allOf(withId(dataEditR.id.tvDataEditSelectedRecords), withSubstring("2")), ) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isNotEnabled())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isNotEnabled())) // Select other changes - onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo(), click()) + onView(withId(dataEditR.id.checkboxDataEditChangeActivity)) + .perform(nestedScrollTo(), click()) clickOnViewWithText(name2) onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).check(matches(isChecked())) - onView(withId(dataEditR.id.checkboxDataEditChangeComment)).perform(nestedScrollTo(), click()) + onView(withId(dataEditR.id.checkboxDataEditChangeComment)) + .perform(nestedScrollTo(), click()) typeTextIntoView(dataEditR.id.etDataEditChangeComment, "temp") onView(withId(dataEditR.id.checkboxDataEditChangeComment)).check(matches(isChecked())) - onView(withId(dataEditR.id.checkboxDataEditAddTag)).perform(nestedScrollTo(), click()) + onView(withId(dataEditR.id.checkboxDataEditAddTag)) + .perform(nestedScrollTo(), click()) clickOnViewWithText(tag2) clickOnViewWithText(coreR.string.records_filter_select) onView(withId(dataEditR.id.checkboxDataEditAddTag)).check(matches(isChecked())) - onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).perform(nestedScrollTo(), click()) + onView(withId(dataEditR.id.checkboxDataEditRemoveTag)) + .perform(nestedScrollTo()) + onView(withId(dataEditR.id.nsvDataEdit)) + .perform(swipeUp()) + onView(withId(dataEditR.id.checkboxDataEditRemoveTag)) + .perform(click()) clickOnViewWithText(tag3) clickOnViewWithText(coreR.string.records_filter_select) onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).check(matches(isChecked())) - onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) - onView(withId(dataEditR.id.checkboxDataEditDeleteRecords)).perform(nestedScrollTo(), click()) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isEnabled())) + onView(withId(dataEditR.id.checkboxDataEditDeleteRecords)) + .perform(nestedScrollTo(), click()) // Other changes is reset onView(withId(dataEditR.id.checkboxDataEditChangeActivity)).perform(nestedScrollTo()) @@ -548,11 +593,13 @@ class DataEditTest : BaseUiTest() { onView(withId(dataEditR.id.checkboxDataEditRemoveTag)).check(matches(isNotChecked())) // Change - onView(withText(coreR.string.data_edit_button_change)).check(matches(isEnabled())) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo()).check(matches(isEnabled())) onView(withId(dataEditR.id.checkboxDataEditDeleteRecords)).perform(nestedScrollTo()) onView(withId(dataEditR.id.checkboxDataEditDeleteRecords)).check(matches(isChecked())) - clickOnViewWithText(coreR.string.data_edit_button_change) - clickOnViewWithText(coreR.string.data_edit_button_change) + onView(withText(coreR.string.data_edit_button_change)) + .perform(nestedScrollTo(), click()) + clickOnViewWithText(coreR.string.ok) Thread.sleep(1000) // Check @@ -574,6 +621,85 @@ class DataEditTest : BaseUiTest() { ) } + @Test + fun deleteAllRecords() { + val name1 = "TypeName1" + val name2 = "TypeName2" + + // Add data + testUtils.addActivity(name1) + testUtils.addActivity(name2) + testUtils.addRecord(name1) + testUtils.addRecord(name2) + Thread.sleep(1000) + + // Check before + tryAction { checkViewIsDisplayed(allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(name1)))) } + checkViewIsDisplayed(allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(name2)))) + NavUtils.openRecordsScreen() + checkViewIsDisplayed(allOf(withId(baseR.id.viewRecordItem), hasDescendant(withText(name1)))) + checkViewIsDisplayed(allOf(withId(baseR.id.viewRecordItem), hasDescendant(withText(name2)))) + + // Select + NavUtils.openSettingsScreen() + NavUtils.openDataEditScreen() + onView(withText(R.string.data_edit_button_delete_records)) + .perform(nestedScrollTo(), click()) + clickOnViewWithText(coreR.string.ok) + + // Check + NavUtils.openRunningRecordsScreen() + checkViewIsDisplayed(allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(name1)))) + checkViewIsDisplayed(allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(name2)))) + NavUtils.openRecordsScreen() + checkViewIsDisplayed(withText(R.string.no_records_exist)) + } + + @Test + fun deleteAllData() { + val name1 = "TypeName1" + val name2 = "TypeName2" + + // Add data + testUtils.addActivity(name1) + testUtils.addActivity(name2) + testUtils.addRecord(name1) + testUtils.addRecord(name2) + Thread.sleep(1000) + + // Check before + tryAction { checkViewIsDisplayed(allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(name1)))) } + checkViewIsDisplayed(allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(name2)))) + NavUtils.openRecordsScreen() + checkViewIsDisplayed(allOf(withId(baseR.id.viewRecordItem), hasDescendant(withText(name1)))) + checkViewIsDisplayed(allOf(withId(baseR.id.viewRecordItem), hasDescendant(withText(name2)))) + + // Select + NavUtils.openSettingsScreen() + NavUtils.openDataEditScreen() + onView(withText(R.string.data_edit_button_delete_data)) + .perform(nestedScrollTo()) + onView(withId(dataEditR.id.nsvDataEdit)) + .perform(swipeUp()) + onView(withText(R.string.data_edit_button_delete_data)) + .perform(click()) + clickOnViewWithText(coreR.string.ok) + + // Check + NavUtils.openRunningRecordsScreen() + checkViewIsDisplayed( + withText( + getString( + R.string.running_records_types_empty, + getString(R.string.running_records_add_type), + getString(R.string.running_records_add_default), + ), + ), + ) + NavUtils.openRecordsScreen() + checkViewIsDisplayed(withText(R.string.no_records_exist)) + } + private fun checkRecord( indexes: List, name: String, diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/BackupInteractor.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/BackupInteractor.kt index 50e613bcb..df5708e16 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/BackupInteractor.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/BackupInteractor.kt @@ -44,7 +44,7 @@ class BackupInteractor @Inject constructor( return backupRepo.readBackupFile(uriString) } - private suspend fun doAfterRestore() { + suspend fun doAfterRestore() { notificationTypeInteractor.updateNotifications() notificationGoalTimeInteractor.checkAndReschedule() widgetInteractor.updateWidgets() diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordInteractor.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordInteractor.kt index c74c05ca4..be6c5a39b 100644 --- a/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordInteractor.kt +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/interactor/RecordInteractor.kt @@ -117,6 +117,11 @@ class RecordInteractor @Inject constructor( recordRepo.remove(id) } + suspend fun removeAll() { + recordToRecordTagRepo.clear() + recordRepo.clear() + } + private suspend fun updateTags( recordId: Long, tagIds: List, diff --git a/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/interactor/DateEditChangeInteractor.kt b/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/interactor/DateEditChangeInteractor.kt index 68c825d41..df6e3684b 100644 --- a/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/interactor/DateEditChangeInteractor.kt +++ b/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/interactor/DateEditChangeInteractor.kt @@ -2,6 +2,8 @@ package com.example.util.simpletimetracker.feature_data_edit.interactor import com.example.util.simpletimetracker.core.interactor.RecordFilterInteractor import com.example.util.simpletimetracker.domain.interactor.AddRecordMediator +import com.example.util.simpletimetracker.domain.interactor.BackupInteractor +import com.example.util.simpletimetracker.domain.interactor.ClearDataInteractor import com.example.util.simpletimetracker.domain.interactor.FilterSelectableTagsInteractor import com.example.util.simpletimetracker.domain.interactor.NotificationGoalTimeInteractor import com.example.util.simpletimetracker.domain.interactor.RecordInteractor @@ -25,6 +27,8 @@ class DateEditChangeInteractor @Inject constructor( private val recordTypeToTagInteractor: RecordTypeToTagInteractor, private val notificationGoalTimeInteractor: NotificationGoalTimeInteractor, private val filterSelectableTagsInteractor: FilterSelectableTagsInteractor, + private val clearDataInteractor: ClearDataInteractor, + private val backupInteractor: BackupInteractor, ) { suspend fun changeData( @@ -114,4 +118,14 @@ class DateEditChangeInteractor @Inject constructor( addRecordMediator.doAfterAdd(newTypeId) } } + + suspend fun deleteAllRecords() { + recordInteractor.removeAll() + backupInteractor.doAfterRestore() + } + + suspend fun deleteAllData() { + clearDataInteractor.execute() + backupInteractor.doAfterRestore() + } } \ No newline at end of file diff --git a/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/view/DataEditFragment.kt b/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/view/DataEditFragment.kt index cdef6ef85..354502d9d 100644 --- a/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/view/DataEditFragment.kt +++ b/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/view/DataEditFragment.kt @@ -45,7 +45,7 @@ class DataEditFragment : Binding::inflate override var insetConfiguration: InsetConfiguration = - InsetConfiguration.ApplyToView { binding.root } + InsetConfiguration.ApplyToView { binding.containerDataEdit } private val viewModel: DataEditViewModel by viewModels() @@ -84,6 +84,8 @@ class DataEditFragment : checkboxDataEditDeleteRecords.setOnClick(viewModel::onDeleteRecordsClick) etDataEditChangeComment.doAfterTextChanged { viewModel.onCommentChange(it.toString()) } btnDataEditChange.setOnClick(throttle(viewModel::onChangeClick)) + btnDataEditDeleteRecords.setOnClick(throttle(viewModel::onDeleteAllRecordsClick)) + btnDataEditDeleteData.setOnClick(throttle(viewModel::onDeleteDataClick)) } override fun initViewModel(): Unit = with(viewModel) { @@ -95,6 +97,7 @@ class DataEditFragment : removeTagsState.observe(::setRemoveTagState) deleteRecordsState.observe(::setDeleteRecordsState) changeButtonState.observe(::setChangeButtonState) + disableButtons.observe { disableButtons() } keyboardVisibility.observe { visible -> if (visible) { showKeyboard(etDataEditChangeComment) @@ -249,4 +252,10 @@ class DataEditFragment : btnDataEditChange.isEnabled = state.enabled btnDataEditChange.backgroundTintList = ColorStateList.valueOf(state.backgroundTint) } + + private fun disableButtons() = with(binding) { + btnDataEditChange.isEnabled = false + btnDataEditDeleteRecords.isEnabled = false + btnDataEditDeleteData.isEnabled = false + } } diff --git a/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/viewModel/DataEditViewModel.kt b/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/viewModel/DataEditViewModel.kt index 2fe5107ea..d51a2392c 100644 --- a/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/viewModel/DataEditViewModel.kt +++ b/features/feature_data_edit/src/main/java/com/example/util/simpletimetracker/feature_data_edit/viewModel/DataEditViewModel.kt @@ -4,13 +4,13 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.example.util.simpletimetracker.core.base.SingleLiveEvent import com.example.util.simpletimetracker.core.extension.set import com.example.util.simpletimetracker.core.extension.toParams import com.example.util.simpletimetracker.core.repo.DataEditRepo import com.example.util.simpletimetracker.core.repo.ResourceRepo import com.example.util.simpletimetracker.domain.extension.getTypeIds import com.example.util.simpletimetracker.domain.extension.orZero -import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor import com.example.util.simpletimetracker.domain.interactor.RecordTypeToTagInteractor import com.example.util.simpletimetracker.domain.model.RecordsFilter import com.example.util.simpletimetracker.feature_data_edit.R @@ -42,7 +42,6 @@ class DataEditViewModel @Inject constructor( private val dataEditRepo: DataEditRepo, private val dataEditViewDataInteractor: DateEditViewDataInteractor, private val dataEditChangeInteractor: DateEditChangeInteractor, - private val recordTagInteractor: RecordTagInteractor, private val recordTypeToTagInteractor: RecordTypeToTagInteractor, ) : ViewModel() { @@ -73,6 +72,7 @@ class DataEditViewModel @Inject constructor( initial } } + val disableButtons: LiveData = SingleLiveEvent() val keyboardVisibility: LiveData = MutableLiveData(false) private var filters: List = emptyList() @@ -212,19 +212,22 @@ class DataEditViewModel @Inject constructor( } fun onChangeClick() { - router.navigate( - StandardDialogParams( - tag = ALERT_DIALOG_TAG, - message = resourceRepo.getString(R.string.archive_deletion_alert), - btnPositive = resourceRepo.getString(R.string.data_edit_button_change), - btnNegative = resourceRepo.getString(R.string.cancel), - ), - ) + showAlert(tag = CHANGE_ALERT_DIALOG_TAG) + } + + fun onDeleteAllRecordsClick() { + showAlert(tag = DELETE_RECORDS_ALERT_DIALOG_TAG) + } + + fun onDeleteDataClick() { + showAlert(tag = DELETE_DATA_ALERT_DIALOG_TAG) } fun onPositiveDialogClick(tag: String?) { - if (tag == ALERT_DIALOG_TAG) { - onChangeConfirmed() + when (tag) { + CHANGE_ALERT_DIALOG_TAG -> onChangeConfirmed() + DELETE_RECORDS_ALERT_DIALOG_TAG -> onDeleteRecordsConfirmed() + DELETE_DATA_ALERT_DIALOG_TAG -> onDeleteDataConfirmed() } } @@ -240,19 +243,48 @@ class DataEditViewModel @Inject constructor( updateSelectedRecordsCountViewData() } - private fun onChangeConfirmed() = viewModelScope.launch { - changeButtonState.set(dataEditViewDataInteractor.getChangeButtonState(false)) - dataEditRepo.inProgress.set(true) - - dataEditChangeInteractor.changeData( - typeState = typeState, - commentState = commentState, - addTagState = addTagState, - removeTagState = removeTagState, - deleteRecordsState = deleteState, - filters = filters, + private fun showAlert(tag: String) { + router.navigate( + StandardDialogParams( + tag = tag, + message = resourceRepo.getString(R.string.archive_deletion_alert), + btnPositive = resourceRepo.getString(R.string.ok), + btnNegative = resourceRepo.getString(R.string.cancel), + ), ) + } + + private fun onChangeConfirmed() { + doDataEditWork { + dataEditChangeInteractor.changeData( + typeState = typeState, + commentState = commentState, + addTagState = addTagState, + removeTagState = removeTagState, + deleteRecordsState = deleteState, + filters = filters, + ) + } + } + private fun onDeleteRecordsConfirmed() { + doDataEditWork { + dataEditChangeInteractor.deleteAllRecords() + } + } + + private fun onDeleteDataConfirmed() { + doDataEditWork { + dataEditChangeInteractor.deleteAllData() + } + } + + private fun doDataEditWork( + work: suspend () -> Unit, + ) = viewModelScope.launch { + disableButtons.set(Unit) + dataEditRepo.inProgress.set(true) + work.invoke() dataEditRepo.inProgress.set(false) showMessage(R.string.data_edit_success_message) delay(100) // wait for dialog to close. @@ -361,9 +393,11 @@ class DataEditViewModel @Inject constructor( } companion object { - private const val FILTER_TAG = "data_edit_filter_tag" - private const val ADD_TAGS_TAG = "data_edit_add_tags_tag" - private const val REMOVE_TAGS_TAG = "data_edit_remove_tags_tag" - private const val ALERT_DIALOG_TAG = "alert_dialog_tag" + private const val FILTER_TAG = "DATA_EDIT_FILTER_TAG" + private const val ADD_TAGS_TAG = "DATA_EDIT_ADD_TAGS_TAG" + private const val REMOVE_TAGS_TAG = "DATA_EDIT_REMOVE_TAGS_TAG" + private const val CHANGE_ALERT_DIALOG_TAG = "DATA_EDIT_CHANGE_ALERT_DIALOG_TAG" + private const val DELETE_RECORDS_ALERT_DIALOG_TAG = "DATA_EDIT_DELETE_RECORDS_ALERT_DIALOG_TAG" + private const val DELETE_DATA_ALERT_DIALOG_TAG = "DATA_EDIT_DELETE_DATA_ALERT_DIALOG_TAG" } } diff --git a/features/feature_data_edit/src/main/res/layout/data_edit_fragment.xml b/features/feature_data_edit/src/main/res/layout/data_edit_fragment.xml index 8192d42c4..13e4d5e1a 100644 --- a/features/feature_data_edit/src/main/res/layout/data_edit_fragment.xml +++ b/features/feature_data_edit/src/main/res/layout/data_edit_fragment.xml @@ -29,19 +29,21 @@ android:textColor="?colorSecondary" app:layout_constraintTop_toBottomOf="@id/tvDataEditTitle" /> - @@ -52,6 +54,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginHorizontal="8dp" + android:layout_marginTop="6dp" android:padding="16dp" android:text="@string/data_edit_select_records" app:icon="@drawable/ic_list_24px" @@ -323,16 +326,45 @@ + + + + + + + + - - diff --git a/features/feature_views/src/main/java/com/example/util/simpletimetracker/feature_views/DividerFullView.kt b/features/feature_views/src/main/java/com/example/util/simpletimetracker/feature_views/DividerFullView.kt new file mode 100644 index 000000000..f244a40de --- /dev/null +++ b/features/feature_views/src/main/java/com/example/util/simpletimetracker/feature_views/DividerFullView.kt @@ -0,0 +1,22 @@ +package com.example.util.simpletimetracker.feature_views + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import androidx.constraintlayout.widget.ConstraintLayout +import com.example.util.simpletimetracker.feature_views.databinding.DividerFullViewBinding + +class DividerFullView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0, +) : ConstraintLayout( + context, + attrs, + defStyleAttr, +) { + + init { + DividerFullViewBinding.inflate(LayoutInflater.from(context), this) + } +} \ No newline at end of file diff --git a/features/feature_views/src/main/res/drawable/bg_rounded_gradient.xml b/features/feature_views/src/main/res/drawable/bg_rounded_gradient.xml new file mode 100644 index 000000000..1d820e713 --- /dev/null +++ b/features/feature_views/src/main/res/drawable/bg_rounded_gradient.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/features/feature_views/src/main/res/layout/divider_full_view.xml b/features/feature_views/src/main/res/layout/divider_full_view.xml new file mode 100644 index 000000000..a4a66655a --- /dev/null +++ b/features/feature_views/src/main/res/layout/divider_full_view.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/features/feature_views/src/main/res/values/dimens.xml b/features/feature_views/src/main/res/values/dimens.xml index bb1527b89..e5a3e9c2c 100644 --- a/features/feature_views/src/main/res/values/dimens.xml +++ b/features/feature_views/src/main/res/values/dimens.xml @@ -24,6 +24,7 @@ 8dp 58dp + 46dp 8dp 16dp diff --git a/resources/src/main/res/values-ar/strings.xml b/resources/src/main/res/values-ar/strings.xml index 4b3eafa8c..746d63918 100644 --- a/resources/src/main/res/values-ar/strings.xml +++ b/resources/src/main/res/values-ar/strings.xml @@ -524,6 +524,8 @@ إضافة وسوم حذف الوسوم تغيير + حذف كافة السجلات + احذف كافة البيانات تم تغيير البيانات diff --git a/resources/src/main/res/values-ca/strings.xml b/resources/src/main/res/values-ca/strings.xml index 463e6134e..425575c7c 100644 --- a/resources/src/main/res/values-ca/strings.xml +++ b/resources/src/main/res/values-ca/strings.xml @@ -524,6 +524,8 @@ Exemple:
Afegeix etiquetes Elimina les etiquetes Canviar + Suprimeix tots els registres + Suprimeix totes les dades Dades canviades diff --git a/resources/src/main/res/values-de/strings.xml b/resources/src/main/res/values-de/strings.xml index 5f7bb57bf..6d99783a0 100644 --- a/resources/src/main/res/values-de/strings.xml +++ b/resources/src/main/res/values-de/strings.xml @@ -524,6 +524,8 @@ Beispiel:
Tags hinzufügen Tags entfernen Ändern + Alle Datensätze löschen + Alle Daten löschen Daten geändert diff --git a/resources/src/main/res/values-es/strings.xml b/resources/src/main/res/values-es/strings.xml index 3253931c3..ab68b09ac 100644 --- a/resources/src/main/res/values-es/strings.xml +++ b/resources/src/main/res/values-es/strings.xml @@ -524,6 +524,8 @@ Ejemplo:
Agregar etiquetas Eliminar etiquetas Cambiar + Eliminar todos los registros + Eliminar todos los datos Datos cambiados diff --git a/resources/src/main/res/values-fa/strings.xml b/resources/src/main/res/values-fa/strings.xml index 485d5c23c..15cedb11b 100644 --- a/resources/src/main/res/values-fa/strings.xml +++ b/resources/src/main/res/values-fa/strings.xml @@ -524,6 +524,8 @@ افزودن برچسب حذف برچسب تغییر + حذف تمام رکوردها + تمام داده ها را حذف کنید اطلاعات تغییر کردند diff --git a/resources/src/main/res/values-fr/strings.xml b/resources/src/main/res/values-fr/strings.xml index bfc8855bf..30839978c 100644 --- a/resources/src/main/res/values-fr/strings.xml +++ b/resources/src/main/res/values-fr/strings.xml @@ -524,6 +524,8 @@ Exemple:
Ajouter des balises Supprimer les balises Changement + Supprimer tous les enregistrements + Supprimer toutes les données Données modifiées diff --git a/resources/src/main/res/values-hi/strings.xml b/resources/src/main/res/values-hi/strings.xml index 289ef41b4..042589d14 100644 --- a/resources/src/main/res/values-hi/strings.xml +++ b/resources/src/main/res/values-hi/strings.xml @@ -524,6 +524,8 @@ csv फ़ाइल में कॉमा से अलग किए गए य टैगों को जोड़ें टैग हटाएं परिवर्तन + सभी रिकॉर्ड हटाएँ + सारा डेटा हटा दें डेटा बदल गया diff --git a/resources/src/main/res/values-in/strings.xml b/resources/src/main/res/values-in/strings.xml index 227054b9a..686667c9c 100644 --- a/resources/src/main/res/values-in/strings.xml +++ b/resources/src/main/res/values-in/strings.xml @@ -524,6 +524,8 @@ Contoh:
Tambahkan tanda Hapus tag Mengubah + Hapus semua catatan + Hapus semua data Data berubah diff --git a/resources/src/main/res/values-it/strings.xml b/resources/src/main/res/values-it/strings.xml index 12f5329b3..9d27de95a 100644 --- a/resources/src/main/res/values-it/strings.xml +++ b/resources/src/main/res/values-it/strings.xml @@ -524,6 +524,8 @@ Esempio:
Aggiungere etichette Rimuovi i tag Modifica + Elimina tutti i record + Elimina tutti i dati Dati modificati diff --git a/resources/src/main/res/values-iw/strings.xml b/resources/src/main/res/values-iw/strings.xml index fedbd9762..acd99d5f6 100644 --- a/resources/src/main/res/values-iw/strings.xml +++ b/resources/src/main/res/values-iw/strings.xml @@ -524,6 +524,8 @@ הוסף תגיות הסר תגיות שנה + מחק את כל הרשומות + מחק את כל הנתונים נתונים שונו diff --git a/resources/src/main/res/values-ja/strings.xml b/resources/src/main/res/values-ja/strings.xml index c1e0cf01d..de6ea4ac2 100644 --- a/resources/src/main/res/values-ja/strings.xml +++ b/resources/src/main/res/values-ja/strings.xml @@ -524,6 +524,8 @@ CSV ファイルには、カンマで区切られた次の列が含まれてい タグを追加する タグを削除 変化 + すべてのレコードを削除する + すべてのデータを削除する データが変更されました diff --git a/resources/src/main/res/values-ko/strings.xml b/resources/src/main/res/values-ko/strings.xml index e953e0154..f0312e27a 100644 --- a/resources/src/main/res/values-ko/strings.xml +++ b/resources/src/main/res/values-ko/strings.xml @@ -524,6 +524,8 @@ csv 파일은 다음과 같은 열(column)들을 가져야합니다:
태그 추가 태그 제거 변경 + 모든 기록 삭제 + 모든 데이터 삭제 데이터 변경됨 diff --git a/resources/src/main/res/values-nl/strings.xml b/resources/src/main/res/values-nl/strings.xml index 053e60170..82531ba76 100644 --- a/resources/src/main/res/values-nl/strings.xml +++ b/resources/src/main/res/values-nl/strings.xml @@ -524,6 +524,8 @@ Voorbeeld:
Labels toevoegen Labels verwijderen Wijziging + Verwijder alle records + Verwijder alle gegevens Gegevens gewijzigd diff --git a/resources/src/main/res/values-pl/strings.xml b/resources/src/main/res/values-pl/strings.xml index 0f1a89bea..7228bca65 100644 --- a/resources/src/main/res/values-pl/strings.xml +++ b/resources/src/main/res/values-pl/strings.xml @@ -524,6 +524,8 @@ Przykład:
Dodaj tagi Usuń tagi Zmień + Usuń wszystkie rekordy + Usuń wszystkie dane Nadpisano diff --git a/resources/src/main/res/values-pt-rPT/strings.xml b/resources/src/main/res/values-pt-rPT/strings.xml index 5ad88daa8..8d98449d8 100644 --- a/resources/src/main/res/values-pt-rPT/strings.xml +++ b/resources/src/main/res/values-pt-rPT/strings.xml @@ -524,6 +524,8 @@ Exemplo:
Adicionar etiquetas Remover etiquetas Alterar + Excluir todos os registros + Excluir todos os dados Dados alterados diff --git a/resources/src/main/res/values-pt/strings.xml b/resources/src/main/res/values-pt/strings.xml index 633c639c9..85e4320ac 100644 --- a/resources/src/main/res/values-pt/strings.xml +++ b/resources/src/main/res/values-pt/strings.xml @@ -524,6 +524,8 @@ Exemplo:
Adicionar tags Remover tags Mudar + Excluir todos os registros + Excluir todos os dados Dados alterados diff --git a/resources/src/main/res/values-ro/strings.xml b/resources/src/main/res/values-ro/strings.xml index f869425b8..568b35f8e 100644 --- a/resources/src/main/res/values-ro/strings.xml +++ b/resources/src/main/res/values-ro/strings.xml @@ -524,6 +524,8 @@ Examplu:
Adaug etichete Șterge etichete Modifică + Ștergeți toate înregistrările + Ștergeți toate datele informații modificate diff --git a/resources/src/main/res/values-ru/strings.xml b/resources/src/main/res/values-ru/strings.xml index 17301f813..454f363e7 100644 --- a/resources/src/main/res/values-ru/strings.xml +++ b/resources/src/main/res/values-ru/strings.xml @@ -524,6 +524,8 @@ CSV-файл должен содержать следующие столбцы, Добавить теги Удалить теги Изменить + Удалить все записи + Удалить все данные Данные изменены diff --git a/resources/src/main/res/values-sv/strings.xml b/resources/src/main/res/values-sv/strings.xml index b96e1211b..61f333fa1 100644 --- a/resources/src/main/res/values-sv/strings.xml +++ b/resources/src/main/res/values-sv/strings.xml @@ -524,6 +524,8 @@ Exempel:
Lägg till taggar Ta bort taggar Förändra + Radera alla poster + Radera all data Data har ändrats diff --git a/resources/src/main/res/values-tr/strings.xml b/resources/src/main/res/values-tr/strings.xml index 947c7ee44..88b31f93f 100644 --- a/resources/src/main/res/values-tr/strings.xml +++ b/resources/src/main/res/values-tr/strings.xml @@ -524,6 +524,8 @@ CSV dosyası virgülle ayrılmış şu sütunları içermelidir:
Etiket ekle Etiketleri kaldır Değiştirmek + Tüm kayıtları sil + Tüm verileri sil Veri değişti diff --git a/resources/src/main/res/values-uk/strings.xml b/resources/src/main/res/values-uk/strings.xml index 9303f11a4..23a9dd51d 100644 --- a/resources/src/main/res/values-uk/strings.xml +++ b/resources/src/main/res/values-uk/strings.xml @@ -524,6 +524,8 @@ Додати теги Видалити теги Змінити + Видалити всі записи + Видалити всі дані Дані змінено diff --git a/resources/src/main/res/values-vi/strings.xml b/resources/src/main/res/values-vi/strings.xml index 9e13af068..31fb8fda1 100644 --- a/resources/src/main/res/values-vi/strings.xml +++ b/resources/src/main/res/values-vi/strings.xml @@ -524,6 +524,8 @@ Ví dụ:
Thêm thẻ Xóa thẻ Thay đổi + Xóa tất cả hồ sơ + Xóa tất cả dữ liệu Dữ liệu đã thay đổi diff --git a/resources/src/main/res/values-zh-rTW/strings.xml b/resources/src/main/res/values-zh-rTW/strings.xml index 1c4530eb8..aab678751 100644 --- a/resources/src/main/res/values-zh-rTW/strings.xml +++ b/resources/src/main/res/values-zh-rTW/strings.xml @@ -524,6 +524,8 @@ csv 文件必須包含以逗號分隔的這些列:
添加標籤 刪除標籤 改變 + 刪除所有記錄 + 刪除所有數據 數據已更改 diff --git a/resources/src/main/res/values-zh/strings.xml b/resources/src/main/res/values-zh/strings.xml index d3cf1d8c7..6f81a390e 100644 --- a/resources/src/main/res/values-zh/strings.xml +++ b/resources/src/main/res/values-zh/strings.xml @@ -524,6 +524,8 @@ csv 文件必须包含以逗号分隔的这些列:
添加标签 删除标签 改变 + 删除所有记录 + 删除所有数据 数据已更改 diff --git a/resources/src/main/res/values/strings.xml b/resources/src/main/res/values/strings.xml index c144cfe37..13770275b 100644 --- a/resources/src/main/res/values/strings.xml +++ b/resources/src/main/res/values/strings.xml @@ -524,6 +524,8 @@ Example:
Add tags Remove tags Change + Delete all records + Delete all data Data changed