Skip to content

Commit

Permalink
Merge pull request #319 from PermanentOrg/feature/VSP-1476
Browse files Browse the repository at this point in the history
Login & Security Menu.
  • Loading branch information
flaviahandrea-vsp authored Dec 4, 2024
2 parents c53b0f0 + afe53ee commit 0363401
Show file tree
Hide file tree
Showing 30 changed files with 281 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class UnauthorizedInterceptor : Interceptor {
Log.w(TAG, "Response code 401 or Requires MFA Token, redirecting to log in")
prefsHelper.saveUserLoggedIn(false)
prefsHelper.saveDefaultArchiveId(0)
prefsHelper.saveBiometricsLogIn(true) // Setting back to default
prefsHelper.setBiometricsLogIn(true)
val currentActivity = PermanentApplication.instance.currentActivity
currentActivity?.let {
it.startActivity(Intent(it, AuthenticationActivity::class.java))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PreferencesHelper(private val sharedPreferences: SharedPreferences) {
return sharedPreferences.getBoolean(IS_USER_LOGGED_IN, false)
}

fun saveBiometricsLogIn(isBiometricsLogIn: Boolean) {
fun setBiometricsLogIn(isBiometricsLogIn: Boolean) {
with(sharedPreferences.edit()) {
putBoolean(IS_BIOMETRICS_LOG_IN, isBiometricsLogIn)
apply()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
binding.toolbar.menu?.findItem(R.id.moreItem)?.isVisible = true
}

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

Expand Down Expand Up @@ -163,8 +163,7 @@ class MainActivity : PermanentBaseActivity(), Toolbar.OnMenuItemClickListener {
R.id.invitationsFragment,
R.id.accountFragment,
R.id.publicFilesFragment,
R.id.publicGalleryFragment,
R.id.securityFragment
R.id.publicGalleryFragment
)
appBarConfig = AppBarConfiguration(topLevelDestinations, binding.drawerLayout)
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SplashActivity : PermanentBaseActivity() {
private val errorObserver = Observer<String> {
prefsHelper.saveUserLoggedIn(false)
prefsHelper.saveDefaultArchiveId(0)
prefsHelper.saveBiometricsLogIn(true) // Setting back to default
prefsHelper.setBiometricsLogIn(true)

startLoginActivity()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ 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.Switch
import androidx.compose.material3.SwitchDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
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.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
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.dp
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat
Expand All @@ -29,34 +35,38 @@ import org.permanent.permanent.R
fun MenuItem(
isTablet: Boolean = false,
iconResource: Painter,
iconSize: Dp = 18.dp,
title: String,
subtitle: String,
showNewLabel: Boolean = false,
showOffLabel: Boolean = false,
showOnLabel: Boolean = false,
showArrow: Boolean = false,
showSwitch: Boolean = false,
switchChecked: Boolean = false,
onSwitchCheckedChange: (Boolean) -> Unit = {},
onClick: () -> Unit
) {

val context = LocalContext.current

val blue900Color = Color(ContextCompat.getColor(context, R.color.colorPrimary))
val middleGreyColor = Color(ContextCompat.getColor(context, R.color.middleGrey))
val regularFont = FontFamily(Font(R.font.open_sans_regular_ttf))
val boldFont = FontFamily(Font(R.font.open_sans_bold_ttf))

Row(
modifier = Modifier
.fillMaxWidth()
.clickable { onClick() }
.padding(horizontal = 24.dp),
verticalAlignment = Alignment.CenterVertically,
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceBetween,

) {
Image(
painter = iconResource,
contentDescription = "",
colorFilter = ColorFilter.tint(blue900Color),
modifier = Modifier.size(18.dp)
modifier = Modifier.padding(top = 26.dp).size(iconSize)
)
Column(
modifier = Modifier
Expand All @@ -75,25 +85,48 @@ fun MenuItem(
fontSize = if (isTablet) 18.sp else 14.sp,
lineHeight = 24.sp,
color = blue900Color,
fontFamily = boldFont
fontFamily = FontFamily(Font(R.font.usual_bold))
)

if (showNewLabel) NewFeatureLabel()
if (showNewLabel) MenuLabel(
colorResource(id = R.color.colorAccent),
stringResource(id = R.string.new_label)
)
if (showOffLabel) MenuLabel(
colorResource(id = R.color.error500),
stringResource(id = R.string.off)
)
if (showOnLabel) MenuLabel(
colorResource(id = R.color.success500),
stringResource(id = R.string.on)
)
}
Text(
text = subtitle,
fontSize = if (isTablet) 18.sp else 12.sp,
lineHeight = if (isTablet) 32.sp else 16.sp,
color = middleGreyColor,
fontFamily = regularFont
fontFamily = FontFamily(Font(R.font.usual_regular))
)
}

if (showArrow) {
Image(
painter = painterResource(id = R.drawable.ic_arrow_select_light_blue),
contentDescription = "Next",
modifier = Modifier.size(14.dp)
modifier = Modifier.padding(top = 26.dp).size(14.dp)
)
}

if (showSwitch) {
Switch(
checked = switchChecked,
onCheckedChange = onSwitchCheckedChange,
colors = SwitchDefaults.colors(
checkedThumbColor = colorResource(id = R.color.white),
checkedTrackColor = colorResource(id = R.color.success500),
),
modifier = Modifier.padding(top = 14.dp).scale(0.7f)
)
}
}
Expand All @@ -107,6 +140,6 @@ fun SimpleComposablePreview() {
title = "Add storage!",
subtitle = "Increase your space easily by adding more storage.",
showNewLabel = true,
showArrow = true,
showSwitch = true,
onClick = { })
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,35 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
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 NewFeatureLabel(
) {
val context = LocalContext.current

val accentColor = Color(ContextCompat.getColor(context, R.color.colorAccent))
val whiteColor = Color(ContextCompat.getColor(context, R.color.white))
val semiboldFont = FontFamily(Font(R.font.open_sans_semibold_ttf))
fun MenuLabel(colorResource: Color, stringResource: String) {

Column(
modifier = Modifier
.background(accentColor, RoundedCornerShape(24.dp))
.padding(horizontal = 10.dp, vertical = 4.dp)
.background(colorResource, RoundedCornerShape(24.dp))
.padding(horizontal = 10.dp, vertical = 1.dp)
) {
Text(
modifier = Modifier,
text = stringResource(id = R.string.new_label).uppercase(),
text = stringResource.uppercase(),
fontSize = 12.sp,
color = whiteColor,
fontFamily = semiboldFont
color = Color.White,
fontFamily = FontFamily(Font(R.font.usual_medium))
)
}
}

@Preview
@Composable
fun NewFeatureLabelPreview() {
NewFeatureLabel()
MenuLabel(colorResource(id = R.color.colorAccent), stringResource(id = R.string.new_label))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ 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.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -29,32 +30,41 @@ fun SettingsMenuItem(
iconResource: Painter,
text: String,
itemColor: Color = Color(ContextCompat.getColor(LocalContext.current, R.color.colorPrimary)),
showWarning: Boolean = false,
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),

) {
verticalAlignment = Alignment.CenterVertically
) {
Image(
painter = iconResource,
contentDescription = "Next",
colorFilter = ColorFilter.tint(itemColor),
modifier = Modifier.size(26.dp)
)

Spacer(modifier = Modifier.width(24.dp))

Text(
text = text,
fontSize = smallTextSize,
fontSize = 15.sp,
color = itemColor,
fontFamily = semiboldFont
fontFamily = FontFamily(Font(R.font.usual_medium))
)

if (showWarning) {
Spacer(modifier = Modifier.width(10.dp))

Image(
painter = painterResource(id = R.drawable.ic_warning_red),
contentDescription = "Warning",
modifier = Modifier.size(20.dp)
)
}
}
}

Expand All @@ -64,5 +74,6 @@ fun SettingsMenuItemComposablePreview() {
SettingsMenuItem(
iconResource = painterResource(id = R.drawable.ic_plus_primary),
text = "Add storage!",
showWarning = true,
onClick = { /*TODO*/ })
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import android.view.ViewGroup
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.google.android.material.snackbar.Snackbar
import org.permanent.permanent.databinding.FragmentSecurityBinding
import org.permanent.permanent.databinding.FragmentChangePasswordBinding
import org.permanent.permanent.ui.PermanentBaseFragment
import org.permanent.permanent.ui.hideKeyboardFrom
import org.permanent.permanent.viewmodels.SecurityViewModel
import org.permanent.permanent.viewmodels.ChangePasswordViewModel


class SecurityFragment : PermanentBaseFragment() {
class ChangePasswordFragment : PermanentBaseFragment() {

private lateinit var binding: FragmentSecurityBinding
private lateinit var viewModel: SecurityViewModel
private lateinit var binding: FragmentChangePasswordBinding
private lateinit var viewModel: ChangePasswordViewModel

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
viewModel = ViewModelProvider(this).get(SecurityViewModel::class.java)
binding = FragmentSecurityBinding.inflate(inflater, container, false)
viewModel = ViewModelProvider(this).get(ChangePasswordViewModel::class.java)
binding = FragmentChangePasswordBinding.inflate(inflater, container, false)
binding.executePendingBindings()
binding.lifecycleOwner = this
binding.viewModel = viewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.permanent.permanent.ui.settings

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.platform.ComposeView
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import org.permanent.permanent.R
import org.permanent.permanent.ui.PermanentBaseFragment
import org.permanent.permanent.ui.settings.compose.LoginAndSecurityMenu
import org.permanent.permanent.viewmodels.LoginAndSecurityViewModel

class LoginAndSecurityFragment : PermanentBaseFragment() {

private lateinit var viewModel: LoginAndSecurityViewModel

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
viewModel = ViewModelProvider(this)[LoginAndSecurityViewModel::class.java]

return ComposeView(requireContext()).apply {
setContent {
MaterialTheme {
LoginAndSecurityMenu(viewModel,
onChangePasswordClick = { findNavController().navigate(R.id.action_loginAndSecurityFragment_to_changePasswordFragment) }
) { findNavController().navigate(R.id.action_loginAndSecurityFragment_to_twoStepVerificationFragment) }
}
}
}
}

override fun connectViewModelEvents() {
}

override fun disconnectViewModelEvents() {
}

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

override fun onPause() {
super.onPause()
disconnectViewModelEvents()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class SettingsMenuFragment : PermanentBottomSheetFragment() {
findNavController().navigate(R.id.activityFeedFragment)
this@SettingsMenuFragment.dismiss()
},
onSecurityClick = {
findNavController().navigate(R.id.securityFragment)
onLoginAndSecurityClick = {
findNavController().navigate(R.id.loginAndSecurityFragment)
this@SettingsMenuFragment.dismiss()
},
onLegacyPlanningClick = {
Expand Down
Loading

0 comments on commit 0363401

Please sign in to comment.