Skip to content

Commit af731a8

Browse files
🔨 Added more customization and update sample app
1 parent a9c4357 commit af731a8

File tree

20 files changed

+139
-136
lines changed

20 files changed

+139
-136
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77
compileSdk 31
88

99
defaultConfig {
10-
applicationId "com.example.ssjetpackcomposeswipetodelete"
10+
applicationId "com.example.ssjetpackcomposeswipeableview"
1111
minSdk 21
1212
targetSdk 31
1313
versionCode 1
@@ -57,7 +57,7 @@ dependencies {
5757
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
5858
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
5959
implementation 'androidx.activity:activity-compose:1.4.0'
60-
implementation project(path: ':ssjetpackcomposeswipetodelete')
60+
implementation project(path: ':ssjetpackcomposeswipeableview')
6161
testImplementation 'junit:junit:4.+'
6262
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
6363
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.example.ssjetpackcomposeswipetodelete">
3+
package="com.example.ssjetpackcomposeswipeableview">
44

55
<application
66
android:allowBackup="true"
77
android:icon="@mipmap/ic_launcher"
88
android:label="@string/app_name"
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
11-
android:theme="@style/Theme.SSJetpackComposeSwipeToDelete">
11+
android:theme="@style/Theme.SSJetpackComposeSwipeAbleView">
1212
<activity
13-
android:name=".ui.MainActivity"
13+
android:name="com.example.ssjetpackcomposeswipeableview.ui.MainActivity"
1414
android:exported="true"
1515
android:label="@string/app_name"
16-
android:theme="@style/Theme.SSJetpackComposeSwipeToDelete.NoActionBar">
16+
android:theme="@style/Theme.SSJetpackComposeSwipeAbleView.NoActionBar">
1717
<intent-filter>
1818
<action android:name="android.intent.action.MAIN" />
1919

2020
<category android:name="android.intent.category.LAUNCHER" />
2121
</intent-filter>
2222
</activity>
2323
<activity
24-
android:name=".ui.SwipeToDeleteDirectionActivity"/>
24+
android:name="com.example.ssjetpackcomposeswipeableview.ui.SwipeAbleViewActivity"/>
2525
</application>
2626

2727
</manifest>

app/src/main/java/com/example/ssjetpackcomposeswipetodelete/ui/MainActivity.kt renamed to app/src/main/java/com/example/ssjetpackcomposeswipeableview/ui/MainActivity.kt

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,40 @@
1-
package com.example.ssjetpackcomposeswipetodelete.ui
1+
package com.example.ssjetpackcomposeswipeableview.ui
22

33
import android.content.Context
44
import android.content.Intent
55
import android.os.Bundle
6-
import android.widget.Toast
76
import androidx.activity.ComponentActivity
87
import androidx.activity.compose.setContent
98
import androidx.compose.foundation.background
10-
import androidx.compose.foundation.border
11-
import androidx.compose.foundation.layout.Arrangement
129
import androidx.compose.foundation.layout.Column
13-
import androidx.compose.foundation.layout.PaddingValues
10+
import androidx.compose.foundation.layout.fillMaxHeight
1411
import androidx.compose.foundation.layout.fillMaxWidth
15-
import androidx.compose.foundation.layout.height
1612
import androidx.compose.foundation.layout.padding
17-
import androidx.compose.foundation.lazy.LazyColumn
1813
import androidx.compose.foundation.shape.RoundedCornerShape
1914
import androidx.compose.material.Button
2015
import androidx.compose.material.ExperimentalMaterialApi
21-
import androidx.compose.material.Icon
22-
import androidx.compose.material.IconButton
2316
import androidx.compose.material.MaterialTheme
2417
import androidx.compose.material.Scaffold
2518
import androidx.compose.material.Surface
2619
import androidx.compose.material.Text
2720
import androidx.compose.material.TopAppBar
28-
import androidx.compose.material.icons.Icons
29-
import androidx.compose.material.icons.filled.ArrowBack
30-
import androidx.compose.material.icons.filled.Delete
31-
import androidx.compose.material.icons.filled.Edit
3221
import androidx.compose.runtime.Composable
33-
import androidx.compose.runtime.mutableStateListOf
34-
import androidx.compose.runtime.remember
35-
import androidx.compose.ui.Alignment
3622
import androidx.compose.ui.Modifier
3723
import androidx.compose.ui.graphics.Color
3824
import androidx.compose.ui.platform.LocalContext
3925
import androidx.compose.ui.text.style.TextAlign
4026
import androidx.compose.ui.tooling.preview.Preview
4127
import androidx.compose.ui.unit.dp
42-
import com.example.ssjetpackcomposeswipetodelete.swipetodelete.SwipeAbleItemCell
43-
import com.example.ssjetpackcomposeswipetodelete.swipetodelete.SwipeDirection
44-
import com.example.ssjetpackcomposeswipetodelete.ui.theme.SSJetpackComposeSwipeToDeleteTheme
28+
import com.example.ssjetpackcomposeswipeableview.SwipeDirection
29+
import com.example.ssjetpackcomposeswipeableview.ui.theme.Background
30+
import com.example.ssjetpackcomposeswipeableview.ui.theme.SSJetpackComposeSwipeAbleViewTheme
4531

4632
@ExperimentalMaterialApi
4733
class MainActivity : ComponentActivity() {
4834
override fun onCreate(savedInstanceState: Bundle?) {
4935
super.onCreate(savedInstanceState)
5036
setContent {
51-
SSJetpackComposeSwipeToDeleteTheme {
37+
SSJetpackComposeSwipeAbleViewTheme {
5238
Surface(color = MaterialTheme.colors.background) {
5339
MainContent()
5440
}
@@ -65,10 +51,10 @@ class MainActivity : ComponentActivity() {
6551
title = { Text("SWIPE TO DELETE") },
6652
)
6753
}) {
68-
Column() {
54+
Column(Modifier.fillMaxHeight().background(Background)) {
6955
Button(
7056
onClick = {
71-
navigateToSwipeToDeleteActivity(context, SwipeDirection.LEFT)
57+
navigateToSwipeAbleViewActivity(context, SwipeDirection.LEFT)
7258
}, modifier = Modifier
7359
.padding(16.dp)
7460
.fillMaxWidth(), shape = RoundedCornerShape(8.dp)
@@ -82,7 +68,7 @@ class MainActivity : ComponentActivity() {
8268
}
8369
Button(
8470
onClick = {
85-
navigateToSwipeToDeleteActivity(context, SwipeDirection.RIGHT)
71+
navigateToSwipeAbleViewActivity(context, SwipeDirection.RIGHT)
8672
}, modifier = Modifier
8773
.padding(16.dp)
8874
.fillMaxWidth(), shape = RoundedCornerShape(8.dp)
@@ -96,7 +82,7 @@ class MainActivity : ComponentActivity() {
9682
}
9783
Button(
9884
onClick = {
99-
navigateToSwipeToDeleteActivity(context, SwipeDirection.BOTH)
85+
navigateToSwipeAbleViewActivity(context, SwipeDirection.BOTH)
10086
}, modifier = Modifier
10187
.padding(16.dp)
10288
.fillMaxWidth(), shape = RoundedCornerShape(8.dp)
@@ -112,8 +98,8 @@ class MainActivity : ComponentActivity() {
11298
}
11399
}
114100

115-
private fun navigateToSwipeToDeleteActivity(context: Context, swipeDirection: SwipeDirection) {
116-
val intent = Intent(context, SwipeToDeleteDirectionActivity::class.java)
101+
private fun navigateToSwipeAbleViewActivity(context: Context, swipeDirection: SwipeDirection) {
102+
val intent = Intent(context, SwipeAbleViewActivity::class.java)
117103
intent.putExtra("SwipeDirection", swipeDirection)
118104
startActivity(intent)
119105
}
Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,56 @@
1-
package com.example.ssjetpackcomposeswipetodelete.ui
1+
package com.example.ssjetpackcomposeswipeableview.ui
22

33
import android.content.Context
44
import android.os.Bundle
55
import android.widget.Toast
66
import androidx.activity.ComponentActivity
77
import androidx.activity.compose.setContent
88
import androidx.compose.foundation.background
9-
import androidx.compose.foundation.border
109
import androidx.compose.foundation.layout.Arrangement
1110
import androidx.compose.foundation.layout.Column
1211
import androidx.compose.foundation.layout.PaddingValues
1312
import androidx.compose.foundation.layout.fillMaxWidth
1413
import androidx.compose.foundation.layout.height
1514
import androidx.compose.foundation.lazy.LazyColumn
15+
import androidx.compose.foundation.shape.RoundedCornerShape
1616
import androidx.compose.material.ExperimentalMaterialApi
1717
import androidx.compose.material.Icon
1818
import androidx.compose.material.IconButton
19-
import androidx.compose.material.MaterialTheme
2019
import androidx.compose.material.Scaffold
2120
import androidx.compose.material.Surface
2221
import androidx.compose.material.Text
2322
import androidx.compose.material.TopAppBar
2423
import androidx.compose.material.icons.Icons
2524
import androidx.compose.material.icons.filled.ArrowBack
2625
import androidx.compose.material.icons.filled.Delete
27-
import androidx.compose.material.icons.filled.Edit
2826
import androidx.compose.runtime.Composable
2927
import androidx.compose.runtime.mutableStateListOf
3028
import androidx.compose.runtime.remember
3129
import androidx.compose.ui.Alignment
3230
import androidx.compose.ui.Modifier
31+
import androidx.compose.ui.graphics.Color
32+
import androidx.compose.ui.graphics.vector.rememberVectorPainter
3333
import androidx.compose.ui.platform.LocalContext
3434
import androidx.compose.ui.tooling.preview.Preview
3535
import 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
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.example.ssjetpackcomposeswipeableview.ui.theme
2+
3+
import androidx.compose.ui.graphics.Color
4+
5+
val Primary = Color(0xFF5DB989)
6+
val Secondary = Color(0xFFD0F9E5)
7+
val Background = Color(0xFFEAFFF3)

app/src/main/java/com/example/ssjetpackcomposeswipetodelete/ui/theme/Shape.kt renamed to app/src/main/java/com/example/ssjetpackcomposeswipeableview/ui/theme/Shape.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.ssjetpackcomposeswipetodelete.ui.theme
1+
package com.example.ssjetpackcomposeswipeableview.ui.theme
22

33
import androidx.compose.foundation.shape.RoundedCornerShape
44
import androidx.compose.material.Shapes

app/src/main/java/com/example/ssjetpackcomposeswipetodelete/ui/theme/Theme.kt renamed to app/src/main/java/com/example/ssjetpackcomposeswipeableview/ui/theme/Theme.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
package com.example.ssjetpackcomposeswipetodelete.ui.theme
1+
package com.example.ssjetpackcomposeswipeableview.ui.theme
22

33
import androidx.compose.foundation.isSystemInDarkTheme
44
import androidx.compose.material.MaterialTheme
55
import androidx.compose.material.darkColors
66
import androidx.compose.material.lightColors
77
import androidx.compose.runtime.Composable
8+
import androidx.compose.runtime.remember
89

910
private val DarkColorPalette = darkColors(
10-
primary = Purple200,
11-
primaryVariant = Purple700,
12-
secondary = Teal200
11+
primary = Primary,
12+
primaryVariant = Background,
13+
secondary = Secondary
1314
)
1415

1516
private val LightColorPalette = lightColors(
16-
primary = Purple500,
17-
primaryVariant = Purple700,
18-
secondary = Teal200
17+
primary = Primary,
18+
primaryVariant = Background,
19+
secondary = Secondary
1920

2021
/* Other default colors to override
2122
background = Color.White,
@@ -28,7 +29,7 @@ private val LightColorPalette = lightColors(
2829
)
2930

3031
@Composable
31-
fun SSJetpackComposeSwipeToDeleteTheme(
32+
fun SSJetpackComposeSwipeAbleViewTheme(
3233
darkTheme: Boolean = isSystemInDarkTheme(),
3334
content: @Composable() () -> Unit
3435
) {

app/src/main/java/com/example/ssjetpackcomposeswipetodelete/ui/theme/Type.kt renamed to app/src/main/java/com/example/ssjetpackcomposeswipeableview/ui/theme/Type.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.ssjetpackcomposeswipetodelete.ui.theme
1+
package com.example.ssjetpackcomposeswipeableview.ui.theme
22

33
import androidx.compose.material.Typography
44
import androidx.compose.ui.text.TextStyle

app/src/main/java/com/example/ssjetpackcomposeswipetodelete/ui/theme/Color.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

app/src/main/res/values-night/themes.xml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
<resources xmlns:tools="http://schemas.android.com/tools">
22
<!-- Base application theme. -->
3-
<style name="Theme.SSJetpackComposeSwipeToDelete" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
3+
<style name="Theme.SSJetpackComposeSwipeAbleView" parent="Theme.MaterialComponents.Light">
44
<!-- Primary brand color. -->
5-
<item name="colorPrimary">@color/purple_200</item>
6-
<item name="colorPrimaryVariant">@color/purple_700</item>
7-
<item name="colorOnPrimary">@color/black</item>
5+
<item name="colorPrimary">@color/primary</item>
6+
<item name="colorPrimaryVariant">@color/background</item>
87
<!-- Secondary brand color. -->
9-
<item name="colorSecondary">@color/teal_200</item>
10-
<item name="colorSecondaryVariant">@color/teal_200</item>
11-
<item name="colorOnSecondary">@color/black</item>
8+
<item name="colorSecondary">@color/secondary</item>
129
<!-- Status bar color. -->
1310
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
1411
<!-- Customize your theme here. -->

0 commit comments

Comments
 (0)