├── 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
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_greeter.xml
│ │ │ │ ├── fragment_greeter_fragment_two.xml
│ │ │ │ └── fragment_greeter_fragment_one.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── android
│ │ │ │ └── grpcmvvm
│ │ │ │ ├── view
│ │ │ │ ├── GreeterViewModelFactory.kt
│ │ │ │ ├── GreeterViewModel.kt
│ │ │ │ ├── GreeterActivity.kt
│ │ │ │ ├── GreeterFragmentOne.kt
│ │ │ │ └── GreeterFragmentTwo.kt
│ │ │ │ ├── grpc
│ │ │ │ └── GrpcService.kt
│ │ │ │ ├── data
│ │ │ │ ├── GreeterRepository.kt
│ │ │ │ └── GreeterRemoteDataSource.kt
│ │ │ │ ├── adapters
│ │ │ │ └── GreeterFragmentsViewPagerAdapter.kt
│ │ │ │ └── di
│ │ │ │ └── Injector.kt
│ │ ├── AndroidManifest.xml
│ │ └── proto
│ │ │ └── helloworld.proto
│ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── android
│ │ │ └── grpcmvvm
│ │ │ └── ExampleInstrumentedTest.kt
│ └── test
│ │ └── java
│ │ └── com
│ │ └── android
│ │ └── grpcmvvm
│ │ ├── testrules
│ │ └── CoroutinesTestRule.kt
│ │ └── view
│ │ └── GreeterViewModelUnitTest.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
└── runConfigurations.xml
├── gradle.properties
├── .gitignore
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='GrpcMvvm'
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/benz93chung/GrpcMvvm/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/benz93chung/GrpcMvvm/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/benz93chung/GrpcMvvm/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/benz93chung/GrpcMvvm/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/benz93chung/GrpcMvvm/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/benz93chung/GrpcMvvm/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/benz93chung/GrpcMvvm/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/benz93chung/GrpcMvvm/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/benz93chung/GrpcMvvm/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/benz93chung/GrpcMvvm/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/benz93chung/GrpcMvvm/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GrpcMvvm
3 |
4 |
5 | Hello blank fragment
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Sep 03 20:43:56 MYT 2019
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-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/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/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/grpcmvvm/view/GreeterViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.view
2 |
3 | import androidx.lifecycle.ViewModel
4 | import androidx.lifecycle.ViewModelProvider
5 | import com.android.grpcmvvm.data.GreeterRepository
6 |
7 | class GreeterViewModelFactory(private val greeterRepository: GreeterRepository): ViewModelProvider.NewInstanceFactory() {
8 | @Suppress("UNCHECKED_CAST")
9 | override fun create(modelClass: Class): T {
10 | return GreeterViewModel(greeterRepository) as T
11 | }
12 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/android/grpcmvvm/grpc/GrpcService.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.grpc
2 |
3 | import io.grpc.ManagedChannel
4 | import io.grpc.ManagedChannelBuilder
5 | import java.util.concurrent.Executors
6 |
7 | class GrpcService(private val host: String, private val port: Int) {
8 |
9 | fun createManagedChannel(): ManagedChannel {
10 | return ManagedChannelBuilder
11 | .forAddress(host, port)
12 | .executor(Executors.newSingleThreadExecutor())
13 | .usePlaintext()
14 | .build()
15 | }
16 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/grpcmvvm/view/GreeterViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.view
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.ViewModel
5 | import androidx.lifecycle.viewModelScope
6 | import com.android.grpcmvvm.data.GreeterRepository
7 | import kotlinx.coroutines.launch
8 |
9 | class GreeterViewModel constructor(private val greeterRepository: GreeterRepository) : ViewModel() {
10 |
11 | val greeting: LiveData
12 | get() = greeterRepository.greeting
13 |
14 | fun sayHello(message: String) {
15 | viewModelScope.launch {
16 | greeterRepository.sayHello(message)
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/android/grpcmvvm/data/GreeterRepository.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.data
2 |
3 | import androidx.lifecycle.LiveData
4 | import androidx.lifecycle.MutableLiveData
5 |
6 | class GreeterRepository constructor(private val greeterRemoteDataSource: GreeterRemoteDataSource) {
7 | private val response = MutableLiveData()
8 |
9 | val greeting: LiveData
10 | get() {
11 | if (response.value == null) {
12 | response.value = "Hello world!"
13 | }
14 |
15 | return response
16 | }
17 |
18 | suspend fun sayHello(message: String) {
19 | response.value = greeterRemoteDataSource.sayHello(message)
20 | }
21 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/android/grpcmvvm/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm
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.android.grpcmvvm", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/grpcmvvm/view/GreeterActivity.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.view
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 | import com.android.grpcmvvm.R
6 | import com.android.grpcmvvm.adapters.GreeterFragmentsViewPagerAdapter
7 | import kotlinx.android.synthetic.main.activity_greeter.*
8 |
9 | class GreeterActivity : AppCompatActivity() {
10 |
11 | override fun onCreate(savedInstanceState: Bundle?) {
12 | super.onCreate(savedInstanceState)
13 | setContentView(R.layout.activity_greeter)
14 |
15 | val greeterFragmentsViewPagerAdapter = GreeterFragmentsViewPagerAdapter(supportFragmentManager)
16 | greeterViewPager.adapter = greeterFragmentsViewPagerAdapter
17 |
18 | greeterTabLayout.setupWithViewPager(greeterViewPager)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/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/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/grpcmvvm/adapters/GreeterFragmentsViewPagerAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.adapters
2 |
3 | import androidx.fragment.app.Fragment
4 | import androidx.fragment.app.FragmentManager
5 | import androidx.fragment.app.FragmentStatePagerAdapter
6 | import com.android.grpcmvvm.view.GreeterFragmentOne
7 | import com.android.grpcmvvm.view.GreeterFragmentTwo
8 |
9 | class GreeterFragmentsViewPagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
10 | override fun getItem(position: Int): Fragment {
11 | return when (position) {
12 | 0 -> GreeterFragmentOne()
13 | else -> GreeterFragmentTwo()
14 | }
15 | }
16 |
17 | override fun getCount(): Int = 2
18 |
19 | override fun getPageTitle(position: Int): CharSequence? {
20 | return when (position) {
21 | 0 -> "Fragment 1"
22 | else -> "Fragment 2"
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/android/grpcmvvm/testrules/CoroutinesTestRule.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.testrules
2 |
3 | import kotlinx.coroutines.Dispatchers
4 | import kotlinx.coroutines.ExperimentalCoroutinesApi
5 | import kotlinx.coroutines.test.TestCoroutineDispatcher
6 | import kotlinx.coroutines.test.resetMain
7 | import kotlinx.coroutines.test.setMain
8 | import org.junit.rules.TestWatcher
9 | import org.junit.runner.Description
10 |
11 | @ExperimentalCoroutinesApi
12 | class CoroutinesTestRule(private val dispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()) : TestWatcher() {
13 | override fun starting(description: Description?) {
14 | super.starting(description)
15 | Dispatchers.setMain(dispatcher)
16 | }
17 |
18 | override fun finished(description: Description?) {
19 | super.finished(description)
20 | Dispatchers.resetMain()
21 | dispatcher.cleanupTestCoroutines()
22 | }
23 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/android/grpcmvvm/di/Injector.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.di
2 |
3 | import com.android.grpcmvvm.data.GreeterRemoteDataSource
4 | import com.android.grpcmvvm.data.GreeterRepository
5 | import com.android.grpcmvvm.grpc.GrpcService
6 | import com.android.grpcmvvm.view.GreeterViewModelFactory
7 |
8 | object Injector {
9 | // Provide GrpcService
10 | private fun provideGrpcService() = GrpcService(
11 | "192.168.1.107",
12 | 50051
13 | )
14 |
15 | // Provide DataSource
16 | private fun provideGreeterRemoteDataSource(grpcService: GrpcService) = GreeterRemoteDataSource(grpcService)
17 |
18 | // Provide Repository
19 | private fun provideGreeterRepository(greeterRemoteDataSource: GreeterRemoteDataSource) = GreeterRepository(greeterRemoteDataSource)
20 |
21 | // Provide GreeterViewModel factory
22 | fun provideGreeterViewModelFactory() = GreeterViewModelFactory(
23 | provideGreeterRepository(
24 | provideGreeterRemoteDataSource(
25 | provideGrpcService()
26 | )
27 | )
28 | )
29 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/android/grpcmvvm/data/GreeterRemoteDataSource.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.data
2 |
3 | import com.android.grpcmvvm.grpc.GrpcService
4 | import io.grpc.ManagedChannel
5 | import io.grpc.StatusRuntimeException
6 | import io.grpc.examples.helloworld.GreeterGrpc
7 | import io.grpc.examples.helloworld.HelloRequest
8 | import kotlinx.coroutines.Dispatchers
9 | import kotlinx.coroutines.withContext
10 |
11 | class GreeterRemoteDataSource constructor(private val grpcService: GrpcService) {
12 | private lateinit var channel: ManagedChannel
13 |
14 | suspend fun sayHello(message: String): String =
15 | withContext(Dispatchers.IO) {
16 | channel = grpcService.createManagedChannel()
17 |
18 | val stub = GreeterGrpc.newBlockingStub(channel)
19 | val request = HelloRequest.newBuilder().setName(message).build()
20 |
21 | return@withContext try {
22 | stub.sayHello(request).message
23 | } catch (e: StatusRuntimeException) {
24 | e.printStackTrace()
25 | e.status.code.toString() + "\n" + e.status.cause.toString()
26 | } finally {
27 | channel.shutdown()
28 | }
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 | # 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 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_greeter.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
26 |
--------------------------------------------------------------------------------
/app/src/main/proto/helloworld.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The gRPC Authors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | syntax = "proto3";
15 |
16 | option java_multiple_files = true;
17 | option java_package = "io.grpc.examples.helloworld";
18 | option java_outer_classname = "HelloWorldProto";
19 | option objc_class_prefix = "HLW";
20 |
21 | package helloworld;
22 |
23 | // The getThatGreeting service definition.
24 | service Greeter {
25 | // Sends a getThatGreeting
26 | rpc SayHello (HelloRequest) returns (HelloReply) {}
27 | }
28 |
29 | // The request message containing the user's name.
30 | message HelloRequest {
31 | string name = 1;
32 | }
33 |
34 | // The response message containing the greetings
35 | message HelloReply {
36 | string message = 1;
37 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/android/grpcmvvm/view/GreeterFragmentOne.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.view
2 |
3 | import android.os.Bundle
4 | import androidx.fragment.app.Fragment
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import androidx.lifecycle.Observer
9 | import androidx.lifecycle.ViewModelProvider
10 |
11 | import com.android.grpcmvvm.R
12 | import com.android.grpcmvvm.di.Injector
13 | import kotlinx.android.synthetic.main.fragment_greeter_fragment_one.*
14 |
15 | class GreeterFragmentOne : Fragment() {
16 |
17 | private lateinit var greeterViewModel: GreeterViewModel
18 |
19 | override fun onCreateView(
20 | inflater: LayoutInflater, container: ViewGroup?,
21 | savedInstanceState: Bundle?
22 | ): View? {
23 | // Inflate the layout for this fragment
24 | return inflater.inflate(R.layout.fragment_greeter_fragment_one, container, false)
25 | }
26 |
27 | override fun onActivityCreated(savedInstanceState: Bundle?) {
28 | super.onActivityCreated(savedInstanceState)
29 |
30 | greeterViewModel = activity?.run {
31 | ViewModelProvider(this, Injector.provideGreeterViewModelFactory()).get(GreeterViewModel::class.java)
32 | } ?: throw Exception("Activity not found")
33 |
34 | greeterViewModel.greeting.observe(viewLifecycleOwner, Observer { greeting ->
35 | fragment1ResultView.text = greeting
36 | })
37 |
38 | fragment1SendBtn.setOnClickListener {
39 | greeterViewModel.sayHello(fragment1InputField.text.toString())
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/grpcmvvm/view/GreeterFragmentTwo.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.view
2 |
3 | import android.os.Bundle
4 | import androidx.fragment.app.Fragment
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import androidx.lifecycle.Observer
9 | import androidx.lifecycle.ViewModelProvider
10 |
11 | import com.android.grpcmvvm.R
12 | import com.android.grpcmvvm.di.Injector
13 | import kotlinx.android.synthetic.main.fragment_greeter_fragment_two.*
14 |
15 | class GreeterFragmentTwo : Fragment() {
16 |
17 | private lateinit var greeterViewModel: GreeterViewModel
18 |
19 | override fun onCreateView(
20 | inflater: LayoutInflater, container: ViewGroup?,
21 | savedInstanceState: Bundle?
22 | ): View? {
23 | // Inflate the layout for this fragment
24 | return inflater.inflate(R.layout.fragment_greeter_fragment_two, container, false)
25 | }
26 |
27 | override fun onActivityCreated(savedInstanceState: Bundle?) {
28 | super.onActivityCreated(savedInstanceState)
29 |
30 | greeterViewModel = activity?.run {
31 | ViewModelProvider(this, Injector.provideGreeterViewModelFactory()).get(GreeterViewModel::class.java)
32 | } ?: throw Exception("Activity not found")
33 |
34 | greeterViewModel.greeting.observe(viewLifecycleOwner, Observer { greeting ->
35 | fragment2ResultView.text = greeting
36 | })
37 |
38 | fragment2SendBtn.setOnClickListener {
39 | greeterViewModel.sayHello(fragment2InputField.text.toString())
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 | *.aab
5 |
6 | # Files for the ART/Dalvik VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # Generated files
13 | bin/
14 | gen/
15 | out/
16 | release/
17 |
18 | # Gradle files
19 | .gradle/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Log Files
29 | *.log
30 |
31 | # Android Studio Navigation editor temp files
32 | .navigation/
33 |
34 | # Android Studio captures folder
35 | captures/
36 |
37 | # IntelliJ
38 | *.iml
39 | .idea/workspace.xml
40 | .idea/tasks.xml
41 | .idea/gradle.xml
42 | .idea/assetWizardSettings.xml
43 | .idea/dictionaries
44 | .idea/libraries
45 | # Android Studio 3 in .gitignore file.
46 | .idea/caches
47 | .idea/modules.xml
48 | .idea/misc.xml
49 |
50 | # Keystore files
51 | # Uncomment the following lines if you do not want to check your keystore files in.
52 | #*.jks
53 | #*.keystore
54 |
55 | # External native build folder generated in Android Studio 2.2 and later
56 | .externalNativeBuild
57 |
58 | # Google Services (e.g. APIs or Firebase)
59 | # google-services.json
60 |
61 | # Freeline
62 | freeline.py
63 | freeline/
64 | freeline_project_description.json
65 |
66 | # fastlane
67 | fastlane/report.xml
68 | fastlane/Preview.html
69 | fastlane/screenshots
70 | fastlane/test_output
71 | fastlane/readme.md
72 |
73 | # Version control
74 | vcs.xml
75 |
76 | # lint
77 | lint/intermediates/
78 | lint/generated/
79 | lint/outputs/
80 | lint/tmp/
81 | # lint/reports/
82 |
83 | # DS_Store
84 | .DS_Store
85 |
86 | # .settings
87 | .settings
88 | app/.settings
89 |
90 | #.project
91 | .project
92 | app/.project
93 |
94 | #.classpath
95 | app/.classpath
--------------------------------------------------------------------------------
/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/layout/fragment_greeter_fragment_two.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
25 |
26 |
36 |
37 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_greeter_fragment_one.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
27 |
28 |
38 |
39 |
52 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GrpcMvvm
2 |
3 | # Reactive gRPC Android App
4 | #### An explorative Android project of gRPC + MVVM + LiveData
5 | 
6 |
7 | ### Setup and usage
8 | - Clone this project
9 | - Open project with Android Studio and build it
10 | - Based on helloworld.proto...
11 | - ...protoc will generate gRPC code to Android project in build folder
12 | - Follow this guide to set up and run server (please take note of IP and port it is running on)
13 |
14 | https://grpc.io/docs/quickstart/java/
15 | - Once server is running with said IP and port, change accordingly at Injector.kt
16 | ```kotlin
17 | // Provide GrpcService
18 | private fun provideGrpcService() = GrpcService(
19 | "192.168.1.107", // <- insert your IP here
20 | 50051 // <- insert your port here
21 | )
22 | ```
23 | - Build project, and run at emulator
24 |
25 | ### Bonus
26 | #### Unit test included!
27 | ##### Find out more at .../app/src/test
28 | ```kotlin
29 | @Test
30 | fun sayHello_Mars_ReturnsHelloMars() {
31 | // Given that I want to say hello to Mars
32 | val nameToGreetTo = "Mars"
33 | val expectedGreeting = "Hello Mars"
34 |
35 | greeterViewModel.sayHello(nameToGreetTo)
36 |
37 | val actualGreeting = greeterViewModel.greeting.getTestValue()
38 |
39 | // Then the getThatGreeting is Hello Mars
40 | assertThat(actualGreeting).matches(expectedGreeting)
41 | }
42 | ```
43 |
44 | ### Additional notes on unit test strategy
45 | For the written unit test, it is written as such to explore on how gRPC stuff (protoc generated code) can be mocked and tested along with Android stuff (ViewModel).
46 |
47 |
48 | If you have seen it, a channel is set up based on a fake server implementation and gets injected to the creation of the ViewModel like as if the said channel provides a passage to the "server".
49 |
50 |
51 | You would not need to write such a test down to that level of mocking gRPC stuff or so, but just write tests to test against just the Android stuff instead (in this case, you would mock what the repository returns to the ViewModel), especially if your backend team already wrote unit tests that tests on client interaction of gRPC code.
52 |
53 | ### Credits
54 | This project is inspired by prongbang's Android + gRPC repository
55 |
56 | https://github.com/prongbang/android-grpc
57 |
58 |
59 | If you are going to star this repository, please also leave a star to prongbang's. :)
60 |
--------------------------------------------------------------------------------
/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/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'com.google.protobuf'
4 |
5 | apply plugin: 'kotlin-android'
6 |
7 | apply plugin: 'kotlin-android-extensions'
8 |
9 | android {
10 | compileSdkVersion 28
11 | defaultConfig {
12 | applicationId "com.android.grpcmvvm"
13 | minSdkVersion 15
14 | targetSdkVersion 28
15 | multiDexEnabled true
16 | versionCode 1
17 | versionName "1.0"
18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
19 | }
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | def grpc_version = "1.22.1"
30 | def lifecycle_version = "2.2.0-alpha04"
31 | def mockito_version = "3.0.0"
32 | def mockk_version = "1.9.3"
33 | def multidex_version = "2.0.1"
34 | def truth_version = "0.45"
35 |
36 | implementation fileTree(dir: 'libs', include: ['*.jar'])
37 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
38 | implementation 'androidx.core:core-ktx:1.1.0'
39 | implementation "androidx.multidex:multidex:$multidex_version"
40 | implementation 'com.google.android.material:material:1.0.0'
41 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
42 | implementation 'javax.annotation:javax.annotation-api:1.3.2'
43 |
44 | // gRPC
45 | implementation "io.grpc:grpc-okhttp:$grpc_version"
46 | implementation "io.grpc:grpc-protobuf-lite:$grpc_version"
47 | implementation "io.grpc:grpc-stub:$grpc_version"
48 |
49 | // Lifecycle
50 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
51 |
52 | // Instrumented tests
53 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
54 | androidTestImplementation 'androidx.test:runner:1.2.0'
55 |
56 | // Unit tests
57 | testImplementation "androidx.arch.core:core-testing:2.1.0"
58 | testImplementation "com.google.truth:truth:$truth_version"
59 | testImplementation "io.grpc:grpc-testing:$grpc_version"
60 | testImplementation "io.mockk:mockk:$mockk_version"
61 | testImplementation 'junit:junit:4.12'
62 | testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.1'
63 | testImplementation "org.mockito:mockito-core:$mockito_version"
64 | }
65 |
66 | protobuf {
67 | protoc {
68 | artifact = 'com.google.protobuf:protoc:3.9.0'
69 | }
70 | plugins {
71 | grpc {
72 | artifact = "io.grpc:protoc-gen-grpc-java:1.22.1"
73 | }
74 | javalite {
75 | artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
76 | }
77 | }
78 | generateProtoTasks {
79 | all()*.plugins {
80 | javalite {}
81 | }
82 | ofNonTest()*.plugins {
83 | grpc {
84 | // Options added to --grpc_out
85 | option 'lite'
86 | }
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | xmlns:android
17 |
18 | ^$
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | xmlns:.*
28 |
29 | ^$
30 |
31 |
32 | BY_NAME
33 |
34 |
35 |
36 |
37 |
38 |
39 | .*:id
40 |
41 | http://schemas.android.com/apk/res/android
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | .*:name
51 |
52 | http://schemas.android.com/apk/res/android
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | name
62 |
63 | ^$
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | style
73 |
74 | ^$
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | .*
84 |
85 | ^$
86 |
87 |
88 | BY_NAME
89 |
90 |
91 |
92 |
93 |
94 |
95 | .*
96 |
97 | http://schemas.android.com/apk/res/android
98 |
99 |
100 | ANDROID_ATTRIBUTE_ORDER
101 |
102 |
103 |
104 |
105 |
106 |
107 | .*
108 |
109 | .*
110 |
111 |
112 | BY_NAME
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/app/src/test/java/com/android/grpcmvvm/view/GreeterViewModelUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.android.grpcmvvm.view
2 |
3 | import androidx.arch.core.executor.testing.InstantTaskExecutorRule
4 | import androidx.lifecycle.LiveData
5 | import androidx.lifecycle.Observer
6 | import com.android.grpcmvvm.data.GreeterRemoteDataSource
7 | import com.android.grpcmvvm.data.GreeterRepository
8 | import com.android.grpcmvvm.grpc.GrpcService
9 | import com.android.grpcmvvm.testrules.CoroutinesTestRule
10 | import com.google.common.truth.Truth.assertThat
11 | import io.grpc.ManagedChannel
12 | import io.grpc.examples.helloworld.GreeterGrpc
13 | import io.grpc.examples.helloworld.HelloReply
14 | import io.grpc.examples.helloworld.HelloRequest
15 | import io.grpc.inprocess.InProcessChannelBuilder
16 | import io.grpc.inprocess.InProcessServerBuilder
17 | import io.grpc.stub.StreamObserver
18 | import io.grpc.testing.GrpcCleanupRule
19 | import io.mockk.MockKAnnotations
20 | import io.mockk.every
21 | import io.mockk.impl.annotations.MockK
22 | import kotlinx.coroutines.ExperimentalCoroutinesApi
23 | import org.junit.Before
24 | import org.junit.Rule
25 | import org.junit.Test
26 | import org.junit.runner.RunWith
27 | import org.junit.runners.JUnit4
28 | import org.mockito.*
29 | import org.mockito.AdditionalAnswers.delegatesTo
30 | import org.mockito.internal.matchers.Any
31 | import java.util.concurrent.CountDownLatch
32 | import java.util.concurrent.TimeUnit
33 |
34 | @RunWith(JUnit4::class)
35 | class GreeterViewModelUnitTest {
36 | // region Test rules
37 | @ExperimentalCoroutinesApi
38 | @get:Rule
39 | val coroutinesTestRule = CoroutinesTestRule()
40 |
41 | @get:Rule
42 | val grpcCleanupRule = GrpcCleanupRule()
43 |
44 | @get:Rule
45 | val taskExecutorRule = InstantTaskExecutorRule()
46 | // endregion
47 |
48 | // region Mocks
49 | // Kotlin classes are final. Won't play nice with Mockito, so use MockK instead
50 | @MockK
51 | private lateinit var mockGrpcService: GrpcService
52 |
53 | private val mockServiceImpl = Mockito.mock(GreeterGrpc.GreeterImplBase::class.java, delegatesTo(
54 | object: GreeterGrpc.GreeterImplBase() {
55 |
56 | override fun sayHello(request: HelloRequest, responseObserver: StreamObserver) {
57 | val reply = HelloReply.newBuilder().setMessage("Hello " + request.name).build()
58 | responseObserver.onNext(reply)
59 | responseObserver.onCompleted()
60 | }}))
61 | // endregion
62 |
63 | // region Private properties
64 | private lateinit var managedChannel: ManagedChannel
65 | private lateinit var greeterViewModel: GreeterViewModel
66 | private lateinit var greeterViewModelFactory: GreeterViewModelFactory
67 | // endregion
68 |
69 | // region Unit tests
70 | @Before
71 | @Throws(Exception::class)
72 | fun setUp() {
73 | // MockitoAnnotations.initMocks(this)
74 | MockKAnnotations.init(this)
75 |
76 | val serverName = InProcessServerBuilder.generateName()
77 |
78 | grpcCleanupRule.register(InProcessServerBuilder
79 | .forName(serverName)
80 | .directExecutor()
81 | .addService(mockServiceImpl)
82 | .build()
83 | .start())
84 |
85 | managedChannel = grpcCleanupRule.register(InProcessChannelBuilder
86 | .forName(serverName)
87 | .directExecutor()
88 | .build())
89 |
90 | every { mockGrpcService.createManagedChannel() } returns managedChannel
91 |
92 | greeterViewModelFactory = GreeterViewModelFactory(GreeterRepository(GreeterRemoteDataSource(mockGrpcService)))
93 | greeterViewModel = greeterViewModelFactory.create(GreeterViewModel::class.java)
94 | }
95 |
96 | @Test
97 | fun getGreeting_ReturnsHelloWorld() {
98 | // Given that I expect Hello World as a getThatGreeting if I get it right away
99 | val expectedGreeting = "Hello world!"
100 |
101 | // When I get getThatGreeting
102 | val actualGreeting = greeterViewModel.greeting.getTestValue()
103 |
104 | // Then the getThatGreeting is Hello world!
105 | assertThat(actualGreeting).matches(expectedGreeting)
106 | }
107 |
108 | @Test
109 | fun sayHello_Mars_ReturnsHelloMars() {
110 | // Given that I want to say hello to Mars
111 | val nameToGreetTo = "Mars"
112 | val expectedGreeting = "Hello Mars"
113 |
114 | greeterViewModel.sayHello(nameToGreetTo)
115 |
116 | val actualGreeting = greeterViewModel.greeting.getTestValue()
117 |
118 | // Then the getThatGreeting is Hello Mars
119 | assertThat(actualGreeting).matches(expectedGreeting)
120 | }
121 | // endregion
122 |
123 | // region Extensions
124 | @Throws(InterruptedException::class)
125 | fun LiveData.getTestValue(): T? {
126 | var value: T? = null
127 | val latch = CountDownLatch(1)
128 | val observer = Observer {
129 | value = it
130 | latch.countDown()
131 | }
132 | latch.await(2, TimeUnit.SECONDS)
133 | observeForever(observer)
134 | removeObserver(observer)
135 | return value
136 | }
137 | // endregion
138 | }
139 |
140 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------