├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── anim
│ │ │ │ ├── slide_in_right.xml
│ │ │ │ └── slide_out_left.xml
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_dark.xml
│ │ │ │ ├── ic_newzz_error.xml
│ │ │ │ ├── ic_general.xml
│ │ │ │ ├── ic_tech.xml
│ │ │ │ ├── ic_light.xml
│ │ │ │ ├── ic_business.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── akash
│ │ │ │ └── newzz_compose
│ │ │ │ ├── NewzzApplication.kt
│ │ │ │ ├── ui
│ │ │ │ ├── newzzappui
│ │ │ │ │ ├── ArticleListUiState.kt
│ │ │ │ │ ├── BottomBar.kt
│ │ │ │ │ ├── TopAppBar.kt
│ │ │ │ │ ├── NewzzAppUI.kt
│ │ │ │ │ ├── NewzzListContainer.kt
│ │ │ │ │ └── ArticleList.kt
│ │ │ │ ├── style
│ │ │ │ │ ├── TextStyle.kt
│ │ │ │ │ └── Theme.kt
│ │ │ │ ├── NewzzActivity.kt
│ │ │ │ └── commoncomposable
│ │ │ │ │ └── CommonComposables.kt
│ │ │ │ ├── di
│ │ │ │ ├── RepositoryModule.kt
│ │ │ │ └── NewzzActivityModule.kt
│ │ │ │ ├── other
│ │ │ │ └── Category.kt
│ │ │ │ ├── util
│ │ │ │ └── CustomTabUtil.kt
│ │ │ │ └── viewmodel
│ │ │ │ └── NewzzViewModel.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── akash
│ │ │ └── newzz_compose
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── akash
│ │ └── newzz_compose
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── data
├── .gitignore
├── consumer-rules.pro
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── akash
│ │ │ └── newzz
│ │ │ └── data
│ │ │ ├── Constants.kt
│ │ │ ├── response
│ │ │ ├── NewsSource.kt
│ │ │ ├── NewsError.kt
│ │ │ ├── NewsResponse.kt
│ │ │ └── NewsArticle.kt
│ │ │ ├── Result.kt
│ │ │ ├── repository
│ │ │ ├── NewsRepository.kt
│ │ │ └── NewsRepositoryImpl.kt
│ │ │ ├── BaseApplication.kt
│ │ │ └── apiservice
│ │ │ └── NewzzApiService.kt
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── akash
│ │ │ └── newzz
│ │ │ └── data
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── akash
│ │ └── newzz
│ │ └── data
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── .idea
├── .name
├── dictionaries
│ └── nbt762.xml
├── compiler.xml
├── vcs.xml
├── render.experimental.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── misc.xml
├── runConfigurations.xml
├── gradle.xml
├── jarRepositories.xml
└── codeStyles
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/data/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/data/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Newzz-Compose
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':data'
2 | include ':app'
3 | rootProject.name = "Newzz-Compose"
--------------------------------------------------------------------------------
/.idea/dictionaries/nbt762.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Akashkamble/Newzz-Compose/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/render.experimental.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_in_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_out_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
--------------------------------------------------------------------------------
/data/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 | /
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 05 18:29:18 IST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
7 |
--------------------------------------------------------------------------------
/data/src/main/java/com/akash/newzz/data/Constants.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data
2 |
3 | /**
4 | * Created by Akash on 06/06/20
5 | */
6 | object Constants {
7 | val API_KEY: String
8 | get() = BuildConfig.API_KEY
9 | val COUNTRY: String
10 | get() = "in"
11 | }
12 |
--------------------------------------------------------------------------------
/data/src/main/java/com/akash/newzz/data/response/NewsSource.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data.response
2 |
3 | import com.squareup.moshi.JsonClass
4 |
5 | /**
6 | * Created by Akash on 06/06/20
7 | */
8 |
9 | @JsonClass(generateAdapter = true)
10 | data class NewsSource(
11 | val name: String?
12 | )
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Newzz-Compose
3 | General
4 | Business
5 | Technology
6 | Retry
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/data/src/main/java/com/akash/newzz/data/Result.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data
2 |
3 | /**
4 | * Created by Akash on 02/07/20
5 | */
6 |
7 | sealed class Result {
8 | data class Success(val data: T) : Result()
9 | data class Error(val errorMessage: String, val showRetry: Boolean = true) : Result()
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 | #FF121212
7 | #FF4a148c
8 |
--------------------------------------------------------------------------------
/data/src/main/java/com/akash/newzz/data/response/NewsError.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data.response
2 |
3 | import com.squareup.moshi.JsonClass
4 |
5 | /**
6 | * Created by Akash on 06/06/20
7 | */
8 |
9 | @JsonClass(generateAdapter = true)
10 | data class NewsError(
11 | val code: String,
12 |
13 | val message: String,
14 |
15 | val status: String
16 | )
17 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/data/src/main/java/com/akash/newzz/data/response/NewsResponse.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data.response
2 |
3 | import com.squareup.moshi.JsonClass
4 |
5 | /**
6 | * Created by Akash on 06/06/20
7 | */
8 | @JsonClass(generateAdapter = true)
9 | data class NewsResponse(
10 | val articles: List,
11 |
12 | var status: String,
13 |
14 | val totalResults: Int
15 | )
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/NewzzApplication.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose
2 |
3 | import com.akash.newzz.data.BaseApplication
4 | import dagger.hilt.android.HiltAndroidApp
5 |
6 | /**
7 | * Created by Akash on 28/08/20
8 | */
9 | @HiltAndroidApp
10 | class NewzzApplication : BaseApplication() {
11 | override fun onCreate() {
12 | super.onCreate()
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/data/src/main/java/com/akash/newzz/data/repository/NewsRepository.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data.repository
2 |
3 | import com.akash.newzz.data.Result
4 | import com.akash.newzz.data.response.NewsResponse
5 |
6 | /**
7 | * Created by Akash on 06/06/20
8 | */
9 | interface NewsRepository {
10 | suspend fun getArticlesByCategoryAsync(category: String, page: Int): Result
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/ui/newzzappui/ArticleListUiState.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.ui.newzzappui
2 |
3 | import com.akash.newzz.data.Result
4 | import com.akash.newzz.data.response.NewsArticle
5 |
6 | /**
7 | * Created by Akash on 29/08/20
8 | */
9 |
10 | data class ArticleListUiState(
11 | val isLoading: Boolean = true,
12 | val list: List? = emptyList(),
13 | val error: Result.Error? = null
14 | )
15 |
--------------------------------------------------------------------------------
/data/src/test/java/com/akash/newzz/data/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data
2 |
3 | import org.junit.Assert.assertEquals
4 | import org.junit.Test
5 |
6 | /**
7 | * Example local unit test, which will execute on the development machine (host).
8 | *
9 | * See [testing documentation](http://d.android.com/tools/testing).
10 | */
11 | class ExampleUnitTest {
12 | @Test
13 | fun addition_isCorrect() {
14 | assertEquals(4, 2 + 2)
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/test/java/com/akash/newzz_compose/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose
2 |
3 | import org.junit.Assert.assertEquals
4 | import org.junit.Test
5 |
6 | /**
7 | * Example local unit test, which will execute on the development machine (host).
8 | *
9 | * See [testing documentation](http://d.android.com/tools/testing).
10 | */
11 | class ExampleUnitTest {
12 | @Test
13 | fun addition_isCorrect() {
14 | assertEquals(4, 2 + 2)
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/data/src/main/java/com/akash/newzz/data/response/NewsArticle.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data.response
2 |
3 | import com.squareup.moshi.JsonClass
4 |
5 | /**
6 | * Created by Akash on 06/06/20
7 | */
8 |
9 | @JsonClass(generateAdapter = true)
10 | data class NewsArticle(
11 | val publishedAt: String,
12 |
13 | val source: NewsSource,
14 |
15 | val title: String,
16 |
17 | val description: String? = null,
18 |
19 | val url: String? = null,
20 |
21 | val urlToImage: String? = null
22 | )
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/di/RepositoryModule.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.di
2 |
3 | import com.akash.newzz.data.repository.NewsRepository
4 | import com.akash.newzz.data.repository.NewsRepositoryImpl
5 | import dagger.Binds
6 | import dagger.Module
7 | import dagger.hilt.InstallIn
8 | import dagger.hilt.components.SingletonComponent
9 |
10 | @Module
11 | @InstallIn(SingletonComponent::class)
12 | abstract class RepositoryModule {
13 |
14 | @Binds
15 | abstract fun bindNewsRepo(
16 | newsRepository: NewsRepositoryImpl
17 | ): NewsRepository
18 | }
19 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_dark.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/di/NewzzActivityModule.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.di
2 |
3 | import com.akash.newzz.data.apiservice.NewzzApiService
4 | import com.squareup.moshi.Moshi
5 | import dagger.Module
6 | import dagger.Provides
7 | import dagger.hilt.InstallIn
8 | import dagger.hilt.components.SingletonComponent
9 | import javax.inject.Singleton
10 |
11 | /**
12 | * Created by Akash on 28/08/20
13 | */
14 |
15 | @Module
16 | @InstallIn(SingletonComponent::class)
17 | object NewzzActivityModule {
18 |
19 | @Provides
20 | @Singleton
21 | fun provideMoshi(): Moshi = Moshi.Builder().build()
22 |
23 | @Provides
24 | @Singleton
25 | fun provideNewsApiService(): NewzzApiService = NewzzApiService.invoke()
26 | }
27 |
--------------------------------------------------------------------------------
/data/src/androidTest/java/com/akash/newzz/data/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data
2 |
3 | import androidx.test.ext.junit.runners.AndroidJUnit4
4 | import androidx.test.platform.app.InstrumentationRegistry
5 | import org.junit.Assert.assertEquals
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | /**
10 | * Instrumented test, which will execute on an Android device.
11 | *
12 | * See [testing documentation](http://d.android.com/tools/testing).
13 | */
14 | @RunWith(AndroidJUnit4::class)
15 | class ExampleInstrumentedTest {
16 | @Test
17 | fun useAppContext() {
18 | // Context of the app under test.
19 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
20 | assertEquals("com.akash.newzz.data.test", appContext.packageName)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/akash/newzz_compose/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose
2 |
3 | import androidx.test.ext.junit.runners.AndroidJUnit4
4 | import androidx.test.platform.app.InstrumentationRegistry
5 | import org.junit.Assert.assertEquals
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | /**
10 | * Instrumented test, which will execute on an Android device.
11 | *
12 | * See [testing documentation](http://d.android.com/tools/testing).
13 | */
14 | @RunWith(AndroidJUnit4::class)
15 | class ExampleInstrumentedTest {
16 | @Test
17 | fun useAppContext() {
18 | // Context of the app under test.
19 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
20 | assertEquals("com.akash.newzz_compose", appContext.packageName)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/data/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/ui/style/TextStyle.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.ui.style
2 |
3 | import androidx.compose.ui.graphics.Color
4 | import androidx.compose.ui.text.TextStyle
5 | import androidx.compose.ui.text.font.FontWeight
6 | import androidx.compose.ui.unit.sp
7 |
8 | /**
9 | * Created by Akash on 28/08/20
10 | */
11 |
12 | val categoryTitleStyle = TextStyle(
13 | fontWeight = FontWeight.SemiBold,
14 | fontSize = 20.sp,
15 | letterSpacing = 1.1.sp,
16 | color = Color.White
17 | )
18 |
19 | val articleTitleStyle = TextStyle(
20 | fontWeight = FontWeight.Medium,
21 | fontSize = 16.sp
22 | )
23 |
24 | val sourceTextStyle = TextStyle(
25 | fontSize = 14.sp
26 | )
27 |
28 | val dateTextStyle = TextStyle(
29 | fontWeight = FontWeight.ExtraLight,
30 | fontSize = 12.sp
31 | )
32 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/data/src/main/java/com/akash/newzz/data/BaseApplication.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data
2 |
3 | import android.app.Application
4 | import android.content.Context
5 | import android.net.ConnectivityManager
6 |
7 | /**
8 | * Created by Akash on 02/07/20
9 | */
10 |
11 | @Suppress("DEPRECATION")
12 | open class BaseApplication : Application() {
13 |
14 | override fun onCreate() {
15 | super.onCreate()
16 | instances = this
17 | }
18 |
19 | companion object {
20 | lateinit var instances: BaseApplication
21 |
22 | fun isNetworkConnected(): Boolean {
23 | val connectivityManager =
24 | instances.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
25 | val networkInfo = connectivityManager.activeNetworkInfo
26 | return networkInfo != null && networkInfo.isConnected
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/other/Category.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.other
2 |
3 | import com.akash.newzz_compose.R
4 |
5 | /**
6 | * Created by Akash on 28/08/20
7 | */
8 |
9 | interface Category {
10 | val category: String
11 | val icon: Int
12 | }
13 |
14 | data class General(
15 | override val category: String = "general",
16 | override val icon: Int = R.drawable.ic_general
17 | ) : Category
18 |
19 | data class Business(
20 | override val category: String = "business",
21 | override val icon: Int = R.drawable.ic_business
22 | ) : Category
23 |
24 | data class Technology(
25 | override val category: String = "technology",
26 | override val icon: Int = R.drawable.ic_tech
27 | ) : Category
28 |
29 | fun getTitleResource(activeCategory: Category): Int = when (activeCategory) {
30 | is General -> R.string.title_general
31 | is Business -> R.string.title_business
32 | is Technology -> R.string.title_technology
33 | else -> throw IllegalAccessException("Page number is invalid")
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/ui/NewzzActivity.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.ui
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.compose.setContent
6 | import androidx.activity.viewModels
7 | import androidx.compose.runtime.livedata.observeAsState
8 | import com.akash.newzz_compose.ui.newzzappui.NewzzAppUI
9 | import com.akash.newzz_compose.ui.style.NewzzTheme
10 | import com.akash.newzz_compose.viewmodel.NewzzViewModel
11 | import dagger.hilt.android.AndroidEntryPoint
12 |
13 | /**
14 | * Created by Akash on 27/08/20
15 | */
16 | @AndroidEntryPoint
17 | class NewzzActivity : ComponentActivity() {
18 |
19 | private val viewModel: NewzzViewModel by viewModels()
20 |
21 | override fun onCreate(savedInstanceState: Bundle?) {
22 | super.onCreate(savedInstanceState)
23 | setContent {
24 | val darkTheme = viewModel.isDarkTheme.observeAsState(false)
25 | NewzzTheme(isDarkTheme = darkTheme.value) {
26 | NewzzAppUI(viewModel = viewModel)
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_newzz_error.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_general.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Newzz-Compose
2 | News App built with JetPack Compose(v1.0.5)
3 |
4 | ## Gif
5 | 
6 |
7 | ## Other variants
8 | - [Newzz] (https://github.com/Akashkamble/Newzz)
9 | - [Newzz-Flutter] (https://github.com/Akashkamble/Newzz-Flutter)
10 |
11 | ## The app contains following libraries
12 |
13 | - [Jetpack Compose](https://developer.android.com/jetpack/compose) (UI)
14 |
15 | - [Dagger-Hilt](https://dagger.dev/hilt/) (Dependency Injection)
16 |
17 | - [LifeCycle Components](https://developer.android.com/topic/libraries/architecture/livedata) (ViewModel and LiveData)
18 |
19 | - [Kotlin Coroutines](https://kotlinlang.org/docs/reference/coroutines-overview.html) (Asynchronous programming)
20 |
21 | - [Retrofit](https://square.github.io/retrofit/) (Networking)
22 |
23 | - [Moshi](https://github.com/square/moshi) (Kotlin JSON library for Android from Square)
24 |
25 | - [Accompanist](https://github.com/chrisbanes/accompanist/tree/master/coil) (Image Loading with coil)
26 |
27 |
28 | # Note
29 | This repo is missing api key for [newsapi](https://newsapi.org)
30 | get the api key from [newsapi](https://newsapi.org) and do following steps
31 | - Add **api_key** property in **local.properties** E.g api_key="54e494XXXXXXXXXXXXXXXXXXXXXXXXXX"
32 |
33 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M"
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | android.enableJetifier=true
19 | # Automatically convert third-party libraries to use AndroidX
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 | org.gradle.caching=true
23 | org.gradle.configureondemand=true
24 | org.gradle.daemon=true
25 | org.gradle.parallel=true
26 | org.gradle.console=rich
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_tech.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/.idea/codeStyles:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/ui/newzzappui/BottomBar.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.ui.newzzappui
2 |
3 | import androidx.compose.foundation.layout.Arrangement
4 | import androidx.compose.foundation.layout.Row
5 | import androidx.compose.foundation.layout.fillMaxWidth
6 | import androidx.compose.foundation.layout.requiredHeight
7 | import androidx.compose.material.BottomAppBar
8 | import androidx.compose.material.BottomNavigationItem
9 | import androidx.compose.material.Icon
10 | import androidx.compose.material.MaterialTheme
11 | import androidx.compose.runtime.Composable
12 | import androidx.compose.ui.Modifier
13 | import androidx.compose.ui.res.painterResource
14 | import androidx.compose.ui.unit.dp
15 | import com.akash.newzz_compose.other.Category
16 |
17 | /**
18 | * Created by Akash on 28/08/20
19 | */
20 |
21 | @Composable
22 | fun BottomBar(
23 | categoryList: List,
24 | activeCategory: Category,
25 | onMenuClicked: (Category) -> Unit
26 | ) {
27 | BottomAppBar(
28 | backgroundColor = MaterialTheme.colors.surface,
29 | elevation = 10.dp
30 | ) {
31 | Row(
32 | modifier = Modifier
33 | .fillMaxWidth()
34 | .requiredHeight(50.dp),
35 | horizontalArrangement = Arrangement.SpaceAround
36 | ) {
37 | categoryList.forEach { category ->
38 | BottomNavigationItem(
39 | icon = {
40 | Icon(
41 | painter = painterResource(id = category.icon),
42 | contentDescription = category.category,
43 | )
44 | },
45 | selected = activeCategory == category,
46 | onClick = {
47 | onMenuClicked(category)
48 | },
49 | selectedContentColor = MaterialTheme.colors.primary,
50 | unselectedContentColor = MaterialTheme.colors.secondary
51 | )
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_light.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/ui/newzzappui/TopAppBar.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.ui.newzzappui
2 |
3 | import androidx.annotation.DrawableRes
4 | import androidx.annotation.StringRes
5 | import androidx.compose.foundation.layout.Arrangement
6 | import androidx.compose.foundation.layout.Box
7 | import androidx.compose.foundation.layout.Row
8 | import androidx.compose.foundation.layout.fillMaxWidth
9 | import androidx.compose.foundation.layout.padding
10 | import androidx.compose.material.Icon
11 | import androidx.compose.material.IconButton
12 | import androidx.compose.material.Text
13 | import androidx.compose.runtime.Composable
14 | import androidx.compose.runtime.mutableStateOf
15 | import androidx.compose.runtime.remember
16 | import androidx.compose.ui.Alignment
17 | import androidx.compose.ui.Modifier
18 | import androidx.compose.ui.graphics.Color
19 | import androidx.compose.ui.res.painterResource
20 | import androidx.compose.ui.res.stringResource
21 | import androidx.compose.ui.unit.dp
22 | import com.akash.newzz_compose.R
23 | import com.akash.newzz_compose.ui.style.categoryTitleStyle
24 |
25 | /**
26 | * Created by Akash on 28/08/20
27 | */
28 |
29 | @Composable
30 | fun TopAppBar(@StringRes titleResource: Int, onThemeSwitch: () -> Unit) {
31 | Row(
32 | modifier = Modifier.fillMaxWidth(),
33 | horizontalArrangement = Arrangement.SpaceBetween,
34 | verticalAlignment = Alignment.CenterVertically
35 | ) {
36 | Text(
37 | modifier = Modifier.padding(top = 40.dp, start = 16.dp, end = 16.dp, bottom = 16.dp),
38 | text = stringResource(id = titleResource),
39 | style = categoryTitleStyle
40 | )
41 | Box(modifier = Modifier.padding(top = 24.dp, end = 8.dp)) {
42 | ThemeSwitcher(onThemeSwitch = {
43 | onThemeSwitch()
44 | })
45 | }
46 | }
47 | }
48 |
49 | @Composable
50 | fun ThemeSwitcher(onThemeSwitch: () -> Unit) {
51 | val isDark = remember { mutableStateOf(false) }
52 | @DrawableRes val light = R.drawable.ic_light
53 | @DrawableRes val dark = R.drawable.ic_dark
54 | IconButton(onClick = {
55 | onThemeSwitch()
56 | isDark.value = !isDark.value
57 | }) {
58 | Icon(
59 | painter = if (isDark.value) painterResource(light) else painterResource(dark),
60 | contentDescription = "Theme Switcher",
61 | tint = Color.White
62 | )
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/data/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'kotlin-kapt'
5 | apply plugin: 'dagger.hilt.android.plugin'
6 |
7 | android {
8 | compileSdkVersion 31
9 |
10 | defaultConfig {
11 | minSdkVersion 21
12 | targetSdkVersion 29
13 | versionCode 1
14 | versionName "1.0"
15 | Properties properties = new Properties()
16 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
17 | def apiKey = properties.getProperty("api_key")
18 | buildConfigField("String", "API_KEY", apiKey)
19 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
20 | consumerProguardFiles "consumer-rules.pro"
21 | }
22 |
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 | compileOptions {
30 | sourceCompatibility JavaVersion.VERSION_1_8
31 | targetCompatibility JavaVersion.VERSION_1_8
32 | }
33 | kotlinOptions {
34 | jvmTarget = '1.8'
35 | }
36 | }
37 |
38 | dependencies {
39 | implementation fileTree(dir: "libs", include: ["*.jar"])
40 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
41 |
42 | /* ---------------------Kotlin-coroutines---------------------------*/
43 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
44 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
45 |
46 | /*---------------------Network and Moshi----------------------------*/
47 | implementation 'com.squareup.retrofit2:retrofit:2.7.0'
48 | implementation 'com.squareup.okhttp3:okhttp:4.2.1'
49 | implementation 'com.squareup.retrofit2:converter-moshi:2.6.2'
50 | implementation 'com.squareup.moshi:moshi:1.12.0'
51 | kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.12.0'
52 |
53 | /*----------------------Dagger-Hilt---------------------------------*/
54 | implementation "com.google.dagger:hilt-android:$hilt_version"
55 | kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
56 |
57 | testImplementation 'junit:junit:4.13'
58 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
59 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
60 |
61 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/util/CustomTabUtil.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.util
2 |
3 | import android.content.Context
4 | import android.net.Uri
5 | import androidx.browser.customtabs.CustomTabsIntent
6 | import androidx.core.content.ContextCompat
7 | import com.akash.newzz_compose.R
8 |
9 | /**
10 | * Created by Akash on 29/08/20
11 | */
12 | object CustomTabUtil {
13 |
14 | private var builder: CustomTabsIntent? = null
15 | private var builderDark: CustomTabsIntent? = null
16 |
17 | fun launch(context: Context, url: String, isDark: Boolean) {
18 | if (isDark) {
19 | if (builderDark == null) {
20 | builderDark = CustomTabsIntent.Builder()
21 | .setToolbarColor(
22 | ContextCompat.getColor(context, R.color.darkTheme)
23 | )
24 | .setShowTitle(true)
25 | .setStartAnimations(
26 | context,
27 | R.anim.slide_in_right,
28 | R.anim.slide_out_left
29 | )
30 | .setExitAnimations(
31 | context,
32 | android.R.anim.slide_in_left,
33 | android.R.anim.slide_out_right
34 | )
35 | .build()
36 | }
37 | builderDark?.launchUrl(context, Uri.parse(url))
38 | } else {
39 | if (builder == null) {
40 | builder = CustomTabsIntent.Builder()
41 | .setToolbarColor(
42 | ContextCompat.getColor(context, R.color.lightTheme)
43 | )
44 | .setShowTitle(true)
45 | .setStartAnimations(
46 | context,
47 | R.anim.slide_in_right,
48 | R.anim.slide_out_left
49 | )
50 | .setExitAnimations(
51 | context,
52 | android.R.anim.slide_in_left,
53 | android.R.anim.slide_out_right
54 | )
55 | .build()
56 | }
57 | builder?.launchUrl(context, Uri.parse(url))
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/ui/style/Theme.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.ui.style
2 |
3 | import androidx.compose.material.MaterialTheme
4 | import androidx.compose.material.darkColors
5 | import androidx.compose.material.lightColors
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.ui.graphics.Color
8 |
9 | /**
10 | * Created by Akash on 28/08/20
11 | */
12 | val deepPurple = Color(0xFF4a148c)
13 | val darkColor = Color(0xFF121212)
14 |
15 | val sourceTextColor = Color(0xFF474646)
16 | val sourceTextColorDark = Color(0xFF868080)
17 |
18 | val titleColor = Color.Black
19 | val titleColorDark = Color(0xB3DCDCDC)
20 |
21 | val listBackgroundColor = Color.White
22 | val listBackgroundColorDark = Color(0xFF1E1E1E)
23 |
24 | val bottomNavBackground = Color.White
25 | val bottomNavBackgroundDark = Color(0xFF222222)
26 |
27 | val bottomNavIconActiveColor = Color(0xFF4a148c)
28 | val bottomNavIconInActiveColor = Color.Black
29 |
30 | val bottomNavIconActiveColorDark = Color(0xB3DCDCDC)
31 | val bottomNavIconInActiveColorDark = Color(0xFF5C5757)
32 |
33 | val circularLoaderColor = deepPurple
34 | val circularLoaderColorDark = Color.White
35 |
36 | val dividerColor = Color(0xFFDCDCDC)
37 | val dividerColorDark = Color(0xFF2B2929)
38 |
39 | private val lightTheme = lightColors(
40 | primary = deepPurple,
41 | onPrimary = Color.White,
42 | primaryVariant = deepPurple,
43 | surface = listBackgroundColor,
44 | onSurface = titleColor,
45 | secondary = sourceTextColor,
46 | onSecondary = Color.White,
47 | background = listBackgroundColor,
48 | onBackground = titleColor,
49 | secondaryVariant = deepPurple,
50 | error = Color.Black,
51 | onError = Color.White
52 | )
53 |
54 | private val darkTheme = darkColors(
55 | primary = darkColor,
56 | onPrimary = Color.White,
57 | primaryVariant = darkColor,
58 | surface = listBackgroundColorDark,
59 | onSurface = titleColorDark,
60 | secondary = sourceTextColorDark,
61 | onSecondary = Color.White,
62 | background = listBackgroundColorDark,
63 | onBackground = titleColorDark,
64 | secondaryVariant = darkColor,
65 | error = Color.White,
66 | onError = Color.Black
67 | )
68 |
69 | @Composable
70 | fun NewzzTheme(
71 | isDarkTheme: Boolean,
72 | content: @Composable () -> Unit,
73 | ) {
74 | val colors = if (isDarkTheme) darkTheme else lightTheme
75 | MaterialTheme(
76 | colors = colors,
77 | content = content
78 | )
79 | }
80 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/ui/newzzappui/NewzzAppUI.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.ui.newzzappui
2 |
3 | import androidx.compose.foundation.layout.Column
4 | import androidx.compose.foundation.layout.fillMaxSize
5 | import androidx.compose.material.MaterialTheme
6 | import androidx.compose.material.Scaffold
7 | import androidx.compose.material.Surface
8 | import androidx.compose.runtime.Composable
9 | import androidx.compose.runtime.livedata.observeAsState
10 | import androidx.compose.ui.Modifier
11 | import com.akash.newzz_compose.other.Category
12 | import com.akash.newzz_compose.other.getTitleResource
13 | import com.akash.newzz_compose.viewmodel.NewzzViewModel
14 |
15 | /**
16 | * Created by Akash on 28/08/20
17 | */
18 |
19 | @Composable
20 | fun NewzzAppUI(viewModel: NewzzViewModel) {
21 | val categoryList = viewModel.categoryList.observeAsState().value!!
22 | val activeCategory = viewModel.activeCategory.observeAsState().value!!
23 | val uiState = viewModel.activeCategoryUiState.observeAsState().value!!
24 |
25 | Scaffold(
26 | content = {
27 | BodyContent(
28 | activeCategory = activeCategory,
29 | activeCategoryUiState = uiState,
30 | onThemeSwitch = {
31 | viewModel.performAction(NewzzViewModel.Action.SwitchTheme)
32 | },
33 | retryFetchingArticles = { category ->
34 | viewModel.performAction(NewzzViewModel.Action.FetchArticles(category))
35 | }
36 | )
37 | },
38 | bottomBar = {
39 | BottomBar(
40 | categoryList = categoryList,
41 | onMenuClicked = { category ->
42 | viewModel.performAction(NewzzViewModel.Action.ChangePageTo(category))
43 | },
44 | activeCategory = activeCategory
45 | )
46 | }
47 | )
48 | }
49 |
50 | @Composable
51 | fun BodyContent(
52 | activeCategory: Category,
53 | activeCategoryUiState: ArticleListUiState,
54 | onThemeSwitch: () -> Unit,
55 | retryFetchingArticles: (Category) -> Unit
56 | ) {
57 | val stringRes = getTitleResource(activeCategory)
58 | Surface(
59 | modifier = Modifier.fillMaxSize(),
60 | color = MaterialTheme.colors.primary
61 | ) {
62 | Column(modifier = Modifier.fillMaxSize()) {
63 | TopAppBar(stringRes, onThemeSwitch = {
64 | onThemeSwitch()
65 | })
66 | NewzzListContainer(
67 | uiState = activeCategoryUiState,
68 | retry = {
69 | retryFetchingArticles(activeCategory)
70 | }
71 | )
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/ui/commoncomposable/CommonComposables.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.ui.commoncomposable
2 |
3 | import androidx.compose.foundation.Image
4 | import androidx.compose.foundation.layout.Box
5 | import androidx.compose.foundation.layout.Spacer
6 | import androidx.compose.foundation.layout.fillMaxSize
7 | import androidx.compose.foundation.layout.requiredHeight
8 | import androidx.compose.foundation.layout.requiredWidth
9 | import androidx.compose.foundation.shape.RoundedCornerShape
10 | import androidx.compose.material.Icon
11 | import androidx.compose.material.MaterialTheme
12 | import androidx.compose.material.Surface
13 | import androidx.compose.runtime.Composable
14 | import androidx.compose.ui.Modifier
15 | import androidx.compose.ui.graphics.Color
16 | import androidx.compose.ui.graphics.Shape
17 | import androidx.compose.ui.layout.ContentScale
18 | import androidx.compose.ui.res.painterResource
19 | import androidx.compose.ui.unit.Dp
20 | import androidx.compose.ui.unit.dp
21 | import coil.compose.rememberImagePainter
22 | import com.akash.newzz_compose.R
23 | import com.akash.newzz_compose.ui.style.titleColorDark
24 |
25 | /**
26 | * Created by Akash on 29/08/20
27 | */
28 |
29 | @Composable
30 | fun HeightSpacer(value: Dp) {
31 | Spacer(modifier = Modifier.requiredHeight(value))
32 | }
33 |
34 | @Composable
35 | fun WidthSpacer(value: Dp) {
36 | Spacer(modifier = Modifier.requiredWidth(value))
37 | }
38 |
39 | @Composable
40 | fun RemoteImage(
41 | url: String?,
42 | modifier: Modifier,
43 | contentScale: ContentScale = ContentScale.Crop,
44 | shape: Shape = RoundedCornerShape(5.dp)
45 | ) {
46 | Box(
47 | modifier = modifier
48 | ) {
49 | if (url.isNullOrEmpty()) {
50 | Icon(
51 | painter = painterResource(id = R.drawable.ic_newzz_error),
52 | contentDescription = "error image",
53 | tint = if (MaterialTheme.colors.isLight) Color.Black else titleColorDark
54 | )
55 | } else {
56 | Surface(
57 | color = Color.Transparent,
58 | shape = shape
59 | ) {
60 | Image(
61 | painter = rememberImagePainter(
62 | data = url,
63 | onExecute = { _, _ -> true },
64 | builder = {
65 | crossfade(true)
66 | placeholder(R.drawable.ic_newzz_error)
67 | }
68 | ),
69 | contentScale = contentScale,
70 | contentDescription = "article image",
71 | modifier = modifier.fillMaxSize()
72 | )
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/data/src/main/java/com/akash/newzz/data/repository/NewsRepositoryImpl.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data.repository
2 |
3 | import com.akash.newzz.data.Result
4 | import com.akash.newzz.data.apiservice.NewzzApiService
5 | import com.akash.newzz.data.response.NewsError
6 | import com.akash.newzz.data.response.NewsResponse
7 | import com.squareup.moshi.JsonAdapter
8 | import com.squareup.moshi.Moshi
9 | import javax.inject.Inject
10 | import kotlinx.coroutines.Dispatchers
11 | import kotlinx.coroutines.withContext
12 |
13 | /**
14 | * Created by Akash on 06/06/20
15 | */
16 |
17 | class NewsRepositoryImpl @Inject constructor(
18 | private val newsApiService: NewzzApiService,
19 | private val moshi: Moshi
20 | ) : NewsRepository {
21 | private val defaultDispatcher = Dispatchers.Default
22 | private val map = HashMap>()
23 | override suspend fun getArticlesByCategoryAsync(
24 | category: String,
25 | page: Int
26 | ): Result {
27 | if(map.containsKey(category)){
28 | return map[category] as Result
29 | } else {
30 | try {
31 | val response = newsApiService.getArticlesByCateGoryAsync(category)
32 | return if (response.isSuccessful) {
33 | if (response.body() != null) {
34 | map[category] = Result.Success(response.body()!!)
35 | Result.Success(response.body()!!)
36 | } else {
37 | Result.Error("No Data found")
38 | }
39 | } else {
40 | val jsonAdapter: JsonAdapter = moshi.adapter(
41 | NewsError::class.java
42 | )
43 | withContext(defaultDispatcher) {
44 | val newsError = jsonAdapter.fromJson(response.errorBody()?.string()!!)
45 | Result.Error(
46 | newsError!!.message,
47 | showRetry(newsError.code)
48 | )
49 | }
50 | }
51 | } catch (e: Exception) {
52 | e.printStackTrace()
53 | var errorMessage = e.localizedMessage
54 | if (e.localizedMessage!!.contains("Unable to resolve host")) {
55 | errorMessage = "No internet connection"
56 | }
57 | return Result.Error(errorMessage ?: "Something went wrong")
58 | }
59 | }
60 | }
61 |
62 | private fun showRetry(code: String): Boolean = when (code) {
63 | "apiKeyDisabled", "apiKeyExhausted", "apiKeyInvalid", "apiKeyMissing" -> false
64 | else -> true
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/ui/newzzappui/NewzzListContainer.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.ui.newzzappui
2 |
3 | import androidx.compose.foundation.layout.Arrangement
4 | import androidx.compose.foundation.layout.Column
5 | import androidx.compose.foundation.layout.fillMaxSize
6 | import androidx.compose.foundation.layout.padding
7 | import androidx.compose.foundation.shape.RoundedCornerShape
8 | import androidx.compose.material.CircularProgressIndicator
9 | import androidx.compose.material.MaterialTheme
10 | import androidx.compose.material.Surface
11 | import androidx.compose.material.Text
12 | import androidx.compose.material.TextButton
13 | import androidx.compose.runtime.Composable
14 | import androidx.compose.ui.Alignment
15 | import androidx.compose.ui.Modifier
16 | import androidx.compose.ui.res.stringResource
17 | import androidx.compose.ui.text.TextStyle
18 | import androidx.compose.ui.unit.dp
19 | import com.akash.newzz_compose.R
20 | import com.akash.newzz_compose.ui.style.articleTitleStyle
21 |
22 | /**
23 | * Created by Akash on 29/08/20
24 | */
25 |
26 | @Composable
27 | fun NewzzListContainer(
28 | uiState: ArticleListUiState,
29 | retry: () -> Unit
30 | ) {
31 | Surface(
32 | color = MaterialTheme.colors.background,
33 | shape = RoundedCornerShape(topStart = 5.dp, topEnd = 5.dp),
34 | modifier = Modifier
35 | .fillMaxSize()
36 | .padding(
37 | start = 10.dp,
38 | end = 10.dp,
39 | bottom = 50.dp
40 | )
41 | ) {
42 | when {
43 | uiState.isLoading -> {
44 | CircularLoader()
45 | }
46 | uiState.error != null -> {
47 | ErrorView(
48 | errorMessage = uiState.error.errorMessage,
49 | showRetry = uiState.error.showRetry,
50 | retry = retry
51 | )
52 | }
53 | uiState.list?.isEmpty() == false -> {
54 | ArticleList(
55 | articles = uiState.list
56 | )
57 | }
58 | }
59 | }
60 | }
61 |
62 | @Composable
63 | private fun CircularLoader() {
64 | Column(
65 | verticalArrangement = Arrangement.Center,
66 | horizontalAlignment = Alignment.CenterHorizontally
67 | ) {
68 | CircularProgressIndicator(
69 | color = MaterialTheme.colors.primary
70 | )
71 | }
72 | }
73 |
74 | @Composable
75 | fun ErrorView(
76 | errorMessage: String,
77 | showRetry: Boolean,
78 | retry: () -> Unit
79 | ) {
80 | Column(
81 | verticalArrangement = Arrangement.Center,
82 | horizontalAlignment = Alignment.CenterHorizontally
83 | ) {
84 | Text(
85 | text = errorMessage,
86 | style = articleTitleStyle.copy(color = MaterialTheme.colors.onSurface)
87 | )
88 | if (showRetry) {
89 | TextButton(onClick = retry) {
90 | Text(
91 | text = stringResource(id = R.string.retry),
92 | style = TextStyle(
93 | color = MaterialTheme.colors.onSurface
94 | )
95 | )
96 | }
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/ui/newzzappui/ArticleList.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.ui.newzzappui
2 |
3 | import androidx.compose.foundation.clickable
4 | import androidx.compose.foundation.layout.Column
5 | import androidx.compose.foundation.layout.Row
6 | import androidx.compose.foundation.layout.padding
7 | import androidx.compose.foundation.layout.requiredSize
8 | import androidx.compose.foundation.lazy.LazyColumn
9 | import androidx.compose.foundation.lazy.items
10 | import androidx.compose.material.Divider
11 | import androidx.compose.material.MaterialTheme
12 | import androidx.compose.material.Text
13 | import androidx.compose.runtime.Composable
14 | import androidx.compose.ui.Alignment
15 | import androidx.compose.ui.Modifier
16 | import androidx.compose.ui.platform.LocalContext
17 | import androidx.compose.ui.text.style.TextOverflow
18 | import androidx.compose.ui.unit.dp
19 | import com.akash.newzz.data.response.NewsArticle
20 | import com.akash.newzz_compose.ui.commoncomposable.HeightSpacer
21 | import com.akash.newzz_compose.ui.commoncomposable.RemoteImage
22 | import com.akash.newzz_compose.ui.commoncomposable.WidthSpacer
23 | import com.akash.newzz_compose.ui.style.articleTitleStyle
24 | import com.akash.newzz_compose.ui.style.dateTextStyle
25 | import com.akash.newzz_compose.ui.style.sourceTextStyle
26 | import com.akash.newzz_compose.util.CustomTabUtil
27 |
28 | /**
29 | * Created by Akash on 29/08/20
30 | */
31 |
32 | @Composable
33 | fun ArticleRow(article: NewsArticle, onClick: () -> Unit) {
34 | Column(modifier = Modifier.clickable(onClick = { onClick() })) {
35 | Row(
36 | modifier = Modifier.padding(all = 10.dp),
37 | verticalAlignment = Alignment.CenterVertically
38 | ) {
39 | RemoteImage(
40 | url = article.urlToImage,
41 | modifier = Modifier.requiredSize(100.dp)
42 | )
43 | WidthSpacer(value = 10.dp)
44 | Column {
45 | if (!article.source.name.isNullOrEmpty()) {
46 | Text(
47 | text = article.source.name!!,
48 | style = sourceTextStyle.copy(color = MaterialTheme.colors.secondary)
49 | )
50 | HeightSpacer(value = 4.dp)
51 | }
52 | Text(
53 | text = article.title,
54 | style = articleTitleStyle.copy(color = MaterialTheme.colors.onSurface),
55 | maxLines = 3,
56 | overflow = TextOverflow.Ellipsis
57 | )
58 | HeightSpacer(value = 4.dp)
59 | Text(
60 | text = article.publishedAt.substring(0, 10),
61 | style = dateTextStyle.copy(color = MaterialTheme.colors.secondary)
62 | )
63 | }
64 | }
65 | HeightSpacer(value = 10.dp)
66 | Divider(
67 | color = MaterialTheme.colors.secondary.copy(
68 | alpha = 0.2f
69 | )
70 | )
71 | }
72 | }
73 |
74 | @Composable
75 | fun ArticleList(articles: List) {
76 | val context = LocalContext.current
77 | val isDark = MaterialTheme.colors.isLight
78 | LazyColumn {
79 | items(articles) { article ->
80 | ArticleRow(
81 | article = article,
82 | onClick = {
83 | CustomTabUtil.launch(context, article.url.toString(), isDark)
84 | }
85 | )
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'kotlin-kapt'
5 | apply plugin: 'dagger.hilt.android.plugin'
6 |
7 |
8 | android {
9 | compileSdkVersion 31
10 |
11 | defaultConfig {
12 | applicationId "com.akash.newzzcompose"
13 | minSdkVersion 21
14 | targetSdkVersion 29
15 | versionCode 4
16 | versionName "0.0.4"
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled true
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_1_8
28 | targetCompatibility JavaVersion.VERSION_1_8
29 | }
30 | kotlinOptions {
31 | jvmTarget = '1.8'
32 | useIR = true
33 | }
34 | buildFeatures {
35 | compose true
36 | }
37 |
38 | composeOptions {
39 | kotlinCompilerVersion "$kotlin_version"
40 | kotlinCompilerExtensionVersion "$compose_version"
41 | }
42 | }
43 |
44 | dependencies {
45 | implementation fileTree(dir: "libs", include: ["*.jar"])
46 | implementation project(':data')
47 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
48 | implementation 'androidx.core:core-ktx:1.3.1'
49 | implementation 'androidx.appcompat:appcompat:1.2.0'
50 | implementation "androidx.activity:activity-ktx:1.1.0"
51 | implementation 'android.arch.lifecycle:extensions:1.1.1'
52 |
53 | /* ---------------------JetPack Compose-----------------------------*/
54 | implementation "androidx.activity:activity-compose:1.4.0"
55 | implementation("androidx.compose.runtime:runtime:$compose_version")
56 | implementation("androidx.compose.runtime:runtime-livedata:$compose_version")
57 | implementation("androidx.compose.foundation:foundation:$compose_version")
58 | implementation("androidx.compose.foundation:foundation-layout:$compose_version")
59 |
60 | implementation("androidx.compose.ui:ui:$compose_version")
61 | implementation("androidx.compose.material:material:$compose_version")
62 | implementation("androidx.compose.material:material-icons-extended:$compose_version")
63 | implementation("io.coil-kt:coil-compose:1.4.0")
64 |
65 | debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
66 | implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
67 |
68 |
69 | /* ---------------------LifeCycle Extension-----------------------------*/
70 | implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
71 |
72 | /*------------------------Dagger Hilt----------------------------------*/
73 | implementation "com.google.dagger:hilt-android:$hilt_version"
74 | kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
75 |
76 | implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_jetpack_config_version"
77 | kapt "androidx.hilt:hilt-compiler:$hilt_jetpack_config_version"
78 |
79 | /*---------------------ChromeCustomTab------------------------------*/
80 | implementation 'androidx.browser:browser:1.3.0-alpha05'
81 |
82 | /*---------------------CoilImageLoader------------------------------*/
83 | implementation "dev.chrisbanes.accompanist:accompanist-coil:0.2.1"
84 |
85 | /*----------------------------Moshi-------------------------------------*/
86 | implementation 'com.squareup.moshi:moshi:1.9.1'
87 |
88 |
89 | testImplementation 'junit:junit:4.13'
90 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
91 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
92 |
93 | }
--------------------------------------------------------------------------------
/data/src/main/java/com/akash/newzz/data/apiservice/NewzzApiService.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz.data.apiservice
2 |
3 | import com.akash.newzz.data.BaseApplication
4 | import com.akash.newzz.data.Constants
5 | import com.akash.newzz.data.response.NewsResponse
6 | import java.io.File
7 | import java.util.concurrent.TimeUnit
8 | import okhttp3.Cache
9 | import okhttp3.CacheControl
10 | import okhttp3.Interceptor
11 | import okhttp3.OkHttpClient
12 | import retrofit2.Response
13 | import retrofit2.Retrofit
14 | import retrofit2.converter.moshi.MoshiConverterFactory
15 | import retrofit2.http.GET
16 | import retrofit2.http.Query
17 |
18 | /**
19 | * Created by Akash on 02/07/20
20 | */
21 | interface NewzzApiService {
22 | @GET("top-headlines?sortBy=publishedAt&pageSize=50")
23 | suspend fun getArticlesByCateGoryAsync(
24 | @Query("category") category: String,
25 | @Query("country") country: String = Constants.COUNTRY
26 | ): Response
27 |
28 | companion object {
29 |
30 | private const val HEADER_CACHE_CONTROL = "Cache-Control"
31 | private const val HEADER_PRAGMA = "Pragma"
32 | private const val cacheSize = (5 * 1024 * 1024).toLong() // 5 MB
33 |
34 | operator fun invoke(): NewzzApiService {
35 | val requestInterceptor = Interceptor { chain ->
36 |
37 | val response = chain.proceed(chain.request())
38 |
39 | val cacheControl = CacheControl.Builder()
40 | .maxAge(5, TimeUnit.SECONDS)
41 | .build()
42 |
43 | return@Interceptor response.newBuilder()
44 | .removeHeader(HEADER_PRAGMA)
45 | .removeHeader(HEADER_CACHE_CONTROL)
46 | .header(HEADER_CACHE_CONTROL, cacheControl.toString())
47 | .build()
48 | }
49 |
50 | val cache = Cache(
51 | File(BaseApplication.instances.cacheDir, "networkCache"),
52 | cacheSize
53 | )
54 |
55 | val offlineInterceptor = Interceptor { chain ->
56 |
57 | val url = chain.request()
58 | .url
59 | .newBuilder()
60 | .addQueryParameter("apiKey", Constants.API_KEY)
61 | .build()
62 |
63 | var request = chain.request()
64 |
65 | if (BaseApplication.isNetworkConnected()) {
66 |
67 | request = request
68 | .newBuilder()
69 | .url(url)
70 | .build()
71 | } else {
72 |
73 | val cacheControl = CacheControl.Builder()
74 | .maxStale(7, TimeUnit.DAYS)
75 | .build()
76 |
77 | request = request
78 | .newBuilder()
79 | .url(url)
80 | .removeHeader(HEADER_PRAGMA)
81 | .removeHeader(HEADER_CACHE_CONTROL)
82 | .cacheControl(cacheControl)
83 | .build()
84 | }
85 |
86 | return@Interceptor chain.proceed(request)
87 | }
88 |
89 | val okHttpClient = OkHttpClient.Builder()
90 | .cache(cache)
91 | .addInterceptor(offlineInterceptor)
92 | .addNetworkInterceptor(requestInterceptor)
93 | .build()
94 |
95 | return Retrofit.Builder()
96 | .baseUrl("https://newsapi.org/v2/")
97 | .client(okHttpClient)
98 | .addConverterFactory(MoshiConverterFactory.create())
99 | .build()
100 | .create(NewzzApiService::class.java)
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_business.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akash/newzz_compose/viewmodel/NewzzViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.akash.newzz_compose.viewmodel
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.MutableLiveData
5 | import androidx.lifecycle.ViewModel
6 | import androidx.lifecycle.viewModelScope
7 | import com.akash.newzz.data.Result
8 | import com.akash.newzz.data.repository.NewsRepository
9 | import com.akash.newzz.data.response.NewsResponse
10 | import com.akash.newzz_compose.other.Business
11 | import com.akash.newzz_compose.other.Category
12 | import com.akash.newzz_compose.other.General
13 | import com.akash.newzz_compose.other.Technology
14 | import com.akash.newzz_compose.ui.newzzappui.ArticleListUiState
15 | import dagger.hilt.android.lifecycle.HiltViewModel
16 | import javax.inject.Inject
17 | import kotlinx.coroutines.Dispatchers
18 | import kotlinx.coroutines.launch
19 | import kotlinx.coroutines.withContext
20 |
21 | /**
22 | * Created by Akash on 28/08/20
23 | */
24 | @HiltViewModel
25 | class NewzzViewModel @Inject constructor(private val repo: NewsRepository) : ViewModel() {
26 |
27 | private val _isDarkTheme = MutableLiveData().apply { value = false }
28 | val isDarkTheme: LiveData = _isDarkTheme
29 |
30 | private val _categoryList = MutableLiveData>().apply {
31 | value = listOf(General(), Business(), Technology())
32 | }
33 | val categoryList: LiveData> = _categoryList
34 |
35 | private val _activeCategory = MutableLiveData().apply {
36 | value = categoryList.value!![0]
37 | }
38 | val activeCategory: LiveData = _activeCategory
39 |
40 | private val _activeCategoryUiState = MutableLiveData().apply {
41 | value = ArticleListUiState()
42 | }
43 | val activeCategoryUiState: LiveData = _activeCategoryUiState
44 |
45 | init {
46 | getArticlesByCategory(categoryList.value!![0])
47 | }
48 |
49 | private fun getArticlesByCategory(
50 | category: Category,
51 | page: Int = 1
52 | ) {
53 | viewModelScope.launch {
54 | val activeState = ArticleListUiState()
55 | setLoadingState(activeState)
56 | when (val result = repo.getArticlesByCategoryAsync(category.category, page)) {
57 | is Result.Error -> {
58 | withContext(Dispatchers.Main) {
59 | setErrorState(
60 | activeState,
61 | Result.Error(result.errorMessage, result.showRetry)
62 | )
63 | }
64 | }
65 | is Result.Success -> {
66 | withContext(Dispatchers.Main) {
67 | setSuccessState(activeState, result.data)
68 | }
69 | }
70 | }
71 | }
72 | }
73 |
74 | fun performAction(action: Action) {
75 | when (action) {
76 | is Action.ChangePageTo -> {
77 | _activeCategory.value = action.category
78 | getArticlesByCategory(_activeCategory.value!!)
79 | }
80 | is Action.FetchArticles -> {
81 | getArticlesByCategory(action.category)
82 | }
83 | Action.SwitchTheme -> {
84 | _isDarkTheme.value = !_isDarkTheme.value!!
85 | }
86 | }
87 | }
88 |
89 | private fun setErrorState(activeState: ArticleListUiState, error: Result.Error) {
90 | _activeCategoryUiState.value = activeState.copy(
91 | isLoading = false,
92 | list = null,
93 | error = error
94 | )
95 | }
96 |
97 | private fun setSuccessState(activeState: ArticleListUiState, data: NewsResponse) {
98 | _activeCategoryUiState.value = activeState.copy(
99 | isLoading = false,
100 | list = data.articles,
101 | error = null
102 | )
103 | }
104 |
105 | private fun setLoadingState(activeState: ArticleListUiState) {
106 | _activeCategoryUiState.value = activeState.copy(isLoading = true)
107 | }
108 |
109 | sealed class Action {
110 | data class ChangePageTo(val category: Category) : Action()
111 | data class FetchArticles(val category: Category) : Action()
112 | object SwitchTheme : Action()
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------