1.套餐到期年月日时间重新计算,去掉显示一位数补齐0
This commit is contained in:
@@ -120,7 +120,7 @@ class MySubscriptionAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val times = Utils.getDayToYearMonthDay(item.surplusDays)
|
val times = Utils.differYear(System.currentTimeMillis(), item.endTime)
|
||||||
holder.setText(R.id.tv_add_success_device_expires_days, times[0])
|
holder.setText(R.id.tv_add_success_device_expires_days, times[0])
|
||||||
holder.setText(R.id.tv_add_success_device_expires_hours, times[1])
|
holder.setText(R.id.tv_add_success_device_expires_hours, times[1])
|
||||||
holder.setText(R.id.tv_add_success_device_expires_min, times[2])
|
holder.setText(R.id.tv_add_success_device_expires_min, times[2])
|
||||||
|
|||||||
@@ -78,7 +78,9 @@ class PaymentSuccessActivity :
|
|||||||
tvPaymentSuccessExpiresOnDate.text = Utils.stringToDate(
|
tvPaymentSuccessExpiresOnDate.text = Utils.stringToDate(
|
||||||
it.expirationTime, resultFormat = Utils.DATE_FORMAT_PATTERN_EN7
|
it.expirationTime, resultFormat = Utils.DATE_FORMAT_PATTERN_EN7
|
||||||
)
|
)
|
||||||
val times = Utils.getDayToYearMonthDay(it.surplusDays)
|
val times = Utils.differYear(
|
||||||
|
System.currentTimeMillis(), Utils.stringToTimestamp(it.expirationTime)
|
||||||
|
)
|
||||||
ilPaymentSuccessCountDownLayout.tvAddSuccessDeviceExpiresDays.text = times[0]
|
ilPaymentSuccessCountDownLayout.tvAddSuccessDeviceExpiresDays.text = times[0]
|
||||||
ilPaymentSuccessCountDownLayout.tvAddSuccessDeviceExpiresHours.text = times[1]
|
ilPaymentSuccessCountDownLayout.tvAddSuccessDeviceExpiresHours.text = times[1]
|
||||||
ilPaymentSuccessCountDownLayout.tvAddSuccessDeviceExpiresMin.text = times[2]
|
ilPaymentSuccessCountDownLayout.tvAddSuccessDeviceExpiresMin.text = times[2]
|
||||||
|
|||||||
@@ -416,9 +416,11 @@ class HomeTrackFragment :
|
|||||||
private fun shareDeviceState() {
|
private fun shareDeviceState() {
|
||||||
val share = MMKVUtil.getInt(MMKVKey.Shared)
|
val share = MMKVUtil.getInt(MMKVKey.Shared)
|
||||||
if (share == ConstantInt.NoShare) {
|
if (share == ConstantInt.NoShare) {
|
||||||
|
mViewBinding.rvHomePetTrackMenu.visibility=View.VISIBLE
|
||||||
mZoneAdapter.showNoDataAddButton(true)
|
mZoneAdapter.showNoDataAddButton(true)
|
||||||
mFencesAdapter.showNoDataAddButton(true)
|
mFencesAdapter.showNoDataAddButton(true)
|
||||||
} else {
|
} else {
|
||||||
|
mViewBinding.rvHomePetTrackMenu.visibility=View.GONE
|
||||||
mZoneAdapter.showNoDataAddButton(false)
|
mZoneAdapter.showNoDataAddButton(false)
|
||||||
mFencesAdapter.showNoDataAddButton(false)
|
mFencesAdapter.showNoDataAddButton(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="@dimen/dp_8">
|
android:paddingBottom="@dimen/dp_10">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import java.util.Calendar
|
|||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
import kotlin.math.abs
|
|
||||||
import kotlin.math.atan2
|
import kotlin.math.atan2
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@@ -125,31 +124,45 @@ class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算2个日期相册多少年,多少月
|
* 计算2个日期相册多少年,多少月,多少天
|
||||||
*/
|
*/
|
||||||
fun differYear(startDate: String, endDate: String): Array<Int?> {
|
fun differYear(startTimestamp: Long, endTimestamp: Long): Array<String?> {
|
||||||
val result = arrayOfNulls<Int>(2)
|
val result = arrayOfNulls<String>(3)
|
||||||
|
val startDate = formatTime(startTimestamp, DATE_FORMAT_PATTERN_CN)
|
||||||
|
val endDate = formatTime(endTimestamp, DATE_FORMAT_PATTERN_CN)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
val period = Period.between(LocalDate.parse(startDate), LocalDate.parse(endDate))
|
val period = Period.between(LocalDate.parse(startDate), LocalDate.parse(endDate))
|
||||||
result[0] = period.years
|
result[0] = "${period.years}"
|
||||||
result[1] = period.months
|
result[1] = "${period.months}"
|
||||||
|
result[2] = "${period.days}"
|
||||||
} else {
|
} else {
|
||||||
val dfs = SimpleDateFormat(DATE_FORMAT_PATTERN_CN, Locale.getDefault())
|
val dfs = SimpleDateFormat(DATE_FORMAT_PATTERN_CN, Locale.getDefault())
|
||||||
val sDate = dfs.parse(startDate)
|
val sDate = dfs.parse(startDate)!!
|
||||||
val eDate = dfs.parse(endDate)
|
val eDate = dfs.parse(endDate)!!
|
||||||
// 得到两者的毫秒数
|
|
||||||
// val between = (eDate.time - sDate.time)
|
val calendarStart = Calendar.getInstance()
|
||||||
val year = eDate.year - sDate.year
|
calendarStart.time = sDate
|
||||||
val month = eDate.month - sDate.month
|
val calendarEnd = Calendar.getInstance()
|
||||||
//2021-8-1,2122-1-1
|
calendarEnd.time = eDate
|
||||||
if (month < 0) {
|
|
||||||
result[0] = year - 1
|
var years = calendarEnd[Calendar.YEAR] - calendarStart[Calendar.YEAR]
|
||||||
//取绝对值
|
var months = calendarEnd[Calendar.MONTH] - calendarStart[Calendar.MONTH]
|
||||||
result[1] = 12 - abs(month)
|
var days = calendarEnd[Calendar.DAY_OF_MONTH] - calendarStart[Calendar.DAY_OF_MONTH]
|
||||||
} else {
|
|
||||||
result[0] = year
|
// 调整月份和天数以处理跨年情况
|
||||||
result[1] = month
|
if (days < 0) {
|
||||||
|
months--
|
||||||
|
calendarStart.add(Calendar.MONTH, 1) // 将开始日期增加一个月以进行比较
|
||||||
|
days =
|
||||||
|
calendarEnd[Calendar.DAY_OF_MONTH] + (30 - calendarStart[Calendar.DAY_OF_MONTH]) // 假设每个月有30天,简化计算
|
||||||
}
|
}
|
||||||
|
if (months < 0) {
|
||||||
|
years--
|
||||||
|
months += 12 // 将月份调整为正数以处理跨年情况
|
||||||
|
}
|
||||||
|
result[0] = "$years"
|
||||||
|
result[1] = "$months"
|
||||||
|
result[2] = "$days"
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -195,20 +208,6 @@ class Utils {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 把秒转换为 year month day
|
|
||||||
*/
|
|
||||||
fun getDayToYearMonthDay(second: Long): Array<String> {
|
|
||||||
if (second <= 0) return arrayOf("0", "0", "0")
|
|
||||||
val year = second / 365
|
|
||||||
val month = (second % 365) / 30
|
|
||||||
val day = (second % 365) % 30
|
|
||||||
return arrayOf(
|
|
||||||
fill2Digits(year.toInt()), fill2Digits(month.toInt()), fill2Digits(day.toInt())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param d 需要处理的数字
|
* @param d 需要处理的数字
|
||||||
* @param num 保留位数
|
* @param num 保留位数
|
||||||
|
|||||||
Reference in New Issue
Block a user