Skip to content

Commit

Permalink
Merge pull request #307 from PermanentOrg/bugfix/fixes-for-release
Browse files Browse the repository at this point in the history
Bugfix/fixes for release
  • Loading branch information
flaviuvsp authored Oct 7, 2024
2 parents 73c861e + 92f5cba commit 682e565
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/org/permanent/permanent/models/Record.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", " ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,6 +23,7 @@ import org.permanent.permanent.viewmodels.EditFileNamesViewModel
class EditFileNamesFragment : PermanentBottomSheetFragment() {

private lateinit var viewModel: EditFileNamesViewModel
private val onFileNameChanged = MutableLiveData<String>()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
Expand Down Expand Up @@ -60,12 +63,28 @@ class EditFileNamesFragment : PermanentBottomSheetFragment() {
return bottomSheetDialog
}

override fun connectViewModelEvents() {
private val onFileNameChangedObserver = Observer<String> {
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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Record>()

override fun onCreateView(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -85,6 +89,10 @@ class EditMetadataFragment : PermanentBaseFragment() {
viewModel.onDateChanged(it)
}

private val onFilenameChangedObserver = Observer<String> {
viewModel.showInfoMessage.value = it
}


override fun connectViewModelEvents() {

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)
} ?: ""
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -229,6 +230,14 @@ fun EditMetadataScreen(
}
}

LaunchedEffect(infoMessage) {
infoMessage?.let { message ->
coroutineScope.launch {
snackbarHostState.showSnackbar(message)
}
}
}

LaunchedEffect(snackbarEventFlow) {
snackbarEventFlow.collect { message ->
snackbarHostState.showSnackbar(message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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
Expand All @@ -10,12 +12,15 @@ 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())

private var records: MutableList<Record> = mutableListOf()

private val onFileNameChanged = MutableLiveData<String>()

fun setRecords(records: ArrayList<Record>) {
this.records.addAll(records)
records.firstOrNull()?.let {
Expand Down Expand Up @@ -175,6 +180,7 @@ class EditFileNamesViewModel(application: Application) : ObservableAndroidViewMo
isFolderRecordType = false,
object : IResponseListener {
override fun onSuccess(message: String?) {
onFileNameChanged.value = appContext.getString(R.string.file_names_updated)
toggleLoading()
triggerCloseScreen()
}
Expand All @@ -187,6 +193,8 @@ class EditFileNamesViewModel(application: Application) : ObservableAndroidViewMo
}
})
}

fun getOnFileNameChanged() = onFileNameChanged
}

data class EditFileNamesUIState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EditMetadataViewModel(application: Application) : ObservableAndroidViewMod
private var showWarningSomeFilesHaveDescription = MutableLiveData(false)
val showError = MutableLiveData<String>()
val showApplyAllToSelection = MutableLiveData(true)
val showInfoMessage = MutableLiveData<String>()
private val isBusy = MutableLiveData(false)
private val locationMenuName = MutableLiveData(appContext.getString(R.string.locations))
private val dateMenuName = MutableLiveData(appContext.getString(R.string.date_time))
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,6 @@
<string name="date_confirmation_title">New Date &amp; Time</string>
<string name="date_confirmation_substring">Are you sure you want to set a new date &amp; time for the selected items?</string>
<string name="set_date_and_time">Set date and time</string>

<string name="file_names_updated">File names updated successfully</string>

</resources>

0 comments on commit 682e565

Please sign in to comment.