Finished send logs feature from debug popup
This commit is contained in:
parent
cd880ee06d
commit
a880682672
7 changed files with 126 additions and 73 deletions
|
@ -31,8 +31,8 @@ import androidx.lifecycle.ViewModelProvider
|
|||
import androidx.navigation.fragment.findNavController
|
||||
import org.linphone.R
|
||||
import org.linphone.activities.main.MainActivity
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.AboutFragmentBinding
|
||||
import org.linphone.utils.AppUtils
|
||||
|
||||
class AboutFragment : Fragment() {
|
||||
private lateinit var binding: AboutFragmentBinding
|
||||
|
@ -83,27 +83,8 @@ class AboutFragment : Fragment() {
|
|||
val activity = requireActivity() as MainActivity
|
||||
activity.showSnackBar(R.string.logs_url_copied_to_clipboard)
|
||||
|
||||
shareUploadedLogsUrl(url)
|
||||
AppUtils.shareUploadedLogsUrl(activity, url)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Logs
|
||||
private fun shareUploadedLogsUrl(info: String) {
|
||||
val appName = getString(R.string.app_name)
|
||||
val intent = Intent(Intent.ACTION_SEND)
|
||||
intent.putExtra(
|
||||
Intent.EXTRA_EMAIL,
|
||||
arrayOf(getString(R.string.about_bugreport_email))
|
||||
)
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, "$appName Logs")
|
||||
intent.putExtra(Intent.EXTRA_TEXT, info)
|
||||
intent.type = "text/plain"
|
||||
|
||||
try {
|
||||
startActivity(Intent.createChooser(intent, "Send mail..."))
|
||||
} catch (ex: ActivityNotFoundException) {
|
||||
Log.e(ex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,59 +19,14 @@
|
|||
*/
|
||||
package org.linphone.activities.main.about
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.LogsUploadViewModel
|
||||
|
||||
class AboutViewModel : ViewModel() {
|
||||
class AboutViewModel : LogsUploadViewModel() {
|
||||
val appVersion: String = coreContext.appVersion
|
||||
|
||||
val sdkVersion: String = coreContext.sdkVersion
|
||||
|
||||
val showLogsButtons: Boolean = corePreferences.debugLogs
|
||||
|
||||
val uploadInProgress = MutableLiveData<Boolean>()
|
||||
|
||||
val uploadFinishedEvent: MutableLiveData<Event<String>> by lazy {
|
||||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
||||
private val listener = object : CoreListenerStub() {
|
||||
override fun onLogCollectionUploadStateChanged(
|
||||
core: Core,
|
||||
state: Core.LogCollectionUploadState,
|
||||
info: String
|
||||
) {
|
||||
if (state == Core.LogCollectionUploadState.Delivered) {
|
||||
uploadInProgress.value = false
|
||||
uploadFinishedEvent.value = Event(info)
|
||||
} else if (state == Core.LogCollectionUploadState.NotDelivered) {
|
||||
uploadInProgress.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
coreContext.core.addListener(listener)
|
||||
uploadInProgress.value = false
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
coreContext.core.removeListener(listener)
|
||||
|
||||
super.onCleared()
|
||||
}
|
||||
|
||||
fun uploadLogs() {
|
||||
uploadInProgress.value = true
|
||||
coreContext.core.uploadLogCollection()
|
||||
}
|
||||
|
||||
fun resetLogs() {
|
||||
coreContext.core.resetLogCollection()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
package org.linphone.activities.main.dialer.fragments
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
|
@ -32,16 +35,20 @@ import androidx.navigation.fragment.findNavController
|
|||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
import org.linphone.activities.main.MainActivity
|
||||
import org.linphone.activities.main.dialer.viewmodels.DialerViewModel
|
||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.DialerFragmentBinding
|
||||
import org.linphone.utils.AppUtils
|
||||
|
||||
class DialerFragment : Fragment() {
|
||||
private lateinit var binding: DialerFragmentBinding
|
||||
private lateinit var viewModel: DialerViewModel
|
||||
private lateinit var sharedViewModel: SharedMainViewModel
|
||||
|
||||
private var uploadLogsInitiatedByUs = false
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
@ -115,6 +122,23 @@ class DialerFragment : Fragment() {
|
|||
}
|
||||
})
|
||||
|
||||
viewModel.uploadFinishedEvent.observe(viewLifecycleOwner, Observer {
|
||||
it.consume { url ->
|
||||
// To prevent being trigger when using the Send Logs button in About page
|
||||
if (uploadLogsInitiatedByUs) {
|
||||
val clipboard =
|
||||
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText("Logs url", url)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
|
||||
val activity = requireActivity() as MainActivity
|
||||
activity.showSnackBar(R.string.logs_url_copied_to_clipboard)
|
||||
|
||||
AppUtils.shareUploadedLogsUrl(activity, url)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Log.i("[Dialer] Pending call transfer mode = ${sharedViewModel.pendingCallTransfer}")
|
||||
viewModel.transferVisibility.value = sharedViewModel.pendingCallTransfer
|
||||
}
|
||||
|
@ -126,6 +150,7 @@ class DialerFragment : Fragment() {
|
|||
coreContext.core.nativePreviewWindowId = binding.videoPreviewWindow
|
||||
}
|
||||
viewModel.updateShowVideoPreview()
|
||||
uploadLogsInitiatedByUs = false
|
||||
}
|
||||
|
||||
private fun displayDebugPopup() {
|
||||
|
@ -137,7 +162,8 @@ class DialerFragment : Fragment() {
|
|||
corePreferences.debugLogs = false
|
||||
}
|
||||
if (which == 1) {
|
||||
// TODO: upload logs
|
||||
uploadLogsInitiatedByUs = true
|
||||
viewModel.uploadLogs()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -21,14 +21,14 @@ package org.linphone.activities.main.dialer.viewmodels
|
|||
|
||||
import android.provider.Settings
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.activities.main.dialer.NumpadDigitListener
|
||||
import org.linphone.core.*
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.LogsUploadViewModel
|
||||
|
||||
class DialerViewModel : ViewModel() {
|
||||
class DialerViewModel : LogsUploadViewModel() {
|
||||
val enteredUri = MutableLiveData<String>()
|
||||
|
||||
val atLeastOneCall = MutableLiveData<Boolean>()
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
*/
|
||||
package org.linphone.utils
|
||||
|
||||
import android.content.ContentUris
|
||||
import android.content.ContentValues
|
||||
import android.app.Activity
|
||||
import android.content.*
|
||||
import android.provider.ContactsContract
|
||||
import android.text.Spanned
|
||||
import android.util.TypedValue
|
||||
|
@ -29,6 +29,8 @@ import java.util.*
|
|||
import java.util.regex.Pattern
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||
import org.linphone.R
|
||||
import org.linphone.core.tools.Log
|
||||
|
||||
/**
|
||||
* Various utility methods for application
|
||||
|
@ -125,5 +127,23 @@ class AppUtils {
|
|||
coreContext.context.resources.displayMetrics
|
||||
)
|
||||
}
|
||||
|
||||
fun shareUploadedLogsUrl(activity: Activity, info: String) {
|
||||
val appName = activity.getString(R.string.app_name)
|
||||
val intent = Intent(Intent.ACTION_SEND)
|
||||
intent.putExtra(
|
||||
Intent.EXTRA_EMAIL,
|
||||
arrayOf(activity.getString(R.string.about_bugreport_email))
|
||||
)
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, "$appName Logs")
|
||||
intent.putExtra(Intent.EXTRA_TEXT, info)
|
||||
intent.type = "text/plain"
|
||||
|
||||
try {
|
||||
activity.startActivity(Intent.createChooser(intent, activity.getString(R.string.share_uploaded_logs_link)))
|
||||
} catch (ex: ActivityNotFoundException) {
|
||||
Log.e(ex)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
70
app/src/main/java/org/linphone/utils/LogsUploadViewModel.kt
Normal file
70
app/src/main/java/org/linphone/utils/LogsUploadViewModel.kt
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2020 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.utils
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
|
||||
open class LogsUploadViewModel : ViewModel() {
|
||||
val uploadInProgress = MutableLiveData<Boolean>()
|
||||
|
||||
val uploadFinishedEvent: MutableLiveData<Event<String>> by lazy {
|
||||
MutableLiveData<Event<String>>()
|
||||
}
|
||||
|
||||
private val listener = object : CoreListenerStub() {
|
||||
override fun onLogCollectionUploadStateChanged(
|
||||
core: Core,
|
||||
state: Core.LogCollectionUploadState,
|
||||
info: String
|
||||
) {
|
||||
if (state == Core.LogCollectionUploadState.Delivered) {
|
||||
uploadInProgress.value = false
|
||||
uploadFinishedEvent.value = Event(info)
|
||||
} else if (state == Core.LogCollectionUploadState.NotDelivered) {
|
||||
uploadInProgress.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
coreContext.core.addListener(listener)
|
||||
uploadInProgress.value = false
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
coreContext.core.removeListener(listener)
|
||||
|
||||
super.onCleared()
|
||||
}
|
||||
|
||||
fun uploadLogs() {
|
||||
uploadInProgress.value = true
|
||||
coreContext.core.uploadLogCollection()
|
||||
}
|
||||
|
||||
fun resetLogs() {
|
||||
coreContext.core.resetLogCollection()
|
||||
}
|
||||
}
|
|
@ -42,6 +42,7 @@
|
|||
<item quantity="one">%d day</item>
|
||||
<item quantity="other">%d days</item>
|
||||
</plurals>
|
||||
<string name="share_uploaded_logs_link">Share logs link using...</string>
|
||||
|
||||
<!-- Errors -->
|
||||
<string name="invalid_email">Invalid email</string>
|
||||
|
|
Loading…
Reference in a new issue