Skip to content

Commit

Permalink
Merge pull request #38 from solrudev/develop
Browse files Browse the repository at this point in the history
0.2.2
  • Loading branch information
solrudev authored Nov 3, 2023
2 parents 94cd926 + 17079d5 commit 16dfb77
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Ackpine depends on Jetpack libraries, so it's necessary to declare the `google()

```kotlin
dependencies {
val ackpineVersion = "0.2.1"
val ackpineVersion = "0.2.2"
implementation("ru.solrudev.ackpine:ackpine-core:$ackpineVersion")

// optional - Kotlin extensions and Coroutines support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
package ru.solrudev.ackpine.impl.activity

import android.app.Activity
import android.content.Intent
import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.os.Bundle
import android.widget.ProgressBar
import androidx.annotation.RestrictTo
import androidx.core.view.isVisible
import com.google.common.util.concurrent.ListenableFuture
import ru.solrudev.ackpine.DisposableSubscriptionContainer
import ru.solrudev.ackpine.core.R
Expand Down Expand Up @@ -57,6 +61,9 @@ internal abstract class SessionCommitActivity<S : Session<F>, F : Failure> prote

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (savedInstanceState == null) {
setLoading(true)
}
initializeState(savedInstanceState)
setContentView(R.layout.ackpine_activity_session_commit)
registerOnBackInvokedCallback()
Expand All @@ -82,6 +89,16 @@ internal abstract class SessionCommitActivity<S : Session<F>, F : Failure> prote
outState.putBoolean(IS_CONFIG_CHANGE_RECREATION_KEY, isChangingConfigurations)
}

override fun startActivityForResult(intent: Intent?, requestCode: Int) {
setLoading(false)
super.startActivityForResult(intent, requestCode)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
setLoading(true)
}

@Suppress("UNCHECKED_CAST")
@JvmSynthetic
internal inline fun withCompletableSession(crossinline block: (CompletableSession<F>?) -> Unit) {
Expand Down Expand Up @@ -111,6 +128,15 @@ internal abstract class SessionCommitActivity<S : Session<F>, F : Failure> prote
}
}

private fun setLoading(isLoading: Boolean) {
findViewById<ProgressBar>(R.id.ackpine_session_commit_loading_indicator)?.isVisible = isLoading
if (isLoading) {
window?.setBackgroundDrawableResource(android.R.drawable.screen_background_dark_transparent)
} else {
window?.setBackgroundDrawable(ColorDrawable(0))
}
}

private fun registerOnBackInvokedCallback() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
onBackInvokedDispatcher.registerOnBackInvokedCallback(1000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal abstract class AbstractProgressSession<F : Failure> protected construct

final override fun addProgressListener(listener: ProgressSession.ProgressListener): DisposableSubscription {
progressListeners += listener
handler.post {
handler.postAtFrontOfQueue {
listener.onProgressChanged(id, progress)
}
return ProgressDisposableSubscription(this, listener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ internal abstract class AbstractSession<F : Failure> protected constructor(
}
}

// Implementation allows to re-commit the session when it's not in process of being committed or confirmed, e.g.
// when confirmation was interrupted with process death.
final override fun commit() {
if (isCommitted || isCommitting || isCancelling) {
return
Expand Down Expand Up @@ -212,7 +214,10 @@ internal abstract class AbstractSession<F : Failure> protected constructor(

final override fun addStateListener(listener: Session.StateListener<F>): DisposableSubscription {
stateListeners += listener
handler.post {
// postAtFrontOfQueue - notify with current state snapshot immediately to avoid duplicate notifications,
// as using plain Handler#post() can lead to the listener being notified after state has already changed
// and delivered to the same listener
handler.postAtFrontOfQueue {
listener.onStateChanged(id, state)
}
return StateDisposableSubscription(this, listener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
android:layout_height="match_parent">

<ProgressBar
android:id="@+id/ackpine_session_commit_loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
android:layout_gravity="center"
android:visibility="gone" />
</FrameLayout>
1 change: 0 additions & 1 deletion ackpine-core/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

<style name="Base.V16.Theme.Ackpine.SessionCommitActivity" parent="android:Theme.Translucent.NoTitleBar">
<item name="android:progressBarStyle">@android:style/Widget.DeviceDefault.ProgressBar</item>
<item name="android:windowBackground">@android:drawable/screen_background_dark_transparent</item>
</style>

<style name="Base.Theme.Ackpine.SessionCommitActivity" parent="Base.V16.Theme.Ackpine.SessionCommitActivity" />
Expand Down
9 changes: 9 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Change Log
==========

Version 0.2.2 (2023-11-03)
--------------------------

### Bug fixes and improvements

- Fix duplicate session's state change notifications in some cases (e.g. after process restart and re-attaching a listener when session's been completed right before). This also fixes `IllegalStateException` in `Session.await()` in these cases.
- Make confirmation's background fully transparent.
- Don't display loading indicator during confirmation from system.

Version 0.2.1 (2023-10-30)
--------------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Ackpine depends on Jetpack libraries, so it's necessary to declare the `google()

```kotlin
dependencies {
val ackpineVersion = "0.2.1"
val ackpineVersion = "0.2.2"
implementation("ru.solrudev.ackpine:ackpine-core:$ackpineVersion")

// optional - Kotlin extensions and Coroutines support
Expand Down
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MAJOR_VERSION=0
MINOR_VERSION=2
PATCH_VERSION=1
PATCH_VERSION=2
SUFFIX=
SNAPSHOT=false

0 comments on commit 16dfb77

Please sign in to comment.