From 2a43b523447ed554504f35cc265a4c2fa272ce08 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:31:36 +0800 Subject: [PATCH] Logcat add pull-down refresh --- V2rayNG/app/build.gradle.kts | 1 + .../java/com/v2ray/ang/ui/LogcatActivity.kt | 19 ++++++++++----- .../src/main/res/layout/activity_logcat.xml | 23 +++++++++---------- .../app/src/main/res/values-ar/strings.xml | 1 + .../app/src/main/res/values-bn/strings.xml | 1 + .../src/main/res/values-bqi-rIR/strings.xml | 1 + .../app/src/main/res/values-fa/strings.xml | 1 + .../app/src/main/res/values-ru/strings.xml | 1 + .../app/src/main/res/values-vi/strings.xml | 1 + .../src/main/res/values-zh-rCN/strings.xml | 1 + .../src/main/res/values-zh-rTW/strings.xml | 1 + V2rayNG/app/src/main/res/values/strings.xml | 1 + V2rayNG/gradle/libs.versions.toml | 2 ++ 13 files changed, 36 insertions(+), 18 deletions(-) diff --git a/V2rayNG/app/build.gradle.kts b/V2rayNG/app/build.gradle.kts index 7830347d..676dfe9a 100644 --- a/V2rayNG/app/build.gradle.kts +++ b/V2rayNG/app/build.gradle.kts @@ -144,6 +144,7 @@ dependencies { implementation(libs.androidx.constraintlayout) implementation(libs.preference.ktx) implementation(libs.recyclerview) + implementation(libs.androidx.swiperefreshlayout) // UI Libraries implementation(libs.material) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt index cf9f94bd..eb13c538 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt @@ -3,11 +3,11 @@ package com.v2ray.ang.ui import android.os.Bundle import android.view.Menu import android.view.MenuItem -import android.view.View import androidx.appcompat.widget.SearchView import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.R import com.v2ray.ang.databinding.ActivityLogcatBinding @@ -18,7 +18,8 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.IOException -class LogcatActivity : BaseActivity() { + +class LogcatActivity : BaseActivity(), SwipeRefreshLayout.OnRefreshListener { private val binding by lazy { ActivityLogcatBinding.inflate(layoutInflater) } var logsetsAll: MutableList = mutableListOf() @@ -34,15 +35,17 @@ class LogcatActivity : BaseActivity() { binding.recyclerView.setHasFixedSize(true) binding.recyclerView.layoutManager = LinearLayoutManager(this) binding.recyclerView.adapter = adapter - binding.recyclerView.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); + binding.recyclerView.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL)) - getLogcat() + binding.refreshLayout.setOnRefreshListener(this) + + logsets.add(getString(R.string.pull_down_to_refresh)) } private fun getLogcat() { try { - binding.pbWaiting.visibility = View.VISIBLE + binding.refreshLayout.isRefreshing = true lifecycleScope.launch(Dispatchers.Default) { val lst = LinkedHashSet() @@ -61,7 +64,7 @@ class LogcatActivity : BaseActivity() { logsetsAll = allText.toMutableList() logsets = allText.toMutableList() adapter.notifyDataSetChanged() - binding.pbWaiting.visibility = View.GONE + binding.refreshLayout.isRefreshing = false } } } catch (e: IOException) { @@ -139,4 +142,8 @@ class LogcatActivity : BaseActivity() { adapter?.notifyDataSetChanged() return true } + + override fun onRefresh() { + getLogcat() + } } \ No newline at end of file diff --git a/V2rayNG/app/src/main/res/layout/activity_logcat.xml b/V2rayNG/app/src/main/res/layout/activity_logcat.xml index 56ec614a..7c38fd34 100644 --- a/V2rayNG/app/src/main/res/layout/activity_logcat.xml +++ b/V2rayNG/app/src/main/res/layout/activity_logcat.xml @@ -7,20 +7,19 @@ android:fitsSystemWindows="true" tools:context=".ui.LogcatActivity"> - + android:layout_height="match_parent"> - + + + diff --git a/V2rayNG/app/src/main/res/values-ar/strings.xml b/V2rayNG/app/src/main/res/values-ar/strings.xml index 29708941..cbe2933f 100644 --- a/V2rayNG/app/src/main/res/values-ar/strings.xml +++ b/V2rayNG/app/src/main/res/values-ar/strings.xml @@ -8,6 +8,7 @@ إغلاق درج التنقل نجحت عملية ترحيل البيانات! فشلت عملية ترحيل البيانات! + Please pull down to refresh! إيقاف diff --git a/V2rayNG/app/src/main/res/values-bn/strings.xml b/V2rayNG/app/src/main/res/values-bn/strings.xml index e285bc0f..86e9be71 100644 --- a/V2rayNG/app/src/main/res/values-bn/strings.xml +++ b/V2rayNG/app/src/main/res/values-bn/strings.xml @@ -8,6 +8,7 @@ নেভিগেশন ড্রয়ার বন্ধ করুন ডেটা স্থানান্তর সফল! ডেটা স্থানান্তর ব্যর্থ! + Please pull down to refresh! বন্ধ করুন diff --git a/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml b/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml index 57901b41..89efc19e 100644 --- a/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml +++ b/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml @@ -8,6 +8,7 @@ بستن نومگه کشاری مووفقیت من جاگورویی داده جاگورویی داده ٱنجوم نگرؽڌ + Please pull down to refresh! واڌاشتن diff --git a/V2rayNG/app/src/main/res/values-fa/strings.xml b/V2rayNG/app/src/main/res/values-fa/strings.xml index 2e389827..4358ad30 100644 --- a/V2rayNG/app/src/main/res/values-fa/strings.xml +++ b/V2rayNG/app/src/main/res/values-fa/strings.xml @@ -8,6 +8,7 @@ بستن منو کشویی موفقیت در انتقال داده انتقال داده انجام نشد! + Please pull down to refresh! توقف diff --git a/V2rayNG/app/src/main/res/values-ru/strings.xml b/V2rayNG/app/src/main/res/values-ru/strings.xml index 778db646..a4bbc55c 100644 --- a/V2rayNG/app/src/main/res/values-ru/strings.xml +++ b/V2rayNG/app/src/main/res/values-ru/strings.xml @@ -7,6 +7,7 @@ Закрыть панель навигации Успешный перенос данных! Перенос данных не выполнен! + Please pull down to refresh! Остановить diff --git a/V2rayNG/app/src/main/res/values-vi/strings.xml b/V2rayNG/app/src/main/res/values-vi/strings.xml index 0e104e75..691ac1d8 100644 --- a/V2rayNG/app/src/main/res/values-vi/strings.xml +++ b/V2rayNG/app/src/main/res/values-vi/strings.xml @@ -7,6 +7,7 @@ Đóng Menu ứng dụng Đã chuyển dữ liệu! Không thể chuyển dữ liệu! + Please pull down to refresh! Ngắt kết nối v2rayNG diff --git a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml index 4b2d82f7..1a58e3ba 100644 --- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml @@ -7,6 +7,7 @@ Close navigation drawer 数据迁移成功! 数据迁移失败啦! + 请下拉刷新! 停止 diff --git a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml index 4af294f3..50b6b5a8 100644 --- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml @@ -7,6 +7,7 @@ 關閉導覽匣 資料遷移成功! 資料遷移失敗! + 請下拉刷新! 停止 diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml index c902ac00..da1fe1a3 100644 --- a/V2rayNG/app/src/main/res/values/strings.xml +++ b/V2rayNG/app/src/main/res/values/strings.xml @@ -8,6 +8,7 @@ Close navigation drawer Data migration success! Data migration failed! + Please pull down to refresh! Stop diff --git a/V2rayNG/gradle/libs.versions.toml b/V2rayNG/gradle/libs.versions.toml index 3bce7ffb..c789d2ff 100644 --- a/V2rayNG/gradle/libs.versions.toml +++ b/V2rayNG/gradle/libs.versions.toml @@ -17,6 +17,7 @@ quickieFoss = "1.13.1" rxjava = "3.1.9" rxandroid = "3.0.2" rxpermissions = "0.12" +swiperefreshlayout = "1.1.0" toastcompat = "1.1.0" editorkit = "2.9.0" core = "3.5.3" @@ -29,6 +30,7 @@ preferenceKtx = "1.2.1" recyclerview = "1.3.2" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } +androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "swiperefreshlayout" } desugar_jdk_libs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar_jdk_libs" } gradle-license-plugin = { module = "com.jaredsburrows:gradle-license-plugin", version.ref = "gradleLicensePlugin" } junit = { group = "junit", name = "junit", version.ref = "junit" }