Skip to content

Commit

Permalink
Implement JetPack Compose
Browse files Browse the repository at this point in the history
This commit reimplements the UI with JetPack Compose.
  • Loading branch information
hameno committed Sep 17, 2022
1 parent ccefd8c commit b67690f
Show file tree
Hide file tree
Showing 110 changed files with 4,498 additions and 1,420 deletions.
101 changes: 77 additions & 24 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import com.android.build.api.dsl.ManagedVirtualDevice

plugins {
id 'com.google.devtools.ksp' version '1.7.10-1.0.6'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"
apply plugin: "androidx.navigation.safeargs"
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'com.mikepenz.aboutlibraries.plugin'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'com.github.triplet.play'
apply plugin: 'com.dicedmelon.gradle.jacoco-android'

android {
compileSdkVersion Config.compile_sdk
buildToolsVersion Config.build_tools

defaultConfig {
applicationId "de.psdev.devdrawer"
Expand All @@ -22,16 +27,20 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true

resConfig "en"
resConfigs 'en'

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

vectorDrawables {
useSupportLibrary true
}

javaCompileOptions.annotationProcessorOptions.arguments['room.schemaLocation'] = rootProject.file('schemas').toString()
}
buildFeatures {
viewBinding true
compose true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -41,14 +50,28 @@ android {
jvmTarget = "1.8"
freeCompilerArgs += [
"-Xinline-classes",
"-Xopt-in=kotlin.RequiresOptIn",
"-Xopt-in=kotlin.ExperimentalStdlibApi",
"-Xopt-in=kotlin.time.ExperimentalTime",
"-Xopt-in=kotlinx.coroutines.FlowPreview",
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
"-Xjvm-default=all",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlin.ExperimentalStdlibApi",
"-opt-in=kotlin.time.ExperimentalTime",
"-opt-in=kotlinx.coroutines.FlowPreview",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=androidx.compose.foundation.ExperimentalFoundationApi",
"-opt-in=androidx.compose.animation.ExperimentalAnimationApi",
"-opt-in=androidx.compose.material.ExperimentalMaterialApi"
]
}
testOptions {
managedDevices {
devices {
pixel4api31(ManagedVirtualDevice) {
device = "Pixel 4"
apiLevel = 31
systemImageSource = "google"
require64Bit = true
}
}
}
unitTests {
includeAndroidResources = true
all { ignoreFailures = true }
Expand Down Expand Up @@ -92,18 +115,25 @@ android {
}
}
}
lintOptions {
lintConfig project.file('lint.xml')
disable "GoogleAppIndexingWarning"
disable "RemoveWorkManagerInitializer"
packagingOptions {
resources {
excludes += ['**/LICENSE', '**/LICENSE.txt', '**/NOTICE', '**/NOTICE.txt', '**/*.gwt.xml']
}
}
composeOptions {
kotlinCompilerExtensionVersion Versions.androidXComposeCompiler
}
lint {
disable 'GoogleAppIndexingWarning', 'RemoveWorkManagerInitializer'
enable 'Interoperability'
lintConfig file('lint.xml')
}
packagingOptions {
exclude '**/LICENSE'
exclude '**/LICENSE.txt'
exclude '**/NOTICE'
exclude '**/NOTICE.txt'
exclude '**/*.gwt.xml'
applicationVariants.all { variant ->
kotlin.sourceSets {
getByName(variant.name) {
kotlin.srcDir("build/generated/ksp/${variant.name}/kotlin")
}
}
}
}

Expand Down Expand Up @@ -133,30 +163,49 @@ dependencies {
implementation Libs.androidx_browser
implementation Libs.androidx_constraint_layout
implementation Libs.androidx_core
implementation "androidx.core:core-splashscreen:1.0.0"
implementation Libs.androidx_fragment
implementation Libs.androidx_hilt_work
implementation Libs.androidx_lifecycle_viewmodel
implementation Libs.androidx_lifecycle_livedata
implementation Libs.androidx_lifecycle_java8
implementation Libs.androidx_lifecycle_runtime
implementation Libs.androidx_lifecycle_process
implementation Libs.androidx_navigation_fragment
implementation Libs.androidx_navigation_ui
implementation "androidx.navigation:navigation-compose:$Versions.androidXNavigation"
implementation Libs.androidx_preference
implementation Libs.androidx_recyclerview
implementation Libs.androidx_recyclerview_selection
implementation Libs.androidx_room_runtime
implementation Libs.androidx_room_ktx
implementation Libs.androidx_work_runtime
implementation Libs.androidx_work_gcm
implementation 'androidx.activity:activity-compose:1.5.1'
implementation "androidx.compose.ui:ui:$Versions.androidXCompose"
implementation "androidx.compose.foundation:foundation:$Versions.androidXCompose"
implementation "androidx.compose.material:material:$Versions.androidXCompose"
implementation "androidx.compose.material:material-icons-core:$Versions.androidXCompose"
implementation "androidx.compose.material:material-icons-extended:$Versions.androidXCompose"
implementation "androidx.compose.ui:ui-tooling:$Versions.androidXCompose"

implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$Versions.androidXLifecycle"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$Versions.androidXCompose"
kapt Libs.androidx_room_compiler
kapt Libs.androidx_hilt_compiler

// Android Material
implementation Libs.material_components

// Color Picker
implementation "com.github.dhaval2404:colorpicker:2.0"
implementation "com.github.dhaval2404:colorpicker:2.3"

// Compose Destinations
implementation 'io.github.raamcosta.compose-destinations:core:1.7.21-beta'
ksp 'io.github.raamcosta.compose-destinations:ksp:1.7.21-beta'

// Dagger
// Dagger
implementation Libs.daggerHiltAndroid
kapt Libs.daggerHiltAndroidCompiler

Expand All @@ -182,8 +231,8 @@ dependencies {
implementation Libs.kotlinCoroutinesAndroid

// LeakCanary
debugImplementation Libs.leakCanary
implementation Libs.leakCanaryPlumberAndroid
// debugImplementation Libs.leakCanary
// implementation Libs.leakCanaryPlumberAndroid

// Logging
implementation Libs.slf4jAndroidLogger
Expand All @@ -200,6 +249,10 @@ kapt {
correctErrorTypes true
}

jacoco {
toolVersion = "0.8.7"
}

play {
def serviceAccountFileName = "google-play-api.json"
if (rootProject.file(serviceAccountFileName).exists()) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/debug/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">DevDrawer2 (Debug)</string>
<string name="app_name" translatable="false">DevDrawer2 (Debug)</string>
</resources>
21 changes: 17 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
<application
android:name=".DevDrawerApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_descriptor"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -30,6 +34,7 @@
android:name=".appwidget.ClickHandlingActivity"
android:allowTaskReparenting="false"
android:excludeFromRecents="true"
android:exported="true"
android:noHistory="true"
android:taskAffinity=""
android:theme="@android:style/Theme.NoDisplay">
Expand All @@ -46,13 +51,17 @@
android:taskAffinity=""
android:theme="@style/AppTheme.Dialog.NoActionBar" />

<activity android:name=".widgets.WidgetConfigActivity">
<activity
android:name=".widgets.ui.WidgetConfigActivity"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>

<receiver android:name=".appwidget.DDWidgetProvider">
<receiver
android:name=".appwidget.DDWidgetProvider"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
Expand All @@ -65,6 +74,10 @@
android:name=".receivers.UpdateReceiver"
android:exported="false" />

<receiver
android:name=".receivers.PinWidgetSuccessReceiver"
android:exported="false" />

<service
android:name=".appwidget.WidgetService"
android:permission="android.permission.BIND_REMOTEVIEWS" />
Expand All @@ -76,7 +89,7 @@
android:exported="false"
tools:node="merge">
<meta-data
android:name="androidx.work.impl.WorkManagerInitializer"
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup"
tools:node="remove" />
</provider>
Expand Down
41 changes: 4 additions & 37 deletions app/src/main/java/de/psdev/devdrawer/BaseFragment.kt
Original file line number Diff line number Diff line change
@@ -1,59 +1,26 @@
package de.psdev.devdrawer

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.CallSuper
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.lifecycle.lifecycleScope
import androidx.viewbinding.ViewBinding
import de.psdev.devdrawer.analytics.TrackingService
import javax.inject.Inject

abstract class BaseFragment<T : ViewBinding> : Fragment() {
open class BaseFragment : Fragment() {

@Inject
lateinit var trackingService: TrackingService

private var _binding: T? = null
// This property is only valid between onCreateView and onDestroyView.
protected val binding get() = _binding!!

protected var toolbarTitle: CharSequence
get() = requireActivity().title
set(value) {
requireActivity().title = value
}

final override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View = createViewBinding(inflater, container, savedInstanceState).also { viewBinding ->
_binding = viewBinding
}.root

protected abstract fun createViewBinding(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): T

@CallSuper
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
val Fragment.viewLifecycleScope: LifecycleCoroutineScope
get() = viewLifecycleOwner.lifecycleScope

protected fun updateToolbarTitle(@StringRes resId: Int) {
requireActivity().setTitle(resId)
trackingService.trackScreen(this::class.java, getString(resId))
}

val Fragment.viewLifecycleScope: LifecycleCoroutineScope
get() = viewLifecycleOwner.lifecycleScope

}
}
17 changes: 10 additions & 7 deletions app/src/main/java/de/psdev/devdrawer/DevDrawerApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@ class DevDrawerApplication: Application(), Configuration.Provider {
registerAppInstallationReceiver()
setupWorkers()
}.let {
logger.warn("{} version {} ({}) took {}ms to init", this::class.java.simpleName, BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, it)
logger.warn(
"{} version {} ({}) took {}ms to init",
this::class.java.simpleName,
BuildConfig.VERSION_NAME,
BuildConfig.VERSION_CODE,
it
)
}
}

// ==========================================================================================================================
// Configuration.Provider
// ==========================================================================================================================

override fun getWorkManagerConfiguration(): Configuration {
logger.warn { "getWorkManagerConfiguration" }
return Configuration.Builder()
.setWorkerFactory(workerFactory)
.build()
}
override fun getWorkManagerConfiguration(): Configuration = Configuration.Builder()
.setWorkerFactory(workerFactory)
.build()

// ==========================================================================================================================
// Private API
Expand Down
Loading

0 comments on commit b67690f

Please sign in to comment.