From 8571b6908374cfd3a2d490f6e55c15015d8715a8 Mon Sep 17 00:00:00 2001 From: torrydo Date: Mon, 11 Sep 2023 20:12:09 +0700 Subject: [PATCH] fix some known bugs --- .../service/FloatingBubbleService.kt | 2 -- .../expandable/ExpandableBubbleService.kt | 34 +++++++++++++++++-- README.md | 4 +-- .../testfloatingbubble/BubbleCompose.kt | 17 +++------- .../torrydo/testfloatingbubble/MyServiceKt.kt | 18 +++++----- .../java_sample/MyServiceJava.java | 8 ++--- gradle.properties | 4 +-- 7 files changed, 54 insertions(+), 33 deletions(-) diff --git a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/FloatingBubbleService.kt b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/FloatingBubbleService.kt index 96b3c80..0c0c86d 100644 --- a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/FloatingBubbleService.kt +++ b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/FloatingBubbleService.kt @@ -12,8 +12,6 @@ import com.torrydo.floatingbubbleview.sez abstract class FloatingBubbleService : Service() { - - open fun startNotificationForeground() { val noti = NotificationHelper(this) noti.createNotificationChannel() diff --git a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/ExpandableBubbleService.kt b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/ExpandableBubbleService.kt index faab6bb..bec489a 100644 --- a/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/ExpandableBubbleService.kt +++ b/FloatingBubbleView/src/main/java/com/torrydo/floatingbubbleview/service/expandable/ExpandableBubbleService.kt @@ -1,6 +1,7 @@ package com.torrydo.floatingbubbleview.service.expandable import android.content.Context +import android.content.res.Configuration import androidx.dynamicanimation.animation.SpringForce import com.torrydo.floatingbubbleview.CloseBubbleBehavior import com.torrydo.floatingbubbleview.FloatingBubbleListener @@ -9,12 +10,18 @@ import com.torrydo.floatingbubbleview.bubble.FloatingBottomBackground import com.torrydo.floatingbubbleview.bubble.FloatingBubble import com.torrydo.floatingbubbleview.bubble.FloatingCloseBubble import com.torrydo.floatingbubbleview.service.FloatingBubbleService +import com.torrydo.floatingbubbleview.sez abstract class ExpandableBubbleService : FloatingBubbleService() { private var _context: Context? = null private val context get() = _context!! + // 0: nothing + // 1: bubble + // 2: expanded-bubble + private var state = 0 + var bubble: FloatingBubble? = null private set @@ -92,7 +99,6 @@ abstract class ExpandableBubbleService : FloatingBubbleService() { context, containCompose = false, forceDragging = false, -// onDispatchKeyEvent = expandedBuilder.onDispatchKeyEvent, ) expandedBubble!!.rootGroup.addView(expandedView) } else { @@ -101,7 +107,6 @@ abstract class ExpandableBubbleService : FloatingBubbleService() { context, containCompose = true, forceDragging = false, -// onDispatchKeyEvent = expandedBuilder.onDispatchKeyEvent, ) expandedBubble!!.rootGroup.addView(expandedCompose) } @@ -126,16 +131,22 @@ abstract class ExpandableBubbleService : FloatingBubbleService() { closeBubble?.remove() bottomBackground?.remove() expandedBubble?.remove() + + state = 0 } fun expand() { expandedBubble!!.show() bubble?.remove() + + state = 2 } fun minimize() { bubble!!.show() expandedBubble?.remove() + + state = 1 } fun enableBubbleDragging(b: Boolean) { @@ -254,6 +265,25 @@ abstract class ExpandableBubbleService : FloatingBubbleService() { // override service + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + + bubble?.remove() + closeBubble?.remove() + bottomBackground?.remove() + expandedBubble?.remove() + + sez.refresh() + createBubbles(this, configBubble(), configExpandedBubble()) + + when(state){ + 1 -> minimize() + 2 -> expand() + } + + + } + abstract fun configBubble(): BubbleBuilder? abstract fun configExpandedBubble(): ExpandedBubbleBuilder? diff --git a/README.md b/README.md index 33db677..14ed1df 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ class MyService: ExpandableBubbleService() { ## III, Usage 🔥 -### 1, Bubble and ExpandableView +### 1, `configBubble()` and `configExpandedBubble()`
Java @@ -336,7 +336,7 @@ class MyServiceKt : ExpandableBubbleService() { .closeBehavior(CloseBubbleBehavior.DYNAMIC_CLOSE_BUBBLE) // the more value (dp), the larger closeable-area - .distanceToClose(200) + .distanceToClose(100) // enable bottom background, false by default .bottomBackground(true) diff --git a/app/src/main/java/com/torrydo/testfloatingbubble/BubbleCompose.kt b/app/src/main/java/com/torrydo/testfloatingbubble/BubbleCompose.kt index d27a157..091e241 100644 --- a/app/src/main/java/com/torrydo/testfloatingbubble/BubbleCompose.kt +++ b/app/src/main/java/com/torrydo/testfloatingbubble/BubbleCompose.kt @@ -1,16 +1,12 @@ package com.torrydo.testfloatingbubble import android.util.Log -import android.widget.Toast import androidx.compose.foundation.background -import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Pause @@ -30,21 +26,18 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color -import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @Composable fun BubbleCompose( - show: () -> Unit, - hide: () -> Unit, - animateToEdge: () -> Unit, - navigateToExpandable: () -> Unit + show: () -> Unit = {}, + hide: () -> Unit = {}, + animateToEdge: () -> Unit = {}, + expand: () -> Unit = {} ) { val context = LocalContext.current @@ -81,7 +74,7 @@ fun BubbleCompose( ) { IconButton(onClick = { runBlocking { - navigateToExpandable() + expand() } isPlay = isPlay.not() diff --git a/app/src/main/java/com/torrydo/testfloatingbubble/MyServiceKt.kt b/app/src/main/java/com/torrydo/testfloatingbubble/MyServiceKt.kt index bfeb91d..6da82b6 100644 --- a/app/src/main/java/com/torrydo/testfloatingbubble/MyServiceKt.kt +++ b/app/src/main/java/com/torrydo/testfloatingbubble/MyServiceKt.kt @@ -35,12 +35,12 @@ class MyServiceKt : ExpandableBubbleService() { return BubbleBuilder(this) // set bubble view - .bubbleView(imgView) +// .bubbleView(imgView) // or our sweetie, Jetpack Compose -// .bubbleCompose { -// BubbleCompose() -// } + .bubbleCompose { + BubbleCompose(expand = { expand() }) + } // set style for the bubble, fade animation by default .bubbleStyle(null) @@ -60,10 +60,10 @@ class MyServiceKt : ExpandableBubbleService() { // DYNAMIC_CLOSE_BUBBLE: close-bubble moving based on the bubble's location // FIXED_CLOSE_BUBBLE (default): bubble will automatically move to the close-bubble when it reaches the closable-area - .closeBehavior(CloseBubbleBehavior.DYNAMIC_CLOSE_BUBBLE) + .closeBehavior(CloseBubbleBehavior.FIXED_CLOSE_BUBBLE) // the more value (dp), the larger closeable-area - .distanceToClose(200) + .distanceToClose(100) // enable bottom background, false by default .bottomBackground(true) @@ -95,9 +95,9 @@ class MyServiceKt : ExpandableBubbleService() { return ExpandedBubbleBuilder(this) .expandedView(expandedView) - .expandedCompose { - ExpandedCompose() - } +// .expandedCompose { +// ExpandedCompose() +// } .startLocation(0, 0) .draggable(true) .style(null) diff --git a/app/src/main/java/com/torrydo/testfloatingbubble/java_sample/MyServiceJava.java b/app/src/main/java/com/torrydo/testfloatingbubble/java_sample/MyServiceJava.java index 7c09a7b..e50d1ef 100644 --- a/app/src/main/java/com/torrydo/testfloatingbubble/java_sample/MyServiceJava.java +++ b/app/src/main/java/com/torrydo/testfloatingbubble/java_sample/MyServiceJava.java @@ -15,10 +15,10 @@ public class MyServiceJava extends ExpandableBubbleService { - @Override - public void startNotificationForeground() { - startForeground(); - } +// @Override +// public void startNotificationForeground() { +// startForeground(); +// } @Override public void onCreate() { diff --git a/gradle.properties b/gradle.properties index a5ec836..8f61223 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,8 +27,8 @@ RELEASE_SIGNING_ENABLED=true GROUP=io.github.torrydo POM_ARTIFACT_ID=floating-bubble-view -VERSION_NAME=0.6.0 -#prev: 0.5.6 +VERSION_NAME=0.6.1 +#prev: 0.6.0 POM_NAME=FloatingBubbleView POM_PACKAGING=aar