Code Monkey home page Code Monkey logo

wanandroid's Introduction

WanAndroid

Download License 996.icu LICENSE

玩Android项目练习

下载

implementation 'com.hxw.kjm:core:<latestVersion>'

在项目的build.gradle里加上

buildscript {
    ...
    dependencies {
        ...
        classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.5'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        <!--maven{ url 'https://dl.bintray.com/huxiaowei008/maven/'}-->
        google()
        jcenter()
    }
}

再在项目的build.gradle里添加依赖和插件

apply plugin: 'android-aspectjx'

android{
    defaultConfig {
        ...
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        //multiDexEnabled true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}
dependencies {
    ...
    implementation 'com.hxw.kjm:core:<latestVersion>'
}
    
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

使用

注意:由于使用了谷歌的Material, 所以在主题上要继承Material的主题。示例:

<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- ... -->
</style>

继承上面的主题会更改一些控件样式,如果不想改变样式就继承bridge,样式由自己控制,详细按钮参数可以查看 MaterialButton

<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
    <!-- ... -->
</style>

新建一个module继承ConfigModule接口,实现各个方法

class GlobalConfigModule : ConfigModule {
    override fun configGson(context: Context, builder: GsonBuilder) {
        builder.setDateFormat("yyyy-MM-dd HH:mm:ss")
    }

    override fun configOkHttp(context: Context, builder: OkHttpClient.Builder) {

    }

    override fun configRetrofit(context: Context, builder: Retrofit.Builder) {
        builder.baseUrl(WanApi.BASEURL)
    }
}

新建一个Application继承Application,构建内部代理ApplicationDelegate并调用方法,调用startKoin方法, 然后再Manifest中注册Application,注意一定要提供ConfigModule的实现

Kodein-DI 一个kotlin方式的依赖注入,但换成了 koin

class WanKodeinApplication : Application() {
    private val delegate by lazy { ApplicationDelegate(listOf(coreModule, appModule, viewModel)) }

    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        delegate.attachBaseContext(base)
        MultiDex.install(base)
    }

    override fun onCreate() {
        super.onCreate()
        delegate.onCreate(this@WanKodeinApplication)
        Coil.setDefaultImageLoader(ImageLoader(this){
            okHttpClient(get<OkHttpClient>())
            crossfade(true)
            placeholder(R.drawable.ic_placeholder)
            error(R.drawable.ic_error)
        })
    }

    override fun onTerminate() {
        super.onTerminate()
        delegate.onTerminate(this@WanKodeinApplication)
    }
}

val appModule= module {

    single<ConfigModule> { GlobalConfigModule() }

    single { get<Retrofit>().create(WanApi::class.java) }
}

三方库(索引)

KTX

kotlinx.coroutines

Anko

Gson

Retrofit

OkHttp

Timber

Glide

Coil

RxKotlin

RxJava

RxAndroid

RxRelay

RxBinding

Kodein-DI

Dagger2

koin

AutoDispose

RxDocs

Aspectj

License

Copyright huxiaowei008

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.

wanandroid's People

Contributors

huxiaowei008 avatar

Stargazers

Oleg Nikitin avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.