Skip to content

Commit 5ec4d20

Browse files
committed
Implement JetPack Compose
This commit reimplements the UI with JetPack Compose.
1 parent ccefd8c commit 5ec4d20

File tree

103 files changed

+4230
-1420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+4230
-1420
lines changed

app/build.gradle

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-kapt'
4-
apply plugin: "androidx.navigation.safeargs.kotlin"
4+
apply plugin: "androidx.navigation.safeargs"
55
apply plugin: 'com.google.firebase.crashlytics'
66
apply plugin: 'com.google.gms.google-services'
77
apply plugin: 'dagger.hilt.android.plugin'
8-
apply plugin: 'com.mikepenz.aboutlibraries.plugin'
98
apply plugin: 'com.google.firebase.firebase-perf'
109
apply plugin: 'com.github.triplet.play'
10+
apply plugin: 'com.dicedmelon.gradle.jacoco-android'
1111

1212
android {
1313
compileSdkVersion Config.compile_sdk
14-
buildToolsVersion Config.build_tools
1514

1615
defaultConfig {
1716
applicationId "de.psdev.devdrawer"
@@ -22,16 +21,20 @@ android {
2221

2322
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2423
multiDexEnabled true
25-
26-
resConfig "en"
24+
resConfigs 'en'
2725

2826
// Version info
2927
buildConfigField 'String', 'GIT_SHA', "\"${project.ext.gitHash}\""
3028

29+
vectorDrawables {
30+
useSupportLibrary true
31+
}
32+
3133
javaCompileOptions.annotationProcessorOptions.arguments['room.schemaLocation'] = rootProject.file('schemas').toString()
3234
}
3335
buildFeatures {
3436
viewBinding true
37+
compose true
3538
}
3639
compileOptions {
3740
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -41,11 +44,15 @@ android {
4144
jvmTarget = "1.8"
4245
freeCompilerArgs += [
4346
"-Xinline-classes",
44-
"-Xopt-in=kotlin.RequiresOptIn",
45-
"-Xopt-in=kotlin.ExperimentalStdlibApi",
46-
"-Xopt-in=kotlin.time.ExperimentalTime",
47-
"-Xopt-in=kotlinx.coroutines.FlowPreview",
48-
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
47+
"-Xjvm-default=all",
48+
"-opt-in=kotlin.RequiresOptIn",
49+
"-opt-in=kotlin.ExperimentalStdlibApi",
50+
"-opt-in=kotlin.time.ExperimentalTime",
51+
"-opt-in=kotlinx.coroutines.FlowPreview",
52+
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
53+
"-opt-in=androidx.compose.foundation.ExperimentalFoundationApi",
54+
"-opt-in=androidx.compose.animation.ExperimentalAnimationApi",
55+
"-opt-in=androidx.compose.material.ExperimentalMaterialApi"
4956
]
5057
}
5158
testOptions {
@@ -92,18 +99,18 @@ android {
9299
}
93100
}
94101
}
95-
lintOptions {
96-
lintConfig project.file('lint.xml')
97-
disable "GoogleAppIndexingWarning"
98-
disable "RemoveWorkManagerInitializer"
99-
enable 'Interoperability'
100-
}
101102
packagingOptions {
102-
exclude '**/LICENSE'
103-
exclude '**/LICENSE.txt'
104-
exclude '**/NOTICE'
105-
exclude '**/NOTICE.txt'
106-
exclude '**/*.gwt.xml'
103+
resources {
104+
excludes += ['**/LICENSE', '**/LICENSE.txt', '**/NOTICE', '**/NOTICE.txt', '**/*.gwt.xml']
105+
}
106+
}
107+
composeOptions {
108+
kotlinCompilerExtensionVersion Versions.androidXComposeCompiler
109+
}
110+
lint {
111+
disable 'GoogleAppIndexingWarning', 'RemoveWorkManagerInitializer'
112+
enable 'Interoperability'
113+
lintConfig file('lint.xml')
107114
}
108115
}
109116

@@ -133,28 +140,43 @@ dependencies {
133140
implementation Libs.androidx_browser
134141
implementation Libs.androidx_constraint_layout
135142
implementation Libs.androidx_core
143+
implementation "androidx.core:core-splashscreen:1.0.0"
136144
implementation Libs.androidx_fragment
137145
implementation Libs.androidx_hilt_work
138146
implementation Libs.androidx_lifecycle_viewmodel
147+
implementation Libs.androidx_lifecycle_livedata
139148
implementation Libs.androidx_lifecycle_java8
149+
implementation Libs.androidx_lifecycle_runtime
140150
implementation Libs.androidx_lifecycle_process
141151
implementation Libs.androidx_navigation_fragment
142152
implementation Libs.androidx_navigation_ui
153+
implementation "androidx.navigation:navigation-compose:$Versions.androidXNavigation"
143154
implementation Libs.androidx_preference
144155
implementation Libs.androidx_recyclerview
145156
implementation Libs.androidx_recyclerview_selection
146157
implementation Libs.androidx_room_runtime
147158
implementation Libs.androidx_room_ktx
148159
implementation Libs.androidx_work_runtime
149160
implementation Libs.androidx_work_gcm
161+
implementation 'androidx.activity:activity-compose:1.5.1'
162+
implementation "androidx.compose.ui:ui:$Versions.androidXCompose"
163+
implementation "androidx.compose.foundation:foundation:$Versions.androidXCompose"
164+
implementation "androidx.compose.material:material:$Versions.androidXCompose"
165+
implementation "androidx.compose.material:material-icons-core:$Versions.androidXCompose"
166+
implementation "androidx.compose.material:material-icons-extended:$Versions.androidXCompose"
167+
implementation "androidx.compose.ui:ui-tooling:$Versions.androidXCompose"
168+
169+
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$Versions.androidXLifecycle"
170+
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
171+
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$Versions.androidXCompose"
150172
kapt Libs.androidx_room_compiler
151173
kapt Libs.androidx_hilt_compiler
152174

153175
// Android Material
154176
implementation Libs.material_components
155177

156178
// Color Picker
157-
implementation "com.github.dhaval2404:colorpicker:2.0"
179+
implementation "com.github.dhaval2404:colorpicker:2.3"
158180

159181
// Dagger
160182
implementation Libs.daggerHiltAndroid
@@ -182,8 +204,8 @@ dependencies {
182204
implementation Libs.kotlinCoroutinesAndroid
183205

184206
// LeakCanary
185-
debugImplementation Libs.leakCanary
186-
implementation Libs.leakCanaryPlumberAndroid
207+
// debugImplementation Libs.leakCanary
208+
// implementation Libs.leakCanaryPlumberAndroid
187209

188210
// Logging
189211
implementation Libs.slf4jAndroidLogger
@@ -200,6 +222,10 @@ kapt {
200222
correctErrorTypes true
201223
}
202224

225+
jacoco {
226+
toolVersion = "0.8.7"
227+
}
228+
203229
play {
204230
def serviceAccountFileName = "google-play-api.json"
205231
if (rootProject.file(serviceAccountFileName).exists()) {

app/src/debug/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="app_name">DevDrawer2 (Debug)</string>
3+
<string name="app_name" translatable="false">DevDrawer2 (Debug)</string>
44
</resources>

app/src/main/AndroidManifest.xml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
<application
1414
android:name=".DevDrawerApplication"
1515
android:allowBackup="true"
16+
android:dataExtractionRules="@xml/data_extraction_rules"
1617
android:fullBackupContent="@xml/backup_descriptor"
1718
android:icon="@mipmap/ic_launcher"
1819
android:label="@string/app_name"
1920
android:roundIcon="@mipmap/ic_launcher_round"
2021
android:supportsRtl="true"
2122
android:theme="@style/AppTheme.NoActionBar">
22-
<activity android:name=".MainActivity">
23+
<activity
24+
android:name=".MainActivity"
25+
android:exported="true"
26+
android:windowSoftInputMode="adjustResize">
2327
<intent-filter>
2428
<action android:name="android.intent.action.MAIN" />
2529
<category android:name="android.intent.category.LAUNCHER" />
@@ -30,6 +34,7 @@
3034
android:name=".appwidget.ClickHandlingActivity"
3135
android:allowTaskReparenting="false"
3236
android:excludeFromRecents="true"
37+
android:exported="true"
3338
android:noHistory="true"
3439
android:taskAffinity=""
3540
android:theme="@android:style/Theme.NoDisplay">
@@ -46,13 +51,17 @@
4651
android:taskAffinity=""
4752
android:theme="@style/AppTheme.Dialog.NoActionBar" />
4853

49-
<activity android:name=".widgets.WidgetConfigActivity">
54+
<activity
55+
android:name=".widgets.ui.WidgetConfigActivity"
56+
android:exported="true">
5057
<intent-filter>
5158
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
5259
</intent-filter>
5360
</activity>
5461

55-
<receiver android:name=".appwidget.DDWidgetProvider">
62+
<receiver
63+
android:name=".appwidget.DDWidgetProvider"
64+
android:exported="true">
5665
<intent-filter>
5766
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
5867
</intent-filter>
@@ -65,6 +74,10 @@
6574
android:name=".receivers.UpdateReceiver"
6675
android:exported="false" />
6776

77+
<receiver
78+
android:name=".receivers.PinWidgetSuccessReceiver"
79+
android:exported="false" />
80+
6881
<service
6982
android:name=".appwidget.WidgetService"
7083
android:permission="android.permission.BIND_REMOTEVIEWS" />
@@ -76,7 +89,7 @@
7689
android:exported="false"
7790
tools:node="merge">
7891
<meta-data
79-
android:name="androidx.work.impl.WorkManagerInitializer"
92+
android:name="androidx.work.WorkManagerInitializer"
8093
android:value="androidx.startup"
8194
tools:node="remove" />
8295
</provider>
Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,26 @@
11
package de.psdev.devdrawer
22

3-
import android.os.Bundle
4-
import android.view.LayoutInflater
5-
import android.view.View
6-
import android.view.ViewGroup
7-
import androidx.annotation.CallSuper
83
import androidx.annotation.StringRes
94
import androidx.fragment.app.Fragment
105
import androidx.lifecycle.LifecycleCoroutineScope
116
import androidx.lifecycle.lifecycleScope
12-
import androidx.viewbinding.ViewBinding
137
import de.psdev.devdrawer.analytics.TrackingService
148
import javax.inject.Inject
159

16-
abstract class BaseFragment<T : ViewBinding> : Fragment() {
10+
open class BaseFragment : Fragment() {
1711

1812
@Inject
1913
lateinit var trackingService: TrackingService
20-
21-
private var _binding: T? = null
22-
// This property is only valid between onCreateView and onDestroyView.
23-
protected val binding get() = _binding!!
24-
2514
protected var toolbarTitle: CharSequence
2615
get() = requireActivity().title
2716
set(value) {
2817
requireActivity().title = value
2918
}
30-
31-
final override fun onCreateView(
32-
inflater: LayoutInflater,
33-
container: ViewGroup?,
34-
savedInstanceState: Bundle?
35-
): View = createViewBinding(inflater, container, savedInstanceState).also { viewBinding ->
36-
_binding = viewBinding
37-
}.root
38-
39-
protected abstract fun createViewBinding(
40-
inflater: LayoutInflater,
41-
container: ViewGroup?,
42-
savedInstanceState: Bundle?
43-
): T
44-
45-
@CallSuper
46-
override fun onDestroyView() {
47-
super.onDestroyView()
48-
_binding = null
49-
}
19+
val Fragment.viewLifecycleScope: LifecycleCoroutineScope
20+
get() = viewLifecycleOwner.lifecycleScope
5021

5122
protected fun updateToolbarTitle(@StringRes resId: Int) {
5223
requireActivity().setTitle(resId)
5324
trackingService.trackScreen(this::class.java, getString(resId))
5425
}
55-
56-
val Fragment.viewLifecycleScope: LifecycleCoroutineScope
57-
get() = viewLifecycleOwner.lifecycleScope
58-
59-
}
26+
}

app/src/main/java/de/psdev/devdrawer/DevDrawerApplication.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,23 @@ class DevDrawerApplication: Application(), Configuration.Provider {
2929
registerAppInstallationReceiver()
3030
setupWorkers()
3131
}.let {
32-
logger.warn("{} version {} ({}) took {}ms to init", this::class.java.simpleName, BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, it)
32+
logger.warn(
33+
"{} version {} ({}) took {}ms to init",
34+
this::class.java.simpleName,
35+
BuildConfig.VERSION_NAME,
36+
BuildConfig.VERSION_CODE,
37+
it
38+
)
3339
}
3440
}
3541

3642
// ==========================================================================================================================
3743
// Configuration.Provider
3844
// ==========================================================================================================================
3945

40-
override fun getWorkManagerConfiguration(): Configuration {
41-
logger.warn { "getWorkManagerConfiguration" }
42-
return Configuration.Builder()
43-
.setWorkerFactory(workerFactory)
44-
.build()
45-
}
46+
override fun getWorkManagerConfiguration(): Configuration = Configuration.Builder()
47+
.setWorkerFactory(workerFactory)
48+
.build()
4649

4750
// ==========================================================================================================================
4851
// Private API
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package de.psdev.devdrawer
2+
3+
import androidx.annotation.StringRes
4+
import androidx.compose.material.icons.Icons
5+
import androidx.compose.material.icons.filled.Grid3x3
6+
import androidx.compose.material.icons.filled.Info
7+
import androidx.compose.material.icons.filled.Settings
8+
import androidx.compose.material.icons.filled.Widgets
9+
import androidx.compose.ui.graphics.vector.ImageVector
10+
import de.psdev.devdrawer.database.Widget
11+
import de.psdev.devdrawer.database.WidgetProfile
12+
13+
sealed class DevDrawerScreen(
14+
val route: String
15+
)
16+
17+
sealed class TopLevelScreen(route: String): DevDrawerScreen(route) {
18+
abstract val icon: ImageVector
19+
@get:StringRes abstract val label: Int
20+
}
21+
22+
object Widgets: TopLevelScreen(
23+
route = "widgets"
24+
) {
25+
override val icon: ImageVector = Icons.Filled.Widgets
26+
override val label: Int = R.string.widgets
27+
}
28+
29+
object Profiles: TopLevelScreen(
30+
route = "profiles"
31+
) {
32+
override val icon: ImageVector = Icons.Filled.Grid3x3
33+
override val label: Int = R.string.profiles
34+
}
35+
36+
object Settings: TopLevelScreen(
37+
route = "settings"
38+
) {
39+
override val icon: ImageVector = Icons.Filled.Settings
40+
override val label: Int = R.string.settings
41+
}
42+
43+
object AppInfo: TopLevelScreen(
44+
route = "info"
45+
) {
46+
override val icon: ImageVector = Icons.Filled.Info
47+
override val label: Int = R.string.app_info
48+
}
49+
50+
data class WidgetEditorDestination(
51+
val widget: Widget
52+
): DevDrawerScreen(route = "widgets/${widget.id}")
53+
54+
data class ProfileEditorDestination(
55+
val widgetProfile: WidgetProfile
56+
): DevDrawerScreen(route = "profiles/${widgetProfile.id}")

0 commit comments

Comments
 (0)