diff --git a/bottomsheets/build.gradle b/bottomsheets/build.gradle index a52fbc1c7..f97e0c59d 100644 --- a/bottomsheets/build.gradle +++ b/bottomsheets/build.gradle @@ -1,10 +1,10 @@ ext.module_group = "com.afollestad.material-dialogs" ext.module_name = "bottomsheets" -apply from: rootProject.file("gradle/android_library_config.gradle") +apply from: project.file("../gradle/android_library_config.gradle") dependencies { - api project(':core') + api project(':md:core') implementation deps.kotlin.stdlib8 implementation deps.google_material diff --git a/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/BottomSheet.kt b/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/BottomSheet.kt index 5c766a969..850ccd097 100644 --- a/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/BottomSheet.kt +++ b/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/BottomSheet.kt @@ -37,14 +37,15 @@ import com.afollestad.materialdialogs.internal.main.DialogLayout import com.afollestad.materialdialogs.utils.MDUtil.getWidthAndHeight import com.afollestad.materialdialogs.utils.MDUtil.waitForHeight import com.google.android.material.bottomsheet.BottomSheetBehavior -import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED -import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN +import com.google.android.material.bottomsheet.BottomSheetBehavior.* import kotlin.math.min import kotlin.properties.Delegates.notNull /** @author Aidan Follestad (@afollestad) */ class BottomSheet( - private val layoutMode: LayoutMode = MATCH_PARENT + private val layoutMode: LayoutMode = MATCH_PARENT, + private val initialState: Int = STATE_HALF_EXPANDED, + private val animateInitialState: Boolean = true ) : DialogBehavior { internal var bottomSheetBehavior: BottomSheetBehavior? = null private lateinit var bottomSheetView: ViewGroup @@ -56,6 +57,7 @@ class BottomSheet( internal var defaultPeekHeight: Int by notNull() internal var maxPeekHeight: Int = -1 private var actualPeekHeight: Int by notNull() + private var actualFullHeight: Int by notNull() override fun getThemeRes(isDark: Boolean): Int { return if (isDark) { @@ -73,9 +75,9 @@ class BottomSheet( dialog: MaterialDialog ): ViewGroup { rootView = layoutInflater.inflate( - R.layout.md_dialog_base_bottomsheet, - null, - false + R.layout.md_dialog_base_bottomsheet, + null, + false ) as CoordinatorLayout this.dialog = dialog @@ -86,12 +88,13 @@ class BottomSheet( defaultPeekHeight = (windowHeight * DEFAULT_PEEK_HEIGHT_RATIO).toInt() actualPeekHeight = defaultPeekHeight maxPeekHeight = windowHeight + actualFullHeight = windowHeight setupBottomSheetBehavior() if (creatingContext is Activity) { carryOverWindowFlags( - dialogWindow = dialogWindow, - creatingActivity = creatingContext + dialogWindow = dialogWindow, + creatingActivity = creatingContext ) } @@ -110,33 +113,42 @@ class BottomSheet( private fun setupBottomSheetBehavior() { bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetView) - .apply { - isHideable = true + .apply { + isHideable = true + + if (animateInitialState) { // start at 0 so we can animate it up when the dialog lays out the view peekHeight = 0 - - setCallbacks( - onSlide = { currentHeight -> - // Slide the buttons layout down as the bottom sheet is hiding itself - val buttonsLayoutHeight = buttonsLayout.measuredHeight - if (currentHeight in 1..buttonsLayoutHeight) { - val diff = buttonsLayoutHeight - currentHeight - buttonsLayout.translationY = diff.toFloat() - } else if (currentHeight > 0) { - buttonsLayout.translationY = 0f - } - // Show divider over buttons layout if sheet is sliding down - invalidateDividers(currentHeight) - }, - onHide = { - buttonsLayout.visibility = GONE - dialog?.dismiss() - } - ) + state = STATE_COLLAPSED + } else { + peekHeight = defaultPeekHeight + state = initialState } + setCallbacks( + onSlide = { currentHeight -> + // Slide the buttons layout down as the bottom sheet is hiding itself + val buttonsLayoutHeight = buttonsLayout.measuredHeight + if (currentHeight in 1..buttonsLayoutHeight) { + val diff = buttonsLayoutHeight - currentHeight + buttonsLayout.translationY = diff.toFloat() + } else if (currentHeight > 0) { + buttonsLayout.translationY = 0f + } + // Show divider over buttons layout if sheet is sliding down + // Show divider over buttons layout if sheet is sliding down + invalidateDividers(currentHeight) + }, + onHide = { + buttonsLayout.visibility = GONE + dialog?.dismiss() + } + ) + } + bottomSheetView.waitForHeight { actualPeekHeight = min(defaultPeekHeight, min(this.measuredHeight, defaultPeekHeight)) + actualFullHeight = this.measuredHeight } } @@ -172,11 +184,11 @@ class BottomSheet( } window.setSoftInputMode(LayoutParams.SOFT_INPUT_ADJUST_RESIZE) val lp = LayoutParams() - .apply { - copyFrom(window.attributes) - width = LayoutParams.MATCH_PARENT - height = LayoutParams.MATCH_PARENT - } + .apply { + copyFrom(window.attributes) + width = LayoutParams.MATCH_PARENT + height = LayoutParams.MATCH_PARENT + } window.attributes = lp } @@ -187,10 +199,10 @@ class BottomSheet( ) { bottomSheetView.background = GradientDrawable().apply { this.cornerRadii = floatArrayOf( - cornerRadius, cornerRadius, // top left - cornerRadius, cornerRadius, // top right - 0f, 0f, // bottom left - 0f, 0f // bottom right + cornerRadius, cornerRadius, // top left + cornerRadius, cornerRadius, // top right + 0f, 0f, // bottom left + 0f, 0f // bottom right ) setColor(color) } @@ -207,22 +219,25 @@ class BottomSheet( bottomSheetBehavior!!.isHideable = false } - bottomSheetView.waitForHeight { - bottomSheetBehavior?.apply { - peekHeight = 0 - state = STATE_COLLAPSED - animatePeekHeight( + if (animateInitialState) { + bottomSheetView.waitForHeight { + bottomSheetBehavior?.apply { + peekHeight = 0 + state = initialState + val targetHeight = if (initialState == STATE_HALF_EXPANDED) actualPeekHeight else actualFullHeight + animateViewHeight( view = bottomSheetView, start = 0, - dest = actualPeekHeight, + dest = targetHeight, duration = LAYOUT_PEEK_CHANGE_DURATION_MS, onEnd = { - invalidateDividers(actualPeekHeight) + invalidateDividers(targetHeight) } - ) + ) + } } - showButtons() } + showButtons() } override fun onPostShow(dialog: MaterialDialog) = Unit @@ -230,8 +245,8 @@ class BottomSheet( override fun onDismiss(): Boolean { val sheetBehavior = bottomSheetBehavior if (dialog != null && - sheetBehavior != null && - sheetBehavior.state != STATE_HIDDEN + sheetBehavior != null && + sheetBehavior.state != STATE_HIDDEN ) { sheetBehavior.apply { isHideable = true @@ -253,10 +268,10 @@ class BottomSheet( visibility = VISIBLE } val animator = animateValues( - from = start, - to = 0, - duration = BUTTONS_SHOW_DURATION_MS, - onUpdate = { buttonsLayout.translationY = it.toFloat() } + from = start, + to = 0, + duration = BUTTONS_SHOW_DURATION_MS, + onUpdate = { buttonsLayout.translationY = it.toFloat() } ) buttonsLayout.onDetach { animator.cancel() } animator.apply { @@ -268,10 +283,10 @@ class BottomSheet( private fun hideButtons() { if (!buttonsLayout.shouldBeVisible()) return val animator = animateValues( - from = 0, - to = buttonsLayout.measuredHeight, - duration = LAYOUT_PEEK_CHANGE_DURATION_MS, - onUpdate = { buttonsLayout.translationY = it.toFloat() } + from = 0, + to = buttonsLayout.measuredHeight, + duration = LAYOUT_PEEK_CHANGE_DURATION_MS, + onUpdate = { buttonsLayout.translationY = it.toFloat() } ) buttonsLayout.onDetach { animator.cancel() } animator.start() diff --git a/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/BottomSheets.kt b/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/BottomSheets.kt index 760ef8346..110e9596e 100644 --- a/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/BottomSheets.kt +++ b/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/BottomSheets.kt @@ -79,7 +79,7 @@ fun MaterialDialog.setPeekHeight( bottomSheet.defaultPeekHeight = destinationPeekHeight val bottomSheetBehavior = bottomSheet.bottomSheetBehavior if (isShowing) { - bottomSheetBehavior?.animatePeekHeight( + bottomSheetBehavior?.animateViewHeight( view = this.view, dest = destinationPeekHeight, duration = LAYOUT_PEEK_CHANGE_DURATION_MS diff --git a/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/Util.kt b/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/Util.kt index e63db24df..de15e7354 100644 --- a/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/Util.kt +++ b/bottomsheets/src/main/java/com/afollestad/materialdialogs/bottomsheets/Util.kt @@ -61,7 +61,7 @@ internal fun BottomSheetBehavior<*>.setCallbacks( }) } -internal fun BottomSheetBehavior<*>.animatePeekHeight( +internal fun BottomSheetBehavior<*>.animateViewHeight( view: View, start: Int = peekHeight, dest: Int, diff --git a/color/build.gradle b/color/build.gradle index 8c3bf297c..05b838ea8 100644 --- a/color/build.gradle +++ b/color/build.gradle @@ -1,10 +1,10 @@ ext.module_group = "com.afollestad.material-dialogs" ext.module_name = "color" -apply from: rootProject.file("gradle/android_library_config.gradle") +apply from: project.file("../gradle/android_library_config.gradle") dependencies { - api project(':core') + api project(':md:core') implementation deps.kotlin.stdlib8 implementation deps.afollestad.dots_indicator diff --git a/core/build.gradle b/core/build.gradle index b60427684..2485b0555 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,7 +1,7 @@ ext.module_group = "com.afollestad.material-dialogs" ext.module_name = "core" -apply from: rootProject.file("gradle/android_library_config.gradle") +apply from: project.file("../gradle/android_library_config.gradle") dependencies { api deps.androidx.core diff --git a/core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.kt b/core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.kt index d9660f102..fa632a183 100644 --- a/core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.kt +++ b/core/src/main/java/com/afollestad/materialdialogs/MaterialDialog.kt @@ -17,12 +17,14 @@ package com.afollestad.materialdialogs +import android.app.Activity import android.app.Dialog import android.content.Context import android.graphics.Color.TRANSPARENT import android.graphics.Typeface import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable +import android.os.Build import android.util.TypedValue import android.util.TypedValue.COMPLEX_UNIT_DIP import android.view.LayoutInflater @@ -397,6 +399,9 @@ class MaterialDialog( override fun dismiss() { if (dialogBehavior.onDismiss()) return hideKeyboard() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && windowContext is Activity && windowContext.isDestroyed) { + return + } super.dismiss() } diff --git a/datetime/build.gradle b/datetime/build.gradle index 9e06d254c..15da0f857 100644 --- a/datetime/build.gradle +++ b/datetime/build.gradle @@ -1,10 +1,10 @@ ext.module_group = "com.afollestad.material-dialogs" ext.module_name = "datetime" -apply from: rootProject.file("gradle/android_library_config.gradle") +apply from: project.file("../gradle/android_library_config.gradle") dependencies { - api project(':core') + api project(':md:core') api deps.afollestad.date_picker compileOnly deps.androidx.annotations diff --git a/dependencies.gradle b/dependencies.gradle index aab328849..375ed110a 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,15 +1,14 @@ ext.versions = [ min_sdk: 16, compile_sdk: 29, - build_tools: "29.0.0", publish_version: "3.3.0", publish_version_code: 262 ] ext.deps = [ gradle_plugins: [ - android: "com.android.tools.build:gradle:4.1.2", - kotlin: "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61", + android: "com.android.tools.build:gradle:7.0.1", + kotlin: "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30", spotless: "com.diffplug.spotless:spotless-plugin-gradle:3.27.1", versions: "com.github.ben-manes:gradle-versions-plugin:0.27.0" ], diff --git a/files/build.gradle b/files/build.gradle index f985d6b33..076ac255d 100644 --- a/files/build.gradle +++ b/files/build.gradle @@ -1,11 +1,11 @@ ext.module_group = "com.afollestad.material-dialogs" ext.module_name = "files" -apply from: rootProject.file("gradle/android_library_config.gradle") +apply from: project.file("../gradle/android_library_config.gradle") dependencies { - api project(':core') - api project(':input') + api project(':md:core') + api project(':md:input') implementation deps.kotlin.coroutines.android implementation deps.kotlin.stdlib8 diff --git a/gradle/android_application_config.gradle b/gradle/android_application_config.gradle index 5c2ff4881..67fe71230 100644 --- a/gradle/android_application_config.gradle +++ b/gradle/android_application_config.gradle @@ -1,5 +1,5 @@ apply plugin: "com.android.application" -apply from: rootProject.file("gradle/android_common_config.gradle") +apply from: project.file("../gradle/android_common_config.gradle") if (module_package_id == null) { throw new IllegalStateException("module_package_id is missing!") diff --git a/gradle/android_common_config.gradle b/gradle/android_common_config.gradle index 8e99ad82c..a48d3a739 100644 --- a/gradle/android_common_config.gradle +++ b/gradle/android_common_config.gradle @@ -2,12 +2,11 @@ ext.module_package_id = "${module_group}.${module_name}" logger.info("Package ID: $module_package_id") apply plugin: "kotlin-android" -apply from: rootProject.file("dependencies.gradle") -apply from: rootProject.file("gradle/spotless_plugin_config.gradle") +apply from: project.file("../dependencies.gradle") +//apply from: rootProject.file("gradle/spotless_plugin_config.gradle") android { compileSdkVersion versions.compile_sdk - buildToolsVersion versions.build_tools compileOptions { sourceCompatibility 1.8 diff --git a/gradle/android_library_config.gradle b/gradle/android_library_config.gradle index ec87c0526..91a191c3d 100644 --- a/gradle/android_library_config.gradle +++ b/gradle/android_library_config.gradle @@ -1,4 +1,9 @@ apply plugin: "com.android.library" -apply from: rootProject.file("gradle/android_common_config.gradle") -apply from: rootProject.file("gradle/android_publish_mavencentral.gradle") +apply from: project.file("../gradle/android_common_config.gradle") + +// maven +//apply from: project.file("../gradle/android_publish_mavencentral.gradle") + +// jitpack +apply from: project.file("../gradle/android_publish_jitpack.gradle") \ No newline at end of file diff --git a/gradle/android_publish_jitpack.gradle b/gradle/android_publish_jitpack.gradle new file mode 100644 index 000000000..5aa31e0ff --- /dev/null +++ b/gradle/android_publish_jitpack.gradle @@ -0,0 +1,10 @@ +apply plugin: 'maven-publish' +project.afterEvaluate { + publishing { + publications { + release(MavenPublication) { + from components.release + } + } + } +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9fccb7a76..8ad73a75c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip diff --git a/input/build.gradle b/input/build.gradle index 0e91db256..e4bf936b0 100644 --- a/input/build.gradle +++ b/input/build.gradle @@ -1,10 +1,10 @@ ext.module_group = "com.afollestad.material-dialogs" ext.module_name = "input" -apply from: rootProject.file("gradle/android_library_config.gradle") +apply from: project.file("../gradle/android_library_config.gradle") dependencies { - api project(':core') + api project(':md:core') implementation deps.google_material implementation deps.kotlin.stdlib8 diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 000000000..95d3dc5c9 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,3 @@ +jdk: + - openjdk11 + - ./gradlew build :lib:publishToMavenLocal \ No newline at end of file diff --git a/lifecycle/build.gradle b/lifecycle/build.gradle index 780f83305..4f48a05c6 100644 --- a/lifecycle/build.gradle +++ b/lifecycle/build.gradle @@ -1,10 +1,10 @@ ext.module_group = "com.afollestad.material-dialogs" ext.module_name = "lifecycle" -apply from: rootProject.file("gradle/android_library_config.gradle") +apply from: project.file("../gradle/android_library_config.gradle") dependencies { - api project(':core') + api project(':md:core') implementation deps.kotlin.stdlib8 implementation deps.androidx.lifecycle.runtime diff --git a/sample/build.gradle b/sample/build.gradle index 98ba15958..0669c7128 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -6,13 +6,13 @@ apply from: rootProject.file("gradle/android_application_config.gradle") android.defaultConfig.vectorDrawables.useSupportLibrary = true dependencies { - implementation project(':core') - implementation project(':input') - implementation project(':files') - implementation project(':color') - implementation project(':datetime') - implementation project(':bottomsheets') - implementation project(':lifecycle') + implementation project(':md:core') + implementation project(':md:input') + implementation project(':md:files') + implementation project(':md:color') + implementation project(':md:datetime') + implementation project(':md:bottomsheets') + implementation project(':md:lifecycle') implementation deps.kotlin.stdlib8 diff --git a/settings.gradle b/settings.gradle index 17d465a97..5dee753fd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,16 @@ -include ':core', ':sample', ':files', ':color', ':input', ':lifecycle', ':datetime', ':bottomsheets' +include ':sample' + +include ':md:core' +project(':md:core').projectDir = new File("core") +include ':md:input' +project(':md:input').projectDir = new File("input") +include ':md:lifecycle' +project(':md:lifecycle').projectDir = new File("lifecycle") +include ':md:files' +project(':md:files').projectDir = new File("files") +include ':md:color' +project(':md:color').projectDir = new File("color") +include ':md:datetime' +project(':md:datetime').projectDir = new File("datetime") +include ':md:bottomsheets' +project(':md:bottomsheets').projectDir = new File("bottomsheets") \ No newline at end of file