Skip to content

Commit 6ee851f

Browse files
Initial commit
1 parent 79535cb commit 6ee851f

File tree

86 files changed

+3054
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3054
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
apply plugin: 'com.android.library'
2+
3+
apply plugin: 'kotlin-android'
4+
apply plugin: 'kotlin-android-extensions'
5+
apply plugin: 'kotlin-kapt'
6+
7+
android {
8+
compileSdkVersion 28
9+
defaultConfig {
10+
minSdkVersion 19
11+
targetSdkVersion 28
12+
versionCode 1
13+
versionName "1.0.0"
14+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15+
kapt {
16+
arguments {
17+
arg("room.schemaLocation", "$projectDir/schemas".toString())
18+
}
19+
}
20+
}
21+
buildTypes {
22+
release {
23+
minifyEnabled false
24+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25+
}
26+
}
27+
28+
compileOptions {
29+
sourceCompatibility JavaVersion.VERSION_1_8
30+
targetCompatibility JavaVersion.VERSION_1_8
31+
}
32+
33+
testOptions {
34+
unitTests {
35+
includeAndroidResources = true
36+
returnDefaultValues = true
37+
}
38+
}
39+
40+
// add the schema location to the source sets
41+
// used by Room, to test migrations
42+
sourceSets {
43+
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
44+
}
45+
}
46+
47+
dependencies {
48+
implementation fileTree(dir: 'libs', include: ['*.jar'])
49+
50+
implementation "androidx.appcompat:appcompat:$rootProject.compatVersion"
51+
52+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$rootProject.kotlinVersion"
53+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutinesVersion"
54+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutinesVersion"
55+
56+
implementation "com.squareup.okhttp3:okhttp:$rootProject.okhttpVersion"
57+
implementation 'commons-codec:commons-codec:1.10'
58+
implementation "com.google.code.gson:gson:$rootProject.gsonVersion"
59+
implementation 'com.airbnb.android:lottie:2.5.4'
60+
61+
implementation "androidx.legacy:legacy-support-v4:$rootProject.legacySupportVersion"
62+
implementation "androidx.cardview:cardview:$rootProject.cardViewVersion"
63+
implementation "androidx.recyclerview:recyclerview:$rootProject.recyclerViewVersion"
64+
implementation "androidx.palette:palette:$rootProject.paletteVersion"
65+
implementation "com.google.android.material:material:$rootProject.materialVersion"
66+
67+
testImplementation "junit:junit:$rootProject.junitVersion"
68+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.theblissprogrammer.kotlin.common
2+
3+
import androidx.test.InstrumentationRegistry
4+
import androidx.test.runner.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getTargetContext()
22+
assertEquals("com.theblissprogrammer.kotlin.common", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.theblissprogrammer.kotlin.common">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
7+
8+
<application android:networkSecurityConfig="@xml/network_security_config"/>
9+
</manifest>

app/src/main/assets/loading.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.theblissprogrammer.kotlin.common.common
2+
3+
import androidx.lifecycle.LiveData
4+
import com.theblissprogrammer.kotlin.common.errors.DataError
5+
import com.theblissprogrammer.kotlin.common.errors.NetworkError
6+
import kotlinx.coroutines.Deferred
7+
8+
/**
9+
* Created by ahmedsaad on 2019-01-14.
10+
* Copyright © 2019. All rights reserved.
11+
*/
12+
13+
data class Result<T>(val isSuccess: Boolean = false, val value: T? = null, val error: DataError? = null) {
14+
companion object {
15+
fun <T>success(value: T? = null): Result<T> {
16+
return Result(true, value, null)
17+
}
18+
19+
fun <T>failure(error: DataError? = null): Result<T> {
20+
return Result(false, null, error)
21+
}
22+
}
23+
}
24+
25+
data class NetworkResult<T>(val isSuccess: Boolean = false, val value: T? = null, val error: NetworkError? = null) {
26+
companion object {
27+
fun <T>success(value: T? = null): NetworkResult<T> {
28+
return NetworkResult(true, value, null)
29+
}
30+
31+
fun <T>failure(error: NetworkError? = null): NetworkResult<T> {
32+
return NetworkResult(false, null, error)
33+
}
34+
}
35+
}
36+
37+
data class LiveResult<T>(val isSuccess: Boolean = false, val value: LiveData<T>? = null, val error: DataError? = null) {
38+
companion object {
39+
fun <T>success(value: LiveData<T>? = null): LiveResult<T> {
40+
return LiveResult(true, value, null)
41+
}
42+
43+
fun <T>failure(error: DataError? = null): LiveResult<T> {
44+
return LiveResult(false, null, error)
45+
}
46+
}
47+
}
48+
49+
typealias SuspendCompletionResponse<T> = suspend (Result<T>) -> Unit
50+
typealias CompletionResponse<T> = (Result<T>) -> Unit
51+
typealias LiveCompletionResponse<T> = (LiveResult<T>) -> Unit
52+
typealias DeferredLiveResult<T> = Deferred<LiveResult<T>>
53+
typealias DeferredResult<T> = Deferred<Result<T>>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.theblissprogrammer.kotlin.common.common
2+
3+
import com.theblissprogrammer.kotlin.common.errors.DataError
4+
import com.theblissprogrammer.kotlin.common.errors.NetworkError
5+
6+
7+
/**
8+
* Created by ahmedsaad on 2019-01-14.
9+
* Copyright © 2019. All rights reserved.
10+
*/
11+
12+
class NoInternetException: Exception()
13+
14+
fun initDataError(error: NetworkError?): DataError {
15+
// Handle no internet
16+
if (error?.internalError is NoInternetException) {
17+
return DataError.NoInternet
18+
}
19+
20+
// Handle by status code
21+
return when (error?.statusCode) {
22+
400 -> DataError.NetworkFailure(error)
23+
401 -> DataError.Unauthorized
24+
403 -> DataError.Forbidden
25+
else -> DataError.Other(error?.fieldErrors ?: mutableMapOf())
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.theblissprogrammer.kotlin.common.common
2+
3+
import android.content.Context
4+
import android.net.ConnectivityManager
5+
6+
7+
/**
8+
* Created by ahmedsaad on 2019-01-14.
9+
* Copyright © 2019. All rights reserved.
10+
*/
11+
12+
fun isNetworkAvailable(context: Context?): Boolean {
13+
if (context == null)
14+
return false
15+
16+
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
17+
val activeNetworkInfo = connectivityManager.activeNetworkInfo
18+
return activeNetworkInfo != null && activeNetworkInfo.isConnected
19+
}

0 commit comments

Comments
 (0)