Skip to content

Commit 484c845

Browse files
committed
create(Demo): 创建 DevEnvironment 使用示例项目
1 parent fd3f5cf commit 484c845

21 files changed

+306
-37
lines changed
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apply from: rootProject.file(files.build_app_gradle)
2+
3+
android {
4+
namespace "afkt.environment.use"
5+
6+
defaultConfig {
7+
applicationId "afkt.environment.use"
8+
}
9+
}
10+
11+
// Android lib 依赖配置
12+
apply from: rootProject.file(deps_maven.deps_android)
13+
// DevUtils 项目统一依赖配置
14+
apply from: rootProject.file(deps_maven.prop_dev_utils)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="afkt.environment.use">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/icon_launcher"
8+
android:label="@string/app_name"
9+
android:requestLegacyExternalStorage="true"
10+
android:roundIcon="@mipmap/icon_launcher_round"
11+
android:theme="@style/AppTheme">
12+
13+
<activity
14+
android:name=".MainActivity"
15+
android:exported="true">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package afkt.environment.use
2+
3+
import afkt.environment.use.base.BaseViewModel
4+
5+
class AppViewModel : BaseViewModel() {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package afkt.environment.use
2+
3+
import afkt.environment.use.base.BaseActivity
4+
import afkt.environment.use.databinding.ActivityMainBinding
5+
6+
class MainActivity : BaseActivity<ActivityMainBinding, AppViewModel>(
7+
R.layout.activity_main, simple_Agile = {
8+
if (it is MainActivity) {
9+
10+
}
11+
}
12+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package afkt.environment.use
2+
3+
import afkt.environment.use.base.BaseFragment
4+
import afkt.environment.use.databinding.FragmentMainBinding
5+
6+
class MainFragment : BaseFragment<FragmentMainBinding, AppViewModel>(
7+
R.layout.fragment_main, BR.viewModel, simple_Agile = { it ->
8+
if (it is MainFragment) {
9+
10+
}
11+
}
12+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package afkt.environment.use.base
2+
3+
import android.os.Bundle
4+
import androidx.activity.enableEdgeToEdge
5+
import androidx.core.view.ViewCompat
6+
import androidx.core.view.WindowInsetsCompat
7+
import androidx.databinding.ViewDataBinding
8+
import dev.simple.app.BaseAppActivity
9+
import dev.simple.app.base.ActivityVMType
10+
import dev.simple.app.base.inter.BindingActivityView
11+
import dev.simple.app.controller.ui.theme.ActivityUITheme
12+
13+
/**
14+
* detail: Activity MVVM 基类
15+
* @author Ttt
16+
*/
17+
open class BaseActivity<VDB : ViewDataBinding, VM : BaseViewModel> :
18+
BaseAppActivity<VDB, VM> {
19+
20+
// ==========
21+
// = 构造函数 =
22+
// ==========
23+
24+
constructor(
25+
bindLayoutId: Int,
26+
bindViewModelId: Int = -1,
27+
vmType: ActivityVMType = ActivityVMType.ACTIVITY,
28+
simple_Init: ((Any) -> Unit)? = null,
29+
simple_Start: ((Any) -> Unit)? = null,
30+
simple_PreLoad: ((Any) -> Unit)? = null,
31+
simple_Agile: ((Any) -> Unit)? = null,
32+
simple_UITheme: ((ActivityUITheme) -> ActivityUITheme)? = null
33+
) : super(
34+
bindLayoutId, bindViewModelId, vmType,
35+
simple_Init, simple_Start, simple_PreLoad, simple_Agile, simple_UITheme
36+
)
37+
38+
constructor(
39+
bindLayoutView: BindingActivityView?,
40+
bindViewModelId: Int = -1,
41+
vmType: ActivityVMType = ActivityVMType.ACTIVITY,
42+
simple_Init: ((Any) -> Unit)? = null,
43+
simple_Start: ((Any) -> Unit)? = null,
44+
simple_PreLoad: ((Any) -> Unit)? = null,
45+
simple_Agile: ((Any) -> Unit)? = null,
46+
simple_UITheme: ((ActivityUITheme) -> ActivityUITheme)? = null
47+
) : super(
48+
bindLayoutView, bindViewModelId, vmType,
49+
simple_Init, simple_Start, simple_PreLoad, simple_Agile, simple_UITheme
50+
)
51+
52+
// ============
53+
// = override =
54+
// ============
55+
56+
override fun onCreate(savedInstanceState: Bundle?) {
57+
super.onCreate(savedInstanceState)
58+
enableEdgeToEdge()
59+
60+
// 给 view 设置 insets, 使得 view 不会被 system bars 遮挡
61+
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
62+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
63+
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
64+
insets
65+
}
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package afkt.environment.use.base
2+
3+
import androidx.databinding.ViewDataBinding
4+
import dev.simple.app.BaseAppFragment
5+
import dev.simple.app.base.FragmentVMType
6+
import dev.simple.app.base.inter.BindingFragmentView
7+
import dev.simple.app.controller.ui.theme.FragmentUITheme
8+
9+
/**
10+
* detail: Fragment MVVM 基类
11+
* @author Ttt
12+
*/
13+
open class BaseFragment<VDB : ViewDataBinding, VM : BaseViewModel> :
14+
BaseAppFragment<VDB, VM> {
15+
16+
// ==========
17+
// = 构造函数 =
18+
// ==========
19+
20+
constructor(
21+
bindLayoutId: Int,
22+
bindViewModelId: Int = -1,
23+
vmType: FragmentVMType = FragmentVMType.FRAGMENT,
24+
simple_Init: ((Any) -> Unit)? = null,
25+
simple_Start: ((Any) -> Unit)? = null,
26+
simple_PreLoad: ((Any) -> Unit)? = null,
27+
simple_Agile: ((Any) -> Unit)? = null,
28+
simple_UITheme: ((FragmentUITheme) -> FragmentUITheme)? = null
29+
) : super(
30+
bindLayoutId, bindViewModelId, vmType,
31+
simple_Init, simple_Start, simple_PreLoad, simple_Agile, simple_UITheme
32+
)
33+
34+
constructor(
35+
bindLayoutView: BindingFragmentView,
36+
bindViewModelId: Int = -1,
37+
vmType: FragmentVMType = FragmentVMType.FRAGMENT,
38+
simple_Init: ((Any) -> Unit)? = null,
39+
simple_Start: ((Any) -> Unit)? = null,
40+
simple_PreLoad: ((Any) -> Unit)? = null,
41+
simple_Agile: ((Any) -> Unit)? = null,
42+
simple_UITheme: ((FragmentUITheme) -> FragmentUITheme)? = null
43+
) : super(
44+
bindLayoutView, bindViewModelId, vmType,
45+
simple_Init, simple_Start, simple_PreLoad, simple_Agile, simple_UITheme
46+
)
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package afkt.environment.use.base
2+
3+
import dev.simple.app.BaseAppViewModel
4+
5+
/**
6+
* detail: Base ViewModel
7+
* @author Ttt
8+
*/
9+
open class BaseViewModel : BaseAppViewModel()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
5+
<FrameLayout
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent">
8+
9+
<androidx.fragment.app.FragmentContainerView
10+
android:id="@+id/nav_container"
11+
android:name="androidx.navigation.fragment.NavHostFragment"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
app:defaultNavHost="true"
15+
app:navGraph="@navigation/app_navigation" />
16+
</FrameLayout>
17+
</layout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<data>
5+
6+
<variable
7+
name="viewModel"
8+
type="afkt.environment.use.AppViewModel" />
9+
</data>
10+
11+
<androidx.core.widget.NestedScrollView
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
android:background="@color/black"
15+
android:fadingEdge="none"
16+
android:fitsSystemWindows="true"
17+
android:overScrollMode="never"
18+
android:scrollbars="none">
19+
20+
<LinearLayout
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
android:orientation="vertical"></LinearLayout>
24+
</androidx.core.widget.NestedScrollView>
25+
</layout>
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
app:startDestination="@id/MainFragment">
5+
6+
<fragment
7+
android:id="@+id/MainFragment"
8+
android:name="afkt.environment.use.MainFragment"
9+
android:label="MainFragment" />
10+
</navigation>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="app_name" translatable="false">环境配置示例</string>
4+
5+
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" />
6+
</resources>

file/deps/deps_android.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ dependencies {
1313
api deps.kotlin.lifecycle_livedata
1414
api deps.kotlin.lifecycle_viewmodel_savedstate
1515
api deps.kotlin.lifecycle_common_java8
16-
api deps.kotlin.datastore_preferences
1716
api deps.kotlin.fragment
1817
api deps.kotlin.activity
18+
api deps.kotlin.navigation_fragment
19+
api deps.kotlin.navigation_ui
20+
// api deps.kotlin.work_runtime
21+
// api deps.kotlin.palette
22+
api deps.kotlin.datastore_preferences
1923

2024
// ============
2125
// = androidx =

0 commit comments

Comments
 (0)