Skip to content

Commit f35b13e

Browse files
authored
Release/compose/0.0.1 (#39)
1 parent 27eb84f commit f35b13e

File tree

59 files changed

+2193
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2193
-104
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
/release
1111
.idea/*
1212
/.vs
13+
.kotlin

README.md

Lines changed: 192 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,218 @@
11
# StickyTimeLine
22

3+
[![Maven Central](https://img.shields.io/maven-central/v/io.github.sangcomz/stickytimeline-compose)](https://search.maven.org/artifact/io.github.sangcomz/stickytimeline-compose)
34
[![Maven Central](https://img.shields.io/maven-central/v/io.github.sangcomz/StickyTimeLine)](https://search.maven.org/artifact/io.github.sangcomz/StickyTimeLine)
45

5-
StickyTimeLine is timeline view for android.
6+
StickyTimeLine is timeline view for android. Now supports both View system and Jetpack Compose!
67

78
## What's New? :tada:
8-
- [Improvement] lib version update
9+
- [New] Jetpack Compose version released! 🎉
910

1011
## Result Screen
1112

1213
Feel free to send me a pull request with your app and I'll link you here:
13-
14+
### Jetpack Compose
15+
| Sample |
16+
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
17+
| <img width="auto" height="500px" src="/pic/compose.gif"> |
18+
19+
### View System
1420
| Sample <p style="float:left;"> <a href="https://play.google.com/store/apps/details?id=xyz.sangcomz.stickytimeline"> <img HEIGHT="40" WIDTH="135" alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/apps/en-play-badge.png" /></a></p> | AlleysMap <p style="float:left;"> <a href="https://play.google.com/store/apps/details?id=co.alleys.android"> <img HEIGHT="40" WIDTH="135" alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/apps/en-play-badge.png" /> </a></p> | StockRoom <p style="float:left;"> <a href="https://play.google.com/store/apps/details?id=com.thecloudsite.stockroom"> <img HEIGHT="40" WIDTH="135" alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/images/apps/en-play-badge.png" /></a></p> |
1521
|:---------------------------------:|:--------------------------------:|:--------------------------------:|
1622
| <img src="/pic/sample_result.gif">|<img src="/pic/alleys_result.gif">|<img width="auto" height="500px" src="/pic/stockroom_result.gif">|
1723

1824
## How to Use
1925

2026
### Gradle
21-
[![Maven Central](https://img.shields.io/maven-central/v/io.github.sangcomz/StickyTimeLine)](https://search.maven.org/artifact/io.github.sangcomz/StickyTimeLine)
27+
28+
#### View System
2229
```groovy
2330
dependencies {
2431
implementation 'io.github.sangcomz:StickyTimeLine:x.x.x'
2532
}
2633
```
34+
35+
#### Jetpack Compose
36+
```groovy
37+
dependencies {
38+
implementation 'io.github.sangcomz:stickytimeline-compose:x.x.x'
39+
}
40+
```
2741
### Usage
28-
#### activity_main.xml
42+
43+
#### Jetpack Compose Usage
44+
45+
##### Basic Usage - LazyColumn
46+
```kotlin
47+
@Composable
48+
fun TimeLineExample() {
49+
val musicList = remember { MusicRepo().musicList }
50+
val sortedMusicList = musicList.sortedWith(
51+
compareBy(
52+
{ it.year.toIntOrNull() ?: 0 },
53+
{ it.month.toIntOrNull() ?: 0 }
54+
)
55+
)
56+
57+
StickyTimeLineLazyColumn(
58+
items = sortedMusicList,
59+
groupBy = { it.year },
60+
makeHeaderItem = { key, _ -> key },
61+
sectionHeader = { year ->
62+
Column(
63+
modifier = Modifier
64+
.background(Color.White)
65+
.padding(8.dp)
66+
.fillMaxWidth()
67+
) {
68+
Text(
69+
text = year,
70+
style = TextStyle(
71+
fontSize = 18.sp,
72+
fontWeight = FontWeight.Bold,
73+
color = Color(0xFF414FCA)
74+
)
75+
)
76+
Text(
77+
text = "Popular Music",
78+
style = TextStyle(
79+
fontSize = 14.sp,
80+
color = Color(0xFFD16767)
81+
)
82+
)
83+
}
84+
},
85+
itemContent = { music ->
86+
Card(
87+
modifier = Modifier.fillMaxWidth(),
88+
shape = MaterialTheme.shapes.medium,
89+
elevation = CardDefaults.cardElevation(4.dp)
90+
) {
91+
Column(modifier = Modifier.padding(16.dp)) {
92+
Text(music.title, style = MaterialTheme.typography.titleMedium)
93+
Text(music.artist, style = MaterialTheme.typography.bodyMedium)
94+
}
95+
}
96+
},
97+
timeLineDot = {
98+
Box(
99+
modifier = Modifier
100+
.size(24.dp)
101+
.background(
102+
Color.Gray,
103+
shape = CircleShape
104+
)
105+
)
106+
}
107+
)
108+
}
109+
```
110+
111+
##### Basic Usage - LazyRow
112+
```kotlin
113+
@Composable
114+
fun TimeLineRowExample() {
115+
val musicList = remember { MusicRepo().musicList }
116+
val sortedMusicList = musicList.sortedWith(
117+
compareBy(
118+
{ it.year.toIntOrNull() ?: 0 },
119+
{ it.month.toIntOrNull() ?: 0 }
120+
)
121+
)
122+
123+
StickyTimeLineLazyRow(
124+
items = sortedMusicList,
125+
lineColor = Color(0xFF51ae45),
126+
lineWidth = 2.dp,
127+
groupBy = { it.year },
128+
makeHeaderItem = { key, _ -> key },
129+
headerContent = { year ->
130+
Column(
131+
modifier = Modifier
132+
.wrapContentSize()
133+
.padding(horizontal = 8.dp)
134+
) {
135+
Text(
136+
text = year,
137+
style = TextStyle(
138+
fontSize = 18.sp,
139+
fontWeight = FontWeight.Bold,
140+
color = Color(0xFF414FCA)
141+
)
142+
)
143+
Text(
144+
text = "Popular Music",
145+
style = TextStyle(
146+
fontSize = 14.sp,
147+
color = Color(0xFFD16767)
148+
)
149+
)
150+
}
151+
},
152+
itemContent = { music ->
153+
Card(
154+
modifier = Modifier.wrapContentWidth(),
155+
shape = MaterialTheme.shapes.medium,
156+
elevation = CardDefaults.cardElevation(4.dp)
157+
) {
158+
Column(modifier = Modifier.padding(16.dp)) {
159+
Text(music.title, style = MaterialTheme.typography.titleMedium)
160+
Text(music.artist, style = MaterialTheme.typography.bodyMedium)
161+
}
162+
}
163+
},
164+
dotContent = { _ ->
165+
Box(
166+
modifier = Modifier
167+
.size(24.dp)
168+
.background(
169+
Color.Gray,
170+
shape = CircleShape
171+
)
172+
)
173+
}
174+
)
175+
}
176+
```
177+
178+
##### Parameters - StickyTimeLineLazyColumn
179+
180+
| Parameter | Type | Default | Description |
181+
|-----------|------|---------|-------------|
182+
| `modifier` | `Modifier` | `Modifier` | Modifier for the component |
183+
| `items` | `List<T>` | - | List of items to display in the timeline |
184+
| `groupBy` | `(T) -> String` | - | Function to group items by section (returns section key) |
185+
| `makeHeaderItem` | `(key: String, items: List<T>) -> G` | - | Function to create header item from section key and items |
186+
| `generateItemKey` | `(T) -> Any` | `{ it.hashCode() }` | Function to generate unique key for each item (for recomposition optimization) |
187+
| `contentBackgroundColor` | `Color` | `Color.White` | Background color of the content area |
188+
| `lineColor` | `Color` | `Color.Blue` | Color of the timeline line |
189+
| `lineWidth` | `Dp` | `2.dp` | Width of the timeline line |
190+
| `verticalSpaceBy` | `Dp` | `12.dp` | Vertical spacing between items |
191+
| `timeLineHorizontalPadding` | `Dp` | `0.dp` | Horizontal padding for the timeline |
192+
| `timeLineDot` | `@Composable () -> Unit` | - | Composable for timeline dot |
193+
| `sectionHeader` | `@Composable (headerItem: G) -> Unit` | - | Composable for section header |
194+
| `itemContent` | `@Composable (item: T) -> Unit` | - | Composable content for each item |
195+
196+
##### Parameters - StickyTimeLineLazyRow
197+
198+
| Parameter | Type | Default | Description |
199+
|-----------|------|---------|-------------|
200+
| `modifier` | `Modifier` | `Modifier` | Modifier for the component |
201+
| `items` | `List<T>` | - | List of items to display in the timeline |
202+
| `groupBy` | `(T) -> String` | - | Function to group items by section (returns section key) |
203+
| `makeHeaderItem` | `(key: String, items: List<T>) -> G` | - | Function to create header item from section key and items |
204+
| `generateItemKey` | `(T) -> Any` | `{ it.hashCode() }` | Function to generate unique key for each item (for recomposition optimization) |
205+
| `headerContent` | `@Composable (headerItem: G) -> Unit` | - | Composable for section header |
206+
| `itemContent` | `@Composable (item: T) -> Unit` | - | Composable content for each item |
207+
| `dotContent` | `@Composable (group: String) -> Unit` | Default blue circle | Composable for timeline dot |
208+
| `lineColor` | `Color` | `Color.Blue` | Color of the timeline line |
209+
| `lineWidth` | `Dp` | `2.dp` | Width of the timeline line |
210+
| `horizontalSpaceBy` | `Dp` | `12.dp` | Horizontal spacing between items |
211+
| `contentPaddingValues` | `PaddingValues` | `PaddingValues(horizontal = 8.dp)` | Padding values for the content |
212+
213+
#### View System Usage
214+
215+
##### activity_main.xml
29216
```xml
30217
<?xml version="1.0" encoding="utf-8"?>
31218
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

app/build.gradle

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33

44
android {
5+
namespace "xyz.sangcomz.stickytimeline"
56

67
compileSdk gradle.compileSdk
78
defaultConfig {
89
minSdk gradle.minSdk
910
targetSdk gradle.targetSdk
1011
versionName gradle.versionName
1112
versionCode gradle.versionCode
12-
applicationId "xyz.sangcomz.stickytimeline"
1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1414
}
1515

@@ -39,26 +39,25 @@ android {
3939
}
4040
}
4141

42-
namespace 'xyz.sangcomz.stickytimeline'
43-
4442
compileOptions {
45-
sourceCompatibility JavaVersion.VERSION_17
46-
targetCompatibility JavaVersion.VERSION_17
43+
sourceCompatibility JavaVersion.VERSION_21
44+
targetCompatibility JavaVersion.VERSION_21
4745
}
4846

4947
kotlinOptions {
50-
jvmTarget = '17'
48+
jvmTarget = '21'
5149
}
5250
}
5351

5452
dependencies {
5553
implementation fileTree(include: ['*.jar'], dir: 'libs')
5654
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
57-
implementation 'androidx.appcompat:appcompat:1.6.1'
55+
implementation 'androidx.appcompat:appcompat:1.7.0'
5856
implementation "androidx.constraintlayout:constraintlayout:$constraint_version"
59-
implementation "androidx.recyclerview:recyclerview:1.3.2"
57+
implementation "androidx.recyclerview:recyclerview:1.4.0"
6058
implementation 'androidx.cardview:cardview:1.0.0'
6159
implementation project(':stickytimelineview')
60+
implementation project(':data')
6261

6362
testImplementation 'junit:junit:4.13.2'
6463
androidTestImplementation 'androidx.test:runner:1.5.2'

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
33

44
<application
55
android:allowBackup="true"
66
android:icon="@mipmap/ic_launcher"
77
android:label="@string/app_name"
88
android:roundIcon="@mipmap/ic_launcher_round"
99
android:supportsRtl="true"
10-
android:theme="@style/AppTheme">
10+
android:theme="@style/Theme.AppCompat">
1111
<activity android:name=".JavaExampleActivity"></activity>
1212
<activity
1313
android:name=".MainActivity"
14-
android:exported="true">
14+
android:exported="true" >
1515
<intent-filter>
1616
<action android:name="android.intent.action.MAIN" />
1717

app/src/main/java/xyz/sangcomz/stickytimeline/JavaExampleActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import java.util.List;
1414

15+
import io.github.sangcomz.stickytimeline.data.Singer;
16+
import io.github.sangcomz.stickytimeline.data.SingerRepo;
1517
import xyz.sangcomz.stickytimelineview.TimeLineRecyclerView;
1618
import xyz.sangcomz.stickytimelineview.callback.SectionCallback;
1719
import xyz.sangcomz.stickytimelineview.model.SectionInfo;

app/src/main/java/xyz/sangcomz/stickytimeline/MainActivity.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import androidx.appcompat.app.AppCompatActivity
66
import androidx.appcompat.content.res.AppCompatResources
77
import androidx.recyclerview.widget.LinearLayoutManager
88
import androidx.recyclerview.widget.RecyclerView
9+
import io.github.sangcomz.stickytimeline.data.Singer
10+
import io.github.sangcomz.stickytimeline.data.SingerRepo
911
import xyz.sangcomz.stickytimelineview.TimeLineRecyclerView
1012
import xyz.sangcomz.stickytimelineview.callback.SectionCallback
1113
import xyz.sangcomz.stickytimelineview.model.SectionInfo
@@ -37,7 +39,7 @@ class MainActivity : AppCompatActivity() {
3739
}
3840

3941
private fun initVerticalRecyclerView() {
40-
val singerList = getSingerList()
42+
val singerList: List<Singer> = getSingerList()
4143
findViewById<TimeLineRecyclerView>(R.id.vertical_recycler_view).apply {
4244
adapter = SingerAdapter(
4345
layoutInflater,
@@ -54,7 +56,7 @@ class MainActivity : AppCompatActivity() {
5456
}
5557

5658
private fun initHorizontalRecyclerView() {
57-
val singerList = getSingerList()
59+
val singerList: List<Singer> = getSingerList()
5860
findViewById<TimeLineRecyclerView>(R.id.horizontal_recycler_view).apply {
5961
adapter = SingerAdapter(
6062
layoutInflater,
@@ -85,7 +87,7 @@ class MainActivity : AppCompatActivity() {
8587
}
8688

8789
//Get data method
88-
private fun getSingerList(): List<Singer> = SingerRepo().singerList
90+
private fun getSingerList() = SingerRepo().singerList
8991

9092

9193
//Get SectionCallback method

app/src/main/java/xyz/sangcomz/stickytimeline/SingerAdapter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.view.LayoutInflater
66
import android.view.View
77
import android.view.ViewGroup
88
import android.widget.TextView
9+
import io.github.sangcomz.stickytimeline.data.Singer
910

1011
/**
1112
* Created by paetztm on 2/6/2017.

0 commit comments

Comments
 (0)