Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ interface IArchiveService {
@POST("search/archive")
fun searchArchive(@Body requestBody: RequestBody): Call<ResponseVO>

// Used in Share and Manage Access
@POST("search/archiveByEmail")
fun searchArchiveByEmail(@Body requestBody: RequestBody): Call<ResponseVO>

// Used in public profile
@POST("archive/update")
fun updateProfilePhoto(@Body requestBody: RequestBody): Call<ResponseVO>
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/org/permanent/permanent/network/NetworkClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,22 @@ class NetworkClient(private var okHttpClient: OkHttpClient?, context: Context) {
return archiveService.searchArchive(requestBody)
}

fun searchArchiveByEmail(email: String): Call<ResponseVO> {
val request = toJson(RequestContainer().addSearch(email))
val requestBody: RequestBody = request.toRequestBody(jsonMediaType)
return archiveService.searchArchiveByEmail(requestBody)
}

fun grantArchiveAccess(
folderLinkId: Int,
archiveId: Int,
accessRole: AccessRole
): Call<ResponseVO> {
val request = toJson(RequestContainer().addShare(folderLinkId, archiveId, accessRole))
val requestBody: RequestBody = request.toRequestBody(jsonMediaType)
return shareService.updateShare(requestBody)
}

fun updateProfilePhoto(
archiveNr: String?, archiveId: Int, archiveType: ArchiveType, thumbArchiveNr: String?
): Call<ResponseVO> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ class RequestContainer {
return this
}

fun addShare(folderLinkId: Int, archiveId: Int, accessRole: AccessRole): RequestContainer {
val shareVO = ShareVO(folderLinkId, archiveId)
shareVO.accessRole = accessRole.backendString
shareVO.status = Status.OK.toBackendString()
RequestVO.data?.get(0)?.ShareVO = shareVO
return this
}

fun addArchive(archive: Archive): RequestContainer {
val archiveVO = ArchiveVO(archive)
archiveVO.status = Status.OK.toBackendString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ class ArchiveRepositoryImpl(val context: Context) : IArchiveRepository {
})
}

override fun searchArchiveByEmail(email: String, listener: IDataListener) {
NetworkClient.instance().searchArchiveByEmail(email).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(responseVO.getData())
} else {
listener.onFailed(responseVO?.getMessages()?.get(0))
}
}

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

override fun updateProfilePhoto(thumbRecord: Record, listener: IResponseListener) {
NetworkClient.instance().updateProfilePhoto(
prefsHelper.getCurrentArchiveNr(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface IArchiveRepository {

fun searchArchive(name: String?, listener: IDataListener)

fun searchArchiveByEmail(email: String, listener: IDataListener)

fun updateProfilePhoto(thumbRecord: Record, listener: IResponseListener)

fun getAllArchives(listener: IDataListener)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.permanent.permanent.repositories

import org.permanent.permanent.models.AccessRole
import org.permanent.permanent.models.Record
import org.permanent.permanent.models.Share
import org.permanent.permanent.network.IDataListener
Expand All @@ -25,6 +26,13 @@ interface IShareRepository {

fun updateShare(share: Share, listener: IResponseListener)

fun grantArchiveAccess(
folderLinkId: Int,
archiveId: Int,
accessRole: AccessRole,
listener: IShareListener
)

fun deleteShare(share: Share, listener: IResponseListener)

// SHARE PREVIEW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.permanent.permanent.repositories

import android.content.Context
import org.permanent.permanent.R
import org.permanent.permanent.models.AccessRole
import org.permanent.permanent.models.Record
import org.permanent.permanent.models.Share
import org.permanent.permanent.models.Status
Expand Down Expand Up @@ -94,6 +95,29 @@ class ShareRepositoryImpl(val context: Context) : IShareRepository {
})
}

override fun grantArchiveAccess(
folderLinkId: Int,
archiveId: Int,
accessRole: AccessRole,
listener: IShareRepository.IShareListener
) {
NetworkClient.instance().grantArchiveAccess(folderLinkId, archiveId, accessRole)
.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(responseVO.getShareVO())
} else {
listener.onFailed(context.getString(R.string.generic_error))
}
}

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

override fun deleteShare(share: Share, listener: IResponseListener) {
NetworkClient.instance().deleteShare(share)
.enqueue(object : Callback<ResponseVO> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ fun AccessRolesPage(
onCloseClick = onClose
)

val isOwnerSelected = selectedAccessRole == AccessRole.OWNER
val isViewerSelected = selectedAccessRole == AccessRole.VIEWER
LinkSettingsMenuItem(
iconResource = painterResource(id = R.drawable.ic_owner_green),
title = AccessRole.OWNER.toTitleCase(),
subtitle = stringResource(R.string.owner_description),
isSelected = isOwnerSelected
) { viewModel.onAccessRoleClick(AccessRole.OWNER) }
iconResource = painterResource(id = R.drawable.ic_viewer_green),
title = AccessRole.VIEWER.toTitleCase(),
subtitle = stringResource(R.string.viewer_description),
isSelected = isViewerSelected
) { viewModel.onAccessRoleClick(AccessRole.VIEWER) }

HorizontalDivider(
thickness = 1.dp, color = colorResource(R.color.blue25)
)

val isCuratorSelected = selectedAccessRole == AccessRole.CURATOR
val isContributorSelected = selectedAccessRole == AccessRole.CONTRIBUTOR
LinkSettingsMenuItem(
iconResource = painterResource(id = R.drawable.ic_curator_green),
title = AccessRole.CURATOR.toTitleCase(),
subtitle = stringResource(R.string.curator_description),
isSelected = isCuratorSelected
) { viewModel.onAccessRoleClick(AccessRole.CURATOR) }
iconResource = painterResource(id = R.drawable.ic_contributor_green),
title = AccessRole.CONTRIBUTOR.toTitleCase(),
subtitle = stringResource(R.string.contributor_description),
isSelected = isContributorSelected
) { viewModel.onAccessRoleClick(AccessRole.CONTRIBUTOR) }

HorizontalDivider(
thickness = 1.dp, color = colorResource(R.color.blue25)
Expand All @@ -78,25 +78,25 @@ fun AccessRolesPage(
thickness = 1.dp, color = colorResource(R.color.blue25)
)

val isContributorSelected = selectedAccessRole == AccessRole.CONTRIBUTOR
val isCuratorSelected = selectedAccessRole == AccessRole.CURATOR
LinkSettingsMenuItem(
iconResource = painterResource(id = R.drawable.ic_contributor_green),
title = AccessRole.CONTRIBUTOR.toTitleCase(),
subtitle = stringResource(R.string.contributor_description),
isSelected = isContributorSelected
) { viewModel.onAccessRoleClick(AccessRole.CONTRIBUTOR) }
iconResource = painterResource(id = R.drawable.ic_curator_green),
title = AccessRole.CURATOR.toTitleCase(),
subtitle = stringResource(R.string.curator_description),
isSelected = isCuratorSelected
) { viewModel.onAccessRoleClick(AccessRole.CURATOR) }

HorizontalDivider(
thickness = 1.dp, color = colorResource(R.color.blue25)
)

val isViewerSelected = selectedAccessRole == AccessRole.VIEWER
val isOwnerSelected = selectedAccessRole == AccessRole.OWNER
LinkSettingsMenuItem(
iconResource = painterResource(id = R.drawable.ic_viewer_green),
title = AccessRole.VIEWER.toTitleCase(),
subtitle = stringResource(R.string.viewer_description),
isSelected = isViewerSelected
) { viewModel.onAccessRoleClick(AccessRole.VIEWER) }
iconResource = painterResource(id = R.drawable.ic_owner_green),
title = AccessRole.OWNER.toTitleCase(),
subtitle = stringResource(R.string.owner_description),
isSelected = isOwnerSelected
) { viewModel.onAccessRoleClick(AccessRole.OWNER) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,8 @@ private fun AccessRole(accessRole: AccessRole, viewModel: ShareManagementViewMod
), contentAlignment = Alignment.Center
) {
Icon(
painter = painterResource(
id = when (accessRole) {
AccessRole.VIEWER -> R.drawable.ic_viewer_green
AccessRole.CONTRIBUTOR -> R.drawable.ic_contributor_green
AccessRole.EDITOR -> R.drawable.ic_editor_green
AccessRole.CURATOR -> R.drawable.ic_curator_green
AccessRole.OWNER -> R.drawable.ic_owner_green
AccessRole.MANAGER -> TODO()
}
), contentDescription = "", tint = colorResource(R.color.blue900)
painter = painterResource(id = accessRole.iconRes()),
contentDescription = "", tint = colorResource(R.color.blue900)
)
}

Expand Down
Loading