Skip to content

Commit

Permalink
Merge pull request #256 from PermanentOrg/feature/VSP-1355
Browse files Browse the repository at this point in the history
Settings Menu redesign
  • Loading branch information
flaviahandrea-vsp authored Feb 26, 2024
2 parents 1a4bb30 + 7b155f9 commit fbfe255
Show file tree
Hide file tree
Showing 35 changed files with 787 additions and 374 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ import org.permanent.permanent.network.IDataListener
import org.permanent.permanent.network.IResponseListener
import org.permanent.permanent.network.NetworkClient
import org.permanent.permanent.network.models.ResponseVO
import org.permanent.permanent.ui.PREFS_NAME
import org.permanent.permanent.ui.PreferencesHelper
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class NotificationRepositoryImpl(val context: Context): INotificationRepository {
private val prefsHelper = PreferencesHelper(
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE))

override fun getNotifications(listener: IDataListener) {
NetworkClient.instance().getNotifications().enqueue(object : Callback<ResponseVO> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class AccessRolesFragment : PermanentBottomSheetFragment() {
}
}

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

Expand All @@ -130,15 +130,15 @@ class AccessRolesFragment : PermanentBottomSheetFragment() {
override fun connectViewModelEvents() {
viewModel.getShowAccessRolesDocumentation().observe(this, showAccessRolesDocObserver)
viewModel.getOnAccessRoleUpdated().observe(this, onAccessRoleUpdatedObserver)
viewModel.getOnCloseSheetRequest().observe(this, onCloseSheetObserver)
viewModel.getOnCloseScreenRequest().observe(this, onCloseScreenObserver)
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.getOnCloseScreenRequest().removeObserver(onCloseScreenObserver)
viewModel.getShowSnackbar().observe(this, showSnackbar)
viewModel.getShowSnackbarSuccess().observe(this, showSnackbarSuccess)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf
import androidx.core.view.GravityCompat
import androidx.databinding.DataBindingUtil
import androidx.drawerlayout.widget.DrawerLayout
import androidx.lifecycle.Observer
Expand All @@ -29,7 +28,6 @@ import androidx.navigation.ui.onNavDestinationSelected
import androidx.navigation.ui.setupWithNavController
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import org.permanent.permanent.BuildConfig
import org.permanent.permanent.Constants.Companion.REQUEST_CODE_GOOGLE_API_AVAILABILITY
import org.permanent.permanent.CurrentArchivePermissionsManager
import org.permanent.permanent.EventPage
Expand All @@ -43,14 +41,13 @@ import org.permanent.permanent.databinding.DialogLegacyPlanningBinding
import org.permanent.permanent.databinding.DialogTitleTextTwoButtonsBinding
import org.permanent.permanent.databinding.DialogWelcomeBinding
import org.permanent.permanent.databinding.NavMainHeaderBinding
import org.permanent.permanent.databinding.NavSettingsHeaderBinding
import org.permanent.permanent.models.AccessRole
import org.permanent.permanent.ui.PREFS_NAME
import org.permanent.permanent.ui.PreferencesHelper
import org.permanent.permanent.ui.archives.PARCELABLE_ARCHIVE_KEY
import org.permanent.permanent.ui.login.LoginActivity
import org.permanent.permanent.ui.public.LocationSearchFragment
import org.permanent.permanent.ui.public.PublicFolderFragment
import org.permanent.permanent.ui.settings.SettingsMenuFragment
import org.permanent.permanent.ui.shares.RECORD_ID_TO_NAVIGATE_TO_KEY
import org.permanent.permanent.viewmodels.MainViewModel

Expand All @@ -61,9 +58,9 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: MainViewModel
lateinit var binding: ActivityMainBinding
private lateinit var headerMainBinding: NavMainHeaderBinding
private lateinit var headerSettingsBinding: NavSettingsHeaderBinding
private lateinit var navController: NavController
private lateinit var appBarConfig: AppBarConfiguration
private var settingsFragment: SettingsMenuFragment? = null
private var isSubmenuVisible = false

private val onArchiveSwitched = Observer<Void?> {
Expand All @@ -76,12 +73,6 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
binding.drawerLayout.closeDrawers()
}

private val onLoggedOut = Observer<Void?> {
EventsManager(this).resetUser()
startActivity(Intent(this, LoginActivity::class.java))
finish()
}

private val onErrorMessage = Observer<String> { errorMessage ->
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show()
}
Expand Down Expand Up @@ -111,7 +102,7 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
binding.toolbar.menu?.findItem(R.id.moreItem)?.isVisible = true
}

R.id.legacyLoadingFragment, R.id.addStorageFragment, R.id.giftStorageFragment, R.id.redeemCodeFragment -> {
R.id.legacyLoadingFragment, R.id.storageMenuFragment, R.id.addStorageFragment, R.id.giftStorageFragment, R.id.redeemCodeFragment -> {
binding.toolbar.menu?.findItem(R.id.settingsItem)?.isVisible = false
}

Expand Down Expand Up @@ -143,13 +134,6 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
headerMainBinding.lifecycleOwner = this
headerMainBinding.viewModel = viewModel

// Right drawer header binding
headerSettingsBinding =
NavSettingsHeaderBinding.bind(binding.settingsNavigationView.getHeaderView(0))
headerSettingsBinding.executePendingBindings()
headerSettingsBinding.lifecycleOwner = this
headerSettingsBinding.viewModel = viewModel

// NavController setupOnDestinationChangedListener
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.mainNavHostFragment) as NavHostFragment
Expand All @@ -166,7 +150,6 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
R.id.archiveSettings,
R.id.manageTagsFragment,
R.id.membersFragment,
R.id.storageMenuFragment,
R.id.activityFeedFragment,
R.id.invitationsFragment,
R.id.accountFragment,
Expand Down Expand Up @@ -229,40 +212,6 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
true
}

binding.settingsNavigationView.setupWithNavController(navController)
binding.settingsNavigationView.setNavigationItemSelectedListener { menuItem ->
when (menuItem.itemId) {
R.id.storageMenuFragment -> {
val bundle = bundleOf(
SPACE_TOTAL_KEY to viewModel.getSpaceTotal(),
SPACE_LEFT_KEY to viewModel.getSpaceLeft(),
SPACE_USED_PERCENTAGE_KEY to viewModel.getSpaceUsedPercentage().value
)
navController.navigate(R.id.storageMenuFragment, bundle)
binding.drawerLayout.closeDrawers()
}

R.id.contactSupport -> {
binding.drawerLayout.closeDrawers()
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(BuildConfig.HELP_URL)
startActivity(intent)
// Returning 'false' to not remain the item selected on resuming
return@setNavigationItemSelectedListener false
}

R.id.logOut -> {
viewModel.deleteDeviceToken()
EventsManager(this).resetUser()
}

else -> {
menuItem.onNavDestinationSelected(navController)
binding.drawerLayout.closeDrawers()
}
}
true
}
binding.drawerLayout.addDrawerListener(object : DrawerLayout.DrawerListener {
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
}
Expand All @@ -271,9 +220,6 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
if (drawerView.id == binding.mainNavigationView.id) {
viewModel.updateCurrentArchiveHeader()
EventsManager(applicationContext).trackPageView(EventPage.ArchiveMenu)
} else if (drawerView.id == binding.settingsNavigationView.id) {
viewModel.updateUsedStorage()
EventsManager(applicationContext).trackPageView(EventPage.AccountMenu)
}
}

Expand Down Expand Up @@ -373,7 +319,14 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
when (menuItem?.itemId) {
R.id.moreItem, R.id.doneItem -> sendEventToFragment()
R.id.closeItem -> navController.navigate(R.id.myFilesFragment)
else -> binding.drawerLayout.openDrawer(GravityCompat.END) // settings item
else -> {
settingsFragment = SettingsMenuFragment()
settingsFragment?.show(
supportFragmentManager,
settingsFragment?.tag
) // settings item
EventsManager(applicationContext).trackPageView(EventPage.AccountMenu)
}
}
return true
}
Expand Down Expand Up @@ -460,14 +413,12 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
override fun connectViewModelEvents() {
viewModel.getOnArchiveSwitched().observe(this, onArchiveSwitched)
viewModel.getOnViewProfile().observe(this, onViewProfile)
viewModel.getOnLoggedOut().observe(this, onLoggedOut)
viewModel.getErrorMessage().observe(this, onErrorMessage)
}

override fun disconnectViewModelEvents() {
viewModel.getOnArchiveSwitched().removeObserver(onArchiveSwitched)
viewModel.getOnViewProfile().removeObserver(onViewProfile)
viewModel.getOnLoggedOut().removeObserver(onLoggedOut)
viewModel.getErrorMessage().removeObserver(onErrorMessage)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.permanent.permanent.ui.composeComponents

import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.dp

@Composable
fun PartialScreenLayout(
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
Layout(
modifier = modifier.clip(shape = RoundedCornerShape(8.dp)),
content = content
) { measurables, constraints ->
val placeable = measurables[0].measure(constraints)

val width = constraints.maxWidth
val height = (constraints.maxHeight * 0.96).toInt()

layout(width, height) {
placeable.placeRelative(
(constraints.maxWidth - width) / 2,
0
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.permanent.permanent.ui.composeComponents

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat
import org.permanent.permanent.R

@Composable
fun SettingsMenuItem(
iconResource: Painter,
text: String,
itemColor: Color = Color(ContextCompat.getColor(LocalContext.current, R.color.colorPrimary)),
onClick: () -> Unit
) {
val semiboldFont = FontFamily(Font(R.font.open_sans_semibold_ttf))
val smallTextSize = 15.sp

Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp, horizontal = 32.dp)
.clickable { onClick() },
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(24.dp),

) {
Image(
painter = iconResource,
contentDescription = "Next",
colorFilter = ColorFilter.tint(itemColor),
modifier = Modifier.size(26.dp)
)
Text(
text = text,
fontSize = smallTextSize,
color = itemColor,
fontFamily = semiboldFont
)
}
}

@Preview
@Composable
fun SettingsMenuItemComposablePreview() {
SettingsMenuItem(
iconResource = painterResource(id = R.drawable.ic_plus_primary),
text = "Add storage!",
onClick = { /*TODO*/ })
}
Loading

0 comments on commit fbfe255

Please sign in to comment.