Skip to content

Commit

Permalink
Move empty device list in home activity to correctly align it and hid…
Browse files Browse the repository at this point in the history
…e info banner when no devices
  • Loading branch information
PavlosTze committed Feb 14, 2025
1 parent 7c36003 commit 4efa98a
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 713 deletions.
577 changes: 0 additions & 577 deletions app/src/local/assets/mock_files/get_user_devices.json

Large diffs are not rendered by default.

35 changes: 18 additions & 17 deletions app/src/main/java/com/weatherxm/ui/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ class HomeActivity : BaseActivity(), BaseMapFragment.OnMapDebugInfoListener {
devicesViewModel.devices().observe(this) {
val currentDestination = navController.currentDestination?.id
if (it.status == Status.SUCCESS && currentDestination == R.id.navigation_devices) {
checkForClaimingPrompt()
model.getInfoBanner()
checkForEmptyContainer()
} else {
binding.claimStationHere.visible(false)
binding.emptyContainer.visible(false)
}
}

Expand All @@ -108,16 +109,18 @@ class HomeActivity : BaseActivity(), BaseMapFragment.OnMapDebugInfoListener {
navigator.showNetworkStats(this)
}

model.onWalletWarnings().observe(this) {
handleBadge(it.showMissingBadge)
binding.buyStationBtn.setOnClickListener {
navigator.openWebsite(this, getString(R.string.shop_url))
}

model.onOpenExplorer().observe(this) {
if (it == true) {
NavigationUI.onNavDestinationSelected(
binding.navView.menu.findItem(R.id.navigation_explorer), navController
)
}
binding.followStationExplorerBtn.setOnClickListener {
NavigationUI.onNavDestinationSelected(
binding.navView.menu.findItem(R.id.navigation_explorer), navController
)
}

model.onWalletWarnings().observe(this) {
handleBadge(it.showMissingBadge)
}

// Disable BottomNavigationView bottom padding, added by default, and add margin
Expand Down Expand Up @@ -145,27 +148,26 @@ class HomeActivity : BaseActivity(), BaseMapFragment.OnMapDebugInfoListener {
}
}

private fun checkForClaimingPrompt() {
private fun checkForEmptyContainer() {
if (devicesViewModel.hasNoDevices()) {
binding.claimStationHere.visible(true)
binding.claimAnimation.playAnimation()
binding.emptyContainer.visible(true)
}
}

private fun onNavigationChanged(destination: NavDestination) {
if (snackbar?.isShown == true) snackbar?.dismiss()
when (destination.id) {
R.id.navigation_devices -> {
checkForClaimingPrompt()
checkForEmptyContainer()
binding.addDevice.show()
}
R.id.navigation_explorer -> {
explorerModel.setExplorerAfterLoggedIn(true)
binding.claimStationHere.visible(false)
binding.emptyContainer.visible(false)
binding.addDevice.hide()
}
else -> {
binding.claimStationHere.visible(false)
binding.emptyContainer.visible(false)
binding.addDevice.hide()
}
}
Expand All @@ -179,7 +181,6 @@ class HomeActivity : BaseActivity(), BaseMapFragment.OnMapDebugInfoListener {

// Fetch user's devices
devicesViewModel.fetch()
model.getInfoBanner()

/**
* Changing the theme from Profile -> Settings and going back to profile
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/com/weatherxm/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class HomeViewModel(
private val onWalletWarnings = MutableLiveData<WalletWarnings>()
private val onSurvey = SingleLiveEvent<Survey>()
private val onInfoBanner = SingleLiveEvent<InfoBanner?>()
private val onOpenExplorer = SingleLiveEvent<Boolean>()

// Needed for passing info to the activity to show/hide elements when scrolling on the list
private val showOverlayViews = MutableLiveData(true)
Expand All @@ -42,13 +41,8 @@ class HomeViewModel(
fun onWalletWarnings(): LiveData<WalletWarnings> = onWalletWarnings
fun onSurvey(): LiveData<Survey> = onSurvey
fun onInfoBanner(): LiveData<InfoBanner?> = onInfoBanner
fun onOpenExplorer() = onOpenExplorer
fun showOverlayViews() = showOverlayViews

fun openExplorer() {
onOpenExplorer.postValue(true)
}

fun hasDevices() = hasDevices

fun setHasDevices(devices: List<UIDevice>?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ class DevicesFragment : BaseFragment(), DeviceListener {
SortFilterDialogFragment().show(this)
}

binding.buyStationBtn.setOnClickListener {
navigator.openWebsite(context, getString(R.string.shop_url))
}

binding.followStationExplorerBtn.setOnClickListener {
parentModel.openExplorer()
}

model.devices().observe(viewLifecycleOwner) {
onDevices(it)
}
Expand All @@ -124,7 +116,7 @@ class DevicesFragment : BaseFragment(), DeviceListener {
}

private fun onInfoBanner(infoBanner: InfoBanner?) {
if (infoBanner != null) {
if (infoBanner != null && !model.hasNoDevices()) {
binding.infoBanner.setContent {
InfoBannerView(
title = infoBanner.title,
Expand Down Expand Up @@ -238,11 +230,9 @@ class DevicesFragment : BaseFragment(), DeviceListener {
adapter.submitList(devices.data)
adapter.notifyDataSetChanged()
binding.statusView.visible(false)
binding.emptyContainer.visible(false)
binding.contentContainerCard.visible(true)
binding.recycler.visible(true)
} else {
binding.emptyContainer.visible(true)
binding.statusView.visible(false)
adapter.submitList(mutableListOf())
binding.recycler.visible(false)
Expand All @@ -260,7 +250,6 @@ class DevicesFragment : BaseFragment(), DeviceListener {
.listener { model.fetch() }
.visible(true)
binding.recycler.visible(false)
binding.emptyContainer.visible(false)
binding.contentContainerCard.visible(true)
}
Status.LOADING -> {
Expand All @@ -270,7 +259,6 @@ class DevicesFragment : BaseFragment(), DeviceListener {
binding.statusView.clear().visible(false)
binding.swiperefresh.isRefreshing = true
} else {
binding.emptyContainer.visible(false)
binding.recycler.visible(false)
binding.contentContainerCard.visible(false)
binding.statusView.clear().animation(R.raw.anim_loading).visible(true)
Expand Down
97 changes: 64 additions & 33 deletions app/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -8,7 +8,9 @@
<androidx.compose.ui.platform.ComposeView
android:id="@+id/dialogComposeView"
android:layout_width="0dp"
android:layout_height="0dp" />
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<fragment
android:id="@+id/nav_host_fragment"
Expand All @@ -24,14 +26,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginBottom="@dimen/margin_large"
android:contentDescription="@string/go_to_your_location"
android:elevation="@dimen/elevation_normal"
android:src="@drawable/ic_my_location"
android:translationY="-24dp"
app:backgroundTint="@color/colorSurface"
app:layout_anchor="@id/networkStatsBtn"
app:layout_anchorGravity="top|center"
app:layout_behavior="com.google.android.material.floatingactionbutton.FloatingActionButton$Behavior"
app:layout_constraintBottom_toTopOf="@id/networkStatsBtn"
app:layout_constraintEnd_toEndOf="@id/networkStatsBtn"
app:layout_constraintStart_toStartOf="@id/networkStatsBtn"
app:shapeAppearance="@style/ShapeAppearance.WeatherXM.MyLocation"
app:tint="@color/colorOnSurface" />

Expand All @@ -40,15 +43,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_marginEnd="@dimen/margin_normal"
android:layout_marginBottom="@dimen/margin_large"
android:contentDescription="@string/network_stats"
android:elevation="@dimen/elevation_normal"
android:src="@drawable/ic_network_stats"
android:translationY="-24dp"
app:backgroundTint="@color/network_stats_button"
app:layout_anchor="@id/nav_view"
app:layout_anchorGravity="top|end"
app:layout_behavior="com.google.android.material.floatingactionbutton.FloatingActionButton$Behavior"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintStart_toEndOf="@id/nav_view"
app:tint="@color/light_text" />

<com.weatherxm.ui.components.HidingBottomNavigationView
Expand All @@ -58,53 +60,82 @@
android:layout_gravity="bottom|center_horizontal"
android:layout_marginVertical="@dimen/margin_normal"
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_dodgeInsetEdges="bottom"
app:menu="@menu/bottom_nav_menu" />

<LinearLayout
android:id="@+id/claimStationHere"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal"
android:translationX="-80dp"
android:translationY="-10dp"
android:id="@+id/emptyContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginHorizontal="@dimen/margin_normal"
android:layout_marginTop="92dp"
android:layout_marginBottom="@dimen/margin_normal"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
app:layout_anchor="@id/add_device"
app:layout_anchorGravity="top|start"
tools:visibility="visible">
app:layout_constraintBottom_toTopOf="@id/add_device"
app:layout_constraintTop_toTopOf="parent">

<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_normal"
android:gravity="center"
android:text="@string/join_the_network"
android:textAppearance="@style/TextAppearance.WeatherXM.Default.HeadlineSmall"
android:textSize="26sp"
android:textStyle="bold" />

<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/claim_station_here"
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodySmall" />
android:layout_marginTop="@dimen/margin_small"
android:gravity="center"
android:text="@string/join_the_network_subtitle"
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodyMedium" />

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/claimAnimation"
android:layout_width="70dp"
android:layout_height="40dp"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_marginHorizontal="@dimen/margin_small"
android:rotation="152"
android:layout_marginTop="@dimen/margin_large"
android:scaleType="centerInside"
app:lottie_autoPlay="true"
app:lottie_loop="false"
app:lottie_rawRes="@raw/anim_arrow" />
app:lottie_loop="true"
app:lottie_rawRes="@raw/anim_network" />

<com.google.android.material.button.MaterialButton
android:id="@+id/buyStationBtn"
style="@style/Widget.WeatherXM.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
android:text="@string/action_buy_station" />

<com.google.android.material.button.MaterialButton
android:id="@+id/followStationExplorerBtn"
style="@style/Widget.WeatherXM.TextButton.Subtle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_small_to_normal"
android:text="@string/action_follow_a_station_in_explorer" />

</LinearLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_device"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_marginBottom="@dimen/margin_large"
android:contentDescription="@string/add_weather_station"
android:src="@drawable/ic_add"
android:translationY="-24dp"
app:elevation="@dimen/elevation_normal"
app:layout_anchor="@id/nav_view"
app:layout_anchorGravity="top|end"
app:layout_behavior="com.google.android.material.floatingactionbutton.FloatingActionButton$Behavior"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintStart_toEndOf="@id/nav_view"
app:tint="@color/colorOnPrimary" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
56 changes: 0 additions & 56 deletions app/src/main/res/layout/fragment_devices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,62 +279,6 @@

</com.google.android.material.card.MaterialCardView>

<LinearLayout
android:id="@+id/emptyContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorBackground"
android:orientation="vertical"
android:paddingHorizontal="@dimen/padding_normal"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/infoBanner">

<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_normal"
android:gravity="center"
android:text="@string/join_the_network"
android:textAppearance="@style/TextAppearance.WeatherXM.Default.HeadlineSmall"
android:textSize="26sp"
android:textStyle="bold" />

<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_small"
android:gravity="center"
android:text="@string/join_the_network_subtitle"
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodyMedium" />

<com.airbnb.lottie.LottieAnimationView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_marginTop="@dimen/margin_large"
android:scaleType="centerInside"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/anim_network" />

<com.google.android.material.button.MaterialButton
android:id="@+id/buyStationBtn"
style="@style/Widget.WeatherXM.Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_large"
android:text="@string/action_buy_station" />

<com.google.android.material.button.MaterialButton
android:id="@+id/followStationExplorerBtn"
style="@style/Widget.WeatherXM.TextButton.Subtle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_small_to_normal"
android:text="@string/action_follow_a_station_in_explorer" />

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/raw/anim_arrow.json

This file was deleted.

1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<string name="action_delete">Delete</string>
<string name="action_buy_station">Buy a Station</string>
<string name="action_follow_a_station_in_explorer">Follow a station in Explorer Map</string>
<string name="claim_station_here">Claim your station here</string>
<string name="action_claim">Claim</string>
<string name="action_dismiss">Dismiss</string>
<string name="action_close">Close</string>
Expand Down
Loading

0 comments on commit 4efa98a

Please sign in to comment.