-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
557 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../nekocode/gank/di/module/FlipperModule.kt → .../nekocode/caka/di/module/FlipperModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,15 +14,15 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
package cn.nekocode.gank | ||
package cn.nekocode.caka | ||
|
||
import android.app.Application | ||
import androidx.lifecycle.ViewModelProvider | ||
import cn.nekocode.gank.backend.di.module.ApiModule | ||
import cn.nekocode.gank.di.component.AppComponent | ||
import cn.nekocode.gank.di.component.DaggerAppComponent | ||
import cn.nekocode.gank.di.module.AppModule | ||
import cn.nekocode.gank.di.module.FlipperModule | ||
import cn.nekocode.caka.backend.di.module.ApiModule | ||
import cn.nekocode.caka.di.component.AppComponent | ||
import cn.nekocode.caka.di.component.DaggerAppComponent | ||
import cn.nekocode.caka.di.module.AppModule | ||
import cn.nekocode.caka.di.module.FlipperModule | ||
import com.facebook.flipper.core.FlipperClient | ||
import com.google.gson.GsonBuilder | ||
import okhttp3.OkHttpClient | ||
|
@@ -32,7 +32,7 @@ import javax.inject.Inject | |
/** | ||
* @author nekocode ([email protected]) | ||
*/ | ||
open class GankApplication : Application() { | ||
open class MyApplication : Application() { | ||
lateinit var component: AppComponent | ||
@Inject | ||
lateinit var flipperClient: FlipperClient | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,31 +14,24 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
package cn.nekocode.gank.base | ||
package cn.nekocode.caka.base | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProviders | ||
import cn.nekocode.gank.GankApplication | ||
import cn.nekocode.gank.di.component.buildAndInject | ||
import androidx.lifecycle.ViewModelProvider | ||
import cn.nekocode.caka.MyApplication | ||
import cn.nekocode.caka.di.component.buildAndInject | ||
import com.evernote.android.state.StateSaver | ||
import com.uber.autodispose.* | ||
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider | ||
import io.reactivex.* | ||
import io.reactivex.annotations.CheckReturnValue | ||
import io.reactivex.parallel.ParallelFlowable | ||
|
||
/** | ||
* @author nekocode ([email protected]) | ||
*/ | ||
abstract class BaseActivity : AppCompatActivity() { | ||
private val scopeProvider by lazy { AndroidLifecycleScopeProvider.from(this) } | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
(application as GankApplication).component | ||
(application as MyApplication).component | ||
.newActivityComponentBuilder().buildAndInject(this) | ||
super.onCreate(savedInstanceState) | ||
StateSaver.restoreInstanceState(this, savedInstanceState) | ||
|
@@ -56,35 +49,8 @@ abstract class BaseActivity : AppCompatActivity() { | |
getViewModelProvider(this).get(modelClass) | ||
|
||
fun getViewModelProvider(fragment: Fragment) = | ||
ViewModelProviders.of(fragment, (application as GankApplication).viewModelFactory) | ||
ViewModelProvider(fragment, (application as MyApplication).viewModelFactory) | ||
|
||
fun getViewModelProvider(activity: FragmentActivity) = | ||
ViewModelProviders.of(activity, (application as GankApplication).viewModelFactory) | ||
|
||
/** | ||
* Modified from https://github.com/uber/AutoDispose | ||
*/ | ||
@CheckReturnValue | ||
fun <T> Flowable<T>.autoDisposable(): FlowableSubscribeProxy<T> = | ||
this.`as`(AutoDispose.autoDisposable(scopeProvider)) | ||
|
||
@CheckReturnValue | ||
fun <T> Observable<T>.autoDisposable(): ObservableSubscribeProxy<T> = | ||
this.`as`(AutoDispose.autoDisposable(scopeProvider)) | ||
|
||
@CheckReturnValue | ||
fun <T> Single<T>.autoDisposable(): SingleSubscribeProxy<T> = | ||
this.`as`(AutoDispose.autoDisposable(scopeProvider)) | ||
|
||
@CheckReturnValue | ||
fun <T> Maybe<T>.autoDisposable(): MaybeSubscribeProxy<T> = | ||
this.`as`(AutoDispose.autoDisposable(scopeProvider)) | ||
|
||
@CheckReturnValue | ||
fun Completable.autoDisposable(): CompletableSubscribeProxy = | ||
this.`as`(AutoDispose.autoDisposable<Any>(scopeProvider)) | ||
|
||
@CheckReturnValue | ||
fun <T> ParallelFlowable<T>.autoDisposable(): ParallelFlowableSubscribeProxy<T> = | ||
this.`as`(AutoDispose.autoDisposable(scopeProvider)) | ||
ViewModelProvider(activity, (application as MyApplication).viewModelFactory) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2019. nekocode ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.nekocode.caka.base | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentActivity | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import cn.nekocode.caka.MyApplication | ||
import cn.nekocode.caka.di.component.buildAndInject | ||
import com.evernote.android.state.StateSaver | ||
|
||
/** | ||
* @author nekocode ([email protected]) | ||
*/ | ||
abstract class BaseFragment : Fragment { | ||
constructor() : super() | ||
constructor(contentLayoutId: Int) : super(contentLayoutId) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
application?.component?.newFragmentComponentBuilder()?.buildAndInject(this) | ||
super.onCreate(savedInstanceState) | ||
StateSaver.restoreInstanceState(this, savedInstanceState) | ||
} | ||
|
||
override fun onSaveInstanceState(outState: Bundle) { | ||
super.onSaveInstanceState(outState) | ||
StateSaver.saveInstanceState(this, outState) | ||
} | ||
|
||
val application: MyApplication? | ||
get() = context?.applicationContext as MyApplication? | ||
|
||
fun setTitle(title: String) { | ||
(activity as AppCompatActivity?)?.supportActionBar?.title = title | ||
} | ||
|
||
fun <T : ViewModel> getViewModel(key: String, modelClass: Class<T>) = | ||
getViewModelProvider(this).get(key, modelClass) | ||
|
||
fun <T : ViewModel> getViewModel(modelClass: Class<T>) = | ||
getViewModelProvider(this).get(modelClass) | ||
|
||
fun getViewModelProvider(fragment: Fragment) = | ||
ViewModelProvider(fragment, application!!.viewModelFactory) | ||
|
||
fun getViewModelProvider(activity: FragmentActivity) = | ||
ViewModelProvider(activity, application!!.viewModelFactory) | ||
} |
Oops, something went wrong.