Skip to content

Commit

Permalink
dokit集成
Browse files Browse the repository at this point in the history
  • Loading branch information
linxiangcheer committed Mar 19, 2021
1 parent 7eeb21b commit 33a68f9
Show file tree
Hide file tree
Showing 24 changed files with 171 additions and 50 deletions.
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cniao5.cainiaowo">

<!--悬浮窗权限-->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<!--网络权限-->
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Cainiaowo">
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/cniao5/cainiaowo/CnApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cniao5.cainiaowo

import com.cniao5.common.BaseApplication
import com.cniao5.common.ktx.application
import com.test.service.assistant.AssistantApp

class CnApplication : BaseApplication() {

override fun initConfig() {
super.initConfig()
//doKit的初始化配置
AssistantApp.initConfig(application)
}

}
6 changes: 2 additions & 4 deletions app/src/main/java/com/cniao5/cainiaowo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.cniao5.cainiaowo.databinding.ActivityMainBinding
import com.cniao5.common.base.BaseActivity
import com.cniao5.common.ktx.application
import com.test.service.assistant.AssistantApp

class MainActivity : BaseActivity<ActivityMainBinding>() {

Expand All @@ -21,10 +23,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
override fun initView() {
super.initView()
val navController= findNavController(R.id.fcv_main)
val appBarConfiguration = AppBarConfiguration(setOf(
R.id.homeFragment, R.id.courseFragment, R.id.studyFragment, R.id.mineFragment
))
setupActionBarWithNavController(navController, appBarConfiguration)
mBinding.bnvMain.setupWithNavController(navController)
}

Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<layout >
<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?attr/actionBarSize">
android:paddingTop="?attr/actionBarSize"
>

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bnv_main"
Expand Down
18 changes: 6 additions & 12 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Cainiaowo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
18 changes: 6 additions & 12 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Base application theme. -->
<style name="Theme.Cainiaowo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.alibaba.arouter'

buildscript {
ext {
kotlin_version = "1.4.31"
Expand All @@ -25,14 +23,21 @@ buildscript {
classpath "com.android.tools.build:gradle:4.1.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version"
//koin注入框架
classpath "org.koin:koin-gradle-plugin:$koin_version"

//阿里 Arouter
classpath "com.alibaba:arouter-register:1.0.2"
//doki调试辅助工具
classpath 'com.didichuxing.doraemonkit:dokitx-plugin:3.3.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

apply plugin: 'com.alibaba.arouter'
apply plugin: 'com.didi.dokit'
apply plugin: 'koin' //koin依赖注入框架

allprojects {
repositories {
google()
Expand Down
28 changes: 24 additions & 4 deletions common/src/main/java/com/cniao5/common/BaseApplication.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
package com.cniao5.common

import android.app.Application
import com.blankj.utilcode.util.LogUtils
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.logger.Level

/*
*
* 抽象的公用BaseApplication*/
class BaseApplication: Application() {
* 抽象Application配置基础通用的设置配置
* */
abstract class BaseApplication: Application() {

override fun onCreate() {
super.onCreate()

startKoin {
androidLogger(Level.ERROR) //log level error方法,保证这句话不出错不然不写

//context
androidContext(this@BaseApplication)
//依赖注入模块
//module
}

initConfig()
initData()

LogUtils.d("BaseApplication onCreate")
}

/*
* protected只有类的成员和继承该类的类才能访问
* 用于必要的配置初始化
* */
protected open fun initData() { }

/*
* 用于子类实现必要的数据初始化
* */
protected open fun initConfig() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.databinding.ViewDataBinding
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import com.cniao5.common.ktx.bindView
import com.cniao5.common.ktx.immediateStatusBar

/*
* BaseActivity的抽象基类
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import com.blankj.utilcode.util.LogUtils

/*
* Fragment的抽象基类
Expand Down
13 changes: 13 additions & 0 deletions common/src/main/java/com/cniao5/common/ktx/AppKtx.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.cniao5.common.ktx

import android.app.Application

/*
* Application相关的ktx扩展
* */

/*
* Application的扩展字段 参数一致性
* */
val Application.application: Application
get() = this
6 changes: 4 additions & 2 deletions course/src/main/res/layout/fragment_course.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<layout
>

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down
3 changes: 2 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin" //用于navigation传参时候的一种安全防护
apply plugin: 'koin' //koin依赖注入框架



android {
Expand All @@ -16,6 +16,7 @@ android {
versionName lib_version_name

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"

//java中Arouter配置方式 生成schema文件,便于查看数据库创建表的详细信息
javaCompileOptions {
Expand Down
19 changes: 18 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,21 @@ android.enableJetifier=true
kotlin.code.style=official

#配置模块化的运行方式,singleModule=true表示每个模块都独立运行作为单独的apk,false标志作为module,被app模块依赖
singleModule = false
singleModule = false

#// dokit全局配置
#// 插件开关
DOKIT_PLUGIN_SWITCH=true
#// DOKIT读取三方库会和booster冲突 如果你的项目中也集成了booster 建议将开关改成false
DOKIT_THIRD_LIB_SWITCH=true
#// 插件日志
DOKIT_LOG_SWITCH=true
#// 自定义Webview的全限定名 主要是作用于h5 js抓包和数据mock
DOKIT_WEBVIEW_CLASS_NAME=com/didichuxing/doraemonkit/widget/webview/MyWebView
#// dokit 慢函数开关
DOKIT_METHOD_SWITCH=false
#// dokit 函数调用栈层级
DOKIT_METHOD_STACK_LEVEL=4
#// 0:默认模式 打印函数调用栈 需添加指定入口 默认为application onCreate 和attachBaseContext
#// 1:普通模式 运行时打印某个函数的耗时 全局业务代码函数插入
DOKIT_METHOD_STRATEGY=0
6 changes: 4 additions & 2 deletions home/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<layout
>

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down
6 changes: 4 additions & 2 deletions mine/src/main/res/layout/fragment_mine.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<layout
>

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down
4 changes: 4 additions & 0 deletions service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ android {
dependencies {
//others from dependencies.gradle
api project(path: ':common')

//doki 调试辅助工具
debugImplementation 'com.didichuxing.doraemonkit:dokitx:3.3.5'
releaseImplementation 'com.didichuxing.doraemonkit:dokitx-no-op:3.3.5'
}
8 changes: 8 additions & 0 deletions service/src/main/java/com/test/service/LibService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.test.service

import org.koin.dsl.module

/*
* Service模块相关的koin的module配置
* */
val moduleService = module { }
16 changes: 16 additions & 0 deletions service/src/main/java/com/test/service/assistant/AssistantApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.test.service.assistant

import android.app.Application
import com.didichuxing.doraemonkit.DoraemonKit


/*
* 配置dokit的工具类
* */
object AssistantApp {

fun initConfig(application: Application){
DoraemonKit.install(application)
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions service/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FFC107</color>
<color name="colorPrimaryDark">#FFA000</color>
<color name="colorPrimaryLight">#FFECB3</color>
<color name="colorAccent">#FFA000</color>
<color name="color_333333">#333333</color>
<color name="colorPrimaryText">#212121</color>
<color name="colorIcons">#212121</color>
<color name="colorDivider">#BDBDBD</color>
<color name="colorWindowBackGround">#F6F6F6</color>
</resources>
4 changes: 4 additions & 0 deletions service/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="str_server_host_dokit">切换Host</string>
</resources>
4 changes: 4 additions & 0 deletions service/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

</resources>
Loading

0 comments on commit 33a68f9

Please sign in to comment.