-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- finished
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
plugins { | ||
id("com.android.application") | ||
id("org.jetbrains.kotlin.android") | ||
id("com.google.devtools.ksp") | ||
id("dagger.hilt.android.plugin") | ||
} | ||
|
||
android { | ||
|
||
namespace = "sample.latest.news" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
applicationId = "sample.latest.news" | ||
minSdk = 24 | ||
targetSdk = 34 | ||
versionCode = 1 | ||
versionName = "1.0.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
vectorDrawables { | ||
useSupportLibrary = true | ||
} | ||
multiDexEnabled = true | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = true | ||
isShrinkResources = true | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
debug { | ||
applicationIdSuffix = ".debug" | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_17.toString() | ||
} | ||
|
||
buildFeatures { | ||
buildConfig = true | ||
compose = true | ||
} | ||
|
||
composeOptions { | ||
kotlinCompilerExtensionVersion = "1.5.3" | ||
} | ||
|
||
packaging { | ||
resources { | ||
excludes += "/META-INF/{AL2.0,LGPL2.1}" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
// Compose | ||
implementation(platform("androidx.compose:compose-bom:2023.10.01")) | ||
implementation("androidx.compose.ui:ui") | ||
implementation("androidx.compose.ui:ui-graphics") | ||
implementation("androidx.compose.ui:ui-tooling-preview") | ||
implementation("androidx.compose.material3:material3") | ||
implementation("androidx.compose.material:material") | ||
implementation("androidx.compose.foundation:foundation") | ||
implementation("androidx.compose.ui:ui-util") | ||
|
||
implementation("androidx.activity:activity-compose:1.8.1") | ||
implementation("androidx.navigation:navigation-compose:2.7.5") | ||
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2") | ||
|
||
// Hilt | ||
implementation("com.google.dagger:hilt-android:2.48.1") | ||
ksp("com.google.dagger:hilt-android-compiler:2.48.1") | ||
implementation("androidx.hilt:hilt-navigation-compose:1.1.0") | ||
|
||
// Architecture Components | ||
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") | ||
|
||
// Retrofit | ||
val retrofit = "2.9.0" | ||
implementation("com.squareup.retrofit2:retrofit:$retrofit") | ||
implementation("com.squareup.retrofit2:converter-moshi:$retrofit") | ||
|
||
// Okhttp | ||
implementation(platform("com.squareup.okhttp3:okhttp-bom:5.0.0-alpha.11")) | ||
implementation("com.squareup.okhttp3:okhttp") | ||
implementation("com.squareup.okhttp3:logging-interceptor") | ||
|
||
// Moshi Kotlin | ||
val moshi = "1.15.0" | ||
implementation("com.squareup.moshi:moshi-kotlin:$moshi") | ||
ksp("com.squareup.moshi:moshi-kotlin-codegen:$moshi") | ||
|
||
// Coroutine | ||
val coroutines = "1.7.3" | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines") | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines") | ||
|
||
// Coil | ||
implementation("io.coil-kt:coil-compose:2.5.0") | ||
|
||
// Room | ||
val room = "2.6.0" | ||
implementation("androidx.room:room-runtime:$room") | ||
ksp("androidx.room:room-compiler:$room") | ||
implementation("androidx.room:room-ktx:$room") | ||
|
||
// Preferences DataStore | ||
implementation("androidx.datastore:datastore-preferences:1.0.0") | ||
|
||
// KTX | ||
implementation("androidx.core:core-ktx:1.12.0") | ||
|
||
// Multidex | ||
implementation("androidx.multidex:multidex:2.0.1") | ||
|
||
// Splash | ||
implementation("androidx.core:core-splashscreen:1.0.1") | ||
|
||
// Test | ||
testImplementation("junit:junit:4.13.2") | ||
androidTestImplementation("androidx.test.ext:junit:1.1.5") | ||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") | ||
androidTestImplementation(platform("androidx.compose:compose-bom:2023.10.01")) | ||
androidTestImplementation("androidx.compose.ui:ui-test-junit4") | ||
debugImplementation("androidx.compose.ui:ui-tooling") | ||
debugImplementation("androidx.compose.ui:ui-test-manifest") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package sample.latest.news | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("sample.latest.news", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:name=".features.App" | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.App.Starting" | ||
android:usesCleartextTraffic="true" | ||
tools:targetApi="31"> | ||
|
||
<activity | ||
android:name=".features.main.ui.MainActivity" | ||
android:exported="true" | ||
android:screenOrientation="portrait" | ||
android:windowSoftInputMode="adjustResize" | ||
tools:ignore="LockedOrientationActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package sample.latest.news.core.api | ||
|
||
sealed class ApiResult<out T> { | ||
|
||
data class Success<out T>(val data: T) : ApiResult<T>() | ||
|
||
data class Error<out T>(val exception: Exceptions, val data: T? = null) : ApiResult<T>() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sample.latest.news.core.api | ||
|
||
import android.util.Log | ||
import org.json.JSONObject | ||
import sample.latest.news.core.model.AppError | ||
|
||
/** | ||
* Wrap a suspending API [call] in try/catch. In case an exception is thrown, a [ApiResult.Error] is | ||
* created based on the [errorMessage]. | ||
*/ | ||
suspend fun <T : Any> safeApiCall( | ||
call: suspend () -> ApiResult<T>, | ||
errorMessage: String | ||
): ApiResult<T> { | ||
return try { | ||
call() | ||
} catch (e: Exception) { | ||
// An exception was thrown when calling the API so we're converting this to an IOException | ||
Log.d("IOException", e.message.toString()) | ||
ApiResult.Error(Exceptions.IOException(errorMessage, e)) | ||
} | ||
} | ||
|
||
fun errorParser(errorBody: String?): AppError { | ||
|
||
return if (errorBody != null) { | ||
|
||
val errorBodyObject = JSONObject(errorBody) | ||
|
||
val message = errorBodyObject.getString("message").toString() | ||
|
||
AppError(message = message) | ||
|
||
} else { | ||
AppError() | ||
} | ||
} |