From a14aef8418828210f06a47872c38917dc26e2995 Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Mon, 11 Apr 2022 00:00:03 +0200 Subject: [PATCH] added logcat --- .../lagradost/cloudstream3/MainActivity.kt | 20 ++--- .../cloudstream3/ui/result/ResultFragment.kt | 22 ++---- .../cloudstream3/ui/result/SyncViewModel.kt | 4 + .../ui/settings/SettingsFragment.kt | 71 +++++++++++++++++ .../utils/VideoDownloadManager.kt | 2 +- .../res/drawable/baseline_description_24.xml | 10 +++ app/src/main/res/layout/logcat.xml | 79 +++++++++++++++++++ app/src/main/res/values/strings.xml | 9 +++ app/src/main/res/xml/settings.xml | 12 +++ 9 files changed, 205 insertions(+), 24 deletions(-) create mode 100644 app/src/main/res/drawable/baseline_description_24.xml create mode 100644 app/src/main/res/layout/logcat.xml diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 44a36dfc..a43d4741 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -577,16 +577,18 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener { createISO() }*/ - var providersAndroidManifestString = "Current androidmanifest should be:\n" - for (api in allProviders) { - providersAndroidManifestString += "\n" - } + if (BuildConfig.DEBUG) { + var providersAndroidManifestString = "Current androidmanifest should be:\n" + for (api in allProviders) { + providersAndroidManifestString += "\n" + } - println(providersAndroidManifestString) + println(providersAndroidManifestString) + } handleAppIntent(intent) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt index 2c6ecaa7..0762cabb 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragment.kt @@ -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) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/SyncViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/SyncViewModel.kt index 90f0746f..3c8177c2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/SyncViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/SyncViewModel.kt @@ -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 } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt index 381bfa4d..4bad5c57 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt @@ -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) diff --git a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt index 9f6de453..bdb2e4b4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/utils/VideoDownloadManager.kt @@ -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?, diff --git a/app/src/main/res/drawable/baseline_description_24.xml b/app/src/main/res/drawable/baseline_description_24.xml new file mode 100644 index 00000000..f561cdd4 --- /dev/null +++ b/app/src/main/res/drawable/baseline_description_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/logcat.xml b/app/src/main/res/layout/logcat.xml new file mode 100644 index 00000000..ae52fd79 --- /dev/null +++ b/app/src/main/res/layout/logcat.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b50ec557..bea6211b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -40,6 +40,8 @@ prefer_media_type_key app_theme_key episode_sync_enabled_key + log_enabled_key + show_logcat_key @@ -142,6 +144,11 @@ Set watch status Apply Cancel + Copy + Close + Clear + Save + Player Speed Subtitle Settings @@ -178,6 +185,8 @@ No Plot Found No Description Found + Show logcat + Picture-in-picture Continues playback in a miniature player on top of other apps Player resize button diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 3f13c3b0..5552b587 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -206,6 +206,18 @@ android:key="@string/restore_key" android:title="@string/restore_settings" /> + + + +