-
Notifications
You must be signed in to change notification settings - Fork 46
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
1 parent
4f9d8e1
commit a770889
Showing
42 changed files
with
1,600 additions
and
4 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue Feb 18 15:10:19 CST 2020 | ||
#Mon Jun 08 08:08:19 CST 2020 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip |
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,36 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'com.github.dcendents.android-maven' | ||
group='com.github.wangjianxiandev' | ||
|
||
def rootAndroidId = rootProject.ext.android | ||
def support = rootProject.ext.dependencies | ||
|
||
android { | ||
compileSdkVersion rootAndroidId.compileSdkVersion | ||
buildToolsVersion rootAndroidId.buildToolsVersion | ||
defaultConfig { | ||
minSdkVersion rootAndroidId.minSdkVersion | ||
targetSdkVersion rootAndroidId.targetSdkVersion | ||
versionCode rootAndroidId.versionCode | ||
versionName rootAndroidId.versionName | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
ndk { | ||
//设置支持的SO库架构 | ||
abiFilters "armeabi-v7a", "arm64-v8a" | ||
} | ||
} | ||
dataBinding { | ||
enabled = true | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6' | ||
support.each { k, v -> implementation v } | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.0' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' | ||
} |
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
mvvm/src/androidTest/java/com/wjx/android/mvvm/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.wjx.android.mvvm | ||
|
||
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.wjx.android.mvvm.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 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.wjx.android.mvvm"> | ||
|
||
/ | ||
</manifest> |
30 changes: 30 additions & 0 deletions
30
mvvm/src/main/java/com/wjx/android/mvvm/BaseApplication.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.wjx.android.mvvm | ||
|
||
import android.app.Application | ||
import androidx.appcompat.app.AppCompatDelegate | ||
import com.kingja.loadsir.core.LoadSir | ||
import com.wjx.android.wanandroidmvvm.common.utils.Constant | ||
import com.wjx.android.wanandroidmvvm.common.utils.SPreference | ||
|
||
/** | ||
* Created with Android Studio. | ||
* Description: | ||
* @author: Wangjianxian | ||
* @CreateDate: 2020/6/8 8:28 | ||
*/ | ||
open class BaseApplication : Application() { | ||
companion object { | ||
lateinit var instance : BaseApplication | ||
} | ||
override fun onCreate() { | ||
super.onCreate() | ||
instance = this | ||
SPreference.setContext(applicationContext) | ||
initMode() | ||
} | ||
|
||
private fun initMode() { | ||
var isNightMode: Boolean by SPreference(Constant.NIGHT_MODE, false) | ||
AppCompatDelegate.setDefaultNightMode(if (isNightMode) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
mvvm/src/main/java/com/wjx/android/mvvm/common/permission/PermissionFragment.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,58 @@ | ||
package com.wjx.android.mvvm.common.permission | ||
|
||
import android.content.pm.PackageManager | ||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.MutableLiveData | ||
|
||
/** | ||
* Created with Android Studio. | ||
* Description: | ||
* @author: Wangjianxian | ||
* @CreateDate: 2020/4/27 18:56 | ||
*/ | ||
internal class PermissionFragment : Fragment() { | ||
lateinit var liveData: MutableLiveData<PermissionResult> | ||
|
||
private val PERMISSION_REQUEST_CODE = 100 | ||
|
||
// 非中断式的保存 | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
retainInstance = true | ||
} | ||
|
||
fun requestPermissions(permissions: Array<out String>) { | ||
liveData = MutableLiveData() | ||
requestPermissions(permissions, PERMISSION_REQUEST_CODE) | ||
} | ||
|
||
override fun onRequestPermissionsResult( | ||
requestCode: Int, | ||
permissions: Array<out String>, | ||
grantResults: IntArray | ||
) { | ||
if (requestCode == PERMISSION_REQUEST_CODE) { | ||
val denyPermission = ArrayList<String>() | ||
val rationalePermission = ArrayList<String>() | ||
for ((index, value) in grantResults.withIndex()) { | ||
if (value == PackageManager.PERMISSION_DENIED) { | ||
if (shouldShowRequestPermissionRationale(permissions[index])) { | ||
rationalePermission.add(permissions[index]) | ||
} else { | ||
denyPermission.add(permissions[index]) | ||
} | ||
} | ||
} | ||
if (denyPermission.isEmpty() && rationalePermission.isEmpty()) { | ||
liveData.value = PermissionResult.Grant | ||
} else { | ||
if (rationalePermission.isNotEmpty()) { | ||
liveData.value = PermissionResult.Rationale(rationalePermission.toTypedArray()) | ||
} else if (denyPermission.isNotEmpty()) { | ||
liveData.value = PermissionResult.Deny(denyPermission.toTypedArray()) | ||
} | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
mvvm/src/main/java/com/wjx/android/mvvm/common/permission/PermissionResult.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.wjx.android.mvvm.common.permission | ||
|
||
/** | ||
* Created with Android Studio. | ||
* Description: 密封类实现枚举类型 | ||
* @author: Wangjianxian | ||
* @CreateDate: 2020/4/27 18:54 | ||
*/ | ||
sealed class PermissionResult { | ||
object Grant : PermissionResult() | ||
class Deny(val permissions: Array<String>) : PermissionResult() | ||
class Rationale(val permissions: Array<String>) : PermissionResult() | ||
} |
48 changes: 48 additions & 0 deletions
48
mvvm/src/main/java/com/wjx/android/mvvm/common/permission/Permissions.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,48 @@ | ||
package com.wjx.android.mvvm.common.permission | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentManager | ||
import androidx.lifecycle.MutableLiveData | ||
|
||
/** | ||
* Created with Android Studio. | ||
* Description: | ||
* @author: Wangjianxian | ||
* @CreateDate: 2020/4/27 19:04 | ||
*/ | ||
class Permissions { | ||
|
||
@Volatile | ||
private var permissionFragment: PermissionFragment? = null | ||
|
||
private fun getInstance(fragmentManager: FragmentManager) = | ||
permissionFragment ?: synchronized(this) { | ||
permissionFragment | ||
?: if (fragmentManager.findFragmentByTag(TAG) == null) PermissionFragment().run { | ||
fragmentManager.beginTransaction().add(this, TAG).commitNow() | ||
this | ||
} else fragmentManager.findFragmentByTag(TAG) as PermissionFragment | ||
} | ||
|
||
companion object { | ||
const val TAG = "permissions" | ||
} | ||
|
||
constructor(activity: AppCompatActivity) { | ||
permissionFragment = getInstance(activity.supportFragmentManager) | ||
} | ||
|
||
constructor(fragment: Fragment) { | ||
permissionFragment = getInstance(fragment.childFragmentManager) | ||
} | ||
|
||
fun request(vararg permissions: String): MutableLiveData<PermissionResult> { | ||
return this.requestArray(permissions) | ||
} | ||
|
||
fun requestArray(permissions: Array<out String>): MutableLiveData<PermissionResult> { | ||
permissionFragment!!.requestPermissions(permissions) | ||
return permissionFragment!!.liveData | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
mvvm/src/main/java/com/wjx/android/mvvm/common/state/State.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,12 @@ | ||
package com.wjx.android.mvvm.common.state | ||
|
||
import androidx.annotation.StringRes | ||
|
||
/** | ||
* Created with Android Studio. | ||
* Description: 状态类 | ||
* @author: Wangjianxian | ||
* @date: 2020/02/22 | ||
* Time: 15:28 | ||
*/ | ||
data class State(var code : StateType, var message : String = "", @StringRes var tip : Int = 0) |
13 changes: 13 additions & 0 deletions
13
mvvm/src/main/java/com/wjx/android/mvvm/common/state/StateType.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.wjx.android.mvvm.common.state | ||
|
||
/** | ||
* 应用状态 | ||
*/ | ||
enum class StateType { | ||
SUCCESS, | ||
ERROR, | ||
EMPTY, | ||
NETWORK_ERROR, | ||
LOADING, | ||
TIP, | ||
} |
47 changes: 47 additions & 0 deletions
47
mvvm/src/main/java/com/wjx/android/mvvm/common/utils/AppManager.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,47 @@ | ||
package com.wjx.android.mvvm.common.utils | ||
|
||
import android.app.Activity | ||
import android.app.ActivityManager | ||
import android.content.Context | ||
import java.util.* | ||
import kotlin.system.exitProcess | ||
|
||
/** | ||
* Created with Android Studio. | ||
* Description: Activity管理类 | ||
* @author: Wangjianxian | ||
* @date: 2020/02/25 | ||
* Time: 19:05 | ||
*/ | ||
|
||
class AppManager { | ||
private val activityStack : Stack<Activity> = Stack() | ||
|
||
companion object { | ||
val instance by lazy { | ||
AppManager() | ||
} | ||
} | ||
|
||
fun addActivity(activity: Activity) { | ||
activityStack.add(activity) | ||
} | ||
|
||
fun removeActivity(activity: Activity) { | ||
activityStack.remove(activity) | ||
} | ||
|
||
private fun finishAllActivity() { | ||
for(activity in activityStack) { | ||
activity.finish() | ||
} | ||
activityStack.clear() | ||
} | ||
|
||
fun exitApp(context: Context) { | ||
finishAllActivity() | ||
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager | ||
activityManager.killBackgroundProcesses(context.packageName) | ||
exitProcess(0) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
mvvm/src/main/java/com/wjx/android/mvvm/common/utils/ChangeThemeEvent.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,16 @@ | ||
package com.wjx.android.mvvm.common.utils | ||
|
||
import org.greenrobot.eventbus.EventBus | ||
|
||
/** | ||
* Created with Android Studio. | ||
* Description: | ||
* @author: Wangjianxian | ||
* @date: 2020/03/27 | ||
* Time: 18:46 | ||
*/ | ||
class ChangeThemeEvent { | ||
fun post() { | ||
EventBus.getDefault().post(this) | ||
} | ||
} |
Oops, something went wrong.