Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2807,10 +2807,6 @@ open class EditorHandlerActivity :
)
return@runOnUiThread
}
// Routed through the String overload (indefinite duration, must-dismiss) rather
// than flashError(Int) (a ~1s auto-dismissing toast) -- a user who looks away
// right after tapping "Save and close" must not miss that the close was aborted
// and the activity is still open with unsaved changes.
flashError(getString(string.save_failed))
// A later, superseding request (e.g. a third deep link arriving while this save
// was in flight) must not be silently dropped just because THIS attempt's save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,6 @@ class GitBottomSheetFragment : Fragment(R.layout.fragment_git_bottom_sheet) {
if (succeeded && !handler.hasUnsavedWritableFiles()) {
action()
} else {
// The String overload, not flashError(Int): the Int one shows a ~1s
// auto-dismissing bar, and a user who looked away would never learn the git
// action was abandoned and their edits are still unwritten. Matches the
// reasoning EditorHandlerActivity spells out on its own save-failure path.
flashError(getString(R.string.save_failed))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ fun Activity.flashSuccess(

fun Activity.flashError(
@StringRes msg: Int,
) = showFlashBar(msg, IconType.ERROR)
) = flashError(getString(msg))

fun Activity.flashInfo(
@StringRes msg: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.itsaky.androidide.utils

import android.app.Application
import android.os.Looper
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.google.common.truth.Truth.assertThat
import com.itsaky.androidide.resources.R
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
import java.time.Duration

@RunWith(RobolectricTestRunner::class)
@Config(application = Application::class, sdk = [28])
class FlashErrorStringResTest {
private lateinit var activity: AppCompatActivity

@Before
fun setUp() {
FeatureFlags.resetForTest()
activity =
Robolectric
.buildActivity(AppCompatActivity::class.java)
.also { it.get().setTheme(R.style.Theme_AndroidIDE) }
.setup()
.get()
}

@After
fun tearDown() {
FeatureFlags.resetForTest()
}

@Test
fun `string resource error stays until dismissed`() {
activity.flashError(R.string.msg_export_not_built)
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(5))

val root = activity.window.decorView
assertThat(root.findText(activity.getString(R.string.msg_export_not_built))).isNotNull()
val dismiss = root.findText(activity.getString(R.string.dismiss))
assertThat(dismiss).isNotNull()
assertThat(dismiss!!.visibility).isEqualTo(View.VISIBLE)

dismiss.performClick()
shadowOf(Looper.getMainLooper()).idleFor(Duration.ofSeconds(5))

assertThat(root.findText(activity.getString(R.string.msg_export_not_built))).isNull()
}

private fun View.findText(text: String): TextView? {
if (this is TextView && this.text.toString() == text) return this
if (this !is ViewGroup) return null
for (i in 0 until childCount) {
getChildAt(i).findText(text)?.let { return it }
}
return null
}
}
Loading