Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: "Send diagnostic report" function should open the user's email client. #4042

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,26 @@

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Process
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.launch
import org.kiwix.kiwixmobile.core.CoreApp.Companion.coreComponent
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.base.BaseActivity
import org.kiwix.kiwixmobile.core.compat.CompatHelper.Companion.getPackageInformation
import org.kiwix.kiwixmobile.core.compat.CompatHelper.Companion.getVersionCode
import org.kiwix.kiwixmobile.core.compat.CompatHelper.Companion.queryIntentActivitiesCompat
import org.kiwix.kiwixmobile.core.compat.ResolveInfoFlagsCompat
import org.kiwix.kiwixmobile.core.dao.NewBookDao
import org.kiwix.kiwixmobile.core.databinding.ActivityKiwixErrorBinding
import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
import org.kiwix.kiwixmobile.core.utils.CRASH_AND_FEEDBACK_EMAIL_ADDRESS
import org.kiwix.kiwixmobile.core.utils.LanguageUtils.Companion.getCurrentLocale
import org.kiwix.kiwixmobile.core.utils.files.FileLogger
import org.kiwix.kiwixmobile.core.zim_manager.MountPointProducer
Expand Down Expand Up @@ -90,7 +95,14 @@
private fun setupReportButton() {
activityKiwixErrorBinding?.reportButton?.setOnClickListener {
lifecycleScope.launch {
sendEmailLauncher.launch(Intent.createChooser(emailIntent(), "Send email..."))
val emailIntent = emailIntent()
val activities =
packageManager.queryIntentActivitiesCompat(emailIntent, ResolveInfoFlagsCompat.EMPTY)

Check warning on line 100 in core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt#L98-L100

Added lines #L98 - L100 were not covered by tests
if (activities.isNotEmpty()) {
sendEmailLauncher.launch(Intent.createChooser(emailIntent, "Send email..."))

Check warning on line 102 in core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt#L102

Added line #L102 was not covered by tests
} else {
toast(getString(R.string.no_email_application_installed))

Check warning on line 104 in core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt#L104

Added line #L104 was not covered by tests
}
}
}
}
Expand All @@ -102,27 +114,15 @@

private suspend fun emailIntent(): Intent {
val emailBody = buildBody()
return Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(
Intent.EXTRA_EMAIL,
arrayOf("android-crash-feedback@kiwix.org")
)
return Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
putExtra(Intent.EXTRA_EMAIL, arrayOf(CRASH_AND_FEEDBACK_EMAIL_ADDRESS))

Check warning on line 119 in core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt#L117-L119

Added lines #L117 - L119 were not covered by tests
putExtra(Intent.EXTRA_SUBJECT, subject)
putExtra(Intent.EXTRA_TEXT, emailBody)
val file = fileLogger.writeLogFile(
this@ErrorActivity,
activityKiwixErrorBinding?.allowLogs?.isChecked == true
)
file.appendText(emailBody)
val path =
FileProvider.getUriForFile(
this@ErrorActivity,
applicationContext.packageName + ".fileprovider",
file
)
addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION)
putExtra(android.content.Intent.EXTRA_STREAM, path)
putExtra(Intent.EXTRA_TEXT, "$emailBody\n\nDevice Logs:\n$${file.readText()}")

Check warning on line 125 in core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/kiwix/kiwixmobile/core/error/ErrorActivity.kt#L125

Added line #L125 was not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.core.utils

const val TAG_KIWIX = "kiwix"
const val CRASH_AND_FEEDBACK_EMAIL_ADDRESS = "android-crash-feedback@kiwix.org"

// Request stuff
const val REQUEST_STORAGE_PERMISSION = 1
Expand Down
1 change: 1 addition & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<string name="pref_credits_title">Credits</string>
<string name="tts_lang_not_supported">The language of this page is not supported. The article may not be properly read.</string>
<string name="no_reader_application_installed">Could not find an installed application for this type of file</string>
<string name="no_email_application_installed">Please install an email client</string>
<string name="no_app_found_to_select_bookmark_file">No app found to select a bookmark file</string>
<string name="no_section_info">No Content Headers Found</string>
<string name="request_storage">To access offline content we need access to your storage</string>
Expand Down
Loading