Skip to content

Commit

Permalink
fix some known bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
TorryDo committed Sep 11, 2023
1 parent 4316832 commit 8571b69
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import com.torrydo.floatingbubbleview.sez

abstract class FloatingBubbleService : Service() {



open fun startNotificationForeground() {
val noti = NotificationHelper(this)
noti.createNotificationChannel()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -92,7 +99,6 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
context,
containCompose = false,
forceDragging = false,
// onDispatchKeyEvent = expandedBuilder.onDispatchKeyEvent,
)
expandedBubble!!.rootGroup.addView(expandedView)
} else {
Expand All @@ -101,7 +107,6 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
context,
containCompose = true,
forceDragging = false,
// onDispatchKeyEvent = expandedBuilder.onDispatchKeyEvent,
)
expandedBubble!!.rootGroup.addView(expandedCompose)
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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?

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class MyService: ExpandableBubbleService() {

## III, Usage 🔥 <a name="usage"/>

### 1, Bubble and ExpandableView
### 1, `configBubble()` and `configExpandedBubble()`

<details><summary>Java</summary>

Expand Down Expand Up @@ -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)
Expand Down
17 changes: 5 additions & 12 deletions app/src/main/java/com/torrydo/testfloatingbubble/BubbleCompose.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -81,7 +74,7 @@ fun BubbleCompose(
) {
IconButton(onClick = {
runBlocking {
navigateToExpandable()
expand()
}
isPlay = isPlay.not()

Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/torrydo/testfloatingbubble/MyServiceKt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -95,9 +95,9 @@ class MyServiceKt : ExpandableBubbleService() {

return ExpandedBubbleBuilder(this)
.expandedView(expandedView)
.expandedCompose {
ExpandedCompose()
}
// .expandedCompose {
// ExpandedCompose()
// }
.startLocation(0, 0)
.draggable(true)
.style(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

public class MyServiceJava extends ExpandableBubbleService {

@Override
public void startNotificationForeground() {
startForeground();
}
// @Override
// public void startNotificationForeground() {
// startForeground();
// }

@Override
public void onCreate() {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8571b69

Please sign in to comment.