Skip to content

Commit

Permalink
Merge pull request #2 from Akashkamble/migrationdev13
Browse files Browse the repository at this point in the history
Updated Jetpack compose to dev13.
  • Loading branch information
Akashkamble committed Jun 12, 2020
2 parents caa2cce + fbd2177 commit 34a0d2b
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 51 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ News App built with JetPack Compose
- [Newzz] (https://github.com/Akashkamble/Newzz)
- [Newzz-Flutter] (https://github.com/Akashkamble/Newzz-Flutter)

## The app built using MVVM architecture and contains following libraries
## The app contains following libraries

- [Jetpack Compose(v0.1.0-dev12)] (https://developer.android.com/jetpack/compose) (UI)
- [Jetpack Compose(v0.1.0-dev13)] (https://developer.android.com/jetpack/compose) (UI)

- [Koin](https://insert-koin.io/) (Dependency Injection)

Expand All @@ -22,6 +22,8 @@ News App built with JetPack Compose

- [Moshi](https://github.com/square/moshi) (Kotlin JSON library for Android from Square)

- [Accompanist](https://github.com/chrisbanes/accompanist/tree/master/coil) (Image Loading with coil)


# Note
This repo is missing api key for [newsapi](https://newsapi.org)
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {

composeOptions {
kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
kotlinCompilerExtensionVersion "0.1.0-dev12"
kotlinCompilerExtensionVersion "0.1.0-dev13"
}
}

Expand All @@ -57,7 +57,7 @@ dependencies {
implementation "androidx.ui:ui-tooling:$compose_version"
implementation "androidx.ui:ui-livedata:$compose_version"

/* ---------------------JetPack Compose-----------------------------*/
/* ---------------------LifeCycle Extension-----------------------------*/
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"


Expand All @@ -81,7 +81,7 @@ dependencies {
implementation 'androidx.browser:browser:1.3.0-alpha01'

/*---------------------CoilImageLoader------------------------------*/
implementation "dev.chrisbanes.accompanist:accompanist-coil:0.1.3"
implementation "dev.chrisbanes.accompanist:accompanist-coil:0.1.5"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.akash.newzz_compose.data.apiService
package com.akash.newzz_compose.data.apiservice

/**
* Created by Akash on 06/06/20
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.akash.newzz_compose.data.repository

import com.akash.newzz_compose.data.apiService.NewsApiService
import com.akash.newzz_compose.data.apiservice.NewsApiService
import com.akash.newzz_compose.data.response.NewsError
import com.akash.newzz_compose.data.response.NewsResponse
import com.akash.newzz_compose.utils.Result
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/akash/newzz_compose/di/module.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.akash.newzz_compose.di

import com.akash.newzz_compose.viewmodel.NewzzViewModel
import com.akash.newzz_compose.data.apiService.NewsApiService
import com.akash.newzz_compose.data.apiservice.NewsApiService
import com.akash.newzz_compose.data.repository.NewsRepository
import com.akash.newzz_compose.data.repository.NewsRepositoryImpl
import com.squareup.moshi.Moshi
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/akash/newzz_compose/ui/NewzzActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package com.akash.newzz_compose.ui

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.Model
import androidx.ui.core.setContent
import androidx.ui.livedata.observeAsState
import androidx.ui.material.MaterialTheme
import com.akash.newzz_compose.style.darkThemeColor
import com.akash.newzz_compose.style.themeColor
import com.akash.newzz_compose.viewmodel.NewzzViewModel
import com.akash.newzz_compose.ui.home.Home
import com.akash.newzz_compose.viewmodel.NewzzViewModel
import org.koin.android.viewmodel.ext.android.viewModel


Expand All @@ -20,7 +19,7 @@ class NewzzActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContent {
val isDark = viewModel.isDarkTheme.observeAsState(false)
MaterialTheme(colors = if(isDark.value) darkThemeColor else themeColor) {
MaterialTheme(colors = if (isDark.value) darkThemeColor else themeColor) {
Home(viewModel)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.akash.newzz_compose.ui.articleListPage
package com.akash.newzz_compose.ui.articlelist

import androidx.compose.Composable
import androidx.compose.State
import androidx.ui.core.Alignment
import androidx.ui.core.ContextAmbient
import androidx.ui.core.Modifier
import androidx.ui.foundation.Box
import androidx.ui.foundation.Text
import androidx.ui.foundation.VerticalScroller
import androidx.ui.foundation.clickable
Expand All @@ -25,20 +26,9 @@ import com.akash.newzz_compose.utils.CustomTabUtil

@Composable
fun ArticleRow(article: NewsArticle, isDark: State<Boolean>, onClick: () -> Unit) {
Column(modifier = Modifier.padding(start = 10.dp, end = 10.dp, top = 10.dp)) {
Box(modifier = Modifier.clickable(onClick = { onClick() })) {
Row(
/* onClick with more than one modifier was not working hence wrapping it with Column
* Tried modifier = Modifier.clickable(
onClick = {
onClick()
}
).plus(Modifier.padding(start = 10.dp, end = 10.dp, top = 10.dp))
*/
modifier = Modifier.clickable(
onClick = {
onClick()
}
),
modifier = Modifier.padding(all = 10.dp),
verticalGravity = Alignment.CenterVertically
) {
RemoteImage(
Expand Down Expand Up @@ -76,14 +66,24 @@ fun ArticleList(articles: List<NewsArticle>, isDark: State<Boolean>) {
/**
* App crashing while scrolling the AdapterList hence verticalScroller with Columns used.
* @see <a href="https://issuetracker.google.com/issues/154653504">Issue tracker</a>
* Not fixed in version 0.1.0-dev13
*/

val context = ContextAmbient.current
/*AdapterList(data = articles) { article ->
ArticleRow(article = article)
ArticleRow(
article = article,
isDark = isDark,
onClick = {
CustomTabUtil.launch(context, article.url.toString(), isDark.value)
}
)
HeightSpacer(value = 10.dp)
Divider(
color = Color(0xFFDCDCDC)
color = if (isDark.value) dividerColorDark else dividerColor
)
}*/
val context = ContextAmbient.current

VerticalScroller {
Column(modifier = Modifier.fillMaxWidth()) {
articles.forEach { article ->
Expand All @@ -94,7 +94,6 @@ fun ArticleList(articles: List<NewsArticle>, isDark: State<Boolean>) {
CustomTabUtil.launch(context, article.url.toString(), isDark.value)
}
)
HeightSpacer(value = 10.dp)
Divider(
color = if (isDark.value) dividerColorDark else dividerColor
)
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/java/com/akash/newzz_compose/ui/common/Common.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.akash.newzz_compose.ui.common

import androidx.compose.Composable
import androidx.ui.core.Alignment
import androidx.ui.core.ContentScale
import androidx.ui.core.Modifier
import androidx.ui.foundation.Box
Expand All @@ -9,10 +10,8 @@ import androidx.ui.foundation.shape.corner.RoundedCornerShape
import androidx.ui.graphics.Color
import androidx.ui.graphics.Shape
import androidx.ui.graphics.vector.VectorAsset
import androidx.ui.layout.Spacer
import androidx.ui.layout.fillMaxSize
import androidx.ui.layout.preferredHeight
import androidx.ui.layout.preferredWidth
import androidx.ui.layout.*
import androidx.ui.material.CircularProgressIndicator
import androidx.ui.material.Surface
import androidx.ui.res.vectorResource
import androidx.ui.unit.Dp
Expand Down Expand Up @@ -40,11 +39,11 @@ fun RemoteImage(
modifier: Modifier,
errorImage: VectorAsset = vectorResource(id = R.drawable.ic_newzz_error),
contentScale: ContentScale = ContentScale.Crop,
shape : Shape = RoundedCornerShape(5.dp)
shape: Shape = RoundedCornerShape(5.dp)
) {
Box(
modifier = modifier
){
) {
if (url.isNullOrEmpty()) {
Image(
modifier = Modifier.fillMaxSize(),
Expand All @@ -57,7 +56,12 @@ fun RemoteImage(
) {
CoilImageWithCrossfade(
data = url,
contentScale = contentScale
contentScale = contentScale,
loading = {
Stack(Modifier.fillMaxSize()) {
CircularProgressIndicator(Modifier.gravity(Alignment.Center))
}
}
)
}
}
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/java/com/akash/newzz_compose/ui/home/BodyContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.ui.unit.dp
import com.akash.newzz_compose.Category
import com.akash.newzz_compose.R
import com.akash.newzz_compose.style.*
import com.akash.newzz_compose.ui.articleListPage.ArticleList
import com.akash.newzz_compose.ui.articlelist.ArticleList
import com.akash.newzz_compose.viewmodel.NewzzViewModel


Expand Down Expand Up @@ -96,7 +96,11 @@ fun TopAppBar(viewModel: NewzzViewModel) {
}

@Composable
fun ArticleStateWidget(state: State<NewzzViewModel.ArticleState>, isDark: State<Boolean>, onClick: () -> Unit) {
fun ArticleStateWidget(
state: State<NewzzViewModel.ArticleState>,
isDark: State<Boolean>,
onClick: () -> Unit
) {
when {
state.value.isLoading -> {
Loading(isDark)
Expand Down Expand Up @@ -145,21 +149,26 @@ fun Loading(isDark: State<Boolean>) {
}

@Composable
fun ErrorView(errorMessage: String, showRetry: Boolean, isDark: State<Boolean>, onClick: () -> Unit) {
fun ErrorView(
errorMessage: String,
showRetry: Boolean,
isDark: State<Boolean>,
onClick: () -> Unit
) {
Column(
verticalArrangement = Arrangement.Center,
horizontalGravity = Alignment.CenterHorizontally
) {
Text(
text = errorMessage,
style = if(isDark.value) articleTitleStyle.copy(color = titleColorDark) else articleTitleStyle
style = if (isDark.value) articleTitleStyle.copy(color = titleColorDark) else articleTitleStyle
)
if (showRetry) {
TextButton(onClick = onClick) {
Text(
text = "Retry",
style = TextStyle(
color = if(isDark.value) sourceTextColorDark else deepPurple
color = if (isDark.value) sourceTextColorDark else deepPurple
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ fun BottomBar(viewModel: NewzzViewModel) {
}

@Composable
fun BottomNavItem(asset: Int, isDark: State<Boolean>, onClick: () -> Unit, isSelected: Boolean = false) {
fun BottomNavItem(
asset: Int,
isDark: State<Boolean>,
onClick: () -> Unit,
isSelected: Boolean = false
) {
IconButton(onClick = onClick) {
Icon(
asset = vectorResource(id = asset),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class NewzzViewModel(private val repo: NewsRepository) : ViewModel() {
private val viewModelScope = CoroutineScope(Dispatchers.Main) + job

private val _pageNumber = MutableLiveData<Int>().apply {
value =
General
value = General
}
val pageNumber: LiveData<Int> = _pageNumber

Expand Down Expand Up @@ -120,7 +119,7 @@ class NewzzViewModel(private val repo: NewsRepository) : ViewModel() {
private suspend fun fetchBusinessArticles(category: String) {
val state = businessState.value!!
if (state.list == null || state.list.isEmpty()) {
withContext(Dispatchers.Main){
withContext(Dispatchers.Main) {
val articleState = ArticleState()
_businessState.value = articleState
}
Expand Down Expand Up @@ -152,7 +151,7 @@ class NewzzViewModel(private val repo: NewsRepository) : ViewModel() {
private suspend fun fetchTechArticles(category: String) {
val state = techState.value!!
if (state.list == null || state.list.isEmpty()) {
withContext(Dispatchers.Main){
withContext(Dispatchers.Main) {
val articleState = ArticleState()
_techState.value = articleState
}
Expand Down Expand Up @@ -194,8 +193,8 @@ class NewzzViewModel(private val repo: NewsRepository) : ViewModel() {
)

data class Error(
val errorMessage : String,
val showRetry : Boolean = true
val errorMessage: String,
val showRetry: Boolean = true
)

companion object {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
ext.compose_version = "0.1.0-dev12"
ext.compose_version = "0.1.0-dev13"
ext.coroutines_version = "1.3.6"
ext.koin_version = "2.1.5"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0-alpha09"
classpath "com.android.tools.build:gradle:4.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-rc-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

0 comments on commit 34a0d2b

Please sign in to comment.