├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── bhaicompany
│ │ └── kotlinarchitecturalcomponents
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── bhaicompany
│ │ │ └── kotlinarchitecturalcomponents
│ │ │ ├── AppDatabase.kt
│ │ │ ├── MainActivity.kt
│ │ │ ├── User.kt
│ │ │ ├── UserAdapter.kt
│ │ │ ├── UserDAO.kt
│ │ │ ├── UserViewModel.kt
│ │ │ ├── ViewModelFactory.kt
│ │ │ ├── fragments
│ │ │ ├── ListingFragment.kt
│ │ │ ├── StartFragment.kt
│ │ │ └── WelcomeFragment.kt
│ │ │ └── util
│ │ │ └── UI.kt
│ └── res
│ │ ├── drawable-hdpi
│ │ └── ic_play.png
│ │ ├── drawable-mdpi
│ │ └── ic_play.png
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xhdpi
│ │ └── ic_play.png
│ │ ├── drawable-xxhdpi
│ │ └── ic_play.png
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── fragment_listing.xml
│ │ ├── fragment_start.xml
│ │ ├── fragment_welcome.xml
│ │ └── single_item.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── 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
│ │ ├── navigation
│ │ └── nav_item.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── bhaicompany
│ └── kotlinarchitecturalcomponents
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.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 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.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 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android-Architecture-Components-Demo
2 | Demo of the Architecture Components Pattern of Android
3 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | apply plugin: 'kotlin-kapt'
8 |
9 | apply plugin: 'androidx.navigation.safeargs'
10 |
11 | android {
12 | compileSdkVersion 27
13 | defaultConfig {
14 | applicationId "com.bhaicompany.kotlinarchitecturalcomponents"
15 | minSdkVersion 15
16 | targetSdkVersion 27
17 | versionCode 1
18 | versionName "1.0"
19 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
20 | }
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
32 | implementation 'com.android.support:appcompat-v7:27.1.0'
33 | implementation 'com.android.support.constraint:constraint-layout:1.1.0'
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
36 | androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.1", {
37 | exclude group: 'com.android.support', module: 'support-annotations'
38 | })
39 | // ViewModel and LiveData
40 | implementation "android.arch.lifecycle:extensions:1.1.1"
41 | // alternatively, just ViewModel
42 | implementation "android.arch.lifecycle:viewmodel:1.1.1"
43 | // alternatively, just LiveData
44 | implementation "android.arch.lifecycle:livedata:1.1.1"
45 |
46 | annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
47 |
48 | // Room (use 1.1.0-beta2 for latest beta)
49 | implementation "android.arch.persistence.room:runtime:1.1.0-beta2"
50 | annotationProcessor "android.arch.persistence.room:compiler:1.1.0-beta2"
51 | kapt "android.arch.persistence.room:compiler:1.1.0-beta2"
52 |
53 | // Paging
54 | implementation "android.arch.paging:runtime:1.0.0-beta1"
55 |
56 | // Test helpers for LiveData
57 | testImplementation "android.arch.core:core-testing:1.1.1"
58 |
59 | // Test helpers for Room
60 | testImplementation "android.arch.persistence.room:testing:1.0.0"
61 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.21"
62 |
63 | def nav_version = "1.0.0-alpha01"
64 |
65 | implementation "android.arch.navigation:navigation-fragment:$nav_version"
66 | implementation "android.arch.navigation:navigation-ui:$nav_version"
67 |
68 | }
69 |
70 | kotlin {
71 | experimental {
72 | coroutines "enable"
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/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
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/bhaicompany/kotlinarchitecturalcomponents/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.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.bhaicompany.kotlinarchitecturalcomponents", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/AppDatabase.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents
2 |
3 | import android.arch.persistence.room.Room
4 | import android.arch.persistence.room.RoomDatabase
5 | import android.arch.persistence.room.Database
6 | import android.content.Context
7 |
8 |
9 | @Database(entities = [(User::class)], version = 1)
10 | abstract class AppDatabase : RoomDatabase() {
11 |
12 | abstract fun userDao(): UserDAO
13 |
14 | companion object {
15 | private var INSTANCE: AppDatabase? = null
16 |
17 | fun getAppDatabase(context: Context): AppDatabase {
18 | if (INSTANCE == null) {
19 | synchronized(this)
20 | {
21 | INSTANCE = Room.databaseBuilder(context.applicationContext, AppDatabase::class.java, "app-database")
22 | // uncomment to allow queries on the main thread.
23 | /* .allowMainThreadQueries()*/
24 | .build()
25 | }
26 | }
27 | return INSTANCE as AppDatabase
28 | }
29 |
30 | fun destroyInstance() {
31 | INSTANCE = null
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents
2 |
3 | import android.support.v7.app.AppCompatActivity
4 | import android.os.Bundle
5 | import androidx.navigation.Navigation
6 | import com.bhaicompany.kotlinarchitecturalcomponents.fragments.ListingFragment
7 | import com.bhaicompany.kotlinarchitecturalcomponents.fragments.StartFragment
8 | import com.bhaicompany.kotlinarchitecturalcomponents.fragments.WelcomeFragment
9 |
10 |
11 | class MainActivity : AppCompatActivity(), ListingFragment.OnFragmentInteractionListener, StartFragment.OnFragmentInteractionListener, WelcomeFragment.OnFragmentInteractionListener{
12 |
13 | override fun onCreate(savedInstanceState: Bundle?) {
14 | super.onCreate(savedInstanceState)
15 | setContentView(R.layout.activity_main)
16 | }
17 |
18 | override fun onDestroy() {
19 | AppDatabase.destroyInstance()
20 | super.onDestroy()
21 | }
22 |
23 | override fun onFragmentInteraction(string: String) {
24 | println("Log state ==> $string")
25 | supportActionBar?.title = string
26 | }
27 |
28 | override fun onSupportNavigateUp(): Boolean = Navigation.findNavController(this, R.id.nav_host).navigateUp()
29 |
30 | }
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/User.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents
2 |
3 | import android.arch.persistence.room.Entity
4 | import android.arch.persistence.room.PrimaryKey
5 | import android.support.annotation.NonNull
6 | import android.support.v7.util.DiffUtil
7 |
8 |
9 |
10 | @Entity(tableName = "user")
11 | data class User(@PrimaryKey(autoGenerate = true) val uid: Int = 0, var name: String, var age: Int, var gender: String)
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/UserAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents
2 |
3 | import android.arch.paging.PagedListAdapter
4 | import android.support.v7.util.DiffUtil
5 | import android.support.v7.widget.RecyclerView
6 | import android.view.LayoutInflater
7 | import android.view.ViewGroup
8 | import android.view.View
9 | import kotlinx.android.synthetic.main.single_item.view.*
10 |
11 | class UserAdapter: PagedListAdapter(object : DiffUtil.ItemCallback() {
12 | override fun areItemsTheSame(oldItem: User?, newItem: User?): Boolean {
13 | return oldItem?.uid == newItem?.uid
14 | }
15 |
16 | override fun areContentsTheSame(oldItem: User?, newItem: User?): Boolean {
17 | return oldItem == newItem
18 | }
19 | })
20 | {
21 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserItemViewHolder =
22 | UserItemViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.single_item, parent, false))
23 |
24 | override fun onBindViewHolder(holder: UserItemViewHolder, position: Int) {
25 | val user = getItem(position)
26 | user?.let { holder.bindTo(it) }
27 | }
28 |
29 | class UserItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
30 | {
31 | fun bindTo(user: User) = with(itemView)
32 | {
33 | name.text = user.name.capitalize()
34 | uid.text = user.uid.toString()
35 | gender.text = user.gender
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/UserDAO.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents
2 |
3 | import android.arch.lifecycle.LiveData
4 | import android.arch.paging.DataSource
5 | import android.arch.persistence.room.Delete
6 | import android.arch.persistence.room.Dao
7 | import android.arch.persistence.room.Insert
8 | import android.arch.persistence.room.Query
9 |
10 |
11 | @Dao
12 | interface UserDAO {
13 | @get:Query("SELECT * FROM user")
14 | val all: LiveData>
15 |
16 | @Query("SELECT * FROM User")
17 | fun usersAll(): DataSource.Factory
18 |
19 | @Query("SELECT * FROM user where name LIKE :name")
20 | fun findByName(name: String): User
21 |
22 | @Query("SELECT * FROM user where name LIKE :name")
23 | fun findByNameList(name: String): DataSource.Factory
24 |
25 | @Query("UPDATE user SET name = :name where uid = :id")
26 | fun updateName(name: String,id: Int)
27 |
28 | @Query("SELECT COUNT(*) from user")
29 | fun countUsers(): Int
30 |
31 | @Insert
32 | fun insertAll(vararg users: User)
33 |
34 | @Delete
35 | fun delete(user: User)
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/UserViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents
2 |
3 | import android.arch.lifecycle.ViewModel
4 | import android.arch.paging.LivePagedListBuilder
5 | import android.arch.paging.PagedList
6 | import android.arch.lifecycle.LiveData
7 |
8 | import android.app.Application
9 | import android.arch.lifecycle.AndroidViewModel
10 | import android.arch.lifecycle.MutableLiveData
11 |
12 |
13 | class UserViewModel(application: Application) : AndroidViewModel(application){
14 | val dao = AppDatabase.getAppDatabase(application).userDao()
15 | fun initPagerList(name: String) : LiveData>
16 | {
17 | println("Name ==> $name")
18 | if(name == "null" || name.trim().isEmpty()) {
19 | val pagedListConfig = PagedList.Config.Builder().setEnablePlaceholders(true)
20 | .setPrefetchDistance(10)
21 | .setPageSize(20).setEnablePlaceholders(false).build()
22 | return LivePagedListBuilder(dao.usersAll(), pagedListConfig)
23 | .build()
24 | }
25 | else
26 | {
27 | val pagedListConfig = PagedList.Config.Builder().setEnablePlaceholders(true)
28 | .setPrefetchDistance(10)
29 | .setPageSize(20).setEnablePlaceholders(false).build()
30 | return LivePagedListBuilder(dao.findByNameList(name.toLowerCase()), pagedListConfig)
31 | .build()
32 | }
33 | }
34 |
35 | private fun addUser(user: User): User {
36 | dao.insertAll(user)
37 | return user
38 | }
39 |
40 | fun populateWithTestData() {
41 | var user = User(name = "ajay", age = 20, gender = "male")
42 | addUser(user)
43 | user = User(name = "shyam", age = 21, gender = "male")
44 | addUser(user)
45 | }
46 |
47 |
48 | fun countUsers() = dao.countUsers()
49 |
50 | fun updateUser(name: String, id: Int) = dao.updateName(name, id)
51 |
52 | fun getUsersList() = dao.all
53 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/ViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents
2 |
3 | import android.app.Application
4 | import android.arch.lifecycle.ViewModel
5 | import android.arch.lifecycle.ViewModelProvider
6 |
7 | class ViewModelFactory(private val mApplication: Application) : ViewModelProvider.NewInstanceFactory() {
8 | override fun create(modelClass: Class): T {
9 | return UserViewModel(mApplication) as T
10 | }
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/fragments/ListingFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents.fragments
2 |
3 | import android.arch.lifecycle.Observer
4 | import android.arch.lifecycle.ViewModelProviders
5 | import android.content.Context
6 | import android.os.Bundle
7 | import android.support.v4.app.Fragment
8 | import android.support.v7.widget.LinearLayoutManager
9 | import android.view.LayoutInflater
10 | import android.view.View
11 | import android.view.ViewGroup
12 | import com.bhaicompany.kotlinarchitecturalcomponents.R
13 | import com.bhaicompany.kotlinarchitecturalcomponents.UserAdapter
14 | import com.bhaicompany.kotlinarchitecturalcomponents.UserViewModel
15 | import com.bhaicompany.kotlinarchitecturalcomponents.util.UI
16 | import kotlinx.android.synthetic.main.fragment_listing.*
17 | import kotlinx.coroutines.experimental.async
18 | import kotlinx.coroutines.experimental.launch
19 |
20 |
21 |
22 | /**
23 | * A simple [Fragment] subclass.
24 | * Activities that contain this fragment must implement the
25 | * [ListingFragment.OnFragmentInteractionListener] interface
26 | * to handle interaction events.
27 | * Use the [ListingFragment.newInstance] factory method to
28 | * create an instance of this fragment.
29 | *
30 | */
31 |
32 |
33 |
34 | class ListingFragment : Fragment() {
35 |
36 | private var listener: OnFragmentInteractionListener? = null
37 | private val userViewModel: UserViewModel by lazy {
38 | ViewModelProviders.of(activity!!).get(UserViewModel::class.java)
39 | }
40 | private val adapter = UserAdapter()
41 |
42 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
43 | savedInstanceState: Bundle?): View? {
44 | // Inflate the layout for this fragment
45 | listener?.onFragmentInteraction("I am in listing Fragment!")
46 | return inflater.inflate(R.layout.fragment_listing, container, false)
47 | }
48 |
49 |
50 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
51 | super.onViewCreated(view, savedInstanceState)
52 | initRecyclerView()
53 | queryText.text = "Loading ..."
54 | if(arguments?.getString("myarg") != null)
55 | {
56 | println("Deeplinked ==> "+arguments?.getString("myarg"))
57 | val args = arguments?.getString("myarg")
58 |
59 | val listData = async {
60 | args?.let { userViewModel.initPagerList(it) }
61 | }
62 | launch {
63 | val ryList = listData.await()
64 | activity?.let {
65 | ryList?.observe(it, Observer {
66 | launch(UI) {
67 | println("Count ==> "+ it?.size)
68 | adapter.submitList(it)
69 | queryText.text = "Query:" + args
70 | }
71 | })
72 | }
73 | // println( "count ==> "+ userViewModel.countUsers())
74 |
75 | }
76 |
77 | }
78 | else
79 | {
80 | val args = ListingFragmentArgs.fromBundle(arguments)
81 |
82 | val listData = async {
83 | userViewModel.initPagerList(args.query)
84 | }
85 | launch {
86 | val ryList = listData.await()
87 | activity?.let {
88 | ryList.observe(it, Observer {
89 | launch(UI) {
90 | println("Count ==> "+ it?.size)
91 | adapter.submitList(it)
92 | queryText.text = "Query:" + args.query
93 | }
94 | })
95 | }
96 | // println( "count ==> "+ userViewModel.countUsers())
97 |
98 | }
99 |
100 | }
101 |
102 |
103 | // Run this once for test data
104 | launch {
105 | repeat(500)
106 | {
107 | userViewModel.populateWithTestData()
108 | }
109 | }
110 | }
111 |
112 |
113 |
114 | override fun onAttach(context: Context) {
115 | super.onAttach(context)
116 | if (context is OnFragmentInteractionListener) {
117 | listener = context
118 | } else {
119 | throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
120 | }
121 | }
122 |
123 | override fun onDetach() {
124 | super.onDetach()
125 | listener = null
126 | }
127 |
128 | /**
129 | * This interface must be implemented by activities that contain this
130 | * fragment to allow an interaction in this fragment to be communicated
131 | * to the activity and potentially other fragments contained in that
132 | * activity.
133 | *
134 | *
135 | * See the Android Training lesson [Communicating with Other Fragments]
136 | * (http://developer.android.com/training/basics/fragments/communicating.html)
137 | * for more information.
138 | */
139 | interface OnFragmentInteractionListener {
140 | fun onFragmentInteraction(string: String)
141 | }
142 |
143 |
144 | private fun initRecyclerView()
145 | {
146 | val llm = LinearLayoutManager(activity)
147 | llm.orientation = LinearLayoutManager.VERTICAL
148 | recycler_view.layoutManager = llm
149 | recycler_view.adapter = adapter
150 | }
151 |
152 | // for info counter
153 | private fun getUserCount()
154 | {
155 | userViewModel.countUsers()
156 | }
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/fragments/StartFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents.fragments
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import android.support.v4.app.Fragment
6 | import android.text.Editable
7 | import android.text.TextWatcher
8 | import android.view.LayoutInflater
9 | import android.view.View
10 | import android.view.ViewGroup
11 | import androidx.navigation.fragment.NavHostFragment
12 | import com.bhaicompany.kotlinarchitecturalcomponents.R
13 | import kotlinx.android.synthetic.main.fragment_start.*
14 |
15 |
16 | /**
17 | * A simple [Fragment] subclass.
18 | * Activities that contain this fragment must implement the
19 | * [StartFragment.OnFragmentInteractionListener] interface
20 | * to handle interaction events.
21 | * Use the [StartFragment.newInstance] factory method to
22 | * create an instance of this fragment.
23 | *
24 | */
25 | class StartFragment : Fragment() {
26 | private var listener: OnFragmentInteractionListener? = null
27 |
28 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
29 | savedInstanceState: Bundle?): View? {
30 | // Inflate the layout for this fragment
31 | listener?.onFragmentInteraction("I am in Start Fragment")
32 | return inflater.inflate(R.layout.fragment_start, container, false)
33 | }
34 |
35 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
36 | super.onViewCreated(view, savedInstanceState)
37 | play.setOnClickListener {
38 | val directions = StartFragmentDirections.action_startFragment_to_listingFragment();
39 | directions.setQuery(editText.text.toString())
40 | NavHostFragment.findNavController(this).navigate(directions)
41 | }
42 | editText.addTextChangedListener(object : TextWatcher
43 | {
44 | override fun afterTextChanged(s: Editable?) {
45 |
46 | }
47 |
48 | override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
49 |
50 | }
51 |
52 | override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
53 | }
54 |
55 | })
56 | }
57 |
58 |
59 | override fun onAttach(context: Context) {
60 | super.onAttach(context)
61 | if (context is OnFragmentInteractionListener) {
62 | listener = context
63 | } else {
64 | throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
65 | }
66 | }
67 |
68 | override fun onDetach() {
69 | super.onDetach()
70 | listener = null
71 | }
72 |
73 | /**
74 | * This interface must be implemented by activities that contain this
75 | * fragment to allow an interaction in this fragment to be communicated
76 | * to the activity and potentially other fragments contained in that
77 | * activity.
78 | *
79 | *
80 | * See the Android Training lesson [Communicating with Other Fragments]
81 | * (http://developer.android.com/training/basics/fragments/communicating.html)
82 | * for more information.
83 | */
84 | interface OnFragmentInteractionListener {
85 | fun onFragmentInteraction(string: String)
86 | }
87 |
88 | companion object {
89 | /**
90 | * Use this factory method to create a new instance of
91 | * this fragment using the provided parameters.
92 | *
93 | * @return A new instance of fragment StartFragment.
94 | */
95 | @JvmStatic
96 | fun newInstance() = StartFragment()
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/fragments/WelcomeFragment.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents.fragments
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import android.support.v4.app.Fragment
6 | import android.view.LayoutInflater
7 | import android.view.View
8 | import android.view.ViewGroup
9 | import androidx.navigation.fragment.NavHostFragment
10 | import com.bhaicompany.kotlinarchitecturalcomponents.R
11 | import kotlinx.android.synthetic.main.fragment_welcome.*
12 |
13 |
14 | /**
15 | * A simple [Fragment] subclass.
16 | * Activities that contain this fragment must implement the
17 | * [WelcomeFragment.OnFragmentInteractionListener] interface
18 | * to handle interaction events.
19 | * Use the [WelcomeFragment.newInstance] factory method to
20 | * create an instance of this fragment.
21 | *
22 | */
23 | class WelcomeFragment : Fragment() {
24 | private var listener: OnFragmentInteractionListener? = null
25 |
26 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
27 | savedInstanceState: Bundle?): View? {
28 | // Inflate the layout for this fragment
29 | listener?.onFragmentInteraction("I am in welcome Fragment!")
30 | return inflater.inflate(R.layout.fragment_welcome, container, false)
31 | }
32 |
33 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
34 | super.onViewCreated(view, savedInstanceState)
35 | play.setOnClickListener {
36 | NavHostFragment.findNavController(this).navigate(R.id.startFragment)
37 | }
38 | }
39 |
40 |
41 |
42 | override fun onAttach(context: Context) {
43 | super.onAttach(context)
44 | if (context is OnFragmentInteractionListener) {
45 | listener = context
46 | } else {
47 | throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
48 | }
49 | }
50 |
51 | override fun onDetach() {
52 | super.onDetach()
53 | listener = null
54 | }
55 |
56 | /**
57 | * This interface must be implemented by activities that contain this
58 | * fragment to allow an interaction in this fragment to be communicated
59 | * to the activity and potentially other fragments contained in that
60 | * activity.
61 | *
62 | *
63 | * See the Android Training lesson [Communicating with Other Fragments]
64 | * (http://developer.android.com/training/basics/fragments/communicating.html)
65 | * for more information.
66 | */
67 |
68 | interface OnFragmentInteractionListener {
69 | fun onFragmentInteraction(string:String)
70 | }
71 |
72 | companion object {
73 | /**
74 | * Use this factory method to create a new instance of
75 | * this fragment using the provided parameters.
76 | *
77 | * @return A new instance of fragment WelcomeFragment.
78 | */
79 |
80 | @JvmStatic
81 | fun newInstance() = WelcomeFragment()
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bhaicompany/kotlinarchitecturalcomponents/util/UI.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents.util
2 | import android.os.Handler
3 | import android.os.Looper
4 | import kotlin.coroutines.experimental.AbstractCoroutineContextElement
5 | import kotlin.coroutines.experimental.Continuation
6 | import kotlin.coroutines.experimental.ContinuationInterceptor
7 |
8 | private class AndroidContinuation(val cont: Continuation) : Continuation by cont {
9 | override fun resume(value: T) {
10 | if (Looper.myLooper() == Looper.getMainLooper()) cont.resume(value)
11 | else Handler(Looper.getMainLooper()).post { cont.resume(value) }
12 | }
13 | override fun resumeWithException(exception: Throwable) {
14 | if (Looper.myLooper() == Looper.getMainLooper()) cont.resumeWithException(exception)
15 | else Handler(Looper.getMainLooper()).post { cont.resumeWithException(exception) }
16 | }
17 | }
18 |
19 | object UI : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
20 | override fun interceptContinuation(continuation: Continuation): Continuation =
21 | AndroidContinuation(continuation)
22 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/drawable-hdpi/ic_play.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/drawable-mdpi/ic_play.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/drawable-xhdpi/ic_play.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/drawable-xxhdpi/ic_play.png
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_listing.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
19 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_start.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
21 |
22 |
29 |
30 |
31 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_welcome.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
23 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/single_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
22 |
23 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/navigation/nav_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
15 |
16 |
22 |
25 |
26 |
30 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Kotlin Architectural Components
3 |
4 |
5 | Hello blank fragment
6 | Welcome to Listing App
7 | Enter a text to get started
8 | Query
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/test/java/com/bhaicompany/kotlinarchitecturalcomponents/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.bhaicompany.kotlinarchitecturalcomponents
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.2.30'
5 | ext.archRoomVersion = "1.1.0-beta2"
6 | repositories {
7 | google()
8 | jcenter()
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
12 | classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha01'
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | google()
23 | jcenter()
24 | }
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
--------------------------------------------------------------------------------
/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=-Xmx1536m
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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ashwin-sp/Android-Architecture-Components-Demo/61ad6f3c8355bc3d57627de9dd963eaee9c8609d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun May 13 11:01:57 IST 2018
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-4.6-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------