Skip to content

Commit

Permalink
Revert "Refactor RetryCardView as composable"
Browse files Browse the repository at this point in the history
This reverts commit ebb4826.
  • Loading branch information
PavlosTze committed Feb 3, 2025
1 parent 760100f commit c290faf
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Activity
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -104,7 +105,7 @@ class SelectStationTypeActivity : BaseActivity() {
Column(
modifier = Modifier.padding(dimensionResource(R.dimen.padding_normal)),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = spacedBy(dimensionResource(R.dimen.margin_small))
verticalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.margin_small))
) {
Image(painter = painterResource(imageResId), contentDescription = null)
MediumText(text = name, fontWeight = FontWeight.Bold, colorRes = R.color.darkestBlue)
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/com/weatherxm/ui/components/RetryCardView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.weatherxm.ui.components

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.weatherxm.databinding.ViewRetryCardBinding

class RetryCardView : ConstraintLayout {

private lateinit var binding: ViewRetryCardBinding

constructor(context: Context) : super(context) {
onCreate(context)
}

constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
onCreate(context)
}

constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context, attrs, defStyleAttr
) {
onCreate(context)
}

private fun onCreate(context: Context) {
binding = ViewRetryCardBinding.inflate(LayoutInflater.from(context), this)
}


fun listener(listener: () -> Unit) = binding.retryCard.setOnClickListener { listener.invoke() }
}
15 changes: 0 additions & 15 deletions app/src/main/java/com/weatherxm/ui/components/compose/Texts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,3 @@ fun MediumText(
style = MaterialTheme.typography.bodyMedium
)
}

@Suppress("FunctionNaming")
@Composable
fun LargeText(
text: String,
fontWeight: FontWeight = FontWeight.Normal,
colorRes: Int = R.color.colorOnSurface
) {
Text(
text = text,
fontWeight = fontWeight,
color = colorResource(colorRes),
style = MaterialTheme.typography.bodyLarge
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,12 @@ class DeviceRewardsAdapter(
binding.detailsStatus.visible(false)
binding.detailsContainer.invisible()
binding.earnedBy.invisible()
binding.retryCard.setContent {
RetryCard {
onFetchNewData.invoke(
deviceId,
absoluteAdapterPosition,
binding.chartRangeSelector.checkedChipId()
)
}
binding.retryCard.listener {
onFetchNewData.invoke(
deviceId,
absoluteAdapterPosition,
binding.chartRangeSelector.checkedChipId()
)
}
binding.chartRangeSelector.enable()
binding.retryCard.visible(true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
package com.weatherxm.ui.devicesrewards

import android.os.Bundle
import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.weatherxm.R
import com.weatherxm.analytics.AnalyticsService
import com.weatherxm.databinding.ActivityDevicesRewardsBinding
Expand All @@ -28,7 +12,6 @@ import com.weatherxm.ui.common.invisible
import com.weatherxm.ui.common.parcelable
import com.weatherxm.ui.common.visible
import com.weatherxm.ui.components.BaseActivity
import com.weatherxm.ui.components.compose.LargeText
import com.weatherxm.util.NumberUtils.formatTokens
import com.weatherxm.util.initTotalEarnedChart
import org.koin.androidx.viewmodel.ext.android.viewModel
Expand Down Expand Up @@ -136,49 +119,11 @@ class DevicesRewardsActivity : BaseActivity() {
binding.totalEarnedChart.invisible()
binding.totalEarned.invisible()
binding.totalEarnedStatus.visible(false)
binding.retryCard.setContent {
RetryCard {
model.getDevicesRewardsByRangeTotals(
binding.totalEarnedRangeSelector.checkedChipId()
)
}
}
binding.retryCard.visible(true)
}
}

@Suppress("FunctionNaming")
@Composable
fun RetryCard(onClickListener: () -> Unit) {
Card(
colors = CardDefaults.cardColors(
containerColor = colorResource(R.color.colorSurface)
),
onClick = { onClickListener() },
elevation = CardDefaults.cardElevation(0.dp)
) {
Column(
Modifier
.padding(0.dp, dimensionResource(R.dimen.padding_normal_to_large))
.fillMaxWidth(),
verticalArrangement = spacedBy(dimensionResource(R.dimen.padding_small)),
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(
modifier = Modifier.padding(
0.dp,
0.dp,
0.dp,
dimensionResource(R.dimen.padding_small_to_normal)
),
painter = painterResource(R.drawable.ic_retry),
contentDescription = null
binding.retryCard.listener {
model.getDevicesRewardsByRangeTotals(
binding.totalEarnedRangeSelector.checkedChipId()
)
LargeText(
text = stringResource(R.string.error_generic_message),
fontWeight = FontWeight.Bold
)
LargeText(text = stringResource(R.string.tap_to_retry))
}
binding.retryCard.visible(true)
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_devices_rewards.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/totalEarnedRangeSelector" />

<androidx.compose.ui.platform.ComposeView
<com.weatherxm.ui.components.RetryCardView
android:id="@+id/retryCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -227,6 +227,7 @@
app:tint="@color/darkGrey"
tools:ignore="ContentDescription" />


<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/list_item_device_rewards.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/detailsHeader" />

<androidx.compose.ui.platform.ComposeView
<com.weatherxm.ui.components.RetryCardView
android:id="@+id/retryCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
53 changes: 53 additions & 0 deletions app/src/main/res/layout/view_retry_card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<merge 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"
android:animateLayoutChanges="true">

<com.google.android.material.card.MaterialCardView
android:id="@+id/retryCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
app:cardElevation="0dp"
app:contentPadding="0dp"
app:contentPaddingBottom="@dimen/padding_normal_to_large"
app:contentPaddingTop="@dimen/padding_normal_to_large">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:importantForAccessibility="no"
android:scaleType="centerCrop"
android:src="@drawable/ic_retry" />

<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_normal_to_large"
android:gravity="center"
android:text="@string/error_generic_message"
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodyLarge"
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/tap_to_retry"
android:textAppearance="@style/TextAppearance.WeatherXM.Default.BodyLarge" />

</LinearLayout>

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

</merge>

0 comments on commit c290faf

Please sign in to comment.