Skip to content

Commit

Permalink
Edit action on view data screen (#101)
Browse files Browse the repository at this point in the history
Signed-off-by: Nitin Verma <canvas.nv@gmail.com>
  • Loading branch information
Ni3verma authored Oct 31, 2021
1 parent 1ad216c commit eae4369
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.*
Expand All @@ -26,6 +27,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.andryoga.safebox.R
import com.andryoga.safebox.common.Utils.logResource
Expand Down Expand Up @@ -89,7 +91,7 @@ class ViewDataDetailsFragment : Fragment() {
)
}
BasicSafeBoxTheme {
UserDataView(map, viewData?.title ?: "", data.status)
UserDataView(map, viewData?.title ?: "", data.status, args.userDataType)
}
}

Expand All @@ -116,7 +118,7 @@ class ViewDataDetailsFragment : Fragment() {
)
}
BasicSafeBoxTheme {
UserDataView(map, viewData?.title ?: "", data.status)
UserDataView(map, viewData?.title ?: "", data.status, args.userDataType)
}
}

Expand All @@ -140,7 +142,7 @@ class ViewDataDetailsFragment : Fragment() {
)
}
BasicSafeBoxTheme {
UserDataView(map, viewData?.title ?: "", data.status)
UserDataView(map, viewData?.title ?: "", data.status, args.userDataType)
}
}

Expand All @@ -159,7 +161,7 @@ class ViewDataDetailsFragment : Fragment() {
)
}
BasicSafeBoxTheme {
UserDataView(map, viewData?.title ?: "", data.status)
UserDataView(map, viewData?.title ?: "", data.status, args.userDataType)
}
}

Expand Down Expand Up @@ -190,9 +192,13 @@ class ViewDataDetailsFragment : Fragment() {
labelResId: Int,
contentDescriptionResId: Int,
iconSize: Dp = 32.dp,
tint: Color = MaterialTheme.colors.primary
tint: Color = MaterialTheme.colors.primary,
onClick: () -> Unit
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.clickable(onClick = onClick)
) {
Icon(
imageVector = imageVector,
contentDescription = stringResource(id = contentDescriptionResId),
Expand All @@ -211,7 +217,8 @@ class ViewDataDetailsFragment : Fragment() {
fun UserDataView(
viewDataMap: Map<Int, String?>,
title: String,
status: Status
status: Status,
dataType: UserDataType
) {
when (status) {
Status.LOADING -> {
Expand Down Expand Up @@ -255,22 +262,22 @@ class ViewDataDetailsFragment : Fragment() {
imageVector = Icons.Filled.Edit,
labelResId = R.string.edit,
contentDescriptionResId = R.string.cd_action_edit
)
) { navigateToEditScreen(dataType) }
ActionIcon(
imageVector = MaterialIconsCopy.ContentCopyFilled,
labelResId = R.string.copy,
contentDescriptionResId = R.string.cd_action_copy
)
) {}
ActionIcon(
imageVector = MaterialIconsCopy.DeleteForeverFilled,
labelResId = R.string.delete,
contentDescriptionResId = R.string.cd_action_delete
)
) {}
ActionIcon(
imageVector = Icons.Filled.Share,
labelResId = R.string.share,
contentDescriptionResId = R.string.cd_action_share
)
) {}
}
Divider(
color = MaterialTheme.colors.primary,
Expand All @@ -289,4 +296,31 @@ class ViewDataDetailsFragment : Fragment() {
}
}
}

private fun navigateToEditScreen(dataType: UserDataType) {
findNavController().navigate(
when (dataType) {
UserDataType.LOGIN_DATA -> {
ViewDataDetailsFragmentDirections.actionViewDataDetailsFragmentToLoginDataFragment(
args.id
)
}
UserDataType.BANK_ACCOUNT -> {
ViewDataDetailsFragmentDirections.actionViewDataDetailsFragmentToBankAccountDataFragment(
args.id
)
}
UserDataType.BANK_CARD -> {
ViewDataDetailsFragmentDirections.actionViewDataDetailsFragmentToBankCardDataFragment(
args.id
)
}
UserDataType.SECURE_NOTE -> {
ViewDataDetailsFragmentDirections.actionViewDataDetailsFragmentToSecureNoteDataFragment(
args.id
)
}
}
)
}
}
16 changes: 12 additions & 4 deletions app/src/main/res/navigation/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,24 @@
app:argType="com.andryoga.safebox.ui.common.UserDataType" />
<action
android:id="@+id/action_viewDataDetailsFragment_to_bankCardDataFragment"
app:destination="@id/bankCardDataFragment" />
app:destination="@id/bankCardDataFragment"
app:popUpTo="@id/viewDataDetailsFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_viewDataDetailsFragment_to_secureNoteDataFragment"
app:destination="@id/secureNoteDataFragment" />
app:destination="@id/secureNoteDataFragment"
app:popUpTo="@id/viewDataDetailsFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_viewDataDetailsFragment_to_loginDataFragment"
app:destination="@id/loginDataFragment" />
app:destination="@id/loginDataFragment"
app:popUpTo="@id/viewDataDetailsFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_viewDataDetailsFragment_to_bankAccountDataFragment"
app:destination="@id/bankAccountDataFragment" />
app:destination="@id/bankAccountDataFragment"
app:popUpTo="@id/viewDataDetailsFragment"
app:popUpToInclusive="true" />
</fragment>

</navigation>

0 comments on commit eae4369

Please sign in to comment.