Show and update subscription last updated time
This commit is contained in:
1 parent
31d29d97c0
commit
b71614a9cd
5 files changed
+47
-2
No files matched your search
@@ -446,7 +446,13 @@ object AngConfigManager {
|
||||
if (configText.isEmpty()) {
|
||||
return 0
|
||||
}
|
||||
return parseConfigViaSub(configText, it.first, false)
|
||||
val count = parseConfigViaSub(configText, it.first, false)
|
||||
if (count > 0) {
|
||||
it.second.lastUpdated = System.currentTimeMillis()
|
||||
MmkvManager.encodeSubscription(it.first, it.second)
|
||||
Log.i(AppConfig.TAG, "Subscription updated: ${it.second.remarks}, $count configs")
|
||||
}
|
||||
return count
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to update config via subscription", e)
|
||||
return 0
|
||||
|
||||
@@ -66,6 +66,7 @@ class SubSettingActivity : BaseActivity() {
|
||||
launch(Dispatchers.Main) {
|
||||
if (count > 0) {
|
||||
toastSuccess(R.string.toast_success)
|
||||
refreshData()
|
||||
} else {
|
||||
toastError(R.string.toast_failure)
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ class SubSettingRecyclerAdapter(val activity: SubSettingActivity) : RecyclerView
|
||||
holder.itemSubSettingBinding.tvName.text = subItem.remarks
|
||||
holder.itemSubSettingBinding.tvUrl.text = subItem.url
|
||||
holder.itemSubSettingBinding.chkEnable.isChecked = subItem.enabled
|
||||
holder.itemSubSettingBinding.tvLastUpdated.text = Utils.formatTimestamp(subItem.lastUpdated)
|
||||
holder.itemView.setBackgroundColor(Color.TRANSPARENT)
|
||||
|
||||
holder.itemSubSettingBinding.layoutEdit.setOnClickListener {
|
||||
@@ -65,10 +66,12 @@ class SubSettingRecyclerAdapter(val activity: SubSettingActivity) : RecyclerView
|
||||
holder.itemSubSettingBinding.layoutUrl.visibility = View.GONE
|
||||
holder.itemSubSettingBinding.layoutShare.visibility = View.INVISIBLE
|
||||
holder.itemSubSettingBinding.chkEnable.visibility = View.INVISIBLE
|
||||
holder.itemSubSettingBinding.layoutLastUpdated.visibility = View.INVISIBLE
|
||||
} else {
|
||||
holder.itemSubSettingBinding.layoutUrl.visibility = View.VISIBLE
|
||||
holder.itemSubSettingBinding.layoutShare.visibility = View.VISIBLE
|
||||
holder.itemSubSettingBinding.chkEnable.visibility = View.VISIBLE
|
||||
holder.itemSubSettingBinding.layoutLastUpdated.visibility = View.VISIBLE
|
||||
holder.itemSubSettingBinding.layoutShare.setOnClickListener {
|
||||
AlertDialog.Builder(mActivity)
|
||||
.setItems(share_method.asList().toTypedArray()) { _, i ->
|
||||
|
||||
@@ -27,6 +27,8 @@ import java.net.URLDecoder
|
||||
import java.net.URLEncoder
|
||||
import java.util.Locale
|
||||
import java.util.UUID
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
|
||||
object Utils {
|
||||
|
||||
@@ -567,5 +569,21 @@ object Utils {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a timestamp (milliseconds since epoch) into a date string.
|
||||
* Returns empty string for null or non-positive timestamps.
|
||||
* @param ts timestamp in milliseconds or null
|
||||
* @param pattern SimpleDateFormat pattern, default "yyyy-MM-dd HH:mm"
|
||||
*/
|
||||
fun formatTimestamp(ts: Long?, pattern: String = "yyyy-MM-dd HH:mm", locale: Locale = Locale.getDefault()): String {
|
||||
if (ts == null || ts <= 0L) return ""
|
||||
return try {
|
||||
val sdf = SimpleDateFormat(pattern, locale)
|
||||
sdf.format(Date(ts))
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "Failed to format timestamp", e)
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,6 +151,23 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_last_updated"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="@dimen/padding_spacing_dp8"
|
||||
android:paddingStart="@dimen/padding_spacing_dp8"
|
||||
android:paddingEnd="@dimen/padding_spacing_dp8">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_last_updated"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Caption"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in new issue
Block a user