Added debug popup entry to show config file

This commit is contained in:
Sylvain Berfini 2021-04-14 11:39:39 +02:00
parent a63b057101
commit 6ffe3c22e9
9 changed files with 216 additions and 11 deletions

View file

@ -250,6 +250,15 @@ internal fun DialerFragment.navigateToContacts(uriToAdd: String?) {
)
}
internal fun DialerFragment.navigateToConfigFileViewer() {
val bundle = bundleOf("Secure" to true)
findMasterNavController().navigate(
R.id.action_global_configViewerFragment,
bundle,
getRightToLeftAnimationNavOptions()
)
}
/* Chat related */
internal fun MasterChatRoomsFragment.navigateToChatRoom() {

View file

@ -0,0 +1,69 @@
/*
* Copyright (c) 2010-2021 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.activities.main.dialer.fragments
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import org.linphone.R
import org.linphone.activities.main.dialer.viewmodels.ConfigFileViewModel
import org.linphone.activities.main.fragments.SecureFragment
import org.linphone.core.tools.Log
import org.linphone.databinding.FileConfigViewerFragmentBinding
class ConfigViewerFragment : SecureFragment<FileConfigViewerFragmentBinding>() {
private lateinit var viewModel: ConfigFileViewModel
override fun getLayoutId(): Int = R.layout.file_config_viewer_fragment
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.lifecycleOwner = this
viewModel = ViewModelProvider(this)[ConfigFileViewModel::class.java]
binding.viewModel = viewModel
isSecure = arguments?.getBoolean("Secure") ?: false
binding.setBackClickListener {
findNavController().popBackStack()
}
binding.setExportClickListener {
shareConfig()
}
}
private fun shareConfig() {
val intent = Intent(Intent.ACTION_SEND)
intent.putExtra(Intent.EXTRA_TEXT, viewModel.text.value.orEmpty())
intent.type = "text/plain"
try {
startActivity(Intent.createChooser(intent, getString(R.string.app_name)))
} catch (ex: ActivityNotFoundException) {
Log.e(ex)
}
}
}

View file

@ -36,6 +36,7 @@ import org.linphone.R
import org.linphone.activities.main.MainActivity
import org.linphone.activities.main.dialer.viewmodels.DialerViewModel
import org.linphone.activities.main.fragments.SecureFragment
import org.linphone.activities.main.navigateToConfigFileViewer
import org.linphone.activities.main.navigateToContacts
import org.linphone.activities.main.viewmodels.DialogViewModel
import org.linphone.activities.main.viewmodels.SharedMainViewModel
@ -152,23 +153,31 @@ class DialerFragment : SecureFragment<DialerFragmentBinding>() {
private fun displayDebugPopup() {
val alertDialog = MaterialAlertDialogBuilder(requireContext())
alertDialog.setTitle(getString(R.string.debug_popup_title))
if (corePreferences.debugLogs) {
alertDialog.setItems(resources.getStringArray(R.array.popup_send_log)) { _, which ->
if (which == 0) {
val items = if (corePreferences.debugLogs) {
resources.getStringArray(R.array.popup_send_log)
} else {
resources.getStringArray(R.array.popup_enable_log)
}
alertDialog.setItems(items) { _, which ->
when (items[which]) {
getString(R.string.debug_popup_disable_logs) -> {
corePreferences.debugLogs = false
}
if (which == 1) {
getString(R.string.debug_popup_enable_logs) -> {
corePreferences.debugLogs = true
}
getString(R.string.debug_popup_send_logs) -> {
uploadLogsInitiatedByUs = true
viewModel.uploadLogs()
}
}
} else {
alertDialog.setItems(resources.getStringArray(R.array.popup_enable_log)) { _, which ->
if (which == 0) {
corePreferences.debugLogs = true
getString(R.string.debug_popup_show_config_file) -> {
navigateToConfigFileViewer()
}
}
}
alertDialog.show()
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2010-2021 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.activities.main.dialer.viewmodels
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
class ConfigFileViewModel : ViewModel() {
val text = MutableLiveData<String>()
init {
text.value = coreContext.core.config.dump()
}
}

View file

@ -326,8 +326,12 @@ class FileUtils {
if (type != null) {
Log.i("[File Viewer] Found matching MIME type $type")
} else {
type = "file/$extension"
Log.e("[File Viewer] Can't get MIME type from extension: $extension, will use $type")
type = if (extension == "linphonerc") {
"text/plain"
} else {
"file/$extension"
}
Log.w("[File Viewer] Can't get MIME type from extension: $extension, will use $type")
}
intent.setDataAndType(contentUri, type)

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View"/>
<variable
name="backClickListener"
type="android.view.View.OnClickListener"/>
<variable
name="exportClickListener"
type="android.view.View.OnClickListener"/>
<variable
name="viewModel"
type="org.linphone.activities.main.dialer.viewmodels.ConfigFileViewModel" />
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/backgroundColor">
<LinearLayout
android:id="@+id/top_bar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:background="?attr/lightToolbarBackgroundColor"
android:orientation="horizontal">
<ImageView
android:onClick="@{backClickListener}"
android:contentDescription="@string/content_description_go_back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:background="?attr/button_background_drawable"
android:padding="18dp"
android:src="@drawable/back" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"/>
<ImageView
android:onClick="@{exportClickListener}"
android:contentDescription="@string/content_description_export"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:background="?attr/button_background_drawable"
android:padding="18dp"
android:src="@drawable/settings_network" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/top_bar">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:singleLine="false"
android:text="@{viewModel.text}"/>
</ScrollView>
</RelativeLayout>
</layout>

View file

@ -345,5 +345,10 @@
android:name="org.linphone.activities.main.files.fragments.AudioViewerFragment"
android:label="AudioViewerFragment" />
<action android:id="@+id/action_global_audioViewerFragment" app:destination="@id/audioViewerFragment"/>
<fragment
android:id="@+id/configViewerFragment"
android:name="org.linphone.activities.main.dialer.fragments.ConfigViewerFragment"
android:label="ConfigViewerFragment" />
<action android:id="@+id/action_global_configViewerFragment" app:destination="@id/configViewerFragment" />
</navigation>

View file

@ -575,4 +575,5 @@
<string name="chat_settings_use_in_app_file_viewer_summary">Vous pourrez toujours les exporter dans une appli tierce</string>
<string name="call_settings_ring_during_early_media_title">Sonner durant un appel entrant avec early-media</string>
<string name="call_settings_ring_during_early_media_summary"></string>
<string name="debug_popup_show_config_file">Voir le fichier de config</string>
</resources>

View file

@ -116,13 +116,16 @@
<string name="debug_popup_enable_logs">Enable logs</string>
<string name="debug_popup_disable_logs">Disable logs</string>
<string name="debug_popup_send_logs">Send logs</string>
<string name="debug_popup_show_config_file">Show config file</string>
<string-array name="popup_send_log" translatable="false">
<item>@string/debug_popup_disable_logs</item>
<item>@string/debug_popup_send_logs</item>
<item>@string/debug_popup_show_config_file</item>
<item>@string/cancel</item>
</string-array>
<string-array name="popup_enable_log" translatable="false">
<item>@string/debug_popup_enable_logs</item>
<item>@string/debug_popup_show_config_file</item>
<item>@string/cancel</item>
</string-array>