From 7e195bc8f2311724e2c74125fe839577743341c2 Mon Sep 17 00:00:00 2001 From: flaviuvsp Date: Mon, 7 Oct 2024 12:18:22 +0300 Subject: [PATCH 1/3] Fix date issue Show message when file names updated --- .../org/permanent/permanent/models/Record.kt | 8 +++---- .../permanent/network/models/FileData.kt | 2 +- .../bulkEditMetadata/EditFileNamesFragment.kt | 21 ++++++++++++++++++- .../bulkEditMetadata/EditMetadataFragment.kt | 15 ++++++++++--- .../compose/EditDateTimeScreen.kt | 17 ++++++++++++++- .../compose/EditMetadataScreen.kt | 9 ++++++++ .../viewmodels/EditFileNamesViewModel.kt | 6 ++++++ .../viewmodels/EditMetadataViewModel.kt | 1 + 8 files changed, 69 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/permanent/permanent/models/Record.kt b/app/src/main/java/org/permanent/permanent/models/Record.kt index f013a923..0db8e77b 100644 --- a/app/src/main/java/org/permanent/permanent/models/Record.kt +++ b/app/src/main/java/org/permanent/permanent/models/Record.kt @@ -74,7 +74,7 @@ open class Record : Parcelable { folderLinkId = recordInfo.folder_linkId parentFolderLinkId = recordInfo.parentFolder_linkId displayName = recordInfo.displayName - displayDate = recordInfo.displayDT + displayDate = recordInfo.displayDT?.replace("T", " ") showArchiveThumb = false thumbURL200 = recordInfo.thumbURL200 thumbURL2000 = recordInfo.thumbURL2000 @@ -100,7 +100,7 @@ open class Record : Parcelable { folderLinkId = recordInfo.folder_linkId parentFolderLinkId = recordInfo.parentFolder_linkId displayName = recordInfo.displayName - displayDate = recordInfo.displayDT + displayDate = recordInfo.displayDT?.replace("T", " ") showArchiveThumb = false thumbURL200 = recordInfo.thumbURL200 thumbURL2000 = recordInfo.thumbURL2000 @@ -127,7 +127,7 @@ open class Record : Parcelable { folderLinkId = itemVO.folder_linkId parentFolderLinkId = itemVO.parentFolder_linkId displayName = itemVO.displayName - displayDate = itemVO.displayDT + displayDate = itemVO.displayDT?.replace("T", " ") archiveFullName = "The ${archiveVO.fullName} Archive" archiveThumbURL200 = archiveVO.thumbURL200 showArchiveThumb = showArchiveThumbnail @@ -172,7 +172,7 @@ open class Record : Parcelable { folderLinkId = recordInfo?.folder_linkId parentFolderLinkId = recordInfo?.parentFolder_linkId displayName = recordInfo?.displayName - displayDate = recordInfo?.displayDT + displayDate = recordInfo?.displayDT?.replace("T", " ") thumbURL200 = recordInfo?.thumbURL200 thumbURL2000 = recordInfo?.thumbURL2000 isThumbBlurred = shareByUrlVO.previewToggle == null || shareByUrlVO.previewToggle == 0 diff --git a/app/src/main/java/org/permanent/permanent/network/models/FileData.kt b/app/src/main/java/org/permanent/permanent/network/models/FileData.kt index 24d2707a..5db95479 100644 --- a/app/src/main/java/org/permanent/permanent/network/models/FileData.kt +++ b/app/src/main/java/org/permanent/permanent/network/models/FileData.kt @@ -52,7 +52,7 @@ class FileData private constructor() : Parcelable { } displayName = recordVO.displayName description = recordVO.description - displayDate = recordVO.displayDT + displayDate = recordVO.displayDT?.replace("T", " ") createdDate = recordVO.createdDT?.replace("T", " ") updatedDate = recordVO.updatedDT?.replace("T", " ") derivedDate = recordVO.derivedDT?.replace("T", " ") diff --git a/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/EditFileNamesFragment.kt b/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/EditFileNamesFragment.kt index 9f7f808d..bca278ad 100644 --- a/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/EditFileNamesFragment.kt +++ b/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/EditFileNamesFragment.kt @@ -9,6 +9,8 @@ import android.view.ViewGroup import android.widget.FrameLayout import androidx.compose.material3.MaterialTheme import androidx.compose.ui.platform.ComposeView +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog @@ -21,6 +23,7 @@ import org.permanent.permanent.viewmodels.EditFileNamesViewModel class EditFileNamesFragment : PermanentBottomSheetFragment() { private lateinit var viewModel: EditFileNamesViewModel + private val onFileNameChanged = MutableLiveData() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -60,12 +63,28 @@ class EditFileNamesFragment : PermanentBottomSheetFragment() { return bottomSheetDialog } - override fun connectViewModelEvents() { + private val onFileNameChangedObserver = Observer { + onFileNameChanged.value = it + } + override fun connectViewModelEvents() { + viewModel.getOnFileNameChanged().observe(this, onFileNameChangedObserver) } override fun disconnectViewModelEvents() { + viewModel.getOnFileNameChanged().removeObserver(onFileNameChangedObserver) + } + override fun onResume() { + super.onResume() + connectViewModelEvents() } + override fun onPause() { + super.onPause() + disconnectViewModelEvents() + } + + fun getOnFilenameChanged() = onFileNameChanged + } \ No newline at end of file diff --git a/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/EditMetadataFragment.kt b/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/EditMetadataFragment.kt index 41cf9eb8..2e6212f4 100644 --- a/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/EditMetadataFragment.kt +++ b/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/EditMetadataFragment.kt @@ -8,6 +8,7 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.ui.platform.ComposeView import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider +import com.google.android.material.snackbar.Snackbar import org.permanent.permanent.models.Record import org.permanent.permanent.models.Tag import org.permanent.permanent.ui.PermanentBaseFragment @@ -21,6 +22,7 @@ class EditMetadataFragment : PermanentBaseFragment() { private var newTagFragment: NewTagFragment? = null private var locationFragment: EditLocationFragment? = null private var dateFragment: EditDateTimeFragment? = null + private var fileNameFragment: EditFileNamesFragment? = null private var records = ArrayList() override fun onCreateView( @@ -49,9 +51,11 @@ class EditMetadataFragment : PermanentBaseFragment() { ?.observe(lifecycleOwner, onTagsAddedToSelectionObserver) }, openEditFileNamesScreen = { - var fragment = EditFileNamesFragment() - fragment?.setBundleArguments(records) - fragment?.show(parentFragmentManager, fragment?.tag) + fileNameFragment = EditFileNamesFragment() + fileNameFragment?.setBundleArguments(records) + fileNameFragment?.show(parentFragmentManager, fileNameFragment?.tag) + fileNameFragment?.getOnFilenameChanged() + ?.observe(lifecycleOwner, onFilenameChangedObserver) }, openDateAndTimeScreen = { dateFragment = EditDateTimeFragment() @@ -85,6 +89,10 @@ class EditMetadataFragment : PermanentBaseFragment() { viewModel.onDateChanged(it) } + private val onFilenameChangedObserver = Observer { + viewModel.showInfoMessage.value = it + } + override fun connectViewModelEvents() { @@ -94,6 +102,7 @@ class EditMetadataFragment : PermanentBaseFragment() { newTagFragment?.getOnTagsAddedToSelection()?.removeObserver(onTagsAddedToSelectionObserver) locationFragment?.getOnLocationChanged()?.removeObserver(onLocationChangedObserver) dateFragment?.getOnDateChanged()?.removeObserver(onDateChangedObserver) + fileNameFragment?.getOnFilenameChanged()?.removeObserver(onFilenameChangedObserver) } override fun onResume() { diff --git a/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditDateTimeScreen.kt b/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditDateTimeScreen.kt index 8b486363..9f021fff 100644 --- a/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditDateTimeScreen.kt +++ b/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditDateTimeScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.DatePicker import androidx.compose.material3.DatePickerDefaults import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.SelectableDates import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.material3.TimePicker @@ -47,6 +48,7 @@ import androidx.core.content.ContextCompat import org.permanent.permanent.R import org.permanent.permanent.viewmodels.EditDateTimeViewModel import java.text.SimpleDateFormat +import java.time.LocalDate import java.util.Date import java.util.Locale @@ -63,8 +65,10 @@ fun EditDateTimeScreen( val openAlertDialog = remember { mutableStateOf(false) } val datePickerState = rememberDatePickerState( - initialSelectedDateMillis = viewModel.initialDateMilis + initialSelectedDateMillis = viewModel.initialDateMilis, + selectableDates = PastOrPresentSelectableDates ) + val selectedDate = datePickerState.selectedDateMillis?.let { convertMillisToDate(it) } ?: "" @@ -264,4 +268,15 @@ fun convertTimeToString(hour: Int, min: Int, sec: Int): String { val secString = String.format("%02d", sec) return "$hourString:$minString:$secString" +} + +@OptIn(ExperimentalMaterial3Api::class) +private object PastOrPresentSelectableDates: SelectableDates { + override fun isSelectableDate(utcTimeMillis: Long): Boolean { + return utcTimeMillis <= System.currentTimeMillis() + } + + override fun isSelectableYear(year: Int): Boolean { + return year <= LocalDate.now().year + } } \ No newline at end of file diff --git a/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditMetadataScreen.kt b/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditMetadataScreen.kt index 7614ae25..3b5a963f 100644 --- a/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditMetadataScreen.kt +++ b/app/src/main/java/org/permanent/permanent/ui/bulkEditMetadata/compose/EditMetadataScreen.kt @@ -88,6 +88,7 @@ fun EditMetadataScreen( val allTags by viewModel.getTagsOfSelectedRecords().observeAsState() val focusRequester = remember { FocusRequester() } val errorMessage by viewModel.showError.observeAsState() + val infoMessage by viewModel.showInfoMessage.observeAsState() val showApplyAllToSelection by viewModel.showApplyAllToSelection.observeAsState() val isBusy by viewModel.getIsBusy().observeAsState() val locationMenuName by viewModel.getLocationMenuName().observeAsState() @@ -229,6 +230,14 @@ fun EditMetadataScreen( } } + LaunchedEffect(infoMessage) { + infoMessage?.let { message -> + coroutineScope.launch { + snackbarHostState.showSnackbar(message) + } + } + } + LaunchedEffect(snackbarEventFlow) { snackbarEventFlow.collect { message -> snackbarHostState.showSnackbar(message) diff --git a/app/src/main/java/org/permanent/permanent/viewmodels/EditFileNamesViewModel.kt b/app/src/main/java/org/permanent/permanent/viewmodels/EditFileNamesViewModel.kt index f09bb859..d37a7607 100644 --- a/app/src/main/java/org/permanent/permanent/viewmodels/EditFileNamesViewModel.kt +++ b/app/src/main/java/org/permanent/permanent/viewmodels/EditFileNamesViewModel.kt @@ -1,6 +1,7 @@ package org.permanent.permanent.viewmodels import android.app.Application +import androidx.lifecycle.MutableLiveData import kotlinx.coroutines.flow.MutableStateFlow import org.permanent.permanent.models.Record import org.permanent.permanent.network.IResponseListener @@ -16,6 +17,8 @@ class EditFileNamesViewModel(application: Application) : ObservableAndroidViewMo private var records: MutableList = mutableListOf() + private val onFileNameChanged = MutableLiveData() + fun setRecords(records: ArrayList) { this.records.addAll(records) records.firstOrNull()?.let { @@ -175,6 +178,7 @@ class EditFileNamesViewModel(application: Application) : ObservableAndroidViewMo isFolderRecordType = false, object : IResponseListener { override fun onSuccess(message: String?) { + onFileNameChanged.value = "File names updated successfully!" toggleLoading() triggerCloseScreen() } @@ -187,6 +191,8 @@ class EditFileNamesViewModel(application: Application) : ObservableAndroidViewMo } }) } + + fun getOnFileNameChanged() = onFileNameChanged } data class EditFileNamesUIState( diff --git a/app/src/main/java/org/permanent/permanent/viewmodels/EditMetadataViewModel.kt b/app/src/main/java/org/permanent/permanent/viewmodels/EditMetadataViewModel.kt index d8081cc4..845f3a5a 100644 --- a/app/src/main/java/org/permanent/permanent/viewmodels/EditMetadataViewModel.kt +++ b/app/src/main/java/org/permanent/permanent/viewmodels/EditMetadataViewModel.kt @@ -30,6 +30,7 @@ class EditMetadataViewModel(application: Application) : ObservableAndroidViewMod private var showWarningSomeFilesHaveDescription = MutableLiveData(false) val showError = MutableLiveData() val showApplyAllToSelection = MutableLiveData(true) + val showInfoMessage = MutableLiveData() private val isBusy = MutableLiveData(false) private val locationMenuName = MutableLiveData(appContext.getString(R.string.locations)) private val dateMenuName = MutableLiveData(appContext.getString(R.string.date_time)) From eebb8eff34856a52bfca0f8dfefbf44d368bba3f Mon Sep 17 00:00:00 2001 From: flaviuvsp Date: Mon, 7 Oct 2024 12:23:23 +0300 Subject: [PATCH 2/3] Update build.gradle --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 59fff758..85eb09d0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,7 +15,7 @@ android { applicationId "org.permanent.PermanentArchive" minSdkVersion 26 targetSdkVersion 34 - versionCode 69 + versionCode 70 versionName "1.9.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" From 92f5cbab09b8052c4e4941589b688507547cd1ed Mon Sep 17 00:00:00 2001 From: flaviuvsp Date: Mon, 7 Oct 2024 14:10:46 +0300 Subject: [PATCH 3/3] move strings to strings.xml --- .../permanent/permanent/viewmodels/EditFileNamesViewModel.kt | 4 +++- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/permanent/permanent/viewmodels/EditFileNamesViewModel.kt b/app/src/main/java/org/permanent/permanent/viewmodels/EditFileNamesViewModel.kt index d37a7607..8ba85c0d 100644 --- a/app/src/main/java/org/permanent/permanent/viewmodels/EditFileNamesViewModel.kt +++ b/app/src/main/java/org/permanent/permanent/viewmodels/EditFileNamesViewModel.kt @@ -3,6 +3,7 @@ package org.permanent.permanent.viewmodels import android.app.Application import androidx.lifecycle.MutableLiveData import kotlinx.coroutines.flow.MutableStateFlow +import org.permanent.permanent.R import org.permanent.permanent.models.Record import org.permanent.permanent.network.IResponseListener import org.permanent.permanent.repositories.FileRepositoryImpl @@ -11,6 +12,7 @@ import org.permanent.permanent.ui.bulkEditMetadata.compose.SequenceDateOptions import org.permanent.permanent.ui.bytesToHumanReadableString class EditFileNamesViewModel(application: Application) : ObservableAndroidViewModel(application) { + private var appContext = application.applicationContext private var fileRepository: IFileRepository = FileRepositoryImpl(application) val uiState = MutableStateFlow(EditFileNamesUIState()) @@ -178,7 +180,7 @@ class EditFileNamesViewModel(application: Application) : ObservableAndroidViewMo isFolderRecordType = false, object : IResponseListener { override fun onSuccess(message: String?) { - onFileNameChanged.value = "File names updated successfully!" + onFileNameChanged.value = appContext.getString(R.string.file_names_updated) toggleLoading() triggerCloseScreen() } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5a944707..95981f47 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -730,6 +730,6 @@ New Date & Time Are you sure you want to set a new date & time for the selected items? Set date and time - + File names updated successfully