Skip to content

Commit

Permalink
Merge pull request #17 from pushpalroy/improve_stability
Browse files Browse the repository at this point in the history
Improve overall stability
  • Loading branch information
pushpalroy authored Jan 22, 2024
2 parents ecccf95 + 097d4a7 commit 61ed3c4
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 134 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ build/

# Local configuration file (sdk path, etc)
local.properties
keystore_release.properties

# Proguard folder generated by Eclipse
proguard/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In `build.gradle` of app module, include the following dependency

```gradle
dependencies {
implementation("io.github.pushpalroy:jetlime:1.0.5")
implementation("io.github.pushpalroy:jetlime:1.0.6")
}
```

Expand Down
3 changes: 2 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/build
/build
/keystore/release
31 changes: 25 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.util.Properties
import java.io.FileInputStream

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
Expand All @@ -17,6 +20,22 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
// Uncomment this line if we are generating a release build manually from IDE
// Not needed while build is generated from CI/CD
// maybeCreate("release").apply {
// val keystorePropertiesFile = rootProject.file("keystore_release.properties")
// val keystoreProperties = Properties()
// if (keystorePropertiesFile.exists()) {
// keystoreProperties.load(FileInputStream(keystorePropertiesFile))
// }
// storeFile = file(path = keystoreProperties["storeFile"] as String)
// storePassword = keystoreProperties["storePassword"] as String
// keyAlias = keystoreProperties["keyAlias"] as String
// keyPassword = keystoreProperties["keyPassword"] as String
// }
}

buildTypes {
getByName("release") {
isDebuggable = false
Expand All @@ -26,6 +45,7 @@ android {
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
// signingConfig = signingConfigs.getByName("release")
}
getByName("debug") {
isDebuggable = true
Expand Down Expand Up @@ -54,23 +74,22 @@ dependencies {
//implementation(libs.jetlime)

implementation(libs.material)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)

implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.material)
implementation(libs.androidx.compose.ui.tooling)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.activity.compose)
implementation(libs.coil.compose)

implementation(libs.multi.fab)

implementation(libs.androidx.lifecycle.compose)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.viewmodel.ktx)
implementation(libs.androidx.lifecycle.viewmodel.compose)

implementation(libs.kotlinx.collections.immutable)
implementation(libs.coil.compose)
implementation(libs.multi.fab)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand Down
21 changes: 18 additions & 3 deletions app/src/main/java/com/pushpal/jetlime/data/FakeData.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.pushpal.jetlime.data

import android.widget.Toast
import androidx.compose.animation.core.keyframes
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyRow
Expand All @@ -15,6 +17,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
Expand All @@ -27,9 +30,10 @@ import com.pushpal.jetlime.data.config.IconType
import com.pushpal.jetlime.data.config.IconType.Filled
import com.pushpal.jetlime.data.config.JetLimeItemConfig
import com.pushpal.jetlime.ui.theme.JetLimeTypography
import kotlinx.collections.immutable.persistentListOf

object FakeData {
val simpleJetLimeItems = mutableListOf(
val simpleJetLimeItems = persistentListOf(
JetLimeItem(
title = "Green Avenue",
description = "12/A Green Avenue",
Expand Down Expand Up @@ -62,6 +66,17 @@ object FakeData {
iconType = IconType.Empty
)
),
JetLimeItem {
val context = LocalContext.current
Text(
text = "Click me to show a toast",
style = JetLimeTypography.body1,
modifier = Modifier
.clickable {
Toast.makeText(context, "This item has been clicked", Toast.LENGTH_SHORT).show()
}
)
},
JetLimeItem(
title = "Blue Lagoon",
description = "14C Mandel Street",
Expand All @@ -82,7 +97,7 @@ object FakeData {
)
)

val animatedJetLimeItems = mutableListOf(
val animatedJetLimeItems = persistentListOf(
JetLimeItem(
title = "Green Avenue",
description = "12/A Green Avenue",
Expand Down Expand Up @@ -146,7 +161,7 @@ object FakeData {

@Composable
fun ImageList() {
val imageUrlsList = listOf(
val imageUrlsList = persistentListOf(
"https://images.unsplash.com/photo-1525183995014-bd94c0750cd5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=200&q=200",
"https://images.unsplash.com/photo-1498889444388-e67ea62c464b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=500",
"https://images.unsplash.com/photo-1501555088652-021faa106b9b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=500",
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/pushpal/jetlime/ui/theme/Surface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import kotlin.math.ln
* An alternative to [androidx.compose.material.Surface]
*/
@Composable
fun JetLimeSurface(
fun JetLimeSampleSurface(
modifier: Modifier = Modifier,
shape: Shape = RectangleShape,
color: Color = JetLimeTheme.colors.uiBackground,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.pushpal.jetlime.data.config.JetLimeItemConfig
import com.pushpal.jetlime.data.config.JetLimeViewConfig
import com.pushpal.jetlime.data.config.LineType
import com.pushpal.jetlime.ui.JetLimeView
import com.pushpal.jetlime.ui.theme.JetLimeSurface
import com.pushpal.jetlime.ui.theme.JetLimeSampleSurface
import com.pushpal.jetlime.ui.theme.JetLimeTheme
import com.pushpal.jetlime.ui.util.multifab.FabIcon
import com.pushpal.jetlime.ui.util.multifab.FabOption
Expand Down Expand Up @@ -59,7 +59,7 @@ fun AnimatedTimeLine() {
)
}
) { paddingValues ->
JetLimeSurface(
JetLimeSampleSurface(
color = JetLimeTheme.colors.uiBackground,
modifier = Modifier
.padding(paddingValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.pushpal.jetlime.data.JetLimeItemsModel
import com.pushpal.jetlime.data.config.JetLimeViewConfig
import com.pushpal.jetlime.data.config.LineType
import com.pushpal.jetlime.ui.JetLimeView
import com.pushpal.jetlime.ui.theme.JetLimeSurface
import com.pushpal.jetlime.ui.theme.JetLimeSampleSurface
import com.pushpal.jetlime.ui.theme.JetLimeTheme

@ExperimentalAnimationApi
Expand All @@ -29,7 +29,7 @@ fun BasicTimeLine() {
showIcons = true
)

JetLimeSurface(
JetLimeSampleSurface(
color = JetLimeTheme.colors.uiBackground,
modifier = Modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.pushpal.jetlime.data.config.JetLimeViewConfig
import com.pushpal.jetlime.data.config.LineType
import com.pushpal.jetlime.ui.JetLimeView
import com.pushpal.jetlime.ui.theme.JetLimeShapes
import com.pushpal.jetlime.ui.theme.JetLimeSurface
import com.pushpal.jetlime.ui.theme.JetLimeSampleSurface
import com.pushpal.jetlime.ui.theme.JetLimeTheme

@ExperimentalAnimationApi
Expand All @@ -35,12 +35,12 @@ fun ModifiedTimeLine() {
showIcons = true
)

JetLimeSurface(
JetLimeSampleSurface(
color = JetLimeTheme.colors.uiBackground,
modifier = Modifier
.fillMaxSize()
) {
JetLimeSurface(
JetLimeSampleSurface(
color = JetLimeTheme.colors.uiBackground,
shape = JetLimeShapes.medium,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.pushpal.jetlime.ui.timelines.updatestate
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
Expand All @@ -16,49 +16,36 @@ import com.pushpal.jetlime.data.config.IconAnimation
import com.pushpal.jetlime.data.config.JetLimeItemConfig
import com.pushpal.jetlime.data.config.JetLimeViewConfig
import com.pushpal.jetlime.ui.JetLimeView
import com.pushpal.jetlime.ui.theme.JetLimeSurface
import com.pushpal.jetlime.ui.theme.JetLimeSampleSurface
import com.pushpal.jetlime.ui.theme.JetLimeTheme
import com.pushpal.jetlime.ui.timelines.updatestate.ItemsListState.Success
import com.pushpal.jetlime.ui.timelines.updatestate.util.viewModelProviderFactoryOf

@OptIn(ExperimentalAnimationApi::class)
@ExperimentalAnimationApi
@Composable
fun ItemUpdateTimeLine() {
val viewModel: ItemUpdateTimeLineViewModel = viewModel(
factory = viewModelProviderFactoryOf {
ItemUpdateTimeLineViewModel()
}
)
val itemsListState by viewModel.itemsListState.collectAsState()
val viewModel: ItemUpdateTimeLineViewModel = viewModel()
val uiState by viewModel.itemsListState.collectAsStateWithLifecycle()

JetLimeSurface(
JetLimeSampleSurface(
color = JetLimeTheme.colors.uiBackground,
modifier = Modifier.fillMaxSize()
) {
val jetLimeItemsModel by remember {
derivedStateOf {
val jetItemList: MutableList<JetLimeItem> = mutableStateListOf()
when (itemsListState) {
is Success -> {
(itemsListState as Success).itemsList.forEach { item ->
jetItemList.add(
JetLimeItem(
title = item.name,
jetLimeItemConfig = JetLimeItemConfig(
position = item.id,
iconAnimation = if (item.activeState) IconAnimation() else null
)
)
)
}
}
else -> {
// Do nothing
}
}
JetLimeItemsModel(jetItemList)
derivedStateOf {
val jetItemList: MutableList<JetLimeItem> = mutableStateListOf()
uiState.itemsList.forEach { item ->
jetItemList.add(
JetLimeItem(
title = item.name,
jetLimeItemConfig = JetLimeItemConfig(
position = item.id,
iconAnimation = if (item.activeState) IconAnimation() else null
)
)
)
}
JetLimeItemsModel(jetItemList)
}
}

JetLimeView(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,51 @@
package com.pushpal.jetlime.ui.timelines.updatestate

import androidx.compose.runtime.Immutable
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.pushpal.jetlime.ui.timelines.updatestate.data.Item
import com.pushpal.jetlime.ui.timelines.updatestate.data.getFakeItems
import com.pushpal.jetlime.ui.timelines.updatestate.data.modify
import com.pushpal.jetlime.ui.timelines.updatestate.data.modifyActiveState
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch

class ItemUpdateTimeLineViewModel : ViewModel() {

var itemsListState = MutableStateFlow<ItemsListState>(ItemsListState.Empty)
private set
private val _itemsListState = MutableStateFlow(ItemsListState(loading = false))
var itemsListState: StateFlow<ItemsListState> = _itemsListState.asStateFlow()

init {
fetchItems()
}

private fun fetchItems() {
_itemsListState.update { it.copy(loading = true) }
viewModelScope.launch {
itemsListState.value = ItemsListState.Loading
itemsListState.value = ItemsListState.Success(itemsList = getFakeItems())

// Modify items list after 2 seconds delay
// Fetch initial items
_itemsListState.update { it.copy(itemsList = getFakeItems(), loading = false) }

// Modify the 2nd item after 2 seconds delay
delay(2000)
_itemsListState.update { it.copy(itemsList = getFakeItems().modifyActiveState(2)) }

// Modify the 3rd item after 2 seconds delay
delay(2000)
itemsListState.value = ItemsListState.Success(itemsList = getFakeItems().modify(2))
_itemsListState.update { it.copy(itemsList = getFakeItems().modifyActiveState(3)) }

// Modify items list after 3 seconds delay
// Modify the 4th item after 3 seconds delay
delay(3000)
itemsListState.value = ItemsListState.Success(itemsList = getFakeItems().modify(3))
_itemsListState.update { it.copy(itemsList = getFakeItems().modifyActiveState(4)) }
}
}
}

sealed class ItemsListState {
data object Empty : ItemsListState()
data object Loading : ItemsListState()
data class Success(val itemsList: List<Item>) : ItemsListState()
}
@Immutable
data class ItemsListState(
val itemsList: List<Item> = listOf(),
val loading: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun getFakeItems(): MutableList<Item> {
)
}

fun MutableList<Item>.modify(index: Int): MutableList<Item> {
fun MutableList<Item>.modifyActiveState(index: Int): MutableList<Item> {
return map { item ->
if (item.id == index) {
item.copy(
Expand Down
Loading

0 comments on commit 61ed3c4

Please sign in to comment.