Skip to content

Commit 6864f2c

Browse files
committed
Initial commit of refactoring
0 parents  commit 6864f2c

Some content is hidden

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

50 files changed

+1415
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.gradle
2+
.idea
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
*.iml
10+
*.apk
11+
*.jobf

README.md

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

app/.gitignore

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

app/build.gradle

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
apply plugin: 'kotlin-kapt'
5+
6+
android {
7+
compileSdkVersion COMPILE_SDK_VERSION.toInteger()
8+
9+
defaultConfig {
10+
applicationId "cn.nekocode.gank"
11+
minSdkVersion 16
12+
targetSdkVersion 27
13+
versionCode 1
14+
versionName "1.0"
15+
16+
def SCHEME = "gank"
17+
18+
buildConfigField "String", "SCHEME", "\"$SCHEME\""
19+
20+
manifestPlaceholders = [
21+
APPLICATION_ID: applicationId,
22+
SCHEME: SCHEME,
23+
]
24+
}
25+
buildTypes {
26+
release {
27+
minifyEnabled false
28+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29+
}
30+
}
31+
}
32+
33+
dependencies {
34+
implementation fileTree(dir: 'libs', include: ['*.jar'])
35+
implementation project(':backend')
36+
37+
// Kotlin
38+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${KOTLIN_VERSION}"
39+
40+
// Android support libraries
41+
implementation "com.android.support:appcompat-v7:${SUPPORT_LIBS_VERSION}"
42+
implementation "com.android.support:recyclerview-v7:${SUPPORT_LIBS_VERSION}"
43+
implementation "com.android.support:support-annotations:${SUPPORT_LIBS_VERSION}"
44+
implementation "com.android.support:design:${SUPPORT_LIBS_VERSION}"
45+
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
46+
47+
// ReactiveX
48+
implementation "io.reactivex.rxjava2:rxjava:2.1.8"
49+
implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
50+
def AUTO_DISPOSE_VERSION = "0.4.0"
51+
implementation "com.uber.autodispose:autodispose:${AUTO_DISPOSE_VERSION}"
52+
implementation "com.uber.autodispose:autodispose-android:${AUTO_DISPOSE_VERSION}"
53+
implementation "com.uber.autodispose:autodispose-android-archcomponents:${AUTO_DISPOSE_VERSION}"
54+
55+
// Others
56+
implementation 'com.squareup.picasso:picasso:2.5.2'
57+
implementation "com.github.nekocode:Meepo:0.3"
58+
def ITEMS_VERSION = '0.8'
59+
implementation "com.github.nekocode.Items:items:${ITEMS_VERSION}"
60+
kapt "com.github.nekocode.Items:items-processor:${ITEMS_VERSION}"
61+
def STATE_VERSION = '1.3.1'
62+
implementation "com.evernote:android-state:${STATE_VERSION}"
63+
kapt "com.evernote:android-state-processor:${STATE_VERSION}"
64+
implementation 'pub.devrel:easypermissions:1.2.0'
65+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="cn.nekocode.gank">
4+
5+
<uses-permission android:name="android.permission.INTERNET"/>
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
7+
8+
<application
9+
android:name=".GankApplication"
10+
android:allowBackup="true"
11+
android:icon="@mipmap/ic_launcher"
12+
android:label="@string/app_name"
13+
android:roundIcon="@mipmap/ic_launcher_round"
14+
android:supportsRtl="true"
15+
android:theme="@style/AppTheme">
16+
<activity android:name=".ui.home.MainActivity"
17+
android:launchMode="singleTop"
18+
>
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN"/>
21+
22+
<category android:name="android.intent.category.LAUNCHER"/>
23+
</intent-filter>
24+
</activity>
25+
26+
<activity
27+
android:name=".ui.pic.PicActivity"
28+
>
29+
</activity>
30+
31+
</application>
32+
33+
</manifest>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2018. nekocode ([email protected])
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.nekocode.gank
18+
19+
import android.content.Context
20+
import cn.nekocode.gank.ui.pic.PicActivity
21+
import cn.nekocode.meepo.annotation.Clazz
22+
23+
/**
24+
* @author nekocode ([email protected])
25+
*/
26+
interface ActivityRouter {
27+
28+
@Clazz(PicActivity::class)
29+
fun gotoPic(context: Context)
30+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2018. nekocode ([email protected])
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.nekocode.gank
18+
19+
import android.app.Application
20+
import android.content.BroadcastReceiver
21+
import android.content.Context
22+
import android.content.Intent
23+
import android.content.IntentFilter
24+
import android.support.v4.content.LocalBroadcastManager
25+
import cn.nekocode.gank.backend.GankIoService
26+
import cn.nekocode.gank.broadcast.BroadcastCallAdapter
27+
import cn.nekocode.gank.broadcast.BroadcastConfig
28+
import cn.nekocode.gank.broadcast.BroadcastRouter
29+
import cn.nekocode.meepo.Meepo
30+
import cn.nekocode.meepo.config.UriConfig
31+
import com.google.gson.Gson
32+
import okhttp3.OkHttpClient
33+
34+
/**
35+
* @author nekocode ([email protected])
36+
*/
37+
class GankApplication: Application() {
38+
lateinit var activityRouter: ActivityRouter
39+
lateinit var broadcastRouter: BroadcastRouter
40+
lateinit var gankIoService: GankIoService
41+
42+
override fun onCreate() {
43+
super.onCreate()
44+
45+
activityRouter = Meepo.Builder()
46+
.config(UriConfig().scheme(BuildConfig.SCHEME).host(BuildConfig.APPLICATION_ID))
47+
.build().create(ActivityRouter::class.java)
48+
broadcastRouter = Meepo.Builder()
49+
.config(BroadcastConfig()).adapter(BroadcastCallAdapter())
50+
.build().create(BroadcastRouter::class.java)
51+
gankIoService = GankIoService(OkHttpClient(), Gson())
52+
}
53+
}
54+
55+
fun Context.activityRouter() = (this.applicationContext as GankApplication).activityRouter
56+
fun Context.broadcastRouter() = (this.applicationContext as GankApplication).broadcastRouter
57+
fun Context.gankIoService() = (this.applicationContext as GankApplication).gankIoService
58+
59+
fun Context.registerLocalReceiver(
60+
receiver: (Context?, Intent?) -> Unit, intentFilter: IntentFilter) {
61+
62+
LocalBroadcastManager.getInstance(this)
63+
.registerReceiver(object : BroadcastReceiver() {
64+
override fun onReceive(context: Context?, intent: Intent?) {
65+
receiver.invoke(context, intent)
66+
}
67+
}, intentFilter)
68+
}
69+
fun Context.registerLocalReceiver(receiver: (Context?, Intent?) -> Unit, vararg actions: String) {
70+
val intentFilter = IntentFilter()
71+
actions.forEach {
72+
intentFilter.addAction(it)
73+
}
74+
registerLocalReceiver(receiver, intentFilter)
75+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2018. nekocode ([email protected])
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.nekocode.gank.base
18+
19+
import android.support.v4.app.NavUtils
20+
import android.support.v7.app.AppCompatActivity
21+
import android.view.MenuItem
22+
23+
/**
24+
* @author nekocode ([email protected])
25+
*/
26+
open class BaseActivity: AppCompatActivity() {
27+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
28+
return when (item.itemId) {
29+
android.R.id.home -> {
30+
if (NavUtils.getParentActivityName(this) != null) {
31+
NavUtils.navigateUpFromSameTask(this)
32+
} else {
33+
finish()
34+
}
35+
true
36+
}
37+
38+
else -> {
39+
super.onOptionsItemSelected(item)
40+
}
41+
}
42+
}
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2018. nekocode ([email protected])
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.nekocode.gank.broadcast
18+
19+
import android.content.Intent
20+
import android.support.v4.content.LocalBroadcastManager
21+
22+
import cn.nekocode.meepo.CallMethod
23+
import cn.nekocode.meepo.MeepoUtils
24+
import cn.nekocode.meepo.adapter.CallAdapter
25+
import cn.nekocode.meepo.config.Config
26+
27+
/**
28+
* @author nekocode ([email protected])
29+
*/
30+
class BroadcastCallAdapter : CallAdapter<Void> {
31+
32+
override fun call(config: Config, method: CallMethod, args: Array<Any>): Void? {
33+
val context = MeepoUtils.getContextFromFirstParameter(args) ?: return null
34+
35+
val intent = Intent()
36+
intent.action = method.action
37+
intent.putExtras(method.getBundle(args))
38+
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
39+
40+
return null
41+
}
42+
}

0 commit comments

Comments
 (0)