-
Notifications
You must be signed in to change notification settings - Fork 0
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
zhouyufeng
committed
Apr 16, 2021
1 parent
64da004
commit 0395e3a
Showing
148 changed files
with
25,104 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
/build |
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,84 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'kotlin-android' | ||
id 'kotlin-kapt' | ||
id 'com.github.dcendents.android-maven' | ||
} | ||
group='com.github.sujianchuan888' | ||
|
||
kapt { | ||
generateStubs = true | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
multiDexEnabled true | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
|
||
javaCompileOptions { | ||
|
||
annotationProcessorOptions { | ||
|
||
arguments = [moduleName: project.getName()] | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
|
||
dataBinding { | ||
enabled = true | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'androidx.core:core-ktx:1.2.0' | ||
implementation 'androidx.appcompat:appcompat:1.1.0' | ||
implementation 'com.google.android.material:material:1.1.0' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
|
||
|
||
implementation 'com.github.goldze:MVVMHabit:3.1.6' | ||
implementation 'com.android.support:multidex:1.0.3' | ||
implementation 'androidx.navigation:navigation-fragment:2.3.0' | ||
implementation 'androidx.navigation:navigation-ui:2.3.0' | ||
|
||
/*下拉刷新上拉加载*/ | ||
api 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-20' | ||
//ARouter | ||
compile'com.alibaba:arouter-api:1.3.1' | ||
annotationProcessor'com.alibaba:arouter-compiler:1.1.4' | ||
|
||
kapt 'com.android.databinding:compiler:3.2.1' | ||
|
||
apply plugin: 'com.github.dcendents.android-maven' | ||
group = 'com.github.sujianchuan888' | ||
//ceshi | ||
} |
Empty file.
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
BaseAndroidKt/src/androidTest/java/com/sjc/baseAndroid/ExampleInstrumentedTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.sjc.baseAndroid | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.sjc.baseAndroid.test", appContext.packageName) | ||
} | ||
} |
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.sjc.baseAndroid"> | ||
|
||
</manifest> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
69 changes: 69 additions & 0 deletions
69
BaseAndroidKt/src/main/java/com/sjc/baseAndroid/KtBaseApplication.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.sjc.baseAndroid | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import android.util.Log | ||
import androidx.multidex.MultiDex | ||
import com.sjc.baseAndroid.login.LoginActivity | ||
import me.goldze.mvvmhabit.BuildConfig | ||
import me.goldze.mvvmhabit.base.BaseApplication | ||
import me.goldze.mvvmhabit.crash.CaocConfig | ||
import me.goldze.mvvmhabit.utils.KLog | ||
|
||
/** | ||
* Created by goldze on 2017/7/16. | ||
*/ | ||
open class KtBaseApplication : BaseApplication() { | ||
|
||
private var appContext: Context? = null | ||
private var application: KtBaseApplication? = null | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
// 解决方法大于65535问题 | ||
MultiDex.install(this) | ||
//是否开启打印日志 | ||
KLog.init(BuildConfig.DEBUG) | ||
//初始化全局异常崩溃 | ||
initCrash() | ||
|
||
appContext = applicationContext | ||
application = this | ||
Log.d("KtBaseApplication"," 初始化") | ||
|
||
|
||
} | ||
|
||
private fun initCrash() { | ||
CaocConfig.Builder.create() | ||
.backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //背景模式,开启沉浸式 | ||
.enabled(true) //是否启动全局异常捕获 | ||
.showErrorDetails(true) //是否显示错误详细信息 | ||
.showRestartButton(true) //是否显示重启按钮 | ||
.trackActivities(true) //是否跟踪Activity | ||
.minTimeBetweenCrashesMs(2000) //崩溃的间隔时间(毫秒) | ||
.errorDrawable(R.mipmap.ic_launcher) //错误图标 | ||
.restartActivity(LoginActivity::class.java) //重新启动后的activity | ||
// .errorActivity(YourCustomErrorActivity.class) //崩溃后的错误activity | ||
// .eventListener(new YourCustomEventListener()) //崩溃后的错误监听 | ||
.apply() | ||
} | ||
|
||
/** | ||
* 获得上下文对象 | ||
* | ||
* @return | ||
*/ | ||
fun getAppContext(): Context? { | ||
return appContext | ||
} | ||
/** | ||
* 获得上下文对象 | ||
* | ||
* @return | ||
*/ | ||
fun getApplication(): Application? { | ||
return application | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
BaseAndroidKt/src/main/java/com/sjc/baseAndroid/base/AppViewModelFactory.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.sjc.baseAndroid.base | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Application | ||
import androidx.annotation.VisibleForTesting | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.example.myapplication.http.AppRepository | ||
import com.sjc.baseAndroid.base.Injection.provideDemoRepository | ||
import com.sjc.baseAndroid.login.LoginViewModel | ||
|
||
/** | ||
* Created by goldze on 2019/3/26. | ||
*/ | ||
class AppViewModelFactory private constructor( | ||
private val mApplication: Application, | ||
private val mRepository: AppRepository? | ||
) : ViewModelProvider.NewInstanceFactory() { | ||
override fun <T : ViewModel?> create(modelClass: Class<T>): T { | ||
if (modelClass.isAssignableFrom(LoginViewModel::class.java)) { | ||
return LoginViewModel(mApplication, mRepository) as T | ||
} | ||
throw IllegalArgumentException("Unknown ViewModel class: " + modelClass.name) | ||
} | ||
|
||
companion object { | ||
@SuppressLint("StaticFieldLeak") | ||
@Volatile | ||
private var INSTANCE: AppViewModelFactory? = null | ||
fun getInstance(application: Application): AppViewModelFactory? { | ||
if (INSTANCE == null) { | ||
synchronized(AppViewModelFactory::class.java) { | ||
if (INSTANCE == null) { | ||
INSTANCE = AppViewModelFactory(application, provideDemoRepository()) | ||
} | ||
} | ||
} | ||
return INSTANCE | ||
} | ||
|
||
@VisibleForTesting | ||
fun destroyInstance() { | ||
INSTANCE = null | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
BaseAndroidKt/src/main/java/com/sjc/baseAndroid/base/BaseBean.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.sjc.baseAndroid.base | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
class BaseBean<T> { | ||
public val code = 0 | ||
|
||
public val msg: String? = null | ||
|
||
public val time: String? = null | ||
|
||
public val data: T? = null | ||
} |
26 changes: 26 additions & 0 deletions
26
BaseAndroidKt/src/main/java/com/sjc/baseAndroid/base/Injection.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.sjc.baseAndroid.base | ||
|
||
import com.example.myapplication.http.AppRepository | ||
import com.example.myapplication.http.AppRepository.Companion.getInstance | ||
import com.example.myapplication.http.RetrofitClient | ||
import com.example.myapplication.http.service.HttpApiService | ||
import com.example.myapplication.http.source.HttpDataSource | ||
import com.example.myapplication.http.source.HttpDataSourceImpl.Companion.getInstance | ||
|
||
/** | ||
* 注入全局的数据仓库,可以考虑使用Dagger2。(根据项目实际情况搭建,千万不要为了架构而架构) | ||
* Created by goldze on 2019/3/26. | ||
*/ | ||
object Injection { | ||
@JvmStatic | ||
fun provideDemoRepository(): AppRepository? { | ||
//网络API服务 | ||
val apiService = RetrofitClient.retrofitClient.create( | ||
HttpApiService::class.java | ||
) | ||
//网络数据源 | ||
val httpDataSource: HttpDataSource? = getInstance(apiService) | ||
//两条分支组成一个数据仓库 | ||
return getInstance(httpDataSource!!) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
BaseAndroidKt/src/main/java/com/sjc/baseAndroid/base/KtBaseViewModel.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.sjc.baseAndroid.base | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import com.example.myapplication.http.AppRepository | ||
import com.sjc.baseAndroid.dialog.BaseLoadingDialog | ||
import me.goldze.mvvmhabit.base.BaseViewModel | ||
|
||
|
||
open class KtBaseViewModel(application: Application, model: AppRepository?) : | ||
BaseViewModel<AppRepository>( | ||
application, | ||
model!! | ||
) { | ||
|
||
var mcontext: Context? = null | ||
/** | ||
* 显示加载对话框 | ||
* 系统返回和外部都取消 | ||
* @param msg | ||
*/ | ||
|
||
fun showLoading(msg: String?) { | ||
BaseLoadingDialog.show(mcontext!!, msg!!, true, true) | ||
} | ||
fun hideLoading() { | ||
BaseLoadingDialog.dismiss(mcontext) | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
BaseAndroidKt/src/main/java/com/sjc/baseAndroid/base/NaviMainActivity.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.sjc.baseAndroid.base | ||
|
||
import android.os.Bundle | ||
import android.os.PersistableBundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.navigation.NavController | ||
import androidx.navigation.Navigation | ||
import androidx.navigation.ui.NavigationUI | ||
import com.google.android.material.bottomnavigation.BottomNavigationView | ||
import com.sjc.baseAndroid.R | ||
|
||
class NaviMainActivity :AppCompatActivity() { | ||
|
||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
val navView = findViewById<BottomNavigationView>(R.id.nav_view) | ||
navView.itemIconTintList = null | ||
val navController: NavController = | ||
Navigation.findNavController(this, R.id.nav_host_fragment) | ||
NavigationUI.setupWithNavController(navView, navController) | ||
// if (intent.getIntExtra("type", 0) == 0) { | ||
// navView.selectedItemId = R.id.navigation_mine | ||
// } | ||
} | ||
} |
Oops, something went wrong.