Skip to content

Commit

Permalink
Fixed warning expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
AIDEA775 committed Nov 18, 2019
1 parent 391520a commit 4c2442b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 6 additions & 9 deletions app/src/main/java/com/uncmorfi/balance/UserCardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/uncmorfi/models/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Expand Down

0 comments on commit 4c2442b

Please sign in to comment.