Skip to content

Commit

Permalink
Merge pull request #34 from TorryDo/release/v0.5.4
Browse files Browse the repository at this point in the history
Release/v0.5.4
  • Loading branch information
TorryDo authored Jul 8, 2023
2 parents cbf4485 + 3aeb439 commit c076868
Show file tree
Hide file tree
Showing 26 changed files with 599 additions and 285 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mp4 filter=lfs diff=lfs merge=lfs -text
52 changes: 52 additions & 0 deletions .github/workflows/publish-maven-central.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Publish to maven central

on:
# push:
# branches: [ release/v* ]
workflow_dispatch:

#env:
# KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
# KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
# KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout github repo
uses: actions/checkout@v2

- name: set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
cache: gradle

- name: Change wrapper permissions
run: chmod +x ./gradlew

# Decode the secring file
- name: Decode Keystore File
id: decode_secring
uses: timheuer/[email protected]
with:
fileDir: './secrets'
fileName: 'secring.gpg'
encodedString: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE }}

# generate docs
- name: Generate docs
run: ./gradlew dokkaJavadoc

# Build bundle and publish to Maven Central
- name: Build & publish to Maven Central
run: ./gradlew
-PmavenCentralUsername=${{ secrets.MAVEN_CENTRAL_USERNAME }}
-PmavenCentralPassword=${{ secrets.MAVEN_CENTRAL_PASSWORD }}
-PsigningKeyId=${{ secrets.SIGNING_KEY_ID }}
-PsigningPassword=${{ secrets.SIGNING_PASSWORD }}
-PsigningSecretKeyRingFile="../${{ steps.decode_secring.outputs.filePath }}"
publishBundle --max-workers 1
2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.savedstate.SavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner


class ComposeLifecycleOwner : LifecycleOwner, SavedStateRegistryOwner {
internal class ComposeLifecycleOwner : LifecycleOwner, SavedStateRegistryOwner {

fun onCreate() {
savedStateRegistryController.performRestore(null)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.util.Size
import android.view.View
import androidx.annotation.DrawableRes
import androidx.annotation.StyleRes
import androidx.compose.runtime.Composable
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap

Expand All @@ -19,6 +20,8 @@ internal constructor(
private var closeBubbleView: FloatingCloseBubbleView? = null
private var bottomBackground: FloatingBottomBackground? = null

private var isComposeInit = false

init {
ScreenInfo.onOrientationChanged(builder.context)

Expand Down Expand Up @@ -65,21 +68,41 @@ internal constructor(
* */
fun onMove(x: Float, y: Float) {}

fun onClick() {}

}

internal interface ServiceInteractor{
internal interface ServiceInteractor {
fun requestStop()
}

//region public methods ------------------------------------------------------------------------

internal fun showIcon() {

if(builder.composeLifecycleOwner != null){
if(isComposeInit.not()){
builder.composeLifecycleOwner?.onCreate()
isComposeInit = true
}

builder.composeLifecycleOwner?.apply {
onStart()
onResume()
}
}

bubbleView.show()
}

internal fun removeIcon() {

if(builder.composeLifecycleOwner != null && isComposeInit){
builder.composeLifecycleOwner!!.apply {
onPause()
onStop()
onDestroy()
}
}

bubbleView.remove()
}

Expand All @@ -103,18 +126,22 @@ internal constructor(
private var isBubbleAnimated = false

override fun onMove(x: Float, y: Float) {

val bubbleSizeCompat = Size(builder.bubbleView!!.width, builder.bubbleView!!.height)

when (builder.behavior) {
BubbleBehavior.DYNAMIC_CLOSE_BUBBLE -> {
bubbleView.updateLocationUI(x, y)
val (bubbleX, bubbleY) = bubbleView.rawLocationOnScreen()
closeBubbleView?.animateCloseIconByBubble(bubbleX.toInt(), bubbleY.toInt())
}

BubbleBehavior.FIXED_CLOSE_BUBBLE -> {
if (isFingerInsideClosableArea(x, y)) {
if (isBubbleAnimated.not()) {

val xOffset = (closeBubbleView!!.width - builder.bubbleSizePx.width) / 2
val yOffset = (closeBubbleView!!.height - builder.bubbleSizePx.height) / 2
val xOffset = (closeBubbleView!!.width - bubbleSizeCompat.width) / 2
val yOffset = (closeBubbleView!!.height - bubbleSizeCompat.height) / 2

val xUpdated = closeBubbleView!!.baseX.toFloat() + xOffset
val yUpdated = closeBubbleView!!.baseY.toFloat() + yOffset
Expand Down Expand Up @@ -142,7 +169,7 @@ internal constructor(
isCloseBubbleVisible = false
tryRemoveCloseBubbleAndBackground()

val shouldDestroy = when(builder.behavior){
val shouldDestroy = when (builder.behavior) {
BubbleBehavior.FIXED_CLOSE_BUBBLE -> isFingerInsideClosableArea(x, y)
BubbleBehavior.DYNAMIC_CLOSE_BUBBLE -> {
val (bubbleX, bubbleY) = bubbleView.rawLocationOnScreen()
Expand Down Expand Up @@ -186,10 +213,8 @@ internal constructor(
private val DEFAULT_BUBBLE_SIZE_PX = 160

// bubble
internal var iconView: View? = null
internal var iconBitmap: Bitmap? = null
internal var bubbleView: View? = null
internal var bubbleStyle: Int? = R.style.default_bubble_style
internal var bubbleSizePx: Size = Size(DEFAULT_BUBBLE_SIZE_PX, DEFAULT_BUBBLE_SIZE_PX)

// close-bubble
internal var closeIconView: View? = null
Expand All @@ -199,18 +224,21 @@ internal constructor(

// config
internal var startPoint = Point(0, 0)
internal var opacity = 1f
internal var isCloseBubbleEnabled = true
internal var isAnimateToEdgeEnabled = true
internal var isBottomBackgroundEnabled = false

internal var closablePerimeterDp = 100
internal var distanceToCloseDp = 100

internal var listener: Listener? = null
internal var serviceInteractor: ServiceInteractor? = null

internal var behavior: BubbleBehavior = BubbleBehavior.FIXED_CLOSE_BUBBLE

// composable
internal var composeView: (@Composable ()->Unit)? = null
internal var composeLifecycleOwner: ComposeLifecycleOwner? = null


/**
* choose behavior for the bubbles
Expand All @@ -226,7 +254,7 @@ internal constructor(
* @param dp distance between bubble and close-bubble
* */
fun distanceToClose(dp: Int): Builder {
this.closablePerimeterDp = dp
this.distanceToCloseDp = dp
return this
}

Expand Down Expand Up @@ -254,43 +282,27 @@ internal constructor(
return this
}

// being developed, therefore this function not exposed to the outside package
internal fun bubble(view: View): Builder {
iconView = view
return this
}
fun bubble(content: @Composable () -> Unit): Builder {
// bubbleView = FloatingComposeView(context).apply {
// setContent { content() }
// }
composeLifecycleOwner = ComposeLifecycleOwner()
// composeLifecycleOwner?.attachToDecorView(bubbleView!!)

/**
* set drawable to bubble with default size
* */
fun bubble(@DrawableRes drawable: Int): Builder {
iconBitmap = ContextCompat.getDrawable(context, drawable)!!.toBitmap()
return this
}
composeView = content

/**
* set drawable to bubble width given width and height in dp
* */
fun bubble(@DrawableRes drawable: Int, widthDp: Int, heightDp: Int): Builder {
bubbleSizePx = Size(widthDp.toPx(), heightDp.toPx())
return bubble(drawable)
return this
}

/**
* set bitmap to bubble width default size
* */
fun bubble(bitmap: Bitmap): Builder {
iconBitmap = bitmap
* set view to bubble
*/
fun bubble(view: View): Builder {
bubbleView = view
// bubbleSizePx = Size(view.measuredWidth, view.measuredHeight)
return this
}

/**
* set bitmap to bubble width given width and height in dp
* */
fun bubble(bitmap: Bitmap, widthDp: Int, heightDp: Int): Builder {
bubbleSizePx = Size(widthDp.toPx(), heightDp.toPx())
return bubble(bitmap)
}

/**
* set open and exit animation to bubble
Expand Down Expand Up @@ -347,11 +359,6 @@ internal constructor(
val tempListener = this.listener
this.listener = object : Listener {

override fun onClick() {
tempListener?.onClick()
listener.onClick()
}

override fun onDown(x: Float, y: Float) {
tempListener?.onDown(x, y)
listener.onDown(x, y)
Expand All @@ -371,7 +378,7 @@ internal constructor(
return this
}

internal fun addServiceInteractor(interactor: ServiceInteractor): Builder{
internal fun addServiceInteractor(interactor: ServiceInteractor): Builder {
this.serviceInteractor = interactor
return this
}
Expand Down Expand Up @@ -404,16 +411,6 @@ internal constructor(
return this
}

/**
* - 0.0f: invisible
* - 0.0f < x < 1.0f: view with opacity
* - 1.0f: fully visible
* */
fun opacity(opacity: Float): Builder {
this.opacity = opacity
return this
}

internal fun build(): FloatingBubble {
return FloatingBubble(this)
}
Expand Down
Loading

0 comments on commit c076868

Please sign in to comment.