added logcat

This commit is contained in:
LagradOst 2022-04-11 00:00:03 +02:00
parent e90862235a
commit a14aef8418
9 changed files with 205 additions and 24 deletions

View file

@ -577,16 +577,18 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
createISO()
}*/
var providersAndroidManifestString = "Current androidmanifest should be:\n"
for (api in allProviders) {
providersAndroidManifestString += "<data android:scheme=\"https\" android:host=\"${
api.mainUrl.removePrefix(
"https://"
)
}\" android:pathPrefix=\"/\"/>\n"
}
if (BuildConfig.DEBUG) {
var providersAndroidManifestString = "Current androidmanifest should be:\n"
for (api in allProviders) {
providersAndroidManifestString += "<data android:scheme=\"https\" android:host=\"${
api.mainUrl.removePrefix(
"https://"
)
}\" android:pathPrefix=\"/\"/>\n"
}
println(providersAndroidManifestString)
println(providersAndroidManifestString)
}
handleAppIntent(intent)

View file

@ -699,27 +699,21 @@ class ResultFragment : Fragment(), PanelsChildGestureRegionObserver.GestureRegio
media_route_button?.alpha = if (chromecastSupport) 1f else 0.3f
if (!chromecastSupport) {
media_route_button.setOnClickListener {
media_route_button?.setOnClickListener {
showToast(activity, R.string.no_chromecast_support_toast, Toast.LENGTH_LONG)
}
}
activity?.let {
if (it.isCastApiAvailable()) {
activity?.let { act ->
if (act.isCastApiAvailable()) {
try {
CastButtonFactory.setUpMediaRouteButton(it, media_route_button)
val castContext = CastContext.getSharedInstance(it.applicationContext)
CastButtonFactory.setUpMediaRouteButton(act, media_route_button)
val castContext = CastContext.getSharedInstance(act.applicationContext)
media_route_button?.isGone = castContext.castState == CastState.NO_DEVICES_AVAILABLE
if (castContext.castState != CastState.NO_DEVICES_AVAILABLE) media_route_button.visibility =
VISIBLE
castContext.addCastStateListener { state ->
if (media_route_button != null) {
if (state == CastState.NO_DEVICES_AVAILABLE) media_route_button.visibility =
GONE else {
if (media_route_button.visibility == GONE) media_route_button.visibility =
VISIBLE
}
}
media_route_button?.isGone = state == CastState.NO_DEVICES_AVAILABLE
}
} catch (e: Exception) {
logError(e)

View file

@ -194,6 +194,8 @@ class SyncViewModel : ViewModel() {
Log.i(TAG, "modifyData ${repo.name} => $newData")
repo.score(id, newData)
}
} else if (result is Resource.Failure){
Log.e(TAG, "modifyData getStatus error ${result.errorString}")
}
}
}
@ -212,6 +214,7 @@ class SyncViewModel : ViewModel() {
_userDataResponse.postValue(result)
return@launch
} else if (result is Resource.Failure) {
Log.e(TAG, "updateUserData error ${result.errorString}")
lastError = result
}
}
@ -233,6 +236,7 @@ class SyncViewModel : ViewModel() {
_metaResponse.postValue(result)
return@launch
} else if (result is Resource.Failure) {
Log.e(TAG, "updateMetadata error ${result.errorString}")
lastError = result
}
}

View file

@ -2,6 +2,8 @@ package com.lagradost.cloudstream3.ui.settings
import android.app.UiModeManager
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
@ -51,9 +53,15 @@ import com.lagradost.cloudstream3.utils.SubtitleHelper.getFlagFromIso
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import com.lagradost.cloudstream3.utils.UIHelper.setImage
import com.lagradost.cloudstream3.utils.VideoDownloadManager
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getDownloadDir
import kotlinx.android.synthetic.main.logcat.*
import okhttp3.internal.closeQuietly
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import java.io.OutputStream
import kotlin.concurrent.thread
@ -500,6 +508,69 @@ class SettingsFragment : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}
getPref(R.string.show_logcat_key)?.setOnPreferenceClickListener { pref ->
val builder =
AlertDialog.Builder(pref.context, R.style.AlertDialogCustom)
.setView(R.layout.logcat)
val dialog = builder.create()
dialog.show()
val log = StringBuilder()
try {
//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)
}
} catch (e: Exception) {
logError(e) // kinda ironic
}
val text = log.toString()
dialog.text1?.text = text
dialog.copy_btt?.setOnClickListener {
val serviceClipboard =
(activity?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?)
?: return@setOnClickListener
val clip = ClipData.newPlainText("logcat", text)
serviceClipboard.setPrimaryClip(clip)
dialog.dismissSafe(activity)
}
dialog.clear_btt?.setOnClickListener {
Runtime.getRuntime().exec("logcat -c")
dialog.dismissSafe(activity)
}
dialog.save_btt?.setOnClickListener {
var fileStream: OutputStream? = null
try {
fileStream =
VideoDownloadManager.setupStream(
it.context,
"logcat",
null,
"txt",
false
).fileStream
fileStream?.writer()?.write(text)
} catch (e: Exception) {
logError(e)
} finally {
fileStream?.closeQuietly()
dialog.dismissSafe(activity)
}
}
dialog.close_btt?.setOnClickListener {
dialog.dismissSafe(activity)
}
return@setOnPreferenceClickListener true
}
getPref(R.string.app_layout_key)?.setOnPreferenceClickListener {
val prefNames = resources.getStringArray(R.array.app_layout)
val prefValues = resources.getIntArray(R.array.app_layout_values)

View file

@ -581,7 +581,7 @@ object VideoDownloadManager {
* Sets up the appropriate file and creates a data stream from the file.
* Used for initializing downloads.
* */
private fun setupStream(
fun setupStream(
context: Context,
name: String,
folder: String?,

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/white">
<path
android:fillColor="@android:color/white"
android:pathData="M14,2L6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6zM16,18L8,18v-2h8v2zM16,14L8,14v-2h8v2zM13,9L13,3.5L18.5,9L13,9z"/>
</vector>

View file

@ -0,0 +1,79 @@
<?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">
<ScrollView
android:layout_marginBottom="60dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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>
<HorizontalScrollView
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">
<LinearLayout
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" />
<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" />
<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" />
<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" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>

View file

@ -40,6 +40,8 @@
<string name="prefer_media_type_key" translatable="false">prefer_media_type_key</string>
<string name="app_theme_key" translatable="false">app_theme_key</string>
<string name="episode_sync_enabled_key" translatable="false">episode_sync_enabled_key</string>
<string name="log_enabled_key" translatable="false">log_enabled_key</string>
<string name="show_logcat_key" translatable="false">show_logcat_key</string>
<!-- FORMAT MIGHT TRANSLATE, WILL CAUSE CRASH IF APPLIED WRONG -->
@ -142,6 +144,11 @@
<string name="action_add_to_bookmarks">Set watch status</string>
<string name="sort_apply">Apply</string>
<string name="sort_cancel">Cancel</string>
<string name="sort_copy">Copy</string>
<string name="sort_close">Close</string>
<string name="sort_clear">Clear</string>
<string name="sort_save">Save</string>
<string name="player_speed">Player Speed</string>
<string name="subtitles_settings">Subtitle Settings</string>
@ -178,6 +185,8 @@
<string name="normal_no_plot">No Plot Found</string>
<string name="torrent_no_plot">No Description Found</string>
<string name="show_log_cat">Show logcat</string>
<string name="picture_in_picture">Picture-in-picture</string>
<string name="picture_in_picture_des">Continues playback in a miniature player on top of other apps</string>
<string name="player_size_settings">Player resize button</string>

View file

@ -206,6 +206,18 @@
android:key="@string/restore_key"
android:title="@string/restore_settings" />
<Preference
android:key="@string/show_logcat_key"
android:title="@string/show_log_cat"
android:icon="@drawable/baseline_description_24" />
<!--<SwitchPreference
android:defaultValue="false"
android:key="@string/log_enabled_key"
android:title="@string/toggle_logcat"
android:summary="@string/toggle_logcat_des"
android:icon="@drawable/baseline_description_24" />-->
<SwitchPreference
android:icon="@drawable/netflix_download"
android:key="@string/killswitch_key"