1- package com.example.ssjetpackcomposeswipetodelete .ui
1+ package com.example.ssjetpackcomposeswipeableview .ui
22
33import android.content.Context
44import android.os.Bundle
55import android.widget.Toast
66import androidx.activity.ComponentActivity
77import androidx.activity.compose.setContent
88import androidx.compose.foundation.background
9- import androidx.compose.foundation.border
109import androidx.compose.foundation.layout.Arrangement
1110import androidx.compose.foundation.layout.Column
1211import androidx.compose.foundation.layout.PaddingValues
1312import androidx.compose.foundation.layout.fillMaxWidth
1413import androidx.compose.foundation.layout.height
1514import androidx.compose.foundation.lazy.LazyColumn
15+ import androidx.compose.foundation.shape.RoundedCornerShape
1616import androidx.compose.material.ExperimentalMaterialApi
1717import androidx.compose.material.Icon
1818import androidx.compose.material.IconButton
19- import androidx.compose.material.MaterialTheme
2019import androidx.compose.material.Scaffold
2120import androidx.compose.material.Surface
2221import androidx.compose.material.Text
2322import androidx.compose.material.TopAppBar
2423import androidx.compose.material.icons.Icons
2524import androidx.compose.material.icons.filled.ArrowBack
2625import androidx.compose.material.icons.filled.Delete
27- import androidx.compose.material.icons.filled.Edit
2826import androidx.compose.runtime.Composable
2927import androidx.compose.runtime.mutableStateListOf
3028import androidx.compose.runtime.remember
3129import androidx.compose.ui.Alignment
3230import androidx.compose.ui.Modifier
31+ import androidx.compose.ui.graphics.Color
32+ import androidx.compose.ui.graphics.vector.rememberVectorPainter
3333import androidx.compose.ui.platform.LocalContext
3434import androidx.compose.ui.tooling.preview.Preview
3535import androidx.compose.ui.unit.dp
36- import com.example.ssjetpackcomposeswipetodelete.swipetodelete.SwipeAbleItemCell
37- import com.example.ssjetpackcomposeswipetodelete.swipetodelete.SwipeDirection
38- import com.example.ssjetpackcomposeswipetodelete.ui.theme.SSJetpackComposeSwipeToDeleteTheme
36+ import com.example.ssjetpackcomposeswipeableview.SwipeAbleItemView
37+ import com.example.ssjetpackcomposeswipeableview.SwipeDirection
38+ import com.example.ssjetpackcomposeswipeableview.ui.theme.Background
39+ import com.example.ssjetpackcomposeswipeableview.ui.theme.Primary
40+ import com.example.ssjetpackcomposeswipeableview.ui.theme.SSJetpackComposeSwipeAbleViewTheme
41+ import com.example.ssjetpackcomposeswipeableview.ui.theme.Secondary
3942
4043@ExperimentalMaterialApi
41- class SwipeToDeleteDirectionActivity : ComponentActivity () {
44+ class SwipeAbleViewActivity : ComponentActivity () {
4245
4346 var swipeDirection: SwipeDirection ? = null
4447
4548 override fun onCreate (savedInstanceState : Bundle ? ) {
4649 super .onCreate(savedInstanceState)
4750 setContent {
4851 swipeDirection = intent.extras?.get(" SwipeDirection" ) as ? SwipeDirection
49- SSJetpackComposeSwipeToDeleteTheme {
50- Surface (color = MaterialTheme .colors.background ) {
52+ SSJetpackComposeSwipeAbleViewTheme {
53+ Surface (color = Background ) {
5154 MainContent ()
5255 }
5356 }
@@ -69,7 +72,8 @@ class SwipeToDeleteDirectionActivity: ComponentActivity() {
6972 IconButton (onClick = { onBackPressed() }) {
7073 Icon (Icons .Filled .ArrowBack , contentDescription = null )
7174 }
72- }
75+ },
76+ backgroundColor = Color .White
7377 )
7478 }) {
7579 Column {
@@ -87,33 +91,35 @@ class SwipeToDeleteDirectionActivity: ComponentActivity() {
8791
8892 @Composable
8993 fun CellItem (number : Int , context : Context ) {
90- SwipeAbleItemCell (
94+ SwipeAbleItemView (
9195 // Pair(Icon, Id)
92- leftViewIcons = arrayListOf (Pair ( Icons . Filled . Edit , " btnEditLeft " ), Pair ( Icons .Filled .Delete , " btnDeleteLeft" )),
93- rightViewIcons = arrayListOf (Pair ( Icons .Filled .Edit , " btnEditRight " )),
96+ leftViewIcons = arrayListOf (Triple (rememberVectorPainter(image = Icons .Filled .Delete ), Color . White , " btnDeleteLeft" )),
97+ rightViewIcons = arrayListOf (Triple ((rememberVectorPainter(image = Icons .Filled .Delete )), Color . White , " btnDeleteRight " )),
9498 position = number,
9599 swipeDirection = swipeDirection ? : SwipeDirection .BOTH ,
96100 onClick = { // Pair(Position, Id)
97101 Toast .makeText(context, " ${it.second} clicked. Position :- ${it.first} " , Toast .LENGTH_SHORT )
98102 .show()
99103 },
100- leftViewWidth = 120 .dp,
101- rightViewWidth = 60 .dp,
104+ leftViewWidth = 70 .dp,
105+ rightViewWidth = 70 .dp,
102106 height = 60 .dp,
103107 fractionalThreshold = 0.3f ,
104- backgroundColor = MaterialTheme .colors.secondary
108+ leftViewBackgroundColor = Primary ,
109+ rightViewBackgroundColor = Primary ,
110+ cornerRadius = 4 .dp,
111+ leftSpace = 10 .dp,
112+ rightSpace = 10 .dp
105113 ) {
106114 Column (
107115 modifier = Modifier
108116 .fillMaxWidth()
109117 .height(60 .dp)
110- .background(MaterialTheme .colors.background)
111- .border(1 .dp, MaterialTheme .colors.primary),
118+ .background(Secondary , shape = RoundedCornerShape (4 .dp)),
112119 verticalArrangement = Arrangement .Center ,
113120 horizontalAlignment = Alignment .CenterHorizontally
114-
115121 ) {
116- Text (text = " Item Number $number " , color = MaterialTheme .colors.primary )
122+ Text (text = " Item Number $number " , color = Color . Black )
117123 }
118124 }
119125 }
0 commit comments