diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index f7c0e442b..5fa7715a6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -228,6 +228,10 @@ public class GBApplication extends Application { logging.setupLogging(enabled); } + public static String getLogPath(){ + return logging.getLogPath(); + } + private void setupExceptionHandler() { LoggingExceptionHandler handler = new LoggingExceptionHandler(Thread.getDefaultUncaughtExceptionHandler()); Thread.setDefaultUncaughtExceptionHandler(handler); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java index b21e634ed..fd77cb097 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/Logging.java @@ -54,6 +54,13 @@ public abstract class Logging { } } + public String getLogPath() { + if (fileLogger != null) + return fileLogger.getFile(); + else + return null; + } + public void debugLoggingConfiguration() { // For debugging problems with the logback configuration LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java index 3a1d8391b..7e87882d9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java @@ -17,12 +17,15 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.activities; +import android.app.AlertDialog; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; +import android.net.Uri; import android.os.Bundle; import android.support.v4.app.NavUtils; import android.support.v4.app.NotificationCompat; @@ -39,6 +42,7 @@ import android.widget.Toast; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.util.ArrayList; import java.util.Objects; @@ -53,9 +57,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes; import nodomain.freeyourgadget.gadgetbridge.util.GB; +import static android.content.Intent.EXTRA_SUBJECT; import static nodomain.freeyourgadget.gadgetbridge.util.GB.NOTIFICATION_CHANNEL_ID; - public class DebugActivity extends AbstractGBActivity { private static final Logger LOG = LoggerFactory.getLogger(DebugActivity.class); @@ -235,12 +239,58 @@ public class DebugActivity extends AbstractGBActivity { testNewFunctionality(); } }); + + Button shareLogButton = findViewById(R.id.shareLog); + shareLogButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showWarning(); + } + }); + } + + private void showWarning() { + new AlertDialog.Builder(this) + .setCancelable(true) + .setTitle(R.string.warning) + .setMessage(R.string.share_log_warning) + .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String fileName = GBApplication.getLogPath(); + if (fileName != null && fileName.length() > 0) { + Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); + emailIntent.setType("*/*"); + emailIntent.putExtra(EXTRA_SUBJECT, "Gadgetbridge log file"); + emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileName))); + startActivity(Intent.createChooser(emailIntent, "Share File")); + } + } + }) + .setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // do nothing + } + }) + .show(); } private void testNewFunctionality() { GBApplication.deviceService().onTestNewFunction(); } + private void shareLog() { + String fileName = GBApplication.getLogPath(); + if(fileName != null && fileName.length() > 0) { + Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); + emailIntent.setType("*/*"); + emailIntent.putExtra(EXTRA_SUBJECT, "Gadgetbridge log file"); + emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileName))); + startActivity(Intent.createChooser(emailIntent, "Share File")); + } + } + private void testNotification() { Intent notificationIntent = new Intent(getApplicationContext(), DebugActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK diff --git a/app/src/main/res/layout/activity_debug.xml b/app/src/main/res/layout/activity_debug.xml index 32aa9a386..6bbfe1b94 100644 --- a/app/src/main/res/layout/activity_debug.xml +++ b/app/src/main/res/layout/activity_debug.xml @@ -138,6 +138,13 @@ grid:layout_columnSpan="2" grid:layout_gravity="fill_horizontal" android:text="Test New Functionality" /> +