Skip to content

Commit

Permalink
Upgraded stuff & renamed packages
Browse files Browse the repository at this point in the history
  • Loading branch information
nekocode committed Feb 5, 2021
1 parent 1a20867 commit 84aaba7
Show file tree
Hide file tree
Showing 43 changed files with 557 additions and 550 deletions.
75 changes: 36 additions & 39 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,38 @@ import org.jetbrains.kotlin.config.KotlinCompilerVersion
plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
kotlin("kapt")
id("kotlin-parcelize")
id("androidx.navigation.safeargs")
id("com.akaita.android.easylauncher")
}

androidExtensions {
isExperimental = true
features = setOf("views", "parcelize")
}

android {
compileSdkVersion(28)
compileSdkVersion(29)
defaultConfig {
targetSdkVersion(28)
minSdkVersion(21)
applicationId = "cn.nekocode.gank"
applicationId = "cn.nekocode.caka"
versionCode = 1
versionName = "1.0"

val scheme = "gank"
val scheme = "caka"

buildConfigField("String", "SCHEME", "\"$scheme\"")

manifestPlaceholders = mapOf(
"APPLICATION_ID" to applicationId,
addManifestPlaceholders(mapOf(
"APPLICATION_ID" to applicationId!!,
"SCHEME" to scheme
)
))
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}
buildFeatures {
viewBinding = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -52,46 +49,46 @@ dependencies {
implementation(kotlin("stdlib-jdk8", KotlinCompilerVersion.VERSION))

// Androidx
implementation("androidx.appcompat:appcompat:1.1.0")
implementation("androidx.core:core-ktx:1.1.0")
implementation("androidx.recyclerview:recyclerview:1.1.0-beta05")
implementation("androidx.constraintlayout:constraintlayout:2.0.0-beta2")
implementation("androidx.lifecycle:lifecycle-extensions:2.1.0")
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("androidx.core:core-ktx:1.3.2")
implementation("androidx.recyclerview:recyclerview:1.2.0-beta01")
implementation("androidx.constraintlayout:constraintlayout:2.1.0-alpha2")
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")

// Navigation
implementation("android.arch.navigation:navigation-fragment-ktx:1.0.0")
implementation("android.arch.navigation:navigation-ui-ktx:1.0.0")
implementation("androidx.navigation:navigation-fragment-ktx:2.3.3")
implementation("androidx.navigation:navigation-ui-ktx:2.3.3")

// ReactiveX
implementation("com.uber.autodispose:autodispose:1.4.0")
implementation("com.uber.autodispose:autodispose-android:1.4.0")
implementation("com.uber.autodispose:autodispose-android-archcomponents:1.4.0")
implementation("com.uber.autodispose2:autodispose:2.0.0")
implementation("com.uber.autodispose2:autodispose-android:2.0.0")
implementation("com.uber.autodispose2:autodispose-androidx-lifecycle:2.0.0")

// Dependency injection
implementation("com.google.dagger:dagger:2.24")
kapt("com.google.dagger:dagger-compiler:2.24")
implementation("com.google.dagger:dagger:2.31.2")
kapt("com.google.dagger:dagger-compiler:2.31.2")

// Others
implementation("com.squareup.picasso:picasso:2.71828")
implementation("com.jakewharton.timber:timber:4.7.1")
implementation("com.evernote:android-state:1.4.1")
kapt("com.evernote:android-state-processor:1.4.1")

// For debugging
debugImplementation("com.facebook.flipper:flipper:0.23.2")
debugImplementation("com.facebook.soloader:soloader:0.8.0")
debugImplementation("com.facebook.soloader:soloader:0.10.1")
releaseImplementation("com.facebook.flipper:flipper-noop:0.23.2")
debugImplementation("com.willowtreeapps.hyperion:hyperion-core:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-attr:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-build-config:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-crash:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-disk:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-geiger-counter:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-measurement:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-phoenix:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-recorder:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-shared-preferences:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-timber:0.9.27")
releaseImplementation("com.willowtreeapps.hyperion:hyperion-core-no-op:0.9.27")
debugImplementation("com.willowtreeapps.hyperion:hyperion-core:0.9.31")
debugImplementation("com.willowtreeapps.hyperion:hyperion-attr:0.9.31")
debugImplementation("com.willowtreeapps.hyperion:hyperion-build-config:0.9.31")
debugImplementation("com.willowtreeapps.hyperion:hyperion-crash:0.9.31")
debugImplementation("com.willowtreeapps.hyperion:hyperion-disk:0.9.31")
debugImplementation("com.willowtreeapps.hyperion:hyperion-geiger-counter:0.9.31")
debugImplementation("com.willowtreeapps.hyperion:hyperion-measurement:0.9.31")
debugImplementation("com.willowtreeapps.hyperion:hyperion-phoenix:0.9.31")
debugImplementation("com.willowtreeapps.hyperion:hyperion-recorder:0.9.31")
debugImplementation("com.willowtreeapps.hyperion:hyperion-shared-preferences:0.9.31")
debugImplementation("com.willowtreeapps.hyperion:hyperion-timber:0.9.31")
releaseImplementation("com.willowtreeapps.hyperion:hyperion-core-no-op:0.9.31")
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).all {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.nekocode.gank.di.module
package cn.nekocode.caka.di.module

import android.app.Application
import cn.nekocode.gank.di.AppScope
import cn.nekocode.caka.di.AppScope
import com.facebook.flipper.android.AndroidFlipperClient
import com.facebook.flipper.android.utils.FlipperUtils
import com.facebook.flipper.core.FlipperClient
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="cn.nekocode.gank">
package="cn.nekocode.caka">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

<application
android:name=".GankApplication"
android:name="cn.nekocode.caka.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand All @@ -18,7 +18,7 @@
tools:ignore="GoogleAppIndexingWarning"
>
<activity
android:name=".ui.MainActivity"
android:name="cn.nekocode.caka.ui.MainActivity"
android:launchMode="singleTop"
>
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
65 changes: 65 additions & 0 deletions app/src/main/java/cn/nekocode/caka/base/BaseFragment.kt
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)
}
Loading

0 comments on commit 84aaba7

Please sign in to comment.