Skip to content

Commit 56f24f7

Browse files
committed
feat: generate image file from emoji and store it in cache directory
1 parent df27968 commit 56f24f7

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

owncloudApp/src/main/java/com/owncloud/android/presentation/spaces/SpacesListFragment.kt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ class SpacesListFragment :
8383
SpacesListAdapter.SpacesListAdapterListener,
8484
Fragment(),
8585
SearchView.OnQueryTextListener,
86-
CreateSpaceDialogFragment.CreateSpaceListener
86+
CreateSpaceDialogFragment.CreateSpaceListener,
87+
SetSpaceIconDialogFragment.SetIconListener
8788
{
8889
private var _binding: SpacesListFragmentBinding? = null
8990
private val binding get() = _binding!!
9091

9192
private var isMultiPersonal = false
9293
private var userPermissions = mutableSetOf<UserPermissions>()
9394
private var editQuotaPermission = false
94-
private var lastUpdatedRemotePath: String? = null
95-
private var selectedImageName: String? = null
95+
private var selectedImagePath: String? = null
9696
private lateinit var currentSpace: OCSpace
9797

9898
private val spacesListViewModel: SpacesListViewModel by viewModel {
@@ -115,7 +115,7 @@ class SpacesListFragment :
115115
val selectedImageUri = result.data?.data ?: return@registerForActivityResult
116116
val accountName = requireArguments().getString(BUNDLE_ACCOUNT_NAME) ?: return@registerForActivityResult
117117
val documentFile = DocumentFile.fromSingleUri(requireContext(), selectedImageUri) ?: return@registerForActivityResult
118-
selectedImageName = documentFile.name
118+
selectedImagePath = SPACE_CONFIG_DIR + documentFile.name
119119

120120
transfersViewModel.uploadFilesFromContentUri(
121121
accountName = accountName,
@@ -248,14 +248,13 @@ class SpacesListFragment :
248248
}
249249

250250
collectLatestLifecycleFlow(transfersViewModel.transfersWithSpaceStateFlow) { transfersWithSpace ->
251-
val remotePath = SPACE_CONFIG_DIR + selectedImageName
252-
val matchedTransfer = transfersWithSpace.map { it.first }.find { it.remotePath == remotePath }
251+
val matchedTransfer = transfersWithSpace.map { it.first }.find { it.remotePath == selectedImagePath }
253252

254-
if (matchedTransfer != null && lastUpdatedRemotePath != matchedTransfer.remotePath) {
253+
matchedTransfer?.let {
255254
when(matchedTransfer.status) {
256255
TransferStatus.TRANSFER_SUCCEEDED -> {
257256
spacesListViewModel.editSpaceImage(currentSpace.id, matchedTransfer.remotePath)
258-
lastUpdatedRemotePath = matchedTransfer.remotePath
257+
transfersViewModel.clearSuccessfulTransferById(matchedTransfer.id!!)
259258
}
260259
TransferStatus.TRANSFER_FAILED -> {
261260
showMessageInSnackbar(getString(R.string.edit_space_image_failed))
@@ -329,6 +328,17 @@ class SpacesListFragment :
329328
spacesListViewModel.editSpace(spaceId, spaceName, spaceSubtitle, spaceQuota)
330329
}
331330

331+
override fun setSpaceIcon(fileName: String, localPath: String) {
332+
selectedImagePath = SPACE_CONFIG_DIR + fileName
333+
transfersViewModel.uploadFilesFromSystem(
334+
accountName = requireArguments().getString(BUNDLE_ACCOUNT_NAME)!!,
335+
listOfLocalPaths = listOf(localPath),
336+
uploadFolderPath = SPACE_CONFIG_DIR,
337+
spaceId = currentSpace.id,
338+
forceOverwrite = true
339+
)
340+
}
341+
332342
fun setSearchListener(searchView: SearchView) {
333343
searchView.setOnQueryTextListener(this)
334344
}
@@ -446,7 +456,7 @@ class SpacesListFragment :
446456
editSpaceImageLauncher.launch(action)
447457
}
448458
SpaceMenuOption.SET_ICON -> {
449-
val setIconDialog = SetSpaceIconDialogFragment.newInstance()
459+
val setIconDialog = SetSpaceIconDialogFragment.newInstance(listener = this@SpacesListFragment)
450460
setIconDialog.show(requireActivity().supportFragmentManager, DIALOG_SET_ICON)
451461
}
452462
}

0 commit comments

Comments
 (0)