Updated on 2026-08-14
This commit is contained in:
parent
d8348e54df
commit
de899b5678
5 changed files with 73 additions and 23 deletions
|
|
@ -1,9 +1,9 @@
|
|||
package com.tangem.tap.common.feedback
|
||||
|
||||
import android.content.Context
|
||||
import com.tangem.datasource.config.models.ChatConfig
|
||||
import com.tangem.domain.common.TapWorkarounds
|
||||
import com.tangem.tap.common.chat.ChatManager
|
||||
import com.tangem.datasource.config.models.ChatConfig
|
||||
import com.tangem.tap.common.extensions.sendEmail
|
||||
import com.tangem.tap.common.log.TangemLogCollector
|
||||
import com.tangem.tap.foregroundActivityObserver
|
||||
|
|
@ -22,32 +22,61 @@ class FeedbackManager(
|
|||
private val chatManager: ChatManager,
|
||||
) {
|
||||
|
||||
private var sessionFeedbackFile: File? = null
|
||||
private var sessionLogsFile: File? = null
|
||||
|
||||
fun sendEmail(feedbackData: FeedbackData, onFail: ((Exception) -> Unit)? = null) {
|
||||
feedbackData.prepare(infoHolder)
|
||||
foregroundActivityObserver.withForegroundActivity { activity ->
|
||||
val fileLog = createLogFile(activity)
|
||||
activity.sendEmail(
|
||||
email = getSupportEmail(),
|
||||
subject = activity.getString(feedbackData.subjectResId),
|
||||
message = feedbackData.joinTogether(activity, infoHolder),
|
||||
file = fileLog,
|
||||
file = getLogFile(activity),
|
||||
onFail = onFail,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun openChat(config: ChatConfig, feedbackData: FeedbackData) {
|
||||
chatManager.open(config) { context ->
|
||||
feedbackData.run {
|
||||
chatManager.open(
|
||||
config = config,
|
||||
createLogsFile = ::getLogFile,
|
||||
createFeedbackFile = { context -> getFeedbackFile(context, feedbackData) },
|
||||
)
|
||||
}
|
||||
|
||||
private fun getFeedbackFile(context: Context, feedbackData: FeedbackData): File? {
|
||||
return try {
|
||||
if (sessionFeedbackFile != null) {
|
||||
return sessionFeedbackFile
|
||||
}
|
||||
val file = File(context.filesDir, FEEDBACK_FILE)
|
||||
file.delete()
|
||||
file.createNewFile()
|
||||
|
||||
val feedback = feedbackData.run {
|
||||
prepare(infoHolder)
|
||||
joinTogether(context, infoHolder)
|
||||
}
|
||||
val fileWriter = FileWriter(file)
|
||||
fileWriter.write(feedback)
|
||||
fileWriter.close()
|
||||
|
||||
sessionFeedbackFile = file
|
||||
sessionFeedbackFile
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(ex, "Can't create the logs file")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun createLogFile(context: Context): File? {
|
||||
private fun getLogFile(context: Context): File? {
|
||||
return try {
|
||||
val file = File(context.filesDir, "logs.txt")
|
||||
if (sessionLogsFile != null) {
|
||||
return sessionLogsFile
|
||||
}
|
||||
val file = File(context.filesDir, LOGS_FILE)
|
||||
file.delete()
|
||||
file.createNewFile()
|
||||
|
||||
|
|
@ -57,7 +86,8 @@ class FeedbackManager(
|
|||
fileWriter.write(stringWriter.toString())
|
||||
fileWriter.close()
|
||||
logCollector.clearLogs()
|
||||
file
|
||||
sessionLogsFile = file
|
||||
sessionLogsFile
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(ex, "Can't create the logs file")
|
||||
null
|
||||
|
|
@ -75,5 +105,7 @@ class FeedbackManager(
|
|||
companion object {
|
||||
const val DEFAULT_SUPPORT_EMAIL = "support@tangem.com"
|
||||
const val S2C_SUPPORT_EMAIL = "cardsupport@start2coin.com"
|
||||
const val FEEDBACK_FILE = "feedback.txt"
|
||||
const val LOGS_FILE = "logs.txt"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue