Skip to content

Commit

Permalink
Merge pull request #283 from PermanentOrg/feature/VSP-944-Edit-Metada…
Browse files Browse the repository at this point in the history
…ta-Location

Edit metadata location
  • Loading branch information
flaviuvsp authored Jul 10, 2024
2 parents f4a3b54 + 863a33c commit 9b8d6e8
Show file tree
Hide file tree
Showing 20 changed files with 730 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ dependencies {
//========================================= MAPS ===============================================
implementation 'com.google.android.gms:play-services-maps:18.0.2'
implementation 'com.google.android.libraries.places:places:2.5.0'
implementation 'com.google.maps.android:maps-compose:2.15.0'
//==============================================================================================

//========================================= BIOMETRICS =========================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class NetworkClient(private var okHttpClient: OkHttpClient?, context: Context) {

fun deleteFilesOrFolders(records: MutableList<Record>): Call<ResponseVO> {
val isFolderRecordType = records[0].type == RecordType.FOLDER
val request = toJson(RequestContainer().addRecords(records, isFolderRecordType))
val request = toJson(RequestContainer().addRecords(records, isFolderRecordType))
val requestBody: RequestBody = request.toRequestBody(jsonMediaType)
return if (isFolderRecordType) {
fileService.deleteFolder(requestBody)
Expand Down Expand Up @@ -452,6 +452,12 @@ class NetworkClient(private var okHttpClient: OkHttpClient?, context: Context) {
}
}

fun updateMultipleRecords(records: MutableList<Record>, locnVO: LocnVO): Call<ResponseVO> {
val request = toJson(RequestContainer().addRecords(records, locnVO, false))
val requestBody: RequestBody = request.toRequestBody(jsonMediaType)
return fileService.updateRecord(requestBody)
}

fun updateMultipleRecords(records: MutableList<Record>, isFolderRecordType: Boolean): Call<ResponseVO> {
val request = toJson(RequestContainer().addRecords(records, isFolderRecordType))
val requestBody: RequestBody = request.toRequestBody(jsonMediaType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ class RequestContainer {
}

fun addRecords(records: MutableList<Record>, isFolderRecordType: Boolean): RequestContainer {
return addRecords(records = records, null, isFolderRecordType)
}

fun addRecords(records: MutableList<Record>, locnVO: LocnVO? = null, isFolderRecordType: Boolean): RequestContainer {
for ((index, record) in records.withIndex()) {
if (isFolderRecordType) {
val folderVO = FolderVO()
Expand All @@ -282,6 +286,9 @@ class RequestContainer {
recordVO.folder_linkId = record.folderLinkId
recordVO.parentFolder_linkId = record.parentFolderLinkId
recordVO.displayName = record.displayName
if(locnVO != null) {
recordVO.LocnVO = locnVO
}
if (index == 0) RequestVO.data?.get(0)?.RecordVO = recordVO
else {
val newData = Datum()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,28 @@ class FileRepositoryImpl(val context: Context) : IFileRepository {
})
}

override fun updateMultipleRecords(
records: MutableList<Record>,
locnVO: LocnVO,
listener: IResponseListener
) {
NetworkClient.instance().updateMultipleRecords(records = records, locnVO = locnVO).enqueue(object : Callback<ResponseVO> {
override fun onResponse(call: Call<ResponseVO>, response: Response<ResponseVO>) {
val responseVO = response.body()

if (responseVO?.isSuccessful != null && responseVO.isSuccessful!!) {
listener.onSuccess(context.getString(R.string.file_info_update_success))
} else {
listener.onFailed(context.getString(R.string.generic_error))
}
}

override fun onFailure(call: Call<ResponseVO>, t: Throwable) {
listener.onFailed(t.message)
}
})
}

override fun updateMultipleRecords(records: MutableList<Record>,
isFolderRecordType: Boolean,
listener: IResponseListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ interface IFileRepository {

fun updateRecord(record: Record, newName: String, listener: IResponseListener)

fun updateMultipleRecords(records: MutableList<Record>, locnVO: LocnVO, listener: IResponseListener)

fun updateMultipleRecords(records: MutableList<Record>, isFolderRecordType: Boolean, listener: IResponseListener)

fun searchRecords(query: String?, tags: List<Tag>, listener: IOnRecordsRetrievedListener)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.permanent.permanent.ui.bulkEditMetadata

import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
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.libraries.places.api.Places
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import org.permanent.permanent.BuildConfig
import org.permanent.permanent.models.Record
import org.permanent.permanent.ui.PermanentBottomSheetFragment
import org.permanent.permanent.ui.bulkEditMetadata.compose.EditLocationScreen
import org.permanent.permanent.ui.myFiles.PARCELABLE_FILES_KEY
import org.permanent.permanent.viewmodels.EditLocationViewModel

class EditLocationFragment : PermanentBottomSheetFragment() {
private lateinit var viewModel: EditLocationViewModel
private val onLocationChanged = MutableLiveData<String>()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
Places.initialize(requireContext(), BuildConfig.GMP_KEY)
viewModel = ViewModelProvider(this)[EditLocationViewModel::class.java]

arguments?.getParcelableArrayList<Record>(PARCELABLE_FILES_KEY)?.let {
viewModel.setRecords(it)
}

return ComposeView(requireContext()).apply {
setContent {
MaterialTheme {
EditLocationScreen(viewModel, cancel = {
this@EditLocationFragment.dismiss()
})
}
}
}
}

fun setBundleArguments(records: ArrayList<Record>) {
val bundle = Bundle()
bundle.putParcelableArrayList(PARCELABLE_FILES_KEY, records)
this.arguments = bundle
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
bottomSheetDialog.setOnShowListener { dialog: DialogInterface ->
val sheetDialog = dialog as BottomSheetDialog
val bottomSheet =
sheetDialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
BottomSheetBehavior.from(bottomSheet as FrameLayout)
.setState(BottomSheetBehavior.STATE_EXPANDED)
}
return bottomSheetDialog
}

private val onLocationChangedObserver = Observer<String> {
onLocationChanged.value = it
}

override fun connectViewModelEvents() {
viewModel.getOnLocationChanged().observe(this, onLocationChangedObserver)
}

override fun disconnectViewModelEvents() {
viewModel.getOnLocationChanged().removeObserver(onLocationChangedObserver)
}

override fun onResume() {
super.onResume()
connectViewModelEvents()
}

override fun onPause() {
super.onPause()
disconnectViewModelEvents()
}

fun getOnLocationChanged() = onLocationChanged
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class EditMetadataFragment : PermanentBaseFragment() {

private lateinit var viewModel: EditMetadataViewModel
private var newTagFragment: NewTagFragment? = null
private var locationFragment: EditLocationFragment? = null
private var records = ArrayList<Record>()

override fun onCreateView(
Expand Down Expand Up @@ -55,24 +56,33 @@ class EditMetadataFragment : PermanentBaseFragment() {

},
openLocationScreen = {

locationFragment = EditLocationFragment()
locationFragment?.setBundleArguments(records)
locationFragment?.show(parentFragmentManager, locationFragment?.tag)
locationFragment?.getOnLocationChanged()
?.observe(lifecycleOwner, onLocationChangedObserver)
}
)
}
}
}
}


private val onTagsAddedToSelectionObserver = Observer<List<Tag>> {
viewModel.onTagsAddedToSelection(it)
}

private val onLocationChangedObserver = Observer<String> {
viewModel.onLocationChanged(it)
}

override fun connectViewModelEvents() {

}

override fun disconnectViewModelEvents() {
newTagFragment?.getOnTagsAddedToSelection()?.removeObserver(onTagsAddedToSelectionObserver)
locationFragment?.getOnLocationChanged()?.removeObserver(onLocationChangedObserver)
}

override fun onResume() {
Expand Down
Loading

0 comments on commit 9b8d6e8

Please sign in to comment.