Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: enable opt-in features for bottom close icon padding & closea… #51

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, can you explain why you changed this line of code? The new code doesn't seem to fix any issues and introduces a new issue as well.

image

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FloatingCloseBubble(
halfWidthPx = width / 2
halfHeightPx = height / 2
baseX = halfSafeScreenWidth - halfWidthPx
baseY = sez.safeHeight - height - bottomPaddingPx
baseY = sez.safeHeight - (halfHeightPx + bottomPaddingPx)

centerCloseBubbleX = halfSafeScreenWidth
centerCloseBubbleY = baseY + halfHeightPx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import android.content.Intent
import android.os.IBinder
import com.torrydo.floatingbubbleview.canDrawOverlays
import com.torrydo.floatingbubbleview.helper.NotificationHelper
import com.torrydo.floatingbubbleview.service.expandable.BubbleBuilder
import com.torrydo.floatingbubbleview.service.expandable.ExpandedBubbleBuilder
import com.torrydo.floatingbubbleview.sez


Expand Down
Copy link
Owner

@TorryDo TorryDo Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should convert the dp value to the px value using .toPx() extension funtion since the function takes dp as a parameter.

Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ class BubbleBuilder(
return this
}

/**
* The padding beneath the close icon.
*
* @param dp Distance beneath the close icon
*/
fun closeBubbleBottomPadding(dp: Int): BubbleBuilder {
this.closeBubbleBottomPaddingPx = dp
return this
}

/**
* @param enabled show gradient dark background on the bottom of the screen
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
var expandedBubble: FloatingBubble? = null
private set

private var enableServiceTermination: Boolean = true
private set

private var closeBubble: FloatingCloseBubble? = null
private var bottomBackground: FloatingBottomBackground? = null

Expand Down Expand Up @@ -159,6 +162,16 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
expandedBubble?.isDraggable = b
}

/**
* Specify whether the background service should be terminated or not.
* If enabled, the floating popup, close icon, expanded view, foreground notification will all be terminated.
*
* @param b Boolean parameter, where true enables automatic service termination.
*/
fun enableServiceTermination(b: Boolean) {
enableServiceTermination = b
}

fun animateBubbleToEdge() {
bubble?.animateIconToEdge()
}
Expand Down Expand Up @@ -255,7 +268,8 @@ abstract class ExpandableBubbleService : FloatingBubbleService() {
}

if (shouldDestroy) {
serviceInteractor?.requestStop()
removeAll()
if (enableServiceTermination) serviceInteractor?.requestStop()
} else {
if (mAnimateToEdge) {
mBubble.animateIconToEdge()
Expand Down
22 changes: 17 additions & 5 deletions app/src/main/java/com/torrydo/testfloatingbubble/MainActivityKt.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.torrydo.testfloatingbubble

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -25,11 +27,21 @@ class MainActivityKt : AppCompatActivity() {
if (isBubbleRunning) {
stopMyService()
} else {
val intent = Intent(this, MyServiceKt::class.java)
intent.putExtra("size", 60)
intent.putExtra("noti_message", "HELLO FROM MAIN ACT")
ContextCompat.startForegroundService(this, intent)
isVisible = false
// Check if the application has draw over other apps permission, and request it if not
if (!Settings.canDrawOverlays(this)) {
startActivity(
Intent(
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:$packageName")
)
)
} else {
val intent = Intent(this, MyServiceKt::class.java)
intent.putExtra("size", 60)
intent.putExtra("noti_message", "HELLO FROM MAIN ACT")
ContextCompat.startForegroundService(this, intent)
isVisible = false
}
}

isBubbleRunning = !isBubbleRunning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MyServiceKt : ExpandableBubbleService() {

override fun onCreate() {
super.onCreate()
super.enableServiceTermination(true)
minimize()
}

Expand Down Expand Up @@ -67,6 +68,9 @@ class MyServiceKt : ExpandableBubbleService() {
// the more value (dp), the larger closeable-area
.distanceToClose(100)

// The more value (dp), the higher the close view
.closeBubbleBottomPadding(10)

// enable bottom background, false by default
.bottomBackground(false)

Expand Down