Skip to content

Commit

Permalink
Merge pull request #185 from PermanentOrg/feature/VSP-857
Browse files Browse the repository at this point in the history
Feature/vsp 857
  • Loading branch information
flaviahandrea-vsp authored Jan 9, 2023
2 parents 0624737 + bfb3de2 commit 1847e34
Show file tree
Hide file tree
Showing 35 changed files with 1,046 additions and 252 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId "org.permanent.PermanentArchive"
minSdkVersion 26
targetSdkVersion 32
versionCode 40
versionName "1.5.0"
versionCode 41
versionName "1.6.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -45,6 +45,7 @@ android {
buildConfigField "String", "BASE_API_URL", "\"https://www.permanent.org/api/\""
buildConfigField "String", "PAYMENT_INTENT_URL", "\"https://us-central1-prpledgeprod.cloudfunctions.net/donation/payment-sheet\""
buildConfigField "String", "ADD_STORAGE_URL", "\"https://www.permanent.org/add-storage/\""
buildConfigField "String", "ACCESS_ROLES_URL", "\"https://desk.zoho.com/portal/permanent/en/kb/articles/roles-for-collaboration-and-sharing/\""
buildConfigField "String", "HELP_URL", "\"https://desk.zoho.com/portal/permanent/en/home/\""
buildConfigField "String", "TERMS_URL", "\"https://www.permanent.org/terms/\""
manifestPlaceholders = ['appAuthRedirectScheme': "${applicationId.toLowerCase()}"]
Expand All @@ -56,6 +57,7 @@ android {
buildConfigField "String", "BASE_API_URL", "\"https://staging.permanent.org/api/\""
buildConfigField "String", "PAYMENT_INTENT_URL", "\"https://us-central1-prpledgestaging.cloudfunctions.net/donation/payment-sheet\""
buildConfigField "String", "ADD_STORAGE_URL", "\"https://staging.permanent.org/add-storage/\""
buildConfigField "String", "ACCESS_ROLES_URL", "\"https://desk.zoho.com/portal/permanent/en/kb/articles/roles-for-collaboration-and-sharing/\""
buildConfigField "String", "HELP_URL", "\"https://desk.zoho.com/portal/permanent/en/home/\""
buildConfigField "String", "TERMS_URL", "\"https://www.permanent.org/terms/\""
manifestPlaceholders = ['appAuthRedirectScheme': "${applicationId}"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.permanent.permanent.ui.PreferencesHelper
class CurrentArchivePermissionsManager private constructor() {

private var accessRole: AccessRole

companion object {
val instance = CurrentArchivePermissionsManager()
}
Expand Down Expand Up @@ -47,24 +48,5 @@ class CurrentArchivePermissionsManager private constructor() {

fun isOwnershipAvailable() = accessRole.isOwnershipAvailable()

fun getPermissionsEnumerated(): String {
var enumeratedPermissions = ""
val currentArchivePermissions = accessRole.getPermissions().toMutableList()
currentArchivePermissions.remove(ArchivePermission.ARCHIVE_SHARE)
currentArchivePermissions.map { it.toLowerCase() }
currentArchivePermissions.forEachIndexed { index, permission ->
enumeratedPermissions += when {
currentArchivePermissions.size == 1 -> {
permission.toUIString()
}
index != currentArchivePermissions.size - 1 -> {
"${permission.toUIString()}, "
}
else -> {
"and ${permission.toUIString()}"
}
}
}
return enumeratedPermissions
}
fun getPermissionsEnumerated(): String = accessRole.getPermissionsEnumerated()
}
21 changes: 21 additions & 0 deletions app/src/main/java/org/permanent/permanent/models/AccessRole.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ enum class AccessRole(val backendString: String) : Parcelable {
return if (otherAccessRole in inferiors()) otherAccessRole else this
}

fun getPermissionsEnumerated(): String {
var enumeratedPermissions = ""
val currentArchivePermissions = getPermissions().toMutableList()
currentArchivePermissions.remove(ArchivePermission.ARCHIVE_SHARE)
currentArchivePermissions.map { it.toLowerCase() }
currentArchivePermissions.forEachIndexed { index, permission ->
enumeratedPermissions += when {
currentArchivePermissions.size == 1 -> {
permission.toUIString()
}
index != currentArchivePermissions.size - 1 -> {
"${permission.toUIString()}, "
}
else -> {
"and ${permission.toUIString()}"
}
}
}
return enumeratedPermissions
}

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(ordinal)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.permanent.permanent.models
import android.os.Parcel
import android.os.Parcelable
import org.permanent.permanent.network.models.Shareby_urlVO
import org.permanent.permanent.models.AccessRole

class ShareByUrl() : Parcelable {
var shareUrl: String? = null
Expand All @@ -13,7 +12,6 @@ class ShareByUrl() : Parcelable {
var defaultAccessRole: String? = null
var expiresDT: String? = null // can be null for no expiration
var maxUses: Int? = null // can be 0 for unlimited uses
var defaultAccessRole: AccessRole? = null
var byAccountId: Int? = null
var byArchiveId: Int? = null

Expand All @@ -25,7 +23,6 @@ class ShareByUrl() : Parcelable {
defaultAccessRole = shareByUrlVO.defaultAccessRole
expiresDT = shareByUrlVO.expiresDT
maxUses = shareByUrlVO.maxUses
defaultAccessRole = AccessRole.createFromBackendString(shareByUrlVO.defaultAccessRole)
byAccountId = shareByUrlVO.byAccountId
byArchiveId = shareByUrlVO.byArchiveId
}
Expand All @@ -38,7 +35,6 @@ class ShareByUrl() : Parcelable {
defaultAccessRole = parcel.readString()
expiresDT = parcel.readString()
maxUses = parcel.readValue(Int::class.java.classLoader) as? Int
defaultAccessRole = parcel.readValue(AccessRole::class.java.classLoader) as? AccessRole
byAccountId = parcel.readValue(Int::class.java.classLoader) as? Int
byArchiveId = parcel.readValue(Int::class.java.classLoader) as? Int
}
Expand All @@ -51,7 +47,6 @@ class ShareByUrl() : Parcelable {
parcel.writeString(defaultAccessRole)
parcel.writeString(expiresDT)
parcel.writeValue(maxUses)
parcel.writeValue(defaultAccessRole)
parcel.writeValue(byAccountId)
parcel.writeValue(byArchiveId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.permanent.permanent.network.models
import android.os.Parcel
import android.os.Parcelable
import org.permanent.permanent.models.ShareByUrl
import org.permanent.permanent.models.AccessRole

class Shareby_urlVO() : Parcelable {
var shareUrl: String? = null
Expand All @@ -13,7 +12,6 @@ class Shareby_urlVO() : Parcelable {
var defaultAccessRole: String? = null
var expiresDT: String? = null // can be null for no expiration
var maxUses: Int? = null // can be 0 for unlimited uses
var defaultAccessRole: String? = null
var byAccountId: Int? = null
var byArchiveId: Int? = null
var urlToken: String? = null
Expand Down Expand Up @@ -44,7 +42,6 @@ class Shareby_urlVO() : Parcelable {
defaultAccessRole = shareByUrl.defaultAccessRole
expiresDT = shareByUrl.expiresDT
maxUses = shareByUrl.maxUses
defaultAccessRole = shareByUrl.defaultAccessRole?.backendString
byAccountId = shareByUrl.byAccountId
byArchiveId = shareByUrl.byArchiveId
}
Expand Down
155 changes: 155 additions & 0 deletions app/src/main/java/org/permanent/permanent/ui/AccessRolesFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package org.permanent.permanent.ui

import android.app.Dialog
import android.content.DialogInterface
import android.content.Intent
import android.graphics.Typeface
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
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
import com.google.android.material.snackbar.Snackbar
import org.permanent.permanent.BuildConfig
import org.permanent.permanent.R
import org.permanent.permanent.databinding.FragmentAccessRolesBinding
import org.permanent.permanent.models.AccessRole
import org.permanent.permanent.models.Share
import org.permanent.permanent.network.models.Shareby_urlVO
import org.permanent.permanent.ui.shareManagement.ShareManagementFragment
import org.permanent.permanent.viewmodels.AccessRolesViewModel
import org.permanent.permanent.viewmodels.SingleLiveEvent

class AccessRolesFragment : PermanentBottomSheetFragment() {
private lateinit var binding: FragmentAccessRolesBinding
private lateinit var viewModel: AccessRolesViewModel
private val onAccessRoleUpdated = SingleLiveEvent<AccessRole?>()

fun setBundleArguments(
shareByUrlVo: Shareby_urlVO,
) {
val bundle = Bundle()
bundle.putParcelable(ShareManagementFragment.SHARE_BY_URL_VO_KEY, shareByUrlVo)
this.arguments = bundle
}

fun setBundleArguments(
share: Share,
) {
val bundle = Bundle()
bundle.putParcelable(ShareManagementFragment.PARCELABLE_SHARE_KEY, share)
this.arguments = bundle
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
viewModel = ViewModelProvider(this)[AccessRolesViewModel::class.java]
binding = FragmentAccessRolesBinding.inflate(inflater, container, false)
binding.executePendingBindings()
binding.lifecycleOwner = this
binding.viewModel = viewModel
viewModel.setShareLink(arguments?.getParcelable(ShareManagementFragment.SHARE_BY_URL_VO_KEY))
viewModel.setShare(arguments?.getParcelable(ShareManagementFragment.PARCELABLE_SHARE_KEY))
initCurrentAccessRole()

return binding.root
}

private fun initCurrentAccessRole() {
when (viewModel.getCheckedAccessRole().value) {
AccessRole.CONTRIBUTOR -> binding.radioGroup.check(R.id.rbContributor)
AccessRole.EDITOR -> binding.radioGroup.check(R.id.rbEditor)
AccessRole.CURATOR -> binding.radioGroup.check(R.id.rbCurator)
AccessRole.OWNER -> binding.radioGroup.check(R.id.rbOwner)
else -> {
binding.radioGroup.check(R.id.rbViewer)
}
}
}

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

private val showSnackbarSuccess = Observer<String> { message ->
dialog?.window?.decorView?.let {
val snackBar = Snackbar.make(it, message, Snackbar.LENGTH_LONG)
val view: View = snackBar.view
context?.let {
view.setBackgroundColor(ContextCompat.getColor(it, R.color.paleGreen))
snackBar.setTextColor(ContextCompat.getColor(it, R.color.green))
}
val snackbarTextTextView = view.findViewById(R.id.snackbar_text) as TextView
snackbarTextTextView.setTypeface(snackbarTextTextView.typeface, Typeface.BOLD)
snackBar.show()
}
}

private val showSnackbar = Observer<String> { message ->
dialog?.window?.decorView?.let {
Snackbar.make(it, message, Snackbar.LENGTH_LONG).show()
}
}

private val onCloseSheetObserver = Observer<Void> {
dismiss()
}

private val onAccessRoleUpdatedObserver = Observer<AccessRole?> {
onAccessRoleUpdated.value = it
dismiss()
}

private val showAccessRolesDocObserver = Observer<Void> {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(BuildConfig.ACCESS_ROLES_URL)
startActivity(intent)
}

fun getOnAccessRoleUpdated(): MutableLiveData<AccessRole?> = onAccessRoleUpdated

override fun connectViewModelEvents() {
viewModel.getShowAccessRolesDocumentation().observe(this, showAccessRolesDocObserver)
viewModel.getOnAccessRoleUpdated().observe(this, onAccessRoleUpdatedObserver)
viewModel.getOnCloseSheetRequest().observe(this, onCloseSheetObserver)
viewModel.getShowSnackbar().observe(this, showSnackbar)
viewModel.getShowSnackbarSuccess().observe(this, showSnackbarSuccess)
}

override fun disconnectViewModelEvents() {
viewModel.getShowAccessRolesDocumentation().removeObserver(showAccessRolesDocObserver)
viewModel.getOnAccessRoleUpdated().removeObserver(onAccessRoleUpdatedObserver)
viewModel.getOnCloseSheetRequest().removeObserver(onCloseSheetObserver)
viewModel.getShowSnackbar().observe(this, showSnackbar)
viewModel.getShowSnackbarSuccess().observe(this, showSnackbarSuccess)
}

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

override fun onPause() {
super.onPause()
disconnectViewModelEvents()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,6 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
// Toolbar back press
override fun onSupportNavigateUp(): Boolean {
return when (navController.currentDestination?.id) {
R.id.linkSettingsFragment -> {
navController.popBackStack(R.id.shareLinkFragment, true)
true
}
R.id.publicFolderFragment -> {
val publicFolderFragment =
supportFragmentManager.primaryNavigationFragment?.childFragmentManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI
import androidx.navigation.ui.navigateUp
import kotlinx.android.synthetic.main.activity_file.*
import org.permanent.permanent.R
import org.permanent.permanent.databinding.ActivityFileBinding
import org.permanent.permanent.ui.activities.PermanentBaseActivity
Expand Down Expand Up @@ -52,11 +51,6 @@ class FileActivity : PermanentBaseActivity() {
this@FileActivity.finish()
true
}
R.id.linkSettingsFragment -> {
navController.popBackStack(R.id.shareLinkFragment, true)
setToolbarAndStatusBarColor(R.color.black)
true
}
R.id.shareLinkFragment -> {
navController.navigateUp(appBarConfig) || super.onSupportNavigateUp()
setToolbarAndStatusBarColor(R.color.black)
Expand Down
Loading

0 comments on commit 1847e34

Please sign in to comment.