Skip to content

Commit ee0312c

Browse files
Abhijit ChakraAbhijit Chakra
Abhijit Chakra
authored and
Abhijit Chakra
committed
git cache cleared
1 parent c00449f commit ee0312c

File tree

56 files changed

+1499
-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.

56 files changed

+1499
-0
lines changed

Android_Clean_Arc_Components.iml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id="Android_Clean_Arc_Components" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="java-gradle" name="Java-Gradle">
5+
<configuration>
6+
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
<option name="BUILDABLE" value="false" />
8+
</configuration>
9+
</facet>
10+
</component>
11+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
12+
<exclude-output />
13+
<content url="file://$MODULE_DIR$">
14+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
15+
</content>
16+
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
17+
<orderEntry type="sourceFolder" forTests="false" />
18+
</component>
19+
</module>

app/.gitignore

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

app/app.iml

Lines changed: 215 additions & 0 deletions
Large diffs are not rendered by default.

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.application'
2+
3+
apply plugin: 'kotlin-android'
4+
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
android {
8+
compileSdkVersion 28
9+
defaultConfig {
10+
applicationId "com.example.android_clean_arc_components"
11+
minSdkVersion 15
12+
targetSdkVersion 28
13+
versionCode 1
14+
versionName "1.0"
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
}
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
sourceSets {
24+
main {
25+
res.srcDirs = ['src/main/res', 'src/main/res/home', 'src/main/res/layouts/home', 'src/main/res/layouts/dashbord', 'src/main/res/layouts/notification', 'src/main/res/layouts/dashbord/layout', 'src/main/res/layouts/home/layout', 'src/main/res/layouts/notification/layout']
26+
}
27+
28+
29+
}
30+
31+
compileOptions {
32+
sourceCompatibility JavaVersion.VERSION_1_8
33+
targetCompatibility JavaVersion.VERSION_1_8
34+
}
35+
}
36+
37+
dependencies {
38+
implementation fileTree(dir: 'libs', include: ['*.jar'])
39+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
40+
implementation 'androidx.appcompat:appcompat:1.0.2'
41+
implementation 'androidx.core:core-ktx:1.0.2'
42+
implementation 'com.google.android.material:material:1.0.0'
43+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
44+
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
45+
46+
//android clean arc dependecies
47+
implementation 'androidx.navigation:navigation-fragment:2.0.0'
48+
implementation 'androidx.navigation:navigation-ui:2.0.0'
49+
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
50+
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
51+
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
52+
53+
//unit testing dependecies
54+
testImplementation 'junit:junit:4.12'
55+
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
56+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
57+
58+
//coroutine
59+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2'
60+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2")
61+
62+
//retrofit
63+
implementation 'com.squareup.retrofit2:retrofit:2.7.0'
64+
implementation("com.squareup.okhttp3:okhttp:4.2.1")
65+
implementation "com.squareup.retrofit2:converter-moshi:2.4.0"
66+
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
67+
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.example.android_clean_arc_components
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.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.getInstrumentation().targetContext
22+
assertEquals("com.example.android_clean_arc_components", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.android_clean_arc_components">
4+
<uses-permission android:name="android.permission.INTERNET"/>
5+
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity
14+
android:name=".MainActivity"
15+
android:label="@string/app_name">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.example.android_clean_arc_components
2+
3+
import android.os.Bundle
4+
import com.google.android.material.bottomnavigation.BottomNavigationView
5+
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.navigation.findNavController
7+
import androidx.navigation.ui.AppBarConfiguration
8+
import androidx.navigation.ui.setupActionBarWithNavController
9+
import androidx.navigation.ui.setupWithNavController
10+
11+
class MainActivity : AppCompatActivity() {
12+
13+
override fun onCreate(savedInstanceState: Bundle?) {
14+
super.onCreate(savedInstanceState)
15+
setContentView(R.layout.activity_main)
16+
val navView: BottomNavigationView = findViewById(R.id.nav_view)
17+
18+
val navController = findNavController(R.id.nav_host_fragment)
19+
// Passing each menu ID as a set of Ids because each
20+
// menu should be considered as top level destinations.
21+
val appBarConfiguration = AppBarConfiguration(
22+
setOf(
23+
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications
24+
)
25+
)
26+
setupActionBarWithNavController(navController, appBarConfiguration)
27+
navView.setupWithNavController(navController)
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.example.android_clean_arc_components.modules.dashboard.model
2+
3+
import com.squareup.moshi.Json
4+
5+
data class SearchResponse (@field:Json(name = "userId")val userId:Int,
6+
@field:Json(name = "id")val id:Int, @field:Json(name = "title")
7+
val title:String, @field:Json(name = "body")val body:String) {
8+
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example.android_clean_arc_components.modules.dashboard.networking
2+
3+
import com.example.android_clean_arc_components.modules.dashboard.model.SearchResponse
4+
import kotlinx.coroutines.Deferred
5+
import retrofit2.http.GET
6+
7+
interface RestUtilsService {
8+
9+
@GET("/posts")
10+
suspend fun getPosts(): List<SearchResponse>
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example.android_clean_arc_components.modules.dashboard.networking
2+
3+
import retrofit2.Retrofit
4+
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
5+
import retrofit2.converter.moshi.MoshiConverterFactory
6+
7+
object RetrofitFactory {
8+
9+
val BASE_URL = "https://jsonplaceholder.typicode.com"
10+
11+
//here we build service call with model class with coroutine
12+
13+
fun makeRetrofitService(): RestUtilsService {
14+
return Retrofit.Builder()
15+
.baseUrl(BASE_URL)
16+
.addConverterFactory(MoshiConverterFactory.create())
17+
18+
.build().create(RestUtilsService::class.java)
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.example.android_clean_arc_components.modules.dashboard.repository
2+
3+
import androidx.lifecycle.MutableLiveData
4+
import com.example.android_clean_arc_components.modules.dashboard.model.SearchResponse
5+
import com.example.android_clean_arc_components.modules.dashboard.networking.RestUtilsService
6+
import com.example.android_clean_arc_components.modules.dashboard.networking.RetrofitFactory
7+
import kotlinx.coroutines.*
8+
import retrofit2.HttpException
9+
10+
class SearchResponseRepository {
11+
12+
13+
14+
private var movies = mutableListOf<SearchResponse>()
15+
private var mutableLiveData = MutableLiveData<List<SearchResponse>>()
16+
val completableJob = Job()
17+
private val coroutineScope = CoroutineScope(Dispatchers.IO + completableJob)
18+
19+
private val thisApiCorService by lazy {
20+
RetrofitFactory.makeRetrofitService()
21+
}
22+
23+
fun getMutableLiveData():MutableLiveData<List<SearchResponse>> {
24+
coroutineScope.launch {
25+
val request = thisApiCorService.getPosts()
26+
withContext(Dispatchers.Main) {
27+
try {
28+
29+
val response = request
30+
val mBlogWrapper = response;
31+
if (mBlogWrapper != null ) {
32+
movies = mBlogWrapper as MutableList<SearchResponse>;
33+
mutableLiveData.value=movies;
34+
}
35+
36+
} catch (e: HttpException) {
37+
e.printStackTrace()
38+
39+
} catch (e: Throwable) {
40+
e.printStackTrace()
41+
}
42+
}
43+
}
44+
return mutableLiveData;
45+
}
46+
47+
}
48+
49+
50+
51+
52+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.example.android_clean_arc_components.modules.dashboard.view
2+
3+
import android.content.Context
4+
import android.content.res.Configuration
5+
import android.os.Bundle
6+
import android.view.LayoutInflater
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import androidx.fragment.app.Fragment
10+
import androidx.lifecycle.Observer
11+
import androidx.lifecycle.ViewModelProviders
12+
import androidx.recyclerview.widget.DefaultItemAnimator
13+
import androidx.recyclerview.widget.GridLayoutManager
14+
import androidx.recyclerview.widget.LinearLayoutManager
15+
import androidx.recyclerview.widget.RecyclerView
16+
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
17+
18+
import com.example.android_clean_arc_components.R
19+
import com.example.android_clean_arc_components.modules.dashboard.model.SearchResponse
20+
import com.example.android_clean_arc_components.modules.dashboard.viewmodel.DashboardViewModel
21+
import kotlinx.android.synthetic.main.fragment_dashboard.*
22+
23+
class DashboardFragment : Fragment() {
24+
25+
private lateinit var dashboardViewModel: DashboardViewModel
26+
var mBlogAdapter: SearchResponseAdapter? = null
27+
override fun onCreateView(
28+
inflater: LayoutInflater,
29+
container: ViewGroup?,
30+
savedInstanceState: Bundle?): View? {
31+
32+
dashboardViewModel =
33+
ViewModelProviders.of(this).get(DashboardViewModel::class.java)
34+
val root = inflater.inflate(R.layout.fragment_dashboard, container, false)
35+
36+
37+
38+
getPopularBlog()
39+
40+
return root
41+
}
42+
43+
fun getPopularBlog() {
44+
dashboardViewModel!!.allBlog.observe(this, Observer { blogList ->
45+
prepareRecyclerView(blogList)
46+
})
47+
}
48+
49+
private fun prepareRecyclerView(blogList: List<SearchResponse>) {
50+
mBlogAdapter = SearchResponseAdapter(blogList)
51+
if (this.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
52+
53+
recyclerview.setLayoutManager(LinearLayoutManager(activity))
54+
} else {
55+
recyclerview.setLayoutManager(GridLayoutManager(activity, 4))
56+
}
57+
//recyclerview.setItemAnimator(DefaultItemAnimator())
58+
recyclerview.setAdapter(mBlogAdapter)
59+
}
60+
}
61+
62+

0 commit comments

Comments
 (0)