Skip to content

Commit

Permalink
Added squeeze animation on news feed item click and updated library v…
Browse files Browse the repository at this point in the history
…ersions
  • Loading branch information
rob729 committed Oct 8, 2023
1 parent 385334d commit 2a32d62
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 70 deletions.
4 changes: 1 addition & 3 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 18 additions & 19 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(11)
jvmToolchain(17)
}
buildFeatures {
compose true
Expand All @@ -76,22 +73,23 @@ def rootConfiguration = rootProject.ext

dependencies {

implementation 'androidx.core:core-ktx:1.10.1'
implementation "androidx.compose.ui:ui:${rootConfiguration.compose_version}"
implementation "androidx.compose.material:material:${rootConfiguration.material_ui}"
implementation "androidx.compose.ui:ui-tooling-preview:${rootConfiguration.compose_version}"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.activity:activity-compose:1.7.2'
implementation 'androidx.core:core-ktx:1.12.0'
implementation platform("androidx.compose:compose-bom:${rootConfiguration.compose_bom_version}")
implementation "androidx.compose.ui:ui"
implementation "androidx.compose.material:material"
implementation "androidx.compose.ui:ui-tooling-preview"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.activity:activity-compose:1.8.0'
testImplementation 'junit:junit:4.13.2'

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:${rootConfiguration.compose_version}"
debugImplementation "androidx.compose.ui:ui-tooling:${rootConfiguration.compose_version}"
debugImplementation "androidx.compose.ui:ui-test-manifest:${rootConfiguration.compose_version}"
androidTestImplementation "androidx.compose.ui:ui-test-junit4"
debugImplementation "androidx.compose.ui:ui-tooling"
debugImplementation "androidx.compose.ui:ui-test-manifest"
implementation "androidx.navigation:navigation-compose:${rootConfiguration.nav_version}"
implementation "androidx.compose.material:material-icons-extended:${rootConfiguration.material_ui}"
implementation "androidx.compose.material3:material3:$material3_version"
implementation "androidx.compose.material:material-icons-extended"
implementation "androidx.compose.material3:material3"
implementation "androidx.compose.runtime:runtime-tracing:$compose_tracing"

implementation "androidx.lifecycle:lifecycle-viewmodel-compose:${rootConfiguration.compose_viewmodel}"
Expand All @@ -106,8 +104,8 @@ dependencies {
implementation("org.orbit-mvi:orbit-compose:${rootConfiguration.orbit_version}")

implementation "com.squareup.retrofit2:retrofit:${rootConfiguration.retrofit_version}"
implementation "com.squareup.retrofit2:converter-moshi:2.6.2"
implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
implementation "com.squareup.retrofit2:converter-moshi:2.9.0"
implementation "com.squareup.okhttp3:logging-interceptor:4.9.1"

implementation "org.jetbrains.kotlinx:kotlinx-datetime:${date_time_version}"

Expand All @@ -116,6 +114,7 @@ dependencies {
implementation("androidx.room:room-ktx:${rootConfiguration.room_version}")

implementation "io.insert-koin:koin-android:$koin_android_version"
implementation "io.insert-koin:koin-androidx-compose:$koin_android_version"

implementation "androidx.work:work-runtime-ktx:$work_version"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.rob729.newsfeed.initalizers

import android.content.Context
import androidx.startup.Initializer
import com.pluto.plugins.network.PlutoInterceptor
import com.pluto.plugins.network.okhttp.addPlutoOkhttpInterceptor
import com.rob729.newsfeed.database.NewsDBDataSource
import com.rob729.newsfeed.database.NewsDatabase
import com.rob729.newsfeed.network.NewsApi
Expand Down Expand Up @@ -42,7 +42,7 @@ class KoinInitializer : Initializer<KoinApplication> {
HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.addInterceptor(PlutoInterceptor())
.also { it.addPlutoOkhttpInterceptor() }
.build()

val retrofitInstance = Retrofit.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import com.rob729.newsfeed.database.NewsDatabase
class PlutoInitializer : Initializer<Unit> {
override fun create(context: Context) {
Pluto.Installer(context as Application)
.addPlugin(PlutoNetworkPlugin("network"))
.addPlugin(PlutoLayoutInspectorPlugin("layout-inspector"))
.addPlugin(PlutoRoomsDatabasePlugin("rooms-db"))
.addPlugin(PlutoNetworkPlugin())
.addPlugin(PlutoLayoutInspectorPlugin())
.addPlugin(PlutoRoomsDatabasePlugin())
.install()

PlutoRoomsDBWatcher.watch("news_database", NewsDatabase::class.java)
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/rob729/newsfeed/model/state/UiStatus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.rob729.newsfeed.model.ui.NewsArticleUiData

sealed class UiStatus {
data class Success(val news: List<NewsArticleUiData>): UiStatus()
object Loading: UiStatus()
object Error: UiStatus()
data object Loading: UiStatus()
data object Error: UiStatus()

object EmptyScreen: UiStatus()
data object EmptyScreen: UiStatus()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.rob729.newsfeed.model.state.home
sealed class HomeFeedSideEffect {
data class HomeSourceClicked(val domain: String) : HomeFeedSideEffect()
data class HomeFeedItemClicked(val selectedItemUrl: String) : HomeFeedSideEffect()
object HomeSourceFabClicked : HomeFeedSideEffect()
object ScrollToTopClicked : HomeFeedSideEffect()
data object HomeSourceFabClicked : HomeFeedSideEffect()
data object ScrollToTopClicked : HomeFeedSideEffect()
}
7 changes: 2 additions & 5 deletions app/src/main/java/com/rob729/newsfeed/ui/NewsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
@OptIn(ExperimentalComposeUiApi::class)
class NewsActivity : ComponentActivity() {

private val homeViewModel: HomeViewModel by viewModel()
private val searchViewModel: SearchViewModel by viewModel()

private val notificationHelper: NotificationHelper by lazy {
NotificationHelper(baseContext)
}
Expand Down Expand Up @@ -90,7 +87,7 @@ class NewsActivity : ComponentActivity() {
animationSpec = tween(500)
)
}) {
HomeScreen(navController, homeViewModel, paddingValues) {
HomeScreen(navController, paddingValues = paddingValues) {
openCustomTab(it)
}
}
Expand Down Expand Up @@ -120,7 +117,7 @@ class NewsActivity : ComponentActivity() {
animationSpec = tween(500)
)
}) {
SearchScreen(navController, searchViewModel) {
SearchScreen(navController) {
openCustomTab(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package com.rob729.newsfeed.ui.components

import android.content.Context
import android.content.Intent
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -11,16 +15,19 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.Icon
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Schedule
import androidx.compose.material.icons.filled.Share
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
Expand All @@ -38,11 +45,31 @@ import kotlinx.datetime.Clock
import kotlinx.datetime.toInstant

@Composable
fun NewsFeedItem(newsArticleUiData: NewsArticleUiData, modifier: Modifier = Modifier) {
fun NewsFeedItem(
newsArticleUiData: NewsArticleUiData,
modifier: Modifier = Modifier,
onItemClick: () -> Unit
) {
val context = LocalContext.current

Card(
modifier.padding(start = 8.dp, end = 8.dp, top = 8.dp),
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()


val scale by animateFloatAsState(
targetValue = if (isPressed) 0.95f else 1.0f,
animationSpec = tween(durationMillis = 150), label = ""
)

Surface(
modifier
.padding(8.dp)
.clickable(
interactionSource = interactionSource,
indication = null,
onClick = onItemClick
)
.scale(scale),
elevation = 4.dp,
shape = RoundedCornerShape(12.dp)
) {
Expand Down Expand Up @@ -86,7 +113,8 @@ fun NewsFeedItem(newsArticleUiData: NewsArticleUiData, modifier: Modifier = Modi
Row(
modifier = Modifier
.fillMaxWidth()
.padding(end = 12.dp, bottom = 8.dp), horizontalArrangement = Arrangement.End
.padding(end = 12.dp, bottom = 8.dp),
horizontalArrangement = Arrangement.End
) {
Icon(
imageVector = Icons.Default.Schedule, contentDescription = "time",
Expand Down
14 changes: 6 additions & 8 deletions app/src/main/java/com/rob729/newsfeed/ui/screen/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ import com.rob729.newsfeed.ui.components.Toolbar
import com.rob729.newsfeed.vm.HomeViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.androidx.compose.koinViewModel
import org.orbitmvi.orbit.compose.collectAsState
import org.orbitmvi.orbit.compose.collectSideEffect

@OptIn(
ExperimentalFoundationApi::class, ExperimentalMaterialApi::class,
ExperimentalMaterialApi::class,
)
@Composable
fun HomeScreen(
navController: NavController,
viewModel: HomeViewModel,
viewModel: HomeViewModel = koinViewModel(),
paddingValues: PaddingValues,
openCustomTab: (url: String) -> Unit
) {
Expand Down Expand Up @@ -147,12 +148,9 @@ fun HomeScreen(
is UiStatus.Success -> {
LazyColumn(Modifier.testTag("news_list"), listState) {
items(newsState.uiStatus.news) { item ->
NewsFeedItem(newsArticleUiData = item,
Modifier
.animateItemPlacement()
.clickable {
viewModel.newsFeedItemClicked(item)
})
NewsFeedItem(newsArticleUiData = item) {
viewModel.newsFeedItemClicked(item)
}
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions app/src/main/java/com/rob729/newsfeed/ui/screen/SearchScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ import com.rob729.newsfeed.ui.components.LoadingView
import com.rob729.newsfeed.ui.components.NewsFeedItem
import com.rob729.newsfeed.ui.theme.lexendDecaFontFamily
import com.rob729.newsfeed.vm.SearchViewModel
import org.koin.androidx.compose.koinViewModel
import org.orbitmvi.orbit.compose.collectAsState
import org.orbitmvi.orbit.compose.collectSideEffect

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun SearchScreen(
navController: NavHostController,
viewModel: SearchViewModel,
viewModel: SearchViewModel = koinViewModel(),
openCustomTab: (url: String) -> Unit
) {

Expand Down Expand Up @@ -122,12 +122,9 @@ fun SearchScreen(
is UiStatus.Success -> {
LazyColumn(Modifier.testTag("news_list"), listState) {
items(searchState.uiStatus.news) { item ->
NewsFeedItem(newsArticleUiData = item,
Modifier
.animateItemPlacement()
.clickable {
viewModel.newsFeedItemClicked(item)
})
NewsFeedItem(newsArticleUiData = item) {
viewModel.newsFeedItemClicked(item)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
implementation 'androidx.test.ext:junit:1.1.5'
implementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'androidx.test.uiautomator:uiautomator:2.2.0'
implementation 'androidx.benchmark:benchmark-macro-junit4:1.2.0-beta03'
implementation 'androidx.benchmark:benchmark-macro-junit4:1.2.0-rc02'
implementation 'androidx.test:rules:1.5.0'
}

Expand Down
18 changes: 8 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
buildscript {
ext {
kotlin_version = '1.9.10'
compose_bom_version = '2023.10.00'
ksp_version = '1.9.10-1.0.13'
coil_version = '2.4.0'
moshi_version = '1.15.0'
compose_version = '1.5.0'
compose_tracing = '1.0.0-alpha03'
compose_viewmodel = '2.6.1'
compose_viewmodel = '2.6.2'
orbit_version = '6.0.0'
retrofit_version = '2.9.0'
nav_version = '2.7.1'
nav_version = '2.7.4'
date_time_version = '0.4.1'
room_version = '2.5.2'
koin_android_version= '3.4.3'
koin_android_version= '3.5.0'
work_version = '2.8.1'
material3_version = '1.1.1'
material_ui = '1.5.0'
browser = '1.6.0'
profile_installer = '1.3.1'
startup_runtime = "1.1.1"
pluto = "2.1.5"
pluto = "2.1.7"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.1.1' apply false
id 'com.android.library' version '8.1.1' apply false
id 'com.android.application' version '8.1.2' apply false
id 'com.android.library' version '8.1.2' apply false
id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false
id 'com.google.devtools.ksp' version "$ksp_version"
id 'com.android.test' version '8.1.1' apply false
id 'com.android.test' version '8.1.2' apply false
id 'dev.shreyaspatil.compose-compiler-report-generator' version "1.1.0" apply false
}

Expand Down

0 comments on commit 2a32d62

Please sign in to comment.