Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make logcat a RecyclerView #1528

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.lagradost.cloudstream3.ui.settings

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.lagradost.cloudstream3.databinding.ItemLogcatBinding

class LogcatAdapter(
private val logs: List<String>
) : RecyclerView.Adapter<LogcatAdapter.LogViewHolder>() {

inner class LogViewHolder(
val binding: ItemLogcatBinding
) : RecyclerView.ViewHolder(binding.root)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LogViewHolder {
val binding = ItemLogcatBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return LogViewHolder(binding)
}

override fun onBindViewHolder(holder: LogViewHolder, position: Int) {
holder.binding.logText.text = logs[position]
}

override fun getItemCount(): Int = logs.count()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.lagradost.cloudstream3.AcraApplication
import com.lagradost.cloudstream3.AutoDownloadMode
import com.lagradost.cloudstream3.CommonActivity.showToast
Expand All @@ -18,7 +19,6 @@ import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.network.initClient
import com.lagradost.cloudstream3.services.BackupWorkManager
import com.lagradost.cloudstream3.utils.txt
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
Expand All @@ -37,7 +37,7 @@ import com.lagradost.cloudstream3.utils.UIHelper.clipboardHelper
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.VideoDownloadManager
import okhttp3.internal.closeQuietly
import com.lagradost.cloudstream3.utils.txt
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.OutputStream
Expand Down Expand Up @@ -137,35 +137,30 @@ class SettingsUpdates : PreferenceFragmentCompat() {
}

getPref(R.string.show_logcat_key)?.setOnPreferenceClickListener { pref ->
val builder =
AlertDialog.Builder(pref.context, R.style.AlertDialogCustom)
val builder = AlertDialog.Builder(pref.context, R.style.AlertDialogCustom)

val binding = LogcatBinding.inflate(layoutInflater, null, false)
builder.setView(binding.root)

val dialog = builder.create()
dialog.show()
val log = StringBuilder()

val logList = mutableListOf<String>()
try {
//https://developer.android.com/studio/command-line/logcat
// https://developer.android.com/studio/command-line/logcat
val process = Runtime.getRuntime().exec("logcat -d")
val bufferedReader = BufferedReader(
InputStreamReader(process.inputStream)
)

var line: String?
while (bufferedReader.readLine().also { line = it } != null) {
log.append("${line}\n")
}
val bufferedReader = BufferedReader(InputStreamReader(process.inputStream))
bufferedReader.lineSequence().forEach { logList.add(it) }
} catch (e: Exception) {
logError(e) // kinda ironic
}

val text = log.toString()
binding.text1.text = text
val adapter = LogcatAdapter(logList)
binding.logcatRecyclerView.layoutManager = LinearLayoutManager(pref.context)
binding.logcatRecyclerView.adapter = adapter

binding.copyBtt.setOnClickListener {
clipboardHelper(txt("Logcat"), text)
clipboardHelper(txt("Logcat"), logList.joinToString("\n"))
dialog.dismissSafe(activity)
}

Expand All @@ -179,19 +174,17 @@ class SettingsUpdates : PreferenceFragmentCompat() {
var fileStream: OutputStream? = null
try {
fileStream = VideoDownloadManager.setupStream(
it.context,
"logcat_${date}",
null,
"txt",
false
).openNew()
fileStream.writer().write(text)
it.context,
"logcat_${date}",
null,
"txt",
false
).openNew()
fileStream.writer().use { writer -> writer.write(logList.joinToString("\n")) }
dialog.dismissSafe(activity)
} catch (t: Throwable) {
logError(t)
showToast(t.message)
} finally {
fileStream?.closeQuietly()
}
}

Expand Down Expand Up @@ -274,4 +267,4 @@ class SettingsUpdates : PreferenceFragmentCompat() {
}
} ?: emptyList()
}
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/layout/item_logcat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">

<TextView
android:id="@+id/log_text"
android:textSize="14sp"
android:textColor="?attr/textColor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Test" />
</LinearLayout>
110 changes: 48 additions & 62 deletions app/src/main/res/layout/logcat.xml
Original file line number Diff line number Diff line change
@@ -1,80 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView
android:layout_marginBottom="60dp"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/logcat_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nextFocusRight="@id/save_btt">

<TextView
android:id="@+id/text1"
android:padding="15dp"
android:textSize="15sp"
android:textColor="?attr/textColor"
android:layout_width="match_parent"
android:layout_rowWeight="1"
tools:text="Test"
android:layout_height="wrap_content"/>
</ScrollView>
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="60dp"
android:nextFocusRight="@id/save_btt"
tools:listitem="@layout/item_logcat" />

<HorizontalScrollView
android:scrollbars="none"
android:id="@+id/apply_btt_holder"
android:layout_gravity="bottom"
android:gravity="bottom|end"
android:layout_marginTop="-60dp"
android:layout_width="match_parent"
android:layout_height="60dp">
android:id="@+id/apply_btt_holder"
android:scrollbars="none"
android:gravity="bottom|end"
android:layout_gravity="bottom"
android:layout_marginTop="-60dp"
android:layout_width="match_parent"
android:layout_height="60dp">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">

<com.google.android.material.button.MaterialButton
android:nextFocusRight="@id/copy_btt"
android:id="@+id/save_btt"

style="@style/WhiteButton"
android:layout_gravity="center_vertical|end"
android:text="@string/sort_save"
android:layout_width="wrap_content" />
android:id="@+id/save_btt"
android:text="@string/sort_save"
android:layout_gravity="center_vertical|end"
android:layout_width="wrap_content"
android:nextFocusRight="@id/copy_btt"
style="@style/WhiteButton" />

<com.google.android.material.button.MaterialButton
android:nextFocusLeft="@id/save_btt"
android:nextFocusRight="@id/clear_btt"
android:id="@+id/copy_btt"

style="@style/BlackButton"
android:layout_gravity="center_vertical|end"
android:text="@string/sort_copy"
android:layout_width="wrap_content" />

android:id="@+id/copy_btt"
android:text="@string/sort_copy"
android:layout_gravity="center_vertical|end"
android:layout_width="wrap_content"
android:nextFocusLeft="@id/save_btt"
android:nextFocusRight="@id/clear_btt"
style="@style/BlackButton" />

<com.google.android.material.button.MaterialButton
android:nextFocusRight="@id/close_btt"
android:nextFocusLeft="@id/copy_btt"

style="@style/BlackButton"
android:layout_gravity="center_vertical|end"
android:text="@string/sort_clear"
android:id="@+id/clear_btt"
android:layout_width="wrap_content" />
android:id="@+id/clear_btt"
android:text="@string/sort_clear"
android:layout_gravity="center_vertical|end"
android:layout_width="wrap_content"
android:nextFocusRight="@id/close_btt"
android:nextFocusLeft="@id/copy_btt"
style="@style/BlackButton" />

<com.google.android.material.button.MaterialButton
android:nextFocusLeft="@id/clear_btt"
android:id="@+id/close_btt"

style="@style/BlackButton"
android:layout_gravity="center_vertical|end"
android:text="@string/sort_close"
android:layout_width="wrap_content" />
android:id="@+id/close_btt"
android:text="@string/sort_close"
android:layout_gravity="center_vertical|end"
android:layout_width="wrap_content"
android:nextFocusLeft="@id/clear_btt"
style="@style/BlackButton" />
</LinearLayout>
</HorizontalScrollView>

</LinearLayout>
</LinearLayout>