Skip to content

Commit 46e49d7

Browse files
committed
Implement JetPack Compose
This commit reimplements the UI with JetPack Compose.
1 parent 442f44f commit 46e49d7

Some content is hidden

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

62 files changed

+2183
-1107
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
language: android
2+
jdk:
3+
- openjdk11
24
android:
35
components:
46
- tools

app/build.gradle

+28-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
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'
1110

@@ -28,10 +27,15 @@ android {
2827
// Version info
2928
buildConfigField 'String', 'GIT_SHA', "\"${project.ext.gitHash}\""
3029

30+
vectorDrawables {
31+
useSupportLibrary true
32+
}
33+
3134
javaCompileOptions.annotationProcessorOptions.arguments['room.schemaLocation'] = rootProject.file('schemas').toString()
3235
}
3336
buildFeatures {
3437
viewBinding true
38+
compose true
3539
}
3640
compileOptions {
3741
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -45,8 +49,10 @@ android {
4549
"-Xopt-in=kotlin.ExperimentalStdlibApi",
4650
"-Xopt-in=kotlin.time.ExperimentalTime",
4751
"-Xopt-in=kotlinx.coroutines.FlowPreview",
48-
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
52+
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
53+
"-Xopt-in=androidx.compose.foundation.ExperimentalFoundationApi"
4954
]
55+
useIR = true
5056
}
5157
testOptions {
5258
unitTests {
@@ -105,6 +111,9 @@ android {
105111
exclude '**/NOTICE.txt'
106112
exclude '**/*.gwt.xml'
107113
}
114+
composeOptions {
115+
kotlinCompilerExtensionVersion Versions.androidXCompose
116+
}
108117
}
109118

110119
dependencies {
@@ -136,17 +145,31 @@ dependencies {
136145
implementation Libs.androidx_fragment
137146
implementation Libs.androidx_hilt_work
138147
implementation Libs.androidx_lifecycle_viewmodel
148+
implementation Libs.androidx_lifecycle_livedata
139149
implementation Libs.androidx_lifecycle_java8
150+
implementation Libs.androidx_lifecycle_runtime
140151
implementation Libs.androidx_lifecycle_process
141152
implementation Libs.androidx_navigation_fragment
142153
implementation Libs.androidx_navigation_ui
154+
implementation "androidx.navigation:navigation-compose:$Versions.androidXNavigation"
143155
implementation Libs.androidx_preference
144156
implementation Libs.androidx_recyclerview
145157
implementation Libs.androidx_recyclerview_selection
146158
implementation Libs.androidx_room_runtime
147159
implementation Libs.androidx_room_ktx
148160
implementation Libs.androidx_work_runtime
149161
implementation Libs.androidx_work_gcm
162+
implementation 'com.google.android.material:material:1.3.0'
163+
implementation 'androidx.activity:activity-compose:1.3.0-beta02'
164+
implementation "androidx.compose.ui:ui:$Versions.androidXCompose"
165+
implementation "androidx.compose.foundation:foundation:$Versions.androidXCompose"
166+
implementation "androidx.compose.material:material:$Versions.androidXCompose"
167+
implementation "androidx.compose.material:material-icons-core:$Versions.androidXCompose"
168+
implementation "androidx.compose.material:material-icons-extended:$Versions.androidXCompose"
169+
implementation "androidx.compose.ui:ui-tooling:$Versions.androidXCompose"
170+
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07'
171+
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha03'
172+
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$Versions.androidXCompose"
150173
kapt Libs.androidx_room_compiler
151174
kapt Libs.androidx_hilt_compiler
152175

@@ -182,8 +205,8 @@ dependencies {
182205
implementation Libs.kotlinCoroutinesAndroid
183206

184207
// LeakCanary
185-
debugImplementation Libs.leakCanary
186-
implementation Libs.leakCanaryPlumberAndroid
208+
// debugImplementation Libs.leakCanary
209+
// implementation Libs.leakCanaryPlumberAndroid
187210

188211
// Logging
189212
implementation Libs.slf4jAndroidLogger

app/src/main/AndroidManifest.xml

+8-10
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
android:taskAffinity=""
4747
android:theme="@style/AppTheme.Dialog.NoActionBar" />
4848

49-
<activity android:name=".widgets.WidgetConfigActivity">
49+
<activity android:name=".widgets.ui.WidgetConfigActivity">
5050
<intent-filter>
5151
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
5252
</intent-filter>
@@ -65,21 +65,19 @@
6565
android:name=".receivers.UpdateReceiver"
6666
android:exported="false" />
6767

68+
<receiver
69+
android:name=".receivers.PinWidgetSuccessReceiver"
70+
android:exported="false" />
71+
6872
<service
6973
android:name=".appwidget.WidgetService"
7074
android:permission="android.permission.BIND_REMOTEVIEWS" />
7175

7276
<!-- Disable auto-init of WorkManager -->
7377
<provider
74-
android:name="androidx.startup.InitializationProvider"
75-
android:authorities="${applicationId}.androidx-startup"
76-
android:exported="false"
77-
tools:node="merge">
78-
<meta-data
79-
android:name="androidx.work.impl.WorkManagerInitializer"
80-
android:value="androidx.startup"
81-
tools:node="remove" />
82-
</provider>
78+
android:name="androidx.work.impl.WorkManagerInitializer"
79+
android:authorities="${applicationId}.workmanager-init"
80+
tools:node="remove" />
8381

8482
<!-- Configure Firebase Analytics -->
8583
<meta-data
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

+10-7
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package de.psdev.devdrawer
2+
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
8+
import androidx.viewbinding.ViewBinding
9+
10+
abstract class ViewBindingBaseFragment<T : ViewBinding> : BaseFragment() {
11+
12+
private var _binding: T? = null
13+
14+
// This property is only valid between onCreateView and onDestroyView.
15+
protected val binding get() = _binding!!
16+
17+
final override fun onCreateView(
18+
inflater: LayoutInflater,
19+
container: ViewGroup?,
20+
savedInstanceState: Bundle?
21+
): View = createViewBinding(inflater, container, savedInstanceState).also { viewBinding ->
22+
_binding = viewBinding
23+
}.root
24+
25+
protected abstract fun createViewBinding(
26+
inflater: LayoutInflater,
27+
container: ViewGroup?,
28+
savedInstanceState: Bundle?
29+
): T
30+
31+
@CallSuper
32+
override fun onDestroyView() {
33+
super.onDestroyView()
34+
_binding = null
35+
}
36+
37+
}

app/src/main/java/de/psdev/devdrawer/about/AboutFragment.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import com.mikepenz.aboutlibraries.Libs
1313
import com.mikepenz.aboutlibraries.LibsBuilder
1414
import com.mikepenz.aboutlibraries.util.LibsListenerImpl
1515
import dagger.hilt.android.AndroidEntryPoint
16-
import de.psdev.devdrawer.BaseFragment
1716
import de.psdev.devdrawer.R
17+
import de.psdev.devdrawer.ViewBindingBaseFragment
1818
import de.psdev.devdrawer.databinding.FragmentAboutBinding
1919
import de.psdev.devdrawer.utils.consume
2020

2121
@AndroidEntryPoint
22-
class AboutFragment : BaseFragment<FragmentAboutBinding>() {
22+
class AboutFragment : ViewBindingBaseFragment<FragmentAboutBinding>() {
2323

2424
override fun createViewBinding(
2525
inflater: LayoutInflater,

0 commit comments

Comments
 (0)