feat: finish share log dialog

This commit is contained in:
Harris 2021-09-23 15:47:43 +10:00
parent a295cc384c
commit c21a75c880
3 changed files with 38 additions and 3 deletions

View File

@ -124,6 +124,7 @@ public class ApplicationContext extends Application implements DependencyInjecto
public SignalCommunicationModule communicationModule;
private Job firebaseInstanceIdJob;
private Handler conversationListNotificationHandler;
private PersistentLogger persistentLogger;
private volatile boolean isAppVisible;
@ -135,6 +136,10 @@ public class ApplicationContext extends Application implements DependencyInjecto
return this.conversationListNotificationHandler;
}
public PersistentLogger getPersistentLogger() {
return this.persistentLogger;
}
@Override
public void onCreate() {
super.onCreate();
@ -277,7 +282,10 @@ public class ApplicationContext extends Application implements DependencyInjecto
}
private void initializeLogging() {
Log.initialize(new AndroidLogger(), new PersistentLogger(this));
if (persistentLogger == null) {
persistentLogger = new PersistentLogger(this);
}
Log.initialize(new AndroidLogger(), persistentLogger);
}
private void initializeCrashHandling() {

View File

@ -1,14 +1,20 @@
package org.thoughtcrime.securesms.preferences
import android.content.Intent
import android.os.Build
import android.view.LayoutInflater
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.lifecycleScope
import kotlinx.android.synthetic.main.dialog_share_logs.view.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import network.loki.messenger.BuildConfig
import network.loki.messenger.R
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
import org.thoughtcrime.securesms.providers.BlobProvider
class ShareLogsDialog : BaseDialog() {
@ -31,7 +37,28 @@ class ShareLogsDialog : BaseDialog() {
private fun shareLogs() {
shareJob?.cancel()
shareJob = lifecycleScope.launch(Dispatchers.IO) {
val persistentLogger = ApplicationContext.getInstance(context).persistentLogger
try {
val logs = persistentLogger.logs.get()
val fileName = "${Build.MANUFACTURER}-${Build.DEVICE}-API${Build.VERSION.SDK_INT}-v${BuildConfig.VERSION_NAME}.log"
val logUri = BlobProvider().forData(logs.toByteArray())
.withFileName(fileName)
.withMimeType("text/plain")
.createForSingleSessionOnDisk(requireContext(),null)
val shareIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, logUri)
type = "text/plain"
}
dismiss()
startActivity(Intent.createChooser(shareIntent, getString(R.string.share)))
} catch (e: Exception) {
Toast.makeText(context,"Error saving logs", Toast.LENGTH_LONG).show()
dismiss()
}
}
}

View File

@ -42,10 +42,10 @@
android:text="@string/cancel" />
<Button
style="@style/Widget.Session.Button.Dialog"
style="@style/Widget.Session.Button.Dialog.Unimportant"
android:id="@+id/shareButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="@dimen/small_button_height"
android:layout_weight="1"
android:layout_marginStart="@dimen/medium_spacing"
android:text="@string/share" />