Skip to content

Commit

Permalink
Fix skeleton view breaks server discovery layout
Browse files Browse the repository at this point in the history
Closes openhab#3736

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
  • Loading branch information
mueller-ma committed Jul 11, 2024
1 parent cc6b072 commit edcd98c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
10 changes: 6 additions & 4 deletions mobile/src/main/java/org/openhab/habdroid/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ class MainActivity : AbstractBaseActivity(), ConnectionFactory.UpdateListener {
when {
newConnection != null -> {
handleConnectionChange()
controller.updateConnection(newConnection, null, 0)
controller.updateConnection(newConnection, null, 0, true)
}
failureReason is WrongWifiException -> {
val activeConfig = ServerConfiguration.load(prefs, getSecretPrefs(), prefs.getActiveServerId())
Expand All @@ -547,7 +547,8 @@ class MainActivity : AbstractBaseActivity(), ConnectionFactory.UpdateListener {
controller.updateConnection(
null,
getString(R.string.resolving_openhab),
R.drawable.ic_home_search_outline_grey_340dp
R.drawable.ic_home_search_outline_grey_340dp,
false
)
}
} else {
Expand All @@ -560,7 +561,7 @@ class MainActivity : AbstractBaseActivity(), ConnectionFactory.UpdateListener {
controller.indicateNoNetwork(getString(R.string.error_wifi_not_available), true)
}
failureReason is ConnectionNotInitializedException -> {
controller.updateConnection(null, null, 0)
controller.updateConnection(null, null, 0, true)
}
else -> {
controller.indicateNoNetwork(getString(R.string.error_network_not_available), false)
Expand Down Expand Up @@ -747,7 +748,8 @@ class MainActivity : AbstractBaseActivity(), ConnectionFactory.UpdateListener {
controller.updateConnection(
null,
getString(R.string.waiting_for_wifi),
R.drawable.ic_wifi_strength_outline_grey_24dp
R.drawable.ic_wifi_strength_outline_grey_24dp,
true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ abstract class ContentController protected constructor(private val activity: Mai
}
this.connectionFragment = connectionFragment

defaultProgressFragment = ProgressFragment.newInstance(null, 0)
defaultProgressFragment = ProgressFragment.newInstance(null, 0, true)
connectionFragment.setCallback(this)

fm.registerFragmentLifecycleCallbacks(this, true)
Expand Down Expand Up @@ -362,10 +362,15 @@ abstract class ContentController protected constructor(private val activity: Mai
* @param connection New connection to use; might be null if none is currently available
* @param progressMessage Message to show to the user if no connection is available
*/
fun updateConnection(connection: Connection?, progressMessage: CharSequence?, @DrawableRes icon: Int) {
fun updateConnection(
connection: Connection?,
progressMessage: CharSequence?,
@DrawableRes icon: Int,
showSitemapSkeleton: Boolean
) {
CrashReportingHelper.d(TAG, "Update to connection $connection (message $progressMessage)")
noConnectionFragment = if (connection == null) {
ProgressFragment.newInstance(progressMessage, icon)
ProgressFragment.newInstance(progressMessage, icon, showSitemapSkeleton)
} else {
null
}
Expand Down Expand Up @@ -613,8 +618,7 @@ abstract class ContentController protected constructor(private val activity: Mai
f.arguments = buildArgs(
message,
R.string.try_again_button,
R.drawable.ic_openhab_appicon_340dp,
false
R.drawable.ic_openhab_appicon_340dp
)
return f
}
Expand All @@ -627,9 +631,13 @@ abstract class ContentController protected constructor(private val activity: Mai
}

companion object {
fun newInstance(message: CharSequence?, @DrawableRes image: Int): ProgressFragment {
fun newInstance(
message: CharSequence?,
@DrawableRes image: Int,
sitemapSkeleton: Boolean
): ProgressFragment {
val f = ProgressFragment()
f.arguments = buildArgs(message, 0, image, true)
f.arguments = buildArgs(message, 0, image, !sitemapSkeleton, sitemapSkeleton)
return f
}
}
Expand All @@ -647,8 +655,7 @@ abstract class ContentController protected constructor(private val activity: Mai
f.arguments = buildArgs(
message,
R.string.try_again_button,
R.drawable.ic_network_strength_off_outline_black_24dp,
false
R.drawable.ic_network_strength_off_outline_black_24dp
)
return f
}
Expand All @@ -666,8 +673,7 @@ abstract class ContentController protected constructor(private val activity: Mai
f.arguments = buildArgs(
message,
R.string.enable_wifi_button,
R.drawable.ic_wifi_strength_off_outline_grey_24dp,
false
R.drawable.ic_wifi_strength_off_outline_grey_24dp
)
return f
}
Expand Down Expand Up @@ -699,8 +705,7 @@ abstract class ContentController protected constructor(private val activity: Mai
} else {
0
},
drawableResId = R.drawable.ic_wifi_strength_off_outline_grey_24dp,
showProgress = false
drawableResId = R.drawable.ic_wifi_strength_off_outline_grey_24dp
)
f.arguments = args
return f
Expand Down Expand Up @@ -758,22 +763,19 @@ abstract class ContentController protected constructor(private val activity: Mai
context.getString(R.string.configuration_missing),
R.string.go_to_settings_button,
R.string.enable_demo_mode_button,
R.drawable.ic_home_search_outline_grey_340dp,
false
R.drawable.ic_home_search_outline_grey_340dp
)
hasWifiEnabled -> buildArgs(
context.getString(R.string.no_remote_server),
R.string.try_again_button,
if (wouldHaveUsedOfficialServer) R.string.visit_status_openhab_org else 0,
R.drawable.ic_network_strength_off_outline_black_24dp,
false
R.drawable.ic_network_strength_off_outline_black_24dp
)
else -> buildArgs(
context.getString(R.string.no_remote_server),
R.string.enable_wifi_button,
if (wouldHaveUsedOfficialServer) R.string.visit_status_openhab_org else 0,
R.drawable.ic_wifi_strength_off_outline_grey_24dp,
false
R.drawable.ic_wifi_strength_off_outline_grey_24dp
)
}
args.putBoolean(KEY_RESOLVE_ATTEMPTED, resolveAttempted)
Expand All @@ -795,9 +797,11 @@ abstract class ContentController protected constructor(private val activity: Mai
descriptionText.isVisible = !descriptionText.text.isNullOrEmpty()

val skeleton = view.findViewById<SkeletonLayout>(R.id.skeletonLayout)
skeleton.isVisible = arguments.getBoolean(KEY_PROGRESS)
skeleton.isVisible = arguments.getBoolean(KEY_SITEMAP_SKELETON)
skeleton.showSkeleton()

view.findViewById<View>(R.id.progress).isVisible = arguments.getBoolean(KEY_PROGRESS)

val watermark = view.findViewById<ImageView>(R.id.image)

@DrawableRes val drawableResId = arguments.getInt(KEY_DRAWABLE)
Expand Down Expand Up @@ -832,21 +836,24 @@ abstract class ContentController protected constructor(private val activity: Mai
internal const val KEY_BUTTON_1_TEXT = "button1text"
internal const val KEY_BUTTON_2_TEXT = "button2text"
internal const val KEY_PROGRESS = "progress"
internal const val KEY_SITEMAP_SKELETON = "sitemapSkeleton"
internal const val KEY_RESOLVE_ATTEMPTED = "resolveAttempted"
internal const val KEY_WIFI_ENABLED = "wifiEnabled"

internal fun buildArgs(
message: CharSequence?,
@StringRes buttonTextResId: Int,
@DrawableRes drawableResId: Int,
showProgress: Boolean
showProgress: Boolean = false,
showSitemapSkeleton: Boolean = false
): Bundle {
return buildArgs(
message,
buttonTextResId,
0,
drawableResId,
showProgress
showProgress,
showSitemapSkeleton
)
}

Expand All @@ -855,14 +862,16 @@ abstract class ContentController protected constructor(private val activity: Mai
@StringRes button1TextResId: Int,
@StringRes button2TextResId: Int,
@DrawableRes drawableResId: Int,
showProgress: Boolean
showProgress: Boolean = false,
showSitemapSkeleton: Boolean = false
): Bundle {
return bundleOf(
KEY_MESSAGE to message,
KEY_DRAWABLE to drawableResId,
KEY_BUTTON_1_TEXT to button1TextResId,
KEY_BUTTON_2_TEXT to button2TextResId,
KEY_PROGRESS to showProgress
KEY_PROGRESS to showProgress,
KEY_SITEMAP_SKELETON to showSitemapSkeleton
)
}
}
Expand Down
8 changes: 8 additions & 0 deletions mobile/src/main/res/layout/fragment_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
android:textColor="?colorOnSurfaceVariant"
tools:text="Some status message" />

<ProgressBar
android:id="@+id/progress"
style="?attr/indeterminateProgressStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_gravity="center_horizontal" />

<com.faltenreich.skeletonlayout.SkeletonLayout
android:id="@+id/skeletonLayout"
android:layout_width="match_parent"
Expand Down

0 comments on commit edcd98c

Please sign in to comment.