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
@@ -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()
}
}