diff --git a/app/src/main/java/org/linphone/activities/Navigation.kt b/app/src/main/java/org/linphone/activities/Navigation.kt index 74d85ba7a..738ce365e 100644 --- a/app/src/main/java/org/linphone/activities/Navigation.kt +++ b/app/src/main/java/org/linphone/activities/Navigation.kt @@ -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() { diff --git a/app/src/main/java/org/linphone/activities/main/dialer/fragments/ConfigViewerFragment.kt b/app/src/main/java/org/linphone/activities/main/dialer/fragments/ConfigViewerFragment.kt new file mode 100644 index 000000000..3f963d7d1 --- /dev/null +++ b/app/src/main/java/org/linphone/activities/main/dialer/fragments/ConfigViewerFragment.kt @@ -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 . + */ +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() { + 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) + } + } +} diff --git a/app/src/main/java/org/linphone/activities/main/dialer/fragments/DialerFragment.kt b/app/src/main/java/org/linphone/activities/main/dialer/fragments/DialerFragment.kt index 2d219b40a..3d3a395b7 100644 --- a/app/src/main/java/org/linphone/activities/main/dialer/fragments/DialerFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/dialer/fragments/DialerFragment.kt @@ -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() { 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() } diff --git a/app/src/main/java/org/linphone/activities/main/dialer/viewmodels/ConfigFileViewModel.kt b/app/src/main/java/org/linphone/activities/main/dialer/viewmodels/ConfigFileViewModel.kt new file mode 100644 index 000000000..103511b81 --- /dev/null +++ b/app/src/main/java/org/linphone/activities/main/dialer/viewmodels/ConfigFileViewModel.kt @@ -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 . + */ +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() + + init { + text.value = coreContext.core.config.dump() + } +} diff --git a/app/src/main/java/org/linphone/utils/FileUtils.kt b/app/src/main/java/org/linphone/utils/FileUtils.kt index e71a1c57e..8e5aa6671 100644 --- a/app/src/main/java/org/linphone/utils/FileUtils.kt +++ b/app/src/main/java/org/linphone/utils/FileUtils.kt @@ -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) diff --git a/app/src/main/res/layout/file_config_viewer_fragment.xml b/app/src/main/res/layout/file_config_viewer_fragment.xml new file mode 100644 index 000000000..6730f97e2 --- /dev/null +++ b/app/src/main/res/layout/file_config_viewer_fragment.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/main_nav_graph.xml b/app/src/main/res/navigation/main_nav_graph.xml index 08d848039..15c1055fd 100644 --- a/app/src/main/res/navigation/main_nav_graph.xml +++ b/app/src/main/res/navigation/main_nav_graph.xml @@ -345,5 +345,10 @@ android:name="org.linphone.activities.main.files.fragments.AudioViewerFragment" android:label="AudioViewerFragment" /> + + \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 50746e220..db88d5c44 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -575,4 +575,5 @@ Vous pourrez toujours les exporter dans une appli tierce Sonner durant un appel entrant avec early-media + Voir le fichier de config \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6dbd22dc7..239f99a7c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -116,13 +116,16 @@ Enable logs Disable logs Send logs + Show config file @string/debug_popup_disable_logs @string/debug_popup_send_logs + @string/debug_popup_show_config_file @string/cancel @string/debug_popup_enable_logs + @string/debug_popup_show_config_file @string/cancel