Logcat add pull-down refresh

This commit is contained in:
2dust
2025-01-13 14:31:36 +08:00
parent abff80ec23
commit 2a43b52344
13 changed files with 36 additions and 18 deletions
+1
View File
@@ -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)
@@ -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<String> = 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<String>()
@@ -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()
}
}
@@ -7,20 +7,19 @@
android:fitsSystemWindows="true"
tools:context=".ui.LogcatActivity">
<ProgressBar
android:id="@+id/pb_waiting"
style="@android:style/Widget.DeviceDefault.ProgressBar"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>
@@ -8,6 +8,7 @@
<string name="navigation_drawer_close">إغلاق درج التنقل</string>
<string name="migration_success">نجحت عملية ترحيل البيانات!</string>
<string name="migration_fail">فشلت عملية ترحيل البيانات!</string>
<string name="pull_down_to_refresh">Please pull down to refresh!</string>
<!-- Notifications -->
<string name="notification_action_stop_v2ray">إيقاف</string>
@@ -8,6 +8,7 @@
<string name="navigation_drawer_close">নেভিগেশন ড্রয়ার বন্ধ করুন</string>
<string name="migration_success">ডেটা স্থানান্তর সফল!</string>
<string name="migration_fail">ডেটা স্থানান্তর ব্যর্থ!</string>
<string name="pull_down_to_refresh">Please pull down to refresh!</string>
<!-- Notifications -->
<string name="notification_action_stop_v2ray">বন্ধ করুন</string>
@@ -8,6 +8,7 @@
<string name="navigation_drawer_close">بستن نومگه کشاری</string>
<string name="migration_success">مووفقیت من جاگورویی داده</string>
<string name="migration_fail">جاگورویی داده ٱنجوم نگرؽڌ</string>
<string name="pull_down_to_refresh">Please pull down to refresh!</string>
<!-- Notifications -->
<string name="notification_action_stop_v2ray">واڌاشتن</string>
@@ -8,6 +8,7 @@
<string name="navigation_drawer_close">بستن منو کشویی</string>
<string name="migration_success">موفقیت در انتقال داده</string>
<string name="migration_fail">انتقال داده انجام نشد!</string>
<string name="pull_down_to_refresh">Please pull down to refresh!</string>
<!-- Notifications -->
<string name="notification_action_stop_v2ray">توقف</string>
@@ -7,6 +7,7 @@
<string name="navigation_drawer_close">Закрыть панель навигации</string>
<string name="migration_success">Успешный перенос данных!</string>
<string name="migration_fail">Перенос данных не выполнен!</string>
<string name="pull_down_to_refresh">Please pull down to refresh!</string>
<!-- Notifications -->
<string name="notification_action_stop_v2ray">Остановить</string>
@@ -7,6 +7,7 @@
<string name="navigation_drawer_close">Đóng Menu ứng dụng</string>
<string name="migration_success">Đã chuyển dữ liệu!</string>
<string name="migration_fail">Không thể chuyển dữ liệu!</string>
<string name="pull_down_to_refresh">Please pull down to refresh!</string>
<!-- Notifications -->
<string name="notification_action_stop_v2ray">Ngắt kết nối v2rayNG</string>
@@ -7,6 +7,7 @@
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="migration_success">数据迁移成功!</string>
<string name="migration_fail">数据迁移失败啦!</string>
<string name="pull_down_to_refresh">请下拉刷新!</string>
<!-- Notifications -->
<string name="notification_action_stop_v2ray">停止</string>
@@ -7,6 +7,7 @@
<string name="navigation_drawer_close">關閉導覽匣</string>
<string name="migration_success">資料遷移成功!</string>
<string name="migration_fail">資料遷移失敗!</string>
<string name="pull_down_to_refresh">請下拉刷新!</string>
<!-- Notifications -->
<string name="notification_action_stop_v2ray">停止</string>
@@ -8,6 +8,7 @@
<string name="navigation_drawer_close">Close navigation drawer</string>
<string name="migration_success">Data migration success!</string>
<string name="migration_fail">Data migration failed!</string>
<string name="pull_down_to_refresh">Please pull down to refresh!</string>
<!-- Notifications -->
<string name="notification_action_stop_v2ray">Stop</string>