Skip to content

Commit

Permalink
Reintroduce loading skeleton for sitemaps (openhab#3758)
Browse files Browse the repository at this point in the history
This time the skeleton isn't shown alongside with temporary progress
(e.g. server discovery).

Closes openhab#3736 

Signed-off-by: Danny Baumann <[email protected]>
  • Loading branch information
maniac103 authored Jul 20, 2024
1 parent 753c895 commit dc919bf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks
import androidx.fragment.app.commit
import androidx.fragment.app.commitNow
import com.faltenreich.skeletonlayout.SkeletonLayout
import java.util.Stack
import org.openhab.habdroid.R
import org.openhab.habdroid.core.OpenHabApplication
Expand Down Expand Up @@ -124,7 +125,7 @@ abstract class ContentController protected constructor(private val activity: Mai
}
this.connectionFragment = connectionFragment

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

fm.registerFragmentLifecycleCallbacks(this, true)
Expand Down Expand Up @@ -363,10 +364,10 @@ abstract class ContentController protected constructor(private val activity: Mai
*/
fun updateConnection(connection: Connection?, progressMessage: CharSequence?, @DrawableRes icon: Int) {
CrashReportingHelper.d(TAG, "Update to connection $connection (message $progressMessage)")
noConnectionFragment = if (connection == null) {
ProgressFragment.newInstance(progressMessage, icon)
} else {
null
noConnectionFragment = when {
connection != null -> null
progressMessage != null -> ProgressFragment.newInstance(progressMessage, icon)
else -> LoadingSkeletonFragment.newInstance()
}
resetState()
updateFragmentState(FragmentUpdateReason.PAGE_UPDATE)
Expand Down Expand Up @@ -626,10 +627,8 @@ abstract class ContentController protected constructor(private val activity: Mai
}

companion object {
fun newInstance(message: CharSequence?, @DrawableRes image: Int): ProgressFragment {
val f = ProgressFragment()
f.arguments = buildArgs(message, 0, image, true)
return f
fun newInstance(message: CharSequence, @DrawableRes drawableResId: Int) = ProgressFragment().apply {
arguments = buildArgs(message, 0, drawableResId, true)
}
}
}
Expand Down Expand Up @@ -833,7 +832,7 @@ abstract class ContentController protected constructor(private val activity: Mai
internal const val KEY_WIFI_ENABLED = "wifiEnabled"

internal fun buildArgs(
message: CharSequence?,
message: CharSequence,
@StringRes buttonTextResId: Int,
@DrawableRes drawableResId: Int,
showProgress: Boolean
Expand Down Expand Up @@ -865,6 +864,18 @@ abstract class ContentController protected constructor(private val activity: Mai
}
}

internal class LoadingSkeletonFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val view = inflater.inflate(R.layout.fragment_loading_skeleton, container, false) as SkeletonLayout
view.showSkeleton()
return view
}

companion object {
fun newInstance() = LoadingSkeletonFragment()
}
}

override fun onFragmentStarted(fm: FragmentManager, f: Fragment) {
super.onFragmentStarted(fm, f)
if (f == temporaryPage || f == sitemapFragment || pageStack.any { entry -> f == entry.second }) {
Expand Down
34 changes: 34 additions & 0 deletions mobile/src/main/res/layout/fragment_loading_skeleton.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<com.faltenreich.skeletonlayout.SkeletonLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:maskColor="?colorOnSurfaceInverse">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/widgetlist_frameitem" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_frameitem" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_frameitem" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_frameitem" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
<include layout="@layout/widgetlist_textitem_compact" />
</LinearLayout>

</com.faltenreich.skeletonlayout.SkeletonLayout>

0 comments on commit dc919bf

Please sign in to comment.