5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/client-android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/client-android/.idea/copyright/Apache_V2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/client-android/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.1.0'
5 | repositories {
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:2.3.1'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.0"
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | jcenter()
21 | mavenCentral()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/client-android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GRPC
3 |
4 |
5 | UserName
6 | Password (at least 4 character)
7 | Sign in or register
8 | Sign in
9 | This email address is invalid
10 | This password is too short
11 | This password is incorrect
12 | This field is required
13 | "Contacts permissions are needed for providing email
14 | completions."
15 |
16 |
17 |
--------------------------------------------------------------------------------
/client-android/app/src/test/kotlin/javax/microedition/khronos/opengles/GL.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package javax.microedition.khronos.opengles;
18 |
19 | /**
20 | * Just for fix class not found on unit-test for show dialog.
21 | */
22 | public interface GL { }
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/view/MvpView.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.view
18 |
19 | import android.content.Context
20 |
21 | /**
22 | * Created by Jacksgong on 09/03/2017.
23 | */
24 | interface MvpView {
25 | fun getContext(): Context
26 | }
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/presenter/Presenter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.presenter
18 |
19 | /**
20 | * Created by Jacksgong on 08/03/2017.
21 | */
22 | interface Presenter {
23 | fun attachView(view: V)
24 | fun detachView()
25 | }
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/view/ConversationMvpView.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.view
18 |
19 | import de.mkammerer.grpcchat.protocol.Error
20 | import de.mkammerer.grpcchat.protocol.RoomMessage
21 |
22 | /**
23 | * Created by Jacksgong on 08/03/2017.
24 | */
25 | interface ConversationMvpView : MvpView {
26 | fun showLoading()
27 | fun showConversations(roomMessageList: List)
28 | fun showError(error: Error)
29 | fun createdNewRoom()
30 | }
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/activity/LaunchActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.activity
18 |
19 | import android.content.Intent
20 | import android.os.Bundle
21 | import android.support.v7.app.AppCompatActivity
22 |
23 | class LaunchActivity : AppCompatActivity() {
24 |
25 | override fun onCreate(savedInstanceState: Bundle?) {
26 | super.onCreate(savedInstanceState)
27 | startActivity(Intent(this, InitialActivity::class.java))
28 | finish()
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/view/LoginMvpView.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.view
18 |
19 | import de.mkammerer.grpcchat.protocol.Error
20 |
21 | /**
22 | * Created by Jacksgong on 09/03/2017.
23 | */
24 | interface LoginMvpView : MvpView {
25 | fun showLoading()
26 | fun loggedIn(performedRegister: Boolean)
27 | fun showError(error: Error)
28 | fun showUserNameError(tipsId: Int)
29 | fun showPasswordError(tipsId: Int)
30 | fun resetError()
31 | fun addEmailsToAutoComplete(emailAddressCollection: List)
32 | }
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/tools/Logger.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.tools
18 |
19 | import android.util.Log
20 |
21 | /**
22 | * Created by Jacksgong on 07/03/2017.
23 | */
24 | class Logger {
25 | companion object {
26 | fun log(o: Object, msg: String?, priority: Int = Log.DEBUG) {
27 | log(o.javaClass, msg, priority)
28 | }
29 |
30 | fun log(javaClass: Class<*>, msg: String?, priority: Int = Log.DEBUG) {
31 | msg ?: return
32 |
33 | Log.println(priority, javaClass.simpleName, msg)
34 | }
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/client-android/app/src/test/kotlin/cn/dreamtobe/grpc/client/AndroidTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client
18 |
19 | import android.content.Context
20 | import org.junit.runner.RunWith
21 | import org.robolectric.RobolectricTestRunner
22 | import org.robolectric.RuntimeEnvironment
23 | import org.robolectric.annotation.Config
24 | import java.io.File
25 |
26 | @RunWith(RobolectricTestRunner::class)
27 | @Config(constants = BuildConfig::class,
28 | application = GrpcClientApplication::class,
29 | sdk = intArrayOf(24))
30 | abstract class AndroidTest {
31 |
32 | fun context(): Context {
33 | return RuntimeEnvironment.application
34 | }
35 |
36 | fun cacheDir(): File {
37 | return context().cacheDir
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/client-android/app/src/main/res/layout/activity_initial.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
28 |
29 |
30 |
31 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/GrpcClientApplication.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client
18 |
19 | import android.app.Application
20 | import android.content.Context
21 | import cn.dreamtobe.grpc.client.model.ServerApi
22 |
23 | /**
24 | * Created by Jacksgong on 09/03/2017.
25 | */
26 | class GrpcClientApplication : Application() {
27 | private var mServerApi: ServerApi? = null
28 |
29 | fun getServerApi(): ServerApi {
30 | if (mServerApi == null) mServerApi = ServerApi.Factory.create()
31 | return mServerApi!!
32 | }
33 |
34 | fun setServerApi(serverApi: ServerApi) {
35 | mServerApi = serverApi
36 | }
37 |
38 | companion object {
39 | fun get(context: Context): GrpcClientApplication = context.applicationContext as GrpcClientApplication
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/tools/ProgressSubscriber.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.tools
18 |
19 | import android.app.ProgressDialog
20 | import android.content.Context
21 | import rx.Subscriber
22 |
23 | /**
24 | * Created by Jacksgong on 07/03/2017.
25 | */
26 | open class ProgressSubscriber(context: Context) : Subscriber() {
27 |
28 | val mProgressDialog = ProgressDialog(context)
29 |
30 | override fun onError(e: Throwable?) {
31 | mProgressDialog.dismiss()
32 | }
33 |
34 | override fun onCompleted() {
35 | mProgressDialog.dismiss()
36 | }
37 |
38 | override fun onStart() {
39 | super.onStart()
40 | mProgressDialog.show()
41 | }
42 |
43 | override fun onNext(t: T) {
44 | }
45 |
46 | init {
47 | mProgressDialog.setTitle("loading...")
48 | }
49 | }
--------------------------------------------------------------------------------
/client-android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/activity/InitialActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.activity
18 |
19 | import android.content.Intent
20 | import android.os.Bundle
21 | import android.support.v7.app.AppCompatActivity
22 | import android.view.View
23 | import android.widget.EditText
24 | import cn.dreamtobe.grpc.client.GrpcClientApplication
25 | import cn.dreamtobe.grpc.client.R
26 | import cn.dreamtobe.grpc.client.model.ServerApi
27 |
28 | /**
29 | * Created by Jacksgong on 07/03/2017.
30 | */
31 | class InitialActivity : AppCompatActivity() {
32 |
33 | lateinit var mHostEdt: EditText
34 | lateinit var mPortEdt: EditText
35 | lateinit var mServerApi: ServerApi
36 |
37 | override fun onCreate(savedInstanceState: Bundle?) {
38 | super.onCreate(savedInstanceState)
39 | title = "Initial"
40 | setContentView(R.layout.activity_initial)
41 |
42 | mHostEdt = findViewById(R.id.host_edt) as EditText
43 | mPortEdt = findViewById(R.id.port_edt) as EditText
44 |
45 | mServerApi = GrpcClientApplication.get(this).getServerApi()
46 | mHostEdt.setText(mServerApi.getHost())
47 | mPortEdt.setText(mServerApi.getPort().toString())
48 | }
49 |
50 | fun onClickConfirm(view: View) {
51 | mServerApi.setHost(mHostEdt.text.toString())
52 | mServerApi.setPort(mPortEdt.text.toString().toInt())
53 |
54 | startActivity(Intent(this, LoginActivity::class.java))
55 | finish()
56 | }
57 | }
--------------------------------------------------------------------------------
/client-android/app/src/test/kotlin/cn/dreamtobe/grpc/client/GrpcClientTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client
18 |
19 | import cn.dreamtobe.grpc.client.model.ServerApi
20 | import cn.dreamtobe.grpc.client.presenter.Presenter
21 | import cn.dreamtobe.grpc.client.tools.AndroidSchedulers
22 | import cn.dreamtobe.grpc.client.view.MvpView
23 | import com.nhaarman.mockito_kotlin.doReturn
24 | import com.nhaarman.mockito_kotlin.mock
25 | import org.robolectric.RuntimeEnvironment
26 | import rx.functions.Func1
27 | import rx.plugins.RxJavaHooks
28 | import rx.schedulers.Schedulers
29 |
30 | /**
31 | * Created by Jacksgong on 09/03/2017.
32 | */
33 | abstract class GrpcClientTest> : AndroidTest() {
34 |
35 | lateinit var presenter: P
36 | lateinit var mvpView: V
37 | lateinit var serverApi: ServerApi
38 |
39 | inline fun create() {
40 | val application = RuntimeEnvironment.application as GrpcClientApplication
41 |
42 | serverApi = mock()
43 | application.setServerApi(serverApi)
44 |
45 | presenter = PR::class.java.newInstance()
46 | mvpView = mock {
47 | on { getContext() } doReturn application
48 | }
49 | presenter.attachView(mvpView)
50 |
51 | RxJavaHooks.reset()
52 | RxJavaHooks.setOnIOScheduler { Schedulers.immediate() }
53 | AndroidSchedulers.Hook.setOnMainScheduler(Func1 { Schedulers.immediate() })
54 |
55 | }
56 |
57 | fun destroy() {
58 | presenter.detachView()
59 |
60 | RxJavaHooks.reset()
61 | AndroidSchedulers.Hook.reset()
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/client-android/app/src/main/res/layout/item_conversation.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
32 |
33 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/client-android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Jacksgong/sdk/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # rxjava
20 | -dontwarn rx.**
21 | -dontwarn sun.misc.**
22 | -keep class rx.schedulers.Schedulers {
23 | public static ;
24 | }
25 | -keep class rx.schedulers.ImmediateScheduler {
26 | public ;
27 | }
28 | -keep class rx.schedulers.TestScheduler {
29 | public ;
30 | }
31 | -keep class rx.schedulers.Schedulers {
32 | public static ** test();
33 | }
34 | -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
35 | long producerIndex;
36 | long consumerIndex;
37 | }
38 | -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
39 | long producerNode;
40 | long consumerNode;
41 | rx.internal.util.atomic.LinkedQueueNode producerNode;
42 | }
43 |
44 | -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
45 | rx.internal.util.atomic.LinkedQueueNode consumerNode;
46 | }
47 |
48 | -dontnote rx.internal.util.PlatformDependent
49 |
50 |
51 | # Add project specific ProGuard rules here.
52 | # By default, the flags in this file are appended to flags specified
53 | # in $ANDROID_HOME/tools/proguard/proguard-android.txt
54 | # You can edit the include path and order by changing the proguardFiles
55 | # directive in build.gradle.
56 | #
57 | # For more details, see
58 | # http://developer.android.com/guide/developing/tools/proguard.html
59 |
60 | # Add any project specific keep options here:
61 |
62 | -dontwarn com.google.common.**
63 | -dontwarn okio.**
64 | -dontwarn org.mockito.**
65 | -dontwarn sun.reflect.**
66 | -dontwarn android.test.**
67 | # Ignores: can't find referenced class javax.lang.model.element.Modifier
68 | -dontwarn com.google.errorprone.annotations.**
69 | -keep class io.grpc.internal.DnsNameResolverProvider
70 | -keep class io.grpc.okhttp.OkHttpChannelProvider
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/adapter/ConversationListAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.adapter
18 |
19 | import android.support.v7.widget.RecyclerView
20 | import android.view.LayoutInflater
21 | import android.view.View
22 | import android.view.ViewGroup
23 | import android.widget.TextView
24 | import cn.dreamtobe.grpc.client.R
25 | import de.mkammerer.grpcchat.protocol.RoomMessage
26 |
27 | /**
28 | * Created by Jacksgong on 08/03/2017.
29 | */
30 | class ConversationListAdapter : RecyclerView.Adapter() {
31 |
32 | var conversationList = mutableListOf()
33 | var callback: Callback? = null
34 |
35 | override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ConversationListViewHolder {
36 | val itemView = LayoutInflater.from(parent!!.context)
37 | .inflate(R.layout.item_conversation, parent, false)
38 | val viewHolder = ConversationListViewHolder(itemView)
39 | viewHolder.contentLayout.setOnClickListener {
40 | callback?.onItemClick(viewHolder.roomMessage)
41 | }
42 |
43 | return viewHolder
44 | }
45 |
46 | override fun onBindViewHolder(holder: ConversationListViewHolder, position: Int) {
47 | val roomMessage = conversationList[position]
48 | holder.roomMessage = roomMessage
49 |
50 | holder.titleTv.text = roomMessage.title
51 | holder.descTv.text = roomMessage.desc
52 | }
53 |
54 | override fun getItemCount() = conversationList.size
55 |
56 | class ConversationListViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
57 | val contentLayout = itemView.findViewById(R.id.content_layout)!!
58 | val titleTv: TextView = itemView.findViewById(R.id.title_tv) as TextView
59 | val descTv: TextView = itemView.findViewById(R.id.desc_tv) as TextView
60 |
61 | lateinit var roomMessage : RoomMessage
62 | }
63 |
64 | interface Callback {
65 | fun onItemClick(roomMessage: RoomMessage)
66 | }
67 | }
--------------------------------------------------------------------------------
/client-android/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/client-android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.google.protobuf'
3 | apply plugin: 'kotlin-android'
4 |
5 | android {
6 | signingConfigs {
7 | release {
8 | keyAlias 'GrpcAndroidClient'
9 | keyPassword 'grpc-demo'
10 | storeFile file('/Users/Jacksgong/code/github/grpc-android-kotlin/client-android/app/grpc-demo.jks')
11 | storePassword 'grpc-demo'
12 | }
13 | }
14 |
15 | compileSdkVersion 25
16 | buildToolsVersion "25.0.2"
17 | defaultConfig {
18 | applicationId "cn.dreamtobe.grpc.client"
19 | minSdkVersion 15
20 | targetSdkVersion 25
21 | versionCode 2
22 | versionName "1.1"
23 | }
24 | buildTypes {
25 | release {
26 | minifyEnabled true
27 | shrinkResources true
28 | signingConfig signingConfigs.release
29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
30 | }
31 | }
32 | sourceSets {
33 | test.java.srcDirs += 'src/test/kotlin'
34 |
35 | main {
36 | java.srcDirs 'src/main/kotlin'
37 |
38 | proto {
39 | srcDir '../../grpc-chat-kotlin/protocol/src/main/proto'
40 | }
41 | }
42 | }
43 | }
44 |
45 | protobuf {
46 | protoc {
47 | artifact = 'com.google.protobuf:protoc:3.2.0'
48 | }
49 | plugins {
50 | javalite {
51 | artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
52 | }
53 | grpc {
54 | artifact = 'io.grpc:protoc-gen-grpc-java:1.1.2' // CURRENT_GRPC_VERSION
55 | }
56 | }
57 | generateProtoTasks {
58 | all().each { task ->
59 | task.plugins {
60 | javalite {}
61 | grpc {
62 | // Options added to --grpc_out
63 | option 'lite'
64 | }
65 | }
66 | }
67 | }
68 | }
69 |
70 | dependencies {
71 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
72 |
73 | compile 'com.android.support:appcompat-v7:25.2.0'
74 | compile 'com.android.support:design:25.2.0'
75 | compile 'io.grpc:grpc-okhttp:1.1.2'
76 | compile 'io.grpc:grpc-protobuf-lite:1.1.2'
77 | compile 'io.grpc:grpc-stub:1.1.2'
78 | compile 'javax.annotation:javax.annotation-api:1.2'
79 | compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
80 | compile 'com.android.support:cardview-v7:25.2.0'
81 |
82 | compile 'io.reactivex:rxkotlin:1.0.0-RC2'
83 |
84 | testCompile 'junit:junit:4.12'
85 | testCompile 'com.nhaarman:mockito-kotlin:1.3.0'
86 | testCompile 'org.robolectric:robolectric:3.3'
87 | testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
88 | }
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/tools/HandlerThreadScheduler.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * Licensed under the Apache License, Version 2.0 (the "License");
19 | * you may not use this file except in compliance with the License.
20 | * You may obtain a copy of the License at
21 |
22 | * http://www.apache.org/licenses/LICENSE-2.0
23 |
24 | * Unless required by applicable law or agreed to in writing, software
25 | * distributed under the License is distributed on an "AS IS" BASIS,
26 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 | * See the License for the specific language governing permissions and
28 | * limitations under the License.
29 | */
30 | package cn.dreamtobe.grpc.client.tools
31 |
32 | import android.os.Handler
33 | import rx.Scheduler
34 | import rx.Subscription
35 | import rx.functions.Action0
36 | import rx.internal.schedulers.ScheduledAction
37 | import rx.subscriptions.CompositeSubscription
38 | import rx.subscriptions.Subscriptions
39 | import java.util.concurrent.TimeUnit
40 |
41 | /**
42 | * Refer to RxAndroid
43 | */
44 | class HandlerThreadScheduler(private val handler: Handler) : Scheduler() {
45 |
46 | override fun createWorker(): Scheduler.Worker {
47 | return InnerHandlerThreadScheduler(handler)
48 | }
49 |
50 | private class InnerHandlerThreadScheduler(private val handler: Handler) : Scheduler.Worker() {
51 |
52 | private val compositeSubscription = CompositeSubscription()
53 |
54 | override fun unsubscribe() {
55 | compositeSubscription.unsubscribe()
56 | }
57 |
58 | override fun isUnsubscribed(): Boolean {
59 | return compositeSubscription.isUnsubscribed
60 | }
61 |
62 | override fun schedule(action: Action0, delayTime: Long, unit: TimeUnit): Subscription {
63 | val scheduledAction = ScheduledAction(action)
64 | scheduledAction.add(Subscriptions.create { handler.removeCallbacks(scheduledAction) })
65 | scheduledAction.addParent(compositeSubscription)
66 | compositeSubscription.add(scheduledAction)
67 |
68 | handler.postDelayed(scheduledAction, unit.toMillis(delayTime))
69 |
70 | return scheduledAction
71 | }
72 |
73 | override fun schedule(action: Action0): Subscription {
74 | return schedule(action, 0, TimeUnit.MILLISECONDS)
75 | }
76 |
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/tools/AndroidSchedulers.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.tools
18 |
19 | import android.os.Handler
20 | import android.os.Looper
21 | import rx.Scheduler
22 | import rx.functions.Func1
23 | import rx.schedulers.Schedulers
24 | import java.util.concurrent.LinkedBlockingQueue
25 | import java.util.concurrent.ThreadFactory
26 | import java.util.concurrent.ThreadPoolExecutor
27 | import java.util.concurrent.TimeUnit
28 | import java.util.concurrent.atomic.AtomicInteger
29 |
30 | /**
31 | * Created by Jacksgong on 07/03/2017.
32 | */
33 | class AndroidSchedulers {
34 | companion object {
35 | fun singleTaskThread(): Scheduler {
36 | val executor = ThreadPoolExecutor(1, 1, 5, TimeUnit.SECONDS, LinkedBlockingQueue(), object : ThreadFactory {
37 |
38 | private val threadNumber = AtomicInteger(1)
39 | private val group = Thread.currentThread().threadGroup
40 |
41 | override fun newThread(r: Runnable?): Thread {
42 | val t = Thread(group, r, "singleTaskThread ${threadNumber.getAndIncrement()}")
43 |
44 | if (t.isDaemon) {
45 | t.isDaemon = false
46 | }
47 |
48 | if (t.priority != Thread.NORM_PRIORITY) {
49 | t.priority = Thread.NORM_PRIORITY
50 | }
51 | return t
52 | }
53 | }, ThreadPoolExecutor.DiscardPolicy())
54 |
55 | executor.allowCoreThreadTimeOut(true)
56 |
57 | return Schedulers.from(executor)
58 | }
59 |
60 |
61 | private val mainThreadScheduler by lazy { HandlerThreadScheduler(Handler(Looper.getMainLooper())) }
62 | fun mainThread(): Scheduler {
63 | if (Hook.onMainScheduler != null) return Hook.onMainScheduler!!.call(mainThreadScheduler)
64 |
65 | return mainThreadScheduler
66 | }
67 | }
68 |
69 | class Hook {
70 | companion object {
71 | internal var onMainScheduler: Func1? = null
72 | fun reset() {
73 | onMainScheduler = null
74 | }
75 |
76 | //Func1 onIOScheduler
77 | fun setOnMainScheduler(scheduler: Func1) {
78 | onMainScheduler = scheduler
79 | }
80 | }
81 | }
82 |
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/client-android/app/src/main/res/layout/activity_conversation.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
24 |
36 |
37 |
54 |
55 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/README-zh.md:
--------------------------------------------------------------------------------
1 | # Grpc Android Kotlin
2 |
3 | > 通过[GRPC](https://github.com/grpc/grpc-java),包含后台,Android端,都是用kotlin编写。
4 |
5 | - [English](https://github.com/Jacksgong/grpc-android-kotlin)
6 |
7 | ## 快速预览
8 |
9 | > 由于我已经在我的一台测试VPS上部署了该项目的服务端的代码,如果你仅仅是想要测试Android,你可以通过下载[release-v1.1.apk](https://raw.githubusercontent.com/Jacksgong/grpc-android-kotlin/master/arts/release-v1.1.apk)或者是运行Android项目到你手机上,然后在应用中设置IP为`119.29.88.253`并且设置端口为`5351`, 这样你就可以连接到我的测试VPS,测试Android项目了。
10 |
11 | #### Android
12 |
13 | 
14 |
15 | #### 后端(日志)
16 |
17 | ```
18 | 20:51:16.650 [main] INFO de.mkammerer.grpcchat.server.Server - Server running on port 5001
19 | 20:51:32.803 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - jacks@dreamtobe.cn isn't exist, so register for it first
20 | 20:51:32.804 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - User jacks@dreamtobe.cn registered
21 | 20:51:32.807 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - User jacks@dreamtobe.cn logged in. Access token is qGNmE0/sBn3yO3scx1SRCA==
22 | 20:51:32.946 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - list rooms: 0
23 | 20:51:34.957 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - list rooms: 0
24 | 20:51:36.511 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - create room successfully
25 | 20:51:36.560 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - list rooms: 1
26 | 20:51:37.811 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - create room successfully
27 | 20:51:37.862 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - list rooms: 2
28 | 20:51:39.164 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - list rooms: 2
29 | > Building 93% > :server:run
30 | ```
31 |
32 | ## 运行
33 |
34 | #### 1. 获取后端代码([grpc-chat-kotlin](https://github.com/Jacksgong/grpc-chat-kotlin)):
35 |
36 | ```bash
37 | git submodule init
38 | git submodule update
39 | ```
40 |
41 | #### 2. 运行后端
42 |
43 | ```bash
44 | # generate protocol buffers for back-end
45 | bash refresh-backend-proto.sh
46 |
47 | # run server
48 | bash run-server.sh
49 | ```
50 |
51 | #### 3. 运行Android端
52 |
53 | ```bash
54 | # run Android application
55 | ./gradlew installDebug
56 | ```
57 |
58 | 由于`compile-kotlin`并没有在`compile-proto`之后,因此如果你修改了proto文件,或者clean了Android项目,记得运行下面的脚本,手动刷新生成下对应的proto文件,否则会有找不到proto代码的问题。
59 |
60 | ```bash
61 | # generate protocol buffers for Android
62 | bash refresh-android-proto.sh
63 | ```
64 |
65 | > 如果你想要运行Android项目的单元测试(这也是很好的一个kotlin Android项目[单元测试案例](https://github.com/Jacksgong/grpc-android-kotlin/tree/master/client-android/app/src/test/kotlin/cn/dreamtobe/grpc/client))
66 |
67 | ## LICENSE
68 |
69 | ```
70 | Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
71 |
72 | Licensed under the Apache License, Version 2.0 (the "License");
73 | you may not use this file except in compliance with the License.
74 | You may obtain a copy of the License at
75 |
76 | http://www.apache.org/licenses/LICENSE-2.0
77 |
78 | Unless required by applicable law or agreed to in writing, software
79 | distributed under the License is distributed on an "AS IS" BASIS,
80 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
81 | See the License for the specific language governing permissions and
82 | limitations under the License.
83 | ```
84 |
--------------------------------------------------------------------------------
/client-android/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
21 |
22 |
26 |
27 |
32 |
33 |
36 |
37 |
45 |
46 |
47 |
48 |
51 |
52 |
63 |
64 |
65 |
66 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Grpc Android Kotlin
2 |
3 | > Simple [GRPC](https://github.com/grpc/grpc-java) Server/Android written in kotlin, protobuf generated java files
4 |
5 | - [中文文档](https://github.com/Jacksgong/grpc-android-kotlin/blob/master/README-zh.md)
6 |
7 | ## I. Kickoff
8 |
9 | #### Android
10 |
11 | 
12 |
13 | #### Back-end(Logs)
14 |
15 | ```
16 | 20:51:16.650 [main] INFO de.mkammerer.grpcchat.server.Server - Server running on port 5001
17 | 20:51:32.803 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - jacks@dreamtobe.cn isn't exist, so register for it first
18 | 20:51:32.804 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - User jacks@dreamtobe.cn registered
19 | 20:51:32.807 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - User jacks@dreamtobe.cn logged in. Access token is qGNmE0/sBn3yO3scx1SRCA==
20 | 20:51:32.946 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - list rooms: 0
21 | 20:51:34.957 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - list rooms: 0
22 | 20:51:36.511 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - create room successfully
23 | 20:51:36.560 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - list rooms: 1
24 | 20:51:37.811 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - create room successfully
25 | 20:51:37.862 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - list rooms: 2
26 | 20:51:39.164 [grpc-default-executor-0] INFO de.mkammerer.grpcchat.server.Chat - list rooms: 2
27 | > Building 93% > :server:run
28 | ```
29 |
30 | ## II. Run
31 |
32 | ---
33 |
34 | Because of I'm running the server-side code on my testing-VPS.
35 |
36 | ### If you just want to test the Android Project
37 |
38 | ##### Step1. Install & Run Android project
39 |
40 | Alternative:
41 |
42 | - Download and install the [release-v1.1.apk](https://raw.githubusercontent.com/Jacksgong/grpc-android-kotlin/master/arts/release-v1.1.apk)
43 | - Running the Android-side project by yourself.
44 |
45 | ##### Step2. Configure
46 |
47 | - Set Ip to `119.29.88.253` on the application
48 | - Set Port to `5351` on the application
49 |
50 | So you can test through touching the server-side code on my testing-VPS, Have Fun!
51 |
52 | ---
53 |
54 | #### 1. Fetch the back-end codes([grpc-chat-kotlin](https://github.com/Jacksgong/grpc-chat-kotlin)):
55 |
56 | ```bash
57 | git submodule init
58 | git submodule update
59 | ```
60 |
61 | #### 2. Run back-end codes
62 |
63 | ```bash
64 | # generate protocol buffers for back-end
65 | bash refresh-backend-proto.sh
66 |
67 | # run server
68 | bash run-server.sh
69 | ```
70 |
71 | #### 3. Run Android codes
72 |
73 | ```bash
74 | # run Android application
75 | ./gradlew installDebug
76 | ```
77 |
78 | If your proto is changed or you android project has been cleaned don't forget refresh protocol buffers for Android manually(because compile-kotlin doesn't depence on compile-protocol, so we have to do that manually)
79 |
80 | ```bash
81 | # generate protocol buffers for Android
82 | bash refresh-android-proto.sh
83 | ```
84 |
85 | ## III. LICENSE
86 |
87 | ```
88 | Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
89 |
90 | Licensed under the Apache License, Version 2.0 (the "License");
91 | you may not use this file except in compliance with the License.
92 | You may obtain a copy of the License at
93 |
94 | http://www.apache.org/licenses/LICENSE-2.0
95 |
96 | Unless required by applicable law or agreed to in writing, software
97 | distributed under the License is distributed on an "AS IS" BASIS,
98 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
99 | See the License for the specific language governing permissions and
100 | limitations under the License.
101 | ```
102 |
--------------------------------------------------------------------------------
/client-android/app/src/test/kotlin/cn/dreamtobe/grpc/client/presenter/ConversationPresenterTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.presenter
18 |
19 | import cn.dreamtobe.grpc.client.GrpcClientTest
20 | import cn.dreamtobe.grpc.client.model.Codes
21 | import cn.dreamtobe.grpc.client.view.ConversationMvpView
22 | import com.nhaarman.mockito_kotlin.any
23 | import com.nhaarman.mockito_kotlin.mock
24 | import com.nhaarman.mockito_kotlin.verify
25 | import com.nhaarman.mockito_kotlin.whenever
26 | import de.mkammerer.grpcchat.protocol.CreateRoomResponse
27 | import de.mkammerer.grpcchat.protocol.Error
28 | import de.mkammerer.grpcchat.protocol.ListRoomsResponse
29 | import org.junit.After
30 | import org.junit.Before
31 | import org.junit.Test
32 |
33 | /**
34 | * Created by Jacksgong on 09/03/2017.
35 | */
36 | class ConversationPresenterTest : GrpcClientTest() {
37 |
38 | @Before
39 | fun setup() {
40 | create()
41 | }
42 |
43 | @After
44 | fun tearDown() {
45 | destroy()
46 | }
47 |
48 | @Test
49 | fun createRoom_Success_invokeCreatedNewRoom() {
50 | whenever(serverApi.createRoom()).thenReturn(successCreateRoomResponse)
51 | presenter.createRoom()
52 | verify(mvpView).createdNewRoom()
53 | }
54 |
55 | @Test
56 | fun createRoom_Error_invokeShowError() {
57 | whenever(serverApi.createRoom()).thenReturn(errorCreateRoomResponse)
58 | presenter.createRoom()
59 | verify(mvpView).showError(mockError)
60 | }
61 |
62 | @Test
63 | fun listRooms_Success_invokeShowConversations() {
64 | whenever(serverApi.listRooms()).thenReturn(successListRoomsResponse)
65 | presenter.listRooms()
66 | verify(mvpView).showLoading()
67 | verify(mvpView).showConversations(any())
68 | }
69 |
70 | @Test
71 | fun listRooms_Error_invokeShowError() {
72 | whenever(serverApi.listRooms()).thenReturn(errorListRoomsResponse)
73 | presenter.listRooms()
74 | verify(mvpView).showLoading()
75 | verify(mvpView).showError(mockFailed)
76 | }
77 |
78 | companion object {
79 | val successCreateRoomResponse =
80 | CreateRoomResponse.newBuilder()
81 | .setCreated(true)
82 | // we have to declare type cast, if not, it will raise Type mismatch
83 | .build() as CreateRoomResponse
84 |
85 | val mockError = mock()
86 | val errorCreateRoomResponse =
87 | CreateRoomResponse.newBuilder()
88 | .setCreated(false)
89 | .setError(mockError)
90 | // we have to declare type cast, if not, it will raise Type mismatch
91 | .build() as CreateRoomResponse
92 |
93 | val mockSuccess = Error.newBuilder().setCode(Codes.SUCCESS).build() as Error
94 | val mockFailed = Error.newBuilder().setCode(500).build() as Error
95 | val successListRoomsResponse =
96 | ListRoomsResponse.newBuilder()
97 | .setError(mockSuccess)
98 | .build() as ListRoomsResponse
99 | val errorListRoomsResponse =
100 | ListRoomsResponse.newBuilder()
101 | .setError(mockFailed)
102 | .build() as ListRoomsResponse
103 | }
104 | }
105 |
106 |
--------------------------------------------------------------------------------
/client-android/app/src/test/kotlin/cn/dreamtobe/grpc/client/presenter/LoginPresenterTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.presenter
18 |
19 | import cn.dreamtobe.grpc.client.GrpcClientTest
20 | import cn.dreamtobe.grpc.client.R
21 | import cn.dreamtobe.grpc.client.view.LoginMvpView
22 | import com.nhaarman.mockito_kotlin.mock
23 | import com.nhaarman.mockito_kotlin.verify
24 | import com.nhaarman.mockito_kotlin.whenever
25 | import de.mkammerer.grpcchat.protocol.Error
26 | import de.mkammerer.grpcchat.protocol.LoginOrRegisterResponse
27 | import org.junit.After
28 | import org.junit.Before
29 | import org.junit.Test
30 | import org.mockito.Mockito
31 |
32 | /**
33 | * Created by Jacksgong on 09/03/2017.
34 | */
35 | class LoginPresenterTest : GrpcClientTest() {
36 |
37 |
38 | @Before
39 | fun setup() {
40 | create()
41 | }
42 |
43 | @After
44 | fun tearDown() {
45 | destroy()
46 | }
47 |
48 | @Test
49 | fun attemptLoginOrRegister_success_invokeLoggedIn() {
50 | whenever(serverApi.loginOrRegister(Mockito.anyString(), Mockito.anyString()))
51 | .thenReturn(errorLoginOrRegisterResponse)
52 | presenter.attemptLoginOrRegister(correctUserName, correctPassword)
53 | verify(mvpView).showLoading()
54 | verify(mvpView).showError(mockError)
55 | }
56 |
57 | @Test
58 | fun attemptLoginOrRegister_error_invokeShowError() {
59 | whenever(serverApi.loginOrRegister(Mockito.anyString(), Mockito.anyString()))
60 | .thenReturn(successLoginOrRegisterResponse)
61 | presenter.attemptLoginOrRegister(correctUserName, correctPassword)
62 | verify(mvpView).showLoading()
63 | verify(mvpView).loggedIn(true)
64 | }
65 |
66 | @Test
67 | fun attemptLoginOrRegister_InvalidParams_invokeError() {
68 | presenter.attemptLoginOrRegister(invalidUserName, correctPassword)
69 | verify(mvpView).showUserNameError(R.string.error_invalid_email)
70 |
71 | presenter.attemptLoginOrRegister(correctUserName, shortPassword)
72 | verify(mvpView).showPasswordError(R.string.error_invalid_password)
73 |
74 | presenter.attemptLoginOrRegister(emptyUserName, correctPassword)
75 | verify(mvpView).showUserNameError(R.string.error_field_required)
76 |
77 | presenter.attemptLoginOrRegister(correctUserName, emptyPassword)
78 | verify(mvpView).showPasswordError(R.string.error_field_required)
79 | }
80 |
81 | companion object {
82 | val emptyUserName = ""
83 | val emptyPassword = ""
84 | val invalidUserName = "12"
85 | val shortPassword = "1234"
86 | val correctUserName = "abc@iiii.com"
87 | val correctPassword = "12345"
88 |
89 | val successLoginOrRegisterResponse =
90 | LoginOrRegisterResponse.newBuilder()
91 | .setPerformedRegister(true)
92 | .setToken("tempToken")
93 | .setLoggedIn(true)
94 | // we have to declare type cast, if not, it will raise Type mismatch
95 | .build() as LoginOrRegisterResponse
96 |
97 | val mockError = mock()
98 | val errorLoginOrRegisterResponse =
99 | LoginOrRegisterResponse.newBuilder()
100 | .setLoggedIn(false)
101 | .setError(mockError)
102 | // we have to declare type cast, if not, it will raise Type mismatch
103 | .build() as LoginOrRegisterResponse
104 | }
105 |
106 |
107 | }
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/presenter/ConversationPresenter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.presenter
18 |
19 | import cn.dreamtobe.grpc.client.GrpcClientApplication
20 | import cn.dreamtobe.grpc.client.model.Codes
21 | import cn.dreamtobe.grpc.client.model.ServerApi
22 | import cn.dreamtobe.grpc.client.tools.AndroidSchedulers
23 | import cn.dreamtobe.grpc.client.tools.ProgressSubscriber
24 | import cn.dreamtobe.grpc.client.view.ConversationMvpView
25 | import de.mkammerer.grpcchat.protocol.CreateRoomResponse
26 | import de.mkammerer.grpcchat.protocol.Error
27 | import de.mkammerer.grpcchat.protocol.ListRoomsResponse
28 | import rx.Observable
29 | import rx.schedulers.Schedulers
30 |
31 | /**
32 | * Created by Jacksgong on 08/03/2017.
33 | */
34 | class ConversationPresenter : Presenter {
35 |
36 | private var mView: ConversationMvpView? = null
37 | private lateinit var mServerApi: ServerApi
38 |
39 | override fun attachView(view: ConversationMvpView) {
40 | mView = view
41 | mServerApi = GrpcClientApplication.get(view.getContext()).getServerApi()
42 | }
43 |
44 | override fun detachView() {
45 | mView = null
46 | }
47 |
48 | fun createRoom() {
49 | this.mView ?: return
50 |
51 | Observable.create(Observable.OnSubscribe { subscriber ->
52 | try {
53 | subscriber.onNext(mServerApi.createRoom())
54 | subscriber.onCompleted()
55 | } catch (ex: Throwable) {
56 | subscriber.onError(ex)
57 | }
58 |
59 | }).subscribeOn(Schedulers.io())
60 | .observeOn(AndroidSchedulers.mainThread())
61 | .subscribe(object : ProgressSubscriber(mView!!.getContext()) {
62 | override fun onNext(response: CreateRoomResponse) {
63 | super.onNext(response)
64 | if (response.created) {
65 | mView?.createdNewRoom()
66 | } else {
67 | mView?.showError(response.error)
68 | }
69 | }
70 |
71 | override fun onError(e: Throwable?) {
72 | super.onError(e)
73 | mView?.showError(Error.newBuilder().setCode(Codes.LOCAL_ERROR).setMessage(e.toString()).build())
74 | }
75 | })
76 | }
77 |
78 | fun listRooms() {
79 | this.mView ?: return
80 |
81 | mView?.showLoading()
82 | Observable.create(Observable.OnSubscribe { subscriber ->
83 | try {
84 | subscriber.onNext(mServerApi.listRooms())
85 | subscriber.onCompleted()
86 | } catch (ex: Throwable) {
87 | subscriber.onError(ex)
88 | }
89 |
90 | }).subscribeOn(Schedulers.io())
91 | .observeOn(AndroidSchedulers.mainThread())
92 | .subscribe(
93 | { response ->
94 | if (response.error.code == Codes.SUCCESS) {
95 | mView?.showConversations(response.roomsList)
96 | } else {
97 | mView?.showError(response.error)
98 | }
99 | },
100 |
101 | { e ->
102 | mView?.showError(Error.newBuilder().setCode(400).setMessage(e.toString()).build())
103 | }
104 | )
105 | }
106 | }
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/activity/ConversationActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.activity
18 |
19 | import android.content.Context
20 | import android.os.Bundle
21 | import android.support.design.widget.Snackbar
22 | import android.support.v7.app.AppCompatActivity
23 | import android.support.v7.widget.LinearLayoutManager
24 | import android.support.v7.widget.RecyclerView
25 | import android.support.v7.widget.Toolbar
26 | import android.view.Menu
27 | import android.view.MenuItem
28 | import android.view.View
29 | import android.widget.Button
30 | import android.widget.ProgressBar
31 | import cn.dreamtobe.grpc.client.R
32 | import cn.dreamtobe.grpc.client.adapter.ConversationListAdapter
33 | import cn.dreamtobe.grpc.client.presenter.ConversationPresenter
34 | import cn.dreamtobe.grpc.client.tools.Logger
35 | import cn.dreamtobe.grpc.client.view.ConversationMvpView
36 | import de.mkammerer.grpcchat.protocol.Error
37 | import de.mkammerer.grpcchat.protocol.RoomMessage
38 |
39 | /**
40 | * Created by Jacksgong on 07/03/2017.
41 | */
42 | class ConversationActivity : AppCompatActivity(), ConversationMvpView {
43 | override fun getContext(): Context {
44 | return this
45 | }
46 |
47 | private lateinit var mToolbar: Toolbar
48 |
49 | private lateinit var mPresenter: ConversationPresenter
50 | private lateinit var mProgressView: ProgressBar
51 | private lateinit var mRecyclerView: RecyclerView
52 | private lateinit var mAdapter: ConversationListAdapter
53 | private lateinit var mRefreshBtn: Button
54 |
55 |
56 | override fun onCreate(savedInstanceState: Bundle?) {
57 | super.onCreate(savedInstanceState)
58 |
59 | setContentView(R.layout.activity_conversation)
60 |
61 | mPresenter = ConversationPresenter()
62 | mPresenter.attachView(this)
63 |
64 | mToolbar = findViewById(R.id.toolbar) as Toolbar
65 | setSupportActionBar(mToolbar)
66 | supportActionBar!!.title = "Conversation"
67 |
68 | mProgressView = findViewById(R.id.progressBar) as ProgressBar
69 | mRecyclerView = findViewById(R.id.recycler_view) as RecyclerView
70 | val adapter = ConversationListAdapter()
71 | adapter.callback = object : ConversationListAdapter.Callback {
72 | override fun onItemClick(roomMessage: RoomMessage) {
73 | Snackbar.make(mRecyclerView, "jump to chat page: ${roomMessage.title}, ${roomMessage.desc}", Snackbar.LENGTH_LONG).show()
74 | }
75 | }
76 | this.mAdapter = adapter
77 | mRecyclerView.adapter = adapter
78 | mRecyclerView.layoutManager = LinearLayoutManager(this)
79 |
80 | mRefreshBtn = findViewById(R.id.refresh_btn) as Button
81 | mRefreshBtn.setOnClickListener { mPresenter.listRooms() }
82 | }
83 |
84 | override fun onStart() {
85 | super.onStart()
86 | mPresenter.listRooms()
87 | }
88 |
89 | override fun onDestroy() {
90 | mPresenter.detachView()
91 | super.onDestroy()
92 | }
93 |
94 | override fun showLoading() {
95 | mRecyclerView.visibility = View.GONE
96 | mProgressView.visibility = View.VISIBLE
97 | mRefreshBtn.visibility = View.GONE
98 | }
99 |
100 | override fun showError(error: Error) {
101 | mRefreshBtn.visibility = View.VISIBLE
102 | mProgressView.visibility = View.GONE
103 | Snackbar.make(mRecyclerView, "occur error code: ${error.code} message: ${error.message}",
104 | Snackbar.LENGTH_LONG).show()
105 | Logger.log(javaClass, error.message)
106 | }
107 |
108 | override fun showConversations(roomMessageList: List) {
109 | mRefreshBtn.visibility = View.GONE
110 | mRecyclerView.visibility = View.VISIBLE
111 | mProgressView.visibility = View.GONE
112 |
113 | mAdapter.conversationList = roomMessageList.toMutableList()
114 | mAdapter.notifyDataSetChanged()
115 | mRecyclerView.requestFocus()
116 |
117 | Snackbar.make(mRecyclerView, "load ${roomMessageList.size} rooms from server",
118 | Snackbar.LENGTH_LONG).show()
119 | }
120 |
121 | override fun createdNewRoom() {
122 | Snackbar.make(mRecyclerView, "create one new room",
123 | Snackbar.LENGTH_LONG).show()
124 | mPresenter.listRooms()
125 | }
126 |
127 | override fun onOptionsItemSelected(item: MenuItem?): Boolean {
128 | when (item!!.itemId) {
129 | R.id.menu_refresh -> mPresenter.listRooms()
130 | R.id.menu_create -> mPresenter.createRoom()
131 | else -> return super.onOptionsItemSelected(item)
132 | }
133 | return true
134 | }
135 |
136 | override fun onCreateOptionsMenu(menu: Menu?): Boolean {
137 | menuInflater.inflate(R.menu.menu_conversation, menu)
138 | return super.onCreateOptionsMenu(menu)
139 | }
140 |
141 | }
--------------------------------------------------------------------------------
/client-android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/presenter/LoginPresenter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.presenter
18 |
19 | import android.app.LoaderManager
20 | import android.content.CursorLoader
21 | import android.content.Loader
22 | import android.database.Cursor
23 | import android.net.Uri
24 | import android.os.Bundle
25 | import android.provider.ContactsContract
26 | import android.text.TextUtils
27 | import cn.dreamtobe.grpc.client.GrpcClientApplication
28 | import cn.dreamtobe.grpc.client.R
29 | import cn.dreamtobe.grpc.client.model.Codes
30 | import cn.dreamtobe.grpc.client.model.ServerApi
31 | import cn.dreamtobe.grpc.client.tools.AndroidSchedulers
32 | import cn.dreamtobe.grpc.client.view.LoginMvpView
33 | import de.mkammerer.grpcchat.protocol.Error
34 | import de.mkammerer.grpcchat.protocol.LoginOrRegisterResponse
35 | import rx.Observable
36 | import rx.schedulers.Schedulers
37 |
38 | /**
39 | * Created by Jacksgong on 09/03/2017.
40 | */
41 | class LoginPresenter : Presenter, LoaderManager.LoaderCallbacks {
42 |
43 | private var mView: LoginMvpView? = null
44 | private lateinit var mServerApi: ServerApi
45 |
46 | override fun attachView(view: LoginMvpView) {
47 | mView = view
48 | mServerApi = GrpcClientApplication.get(view.getContext()).getServerApi()
49 | }
50 |
51 | override fun detachView() {
52 | mView = null
53 | }
54 |
55 | private fun isEmailValid(email: String): Boolean {
56 | return email.contains("@")
57 | }
58 |
59 | private fun isPasswordValid(password: String): Boolean {
60 | return password.length > 4
61 | }
62 |
63 | fun attemptLoginOrRegister(username: String, password: String) {
64 | mView?.resetError()
65 |
66 | // Check for a valid password, if the user entered one.
67 | if (TextUtils.isEmpty(password)) {
68 | mView?.showPasswordError(R.string.error_field_required)
69 | return
70 | }
71 | if (!isPasswordValid(password)) {
72 | mView?.showPasswordError(R.string.error_invalid_password)
73 | return
74 | }
75 |
76 | // Check for a valid email address.
77 | if (TextUtils.isEmpty(username)) {
78 | mView?.showUserNameError(R.string.error_field_required)
79 | return
80 | }
81 | if (!isEmailValid(username)) {
82 | mView?.showUserNameError(R.string.error_invalid_email)
83 | return
84 | }
85 |
86 | mView?.showLoading()
87 | Observable.create(Observable.OnSubscribe { subscriber ->
88 | try {
89 | subscriber.onNext(mServerApi.loginOrRegister(username, password))
90 | subscriber.onCompleted()
91 | } catch (ex: Throwable) {
92 | subscriber.onError(ex)
93 | }
94 |
95 | }).subscribeOn(Schedulers.io())
96 | .observeOn(AndroidSchedulers.mainThread())
97 | .subscribe(
98 | { response ->
99 | if (response.loggedIn) {
100 | mView?.loggedIn(response.performedRegister)
101 | } else {
102 | mView?.showError(response.error)
103 | }
104 | },
105 |
106 | { e ->
107 | mView?.showError(Error.newBuilder().setCode(Codes.LOCAL_ERROR).setMessage(e.toString()).build())
108 | }
109 | )
110 | }
111 |
112 | override fun onLoaderReset(loader: Loader?) {
113 | }
114 |
115 | override fun onLoadFinished(cursorLoader: Loader?, cursor: Cursor) {
116 | val emails = ArrayList()
117 | cursor.moveToFirst()
118 | while (!cursor.isAfterLast) {
119 | emails.add(cursor.getString(ProfileQuery.ADDRESS))
120 | cursor.moveToNext()
121 | }
122 |
123 | mView?.addEmailsToAutoComplete(emails)
124 | }
125 |
126 | override fun onCreateLoader(id: Int, args: Bundle?): Loader {
127 | return CursorLoader(mView!!.getContext(),
128 | // Retrieve data rows for the device user's 'profile' contact.
129 | Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
130 | ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
131 |
132 | // Select only email addresses.
133 | ContactsContract.Contacts.Data.MIMETYPE + " = ?", arrayOf(ContactsContract.CommonDataKinds.Email
134 | .CONTENT_ITEM_TYPE),
135 |
136 | // Show primary email addresses first. Note that there won't be
137 | // a primary email address if the user hasn't specified one.
138 | ContactsContract.Contacts.Data.IS_PRIMARY + " DESC")
139 | }
140 |
141 | private interface ProfileQuery {
142 | companion object {
143 | val PROJECTION = arrayOf(ContactsContract.CommonDataKinds.Email.ADDRESS, ContactsContract.CommonDataKinds.Email.IS_PRIMARY)
144 |
145 | val ADDRESS = 0
146 | val IS_PRIMARY = 1
147 | }
148 | }
149 | }
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/model/ServerApi.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.model
18 |
19 | import cn.dreamtobe.grpc.client.tools.Logger
20 | import de.mkammerer.grpcchat.protocol.*
21 | import io.grpc.ManagedChannelBuilder
22 | import java.text.DateFormat
23 | import java.text.SimpleDateFormat
24 | import java.util.*
25 |
26 |
27 | interface ServerApi {
28 |
29 | fun getPort(): Int
30 | fun setPort(port: Int)
31 | fun getHost(): String
32 | fun setHost(host: String)
33 |
34 | fun createRoom(): CreateRoomResponse
35 | fun register(username: String, password: String): Boolean
36 | fun loginOrRegister(username: String, password: String): LoginOrRegisterResponse
37 | fun login(username: String, password: String): Boolean
38 | fun listRooms(): ListRoomsResponse
39 |
40 | class TokenMissingException : Exception("Token is missing. Call login() first")
41 |
42 | class Channel {
43 | internal var port: Int = 5351
44 | internal var host: String = "grpc.jacksgong.com"
45 |
46 | private var connector: ChatGrpc.ChatBlockingStub? = null
47 |
48 | fun setHost(host: String) {
49 | if (host != this.host) {
50 | this.host = host
51 | reset()
52 | }
53 | }
54 |
55 | fun setPort(port: Int) {
56 | if (port != this.port) {
57 | this.port = port
58 | reset()
59 | }
60 | }
61 |
62 | private fun reset() {
63 | connector = null
64 | }
65 |
66 | internal fun stub(): ChatGrpc.ChatBlockingStub {
67 | if (connector == null) {
68 | val channel = ManagedChannelBuilder.forAddress(host, port)
69 | .usePlaintext(true)
70 | .build()
71 | connector = ChatGrpc.newBlockingStub(channel)
72 | }
73 | return connector!!
74 | }
75 |
76 | }
77 |
78 | class Factory {
79 | companion object {
80 | fun create(): ServerApi {
81 | return object : ServerApi {
82 |
83 |
84 | private var mToken: String? = null
85 | private val mDateFormat: DateFormat
86 | private var mLoggedInUser: String? = null
87 | private val mChannel: Channel = Channel()
88 |
89 | init {
90 | mDateFormat = SimpleDateFormat("MM-dd hh:mm:ss", Locale.CHINA)
91 | }
92 |
93 | override fun getPort() = mChannel.port
94 | override fun setPort(port: Int) {
95 | mChannel.setPort(port)
96 | }
97 |
98 | override fun getHost() = mChannel.host
99 | override fun setHost(host: String) {
100 | mChannel.setHost(host)
101 | }
102 |
103 | override fun createRoom(): CreateRoomResponse {
104 | if (mToken == null) throw TokenMissingException()
105 |
106 | val name = mDateFormat.format(Date())
107 | val request = CreateRoomRequest.newBuilder().setToken(mToken).setName(name).setDesc("create by $mLoggedInUser").build()
108 | val response = mChannel.stub().createRoom(request)
109 |
110 | if (response.created) {
111 | Logger.log(javaClass, "Room created: $name")
112 | } else {
113 | Logger.log(javaClass, "Room creation failed: $name, error: ${response.error}")
114 | }
115 |
116 | return response
117 | }
118 |
119 | override fun register(username: String, password: String): Boolean {
120 | val request = RegisterRequest.newBuilder().setUsername(username).setPassword(password).build()
121 | val response = mChannel.stub().register(request)
122 |
123 | if (response.registered) {
124 | Logger.log(javaClass, "Register successful")
125 | mLoggedInUser = username
126 | } else {
127 | Logger.log(javaClass, "Register failed, error: ${response.error}")
128 | mLoggedInUser = null
129 | }
130 |
131 | return response.registered
132 | }
133 |
134 | override fun loginOrRegister(username: String, password: String): LoginOrRegisterResponse {
135 | val request = LoginRequest.newBuilder().setUsername(username).setPassword(password).build()
136 | val response = mChannel.stub().loginOrRegister(request)
137 |
138 | if (response.loggedIn) {
139 | mToken = response.token
140 | Logger.log(javaClass, "Login successful, token is $mToken")
141 | mLoggedInUser = username
142 | } else {
143 | Logger.log(javaClass, "Login failed, error: ${response.error}")
144 | mLoggedInUser = null
145 | }
146 |
147 | return response
148 | }
149 |
150 | override fun login(username: String, password: String): Boolean {
151 | val request = LoginRequest.newBuilder().setUsername(username).setPassword(password).build()
152 | val response = mChannel.stub().login(request)
153 |
154 | if (response.loggedIn) {
155 | mToken = response.token
156 | mLoggedInUser = username
157 | Logger.log(javaClass, "Login successful, token is $mToken")
158 | } else {
159 | Logger.log(javaClass, "Login failed, error: ${response.error}")
160 | mLoggedInUser = null
161 | }
162 |
163 | return response.loggedIn
164 | }
165 |
166 | override fun listRooms(): ListRoomsResponse {
167 | if (mToken == null) throw TokenMissingException()
168 |
169 | val request = ListRoomsRequest.newBuilder().setToken(mToken).build()
170 | val response = mChannel.stub().listRooms(request)
171 |
172 | if (response.error.code == Codes.SUCCESS) {
173 | Logger.log(javaClass, "Rooms on server:")
174 | response.roomsList.forEach { it -> Logger.log(javaClass, it.title) }
175 | } else {
176 | Logger.log(javaClass, "List rooms failed, error: ${response.error}")
177 | }
178 |
179 | return response
180 | }
181 | }
182 | }
183 |
184 | }
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/client-android/app/src/main/kotlin/cn/dreamtobe/grpc/client/activity/LoginActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package cn.dreamtobe.grpc.client.activity
18 |
19 | import android.Manifest.permission.READ_CONTACTS
20 | import android.animation.Animator
21 | import android.animation.AnimatorListenerAdapter
22 | import android.annotation.TargetApi
23 | import android.content.Context
24 | import android.content.Intent
25 | import android.content.pm.PackageManager
26 | import android.os.Build
27 | import android.os.Bundle
28 | import android.support.design.widget.Snackbar
29 | import android.support.v7.app.AppCompatActivity
30 | import android.view.View
31 | import android.view.inputmethod.EditorInfo
32 | import android.widget.*
33 | import cn.dreamtobe.grpc.client.R
34 | import cn.dreamtobe.grpc.client.presenter.LoginPresenter
35 | import cn.dreamtobe.grpc.client.view.LoginMvpView
36 | import de.mkammerer.grpcchat.protocol.Error
37 |
38 | /**
39 | * A login screen that offers login via email/password.
40 | */
41 | class LoginActivity : AppCompatActivity(), LoginMvpView {
42 | override fun getContext(): Context {
43 | return this
44 | }
45 |
46 | // UI references.
47 | private lateinit var mUserNameView: AutoCompleteTextView
48 | private lateinit var mPasswordView: EditText
49 | private lateinit var mProgressView: View
50 | private lateinit var mLoginFormView: View
51 |
52 | private lateinit var mPresenter: LoginPresenter
53 |
54 | // the mock value isn't coupling with back-end logic
55 | private val mMockUserName = "jacks@dreamtobe.cn"
56 | private val mMockPassword = "dreamtobe"
57 |
58 | override fun onCreate(savedInstanceState: Bundle?) {
59 | super.onCreate(savedInstanceState)
60 | title = "Login"
61 | setContentView(R.layout.activity_login)
62 |
63 | mPresenter = LoginPresenter()
64 | mPresenter.attachView(this)
65 |
66 | // Set up the login form.
67 | mUserNameView = findViewById(R.id.username) as AutoCompleteTextView
68 | mUserNameView.setText(mMockUserName)
69 | populateAutoComplete()
70 |
71 | mPasswordView = findViewById(R.id.password) as EditText
72 | mPasswordView.setText(mMockPassword)
73 | mPasswordView.setOnEditorActionListener(TextView.OnEditorActionListener { _, id, _ ->
74 | if (id == R.id.login || id == EditorInfo.IME_NULL) {
75 | mPresenter.attemptLoginOrRegister(mUserNameView.text.toString(), mPasswordView.text.toString())
76 | return@OnEditorActionListener true
77 | }
78 | false
79 | })
80 |
81 | val signInOrRegisterBtn = findViewById(R.id.sign_in_or_register_btn) as Button
82 | signInOrRegisterBtn.setOnClickListener {
83 | mPresenter.attemptLoginOrRegister(mUserNameView.text.toString(), mPasswordView.text.toString())
84 | }
85 |
86 | mLoginFormView = findViewById(R.id.login_form)
87 | mProgressView = findViewById(R.id.login_progress)
88 | }
89 |
90 | override fun onDestroy() {
91 | mPresenter.detachView()
92 | super.onDestroy()
93 | }
94 |
95 | override fun resetError() {
96 | mUserNameView.error = null
97 | mPasswordView.error = null
98 | }
99 |
100 | override fun showPasswordError(tipsId: Int) {
101 | mPasswordView.error = getString(tipsId)
102 | mPasswordView.requestFocus()
103 | }
104 |
105 | override fun showUserNameError(tipsId: Int) {
106 | mUserNameView.error = getString(tipsId)
107 | mUserNameView.requestFocus()
108 | }
109 |
110 | override fun showLoading() {
111 | showProgress(true)
112 | }
113 |
114 | override fun loggedIn(performedRegister: Boolean) {
115 | showProgress(false)
116 | Snackbar.make(mLoginFormView, "complete login with performed register: $performedRegister",
117 | Snackbar.LENGTH_LONG).show()
118 | startActivity(Intent(this, ConversationActivity::class.java))
119 | finish()
120 | }
121 |
122 | override fun showError(error: Error) {
123 | showProgress(false)
124 | Snackbar.make(mLoginFormView, "request loginOrRegister error: ${error.code} with ${error.message}",
125 | Snackbar.LENGTH_LONG).show()
126 | }
127 |
128 | /**
129 | * Shows the progress UI and hides the login form.
130 | */
131 | @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
132 | private fun showProgress(show: Boolean) {
133 | // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
134 | // for very easy animations. If available, use these APIs to fade-in
135 | // the progress spinner.
136 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
137 | val shortAnimTime = resources.getInteger(android.R.integer.config_shortAnimTime)
138 |
139 | mLoginFormView.visibility = if (show) View.GONE else View.VISIBLE
140 | mLoginFormView.animate().setDuration(shortAnimTime.toLong()).alpha(
141 | (if (show) 0 else 1).toFloat()).setListener(object : AnimatorListenerAdapter() {
142 | override fun onAnimationEnd(animation: Animator) {
143 | mLoginFormView.visibility = if (show) View.GONE else View.VISIBLE
144 | }
145 | })
146 |
147 | mProgressView.visibility = if (show) View.VISIBLE else View.GONE
148 | mProgressView.animate().setDuration(shortAnimTime.toLong()).alpha(
149 | (if (show) 1 else 0).toFloat()).setListener(object : AnimatorListenerAdapter() {
150 | override fun onAnimationEnd(animation: Animator) {
151 | mProgressView.visibility = if (show) View.VISIBLE else View.GONE
152 | }
153 | })
154 | } else {
155 | // The ViewPropertyAnimator APIs are not available, so simply show
156 | // and hide the relevant UI components.
157 | mProgressView.visibility = if (show) View.VISIBLE else View.GONE
158 | mLoginFormView.visibility = if (show) View.GONE else View.VISIBLE
159 | }
160 | }
161 |
162 | override fun addEmailsToAutoComplete(emailAddressCollection: List) {
163 | //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
164 | val adapter = ArrayAdapter(this@LoginActivity,
165 | android.R.layout.simple_dropdown_item_1line, emailAddressCollection)
166 |
167 | mUserNameView.setAdapter(adapter)
168 | }
169 |
170 | /**
171 | * Callback received when a permissions request has been completed.
172 | */
173 | override fun onRequestPermissionsResult(requestCode: Int, permissions: Array,
174 | grantResults: IntArray) {
175 | if (requestCode == REQUEST_READ_CONTACTS) {
176 | if (grantResults.size == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
177 | populateAutoComplete()
178 | }
179 | }
180 | }
181 | private fun populateAutoComplete() {
182 | if (!mayRequestContacts()) {
183 | return
184 | }
185 |
186 | loaderManager.initLoader(0, Bundle(), mPresenter)
187 | }
188 |
189 | private fun mayRequestContacts(): Boolean {
190 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
191 | return true
192 | }
193 | if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
194 | return true
195 | }
196 | if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
197 | Snackbar.make(mUserNameView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
198 | .setAction(android.R.string.ok) { requestPermissions(arrayOf(READ_CONTACTS), REQUEST_READ_CONTACTS) }
199 | } else {
200 | requestPermissions(arrayOf(READ_CONTACTS), REQUEST_READ_CONTACTS)
201 | }
202 | return false
203 | }
204 |
205 |
206 | companion object {
207 |
208 | /**
209 | * Id to identity READ_CONTACTS permission request.
210 | */
211 | private val REQUEST_READ_CONTACTS = 0
212 | }
213 | }
214 |
215 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/client-android/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright (C) 2017 Jacksgong(blog.dreamtobe.cn)
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------