From 4c2442bd8532f9913b06107c6d946f6b4975784d Mon Sep 17 00:00:00 2001 From: Silva Alejandro Ismael Date: Mon, 18 Nov 2019 16:39:36 -0300 Subject: [PATCH] Fixed warning expiration --- .../java/com/uncmorfi/balance/UserCardView.kt | 15 ++++++--------- app/src/main/java/com/uncmorfi/models/User.kt | 3 ++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/uncmorfi/balance/UserCardView.kt b/app/src/main/java/com/uncmorfi/balance/UserCardView.kt index 01c9fe1..3c559a1 100644 --- a/app/src/main/java/com/uncmorfi/balance/UserCardView.kt +++ b/app/src/main/java/com/uncmorfi/balance/UserCardView.kt @@ -56,7 +56,8 @@ class UserCardView : RelativeLayout { } private fun relativeLastUpdate(lastUpdate: Calendar): String { - return DateUtils.getRelativeTimeSpanString(lastUpdate.timeInMillis).toString().toLowerCase() + return DateUtils.getRelativeTimeSpanString(lastUpdate.timeInMillis) + .toString().toLowerCase(Locale.getDefault()) } private fun setImage(user: User) { @@ -77,14 +78,14 @@ class UserCardView : RelativeLayout { // Alerta si la tarjeta está vencida o está por vencerse when { - expired(user.expiration) -> { + warning(user.expiration, 0) -> { setBackgroundColor(context.colorOf(R.color.accent)) userBalance.setTextColor(context.colorOf(R.color.white)) userExpiration.setTypeface(null, Typeface.BOLD) userExpiration.setTextColor(context.colorOf(R.color.white)) setTextColor( R.color.white, R.color.white) } - warningExpiration(user.expiration) -> { + warning(user.expiration, WARNING_USER_EXPIRE) -> { setBackgroundColor(context.colorOf(R.color.white)) userExpiration.setTypeface(null, Typeface.NORMAL) userExpiration.setTextColor(context.colorOf(R.color.accent)) @@ -107,17 +108,13 @@ class UserCardView : RelativeLayout { userLastUpdate.setTextColor(context.colorOf(extra)) } - private fun warningExpiration(expiration: Calendar): Boolean { + private fun warning(expiration: Calendar, months: Int): Boolean { val cal = Calendar.getInstance() cal.time = Date() - cal.add(Calendar.MONTH, WARNING_USER_EXPIRE) + cal.add(Calendar.MONTH, months) return expiration.before(cal) } - private fun expired(expiration: Calendar): Boolean { - return expiration.before(Date()) - } - private fun setProgressBar(isLoading: Boolean) { if (isLoading) { userBar.visibility = View.VISIBLE diff --git a/app/src/main/java/com/uncmorfi/models/User.kt b/app/src/main/java/com/uncmorfi/models/User.kt index 3551366..8348c1a 100644 --- a/app/src/main/java/com/uncmorfi/models/User.kt +++ b/app/src/main/java/com/uncmorfi/models/User.kt @@ -9,11 +9,12 @@ import java.util.* @Entity(tableName = "users") data class User( - @PrimaryKey() @SerializedName("code") var card: String = "", + @PrimaryKey @SerializedName("code") var card: String = "", var name: String? = null, var type: String? = null, @SerializedName("imageURL") var image: String? = null, var balance: Int = 0, + @SerializedName("expirationDate") var expiration: Calendar = Calendar.getInstance(), var lastUpdate: Calendar = Calendar.getInstance(),