Feat[UI]: opportunistic log sharing

This commit is contained in:
Mathias-Boulay 2023-05-19 23:49:21 +02:00
parent 0bb4f5d113
commit baeea2916e
4 changed files with 28 additions and 15 deletions

View File

@ -1,7 +1,10 @@
package net.kdt.pojavlaunch; package net.kdt.pojavlaunch;
import static net.kdt.pojavlaunch.Tools.shareLog;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -25,7 +28,7 @@ public class ExitActivity extends AppCompatActivity {
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setMessage(getString(R.string.mcn_exit_title,code)) .setMessage(getString(R.string.mcn_exit_title,code))
.setPositiveButton(android.R.string.ok, null) .setPositiveButton(R.string.main_share_logs, (dialog, which) -> shareLog(this))
.setOnDismissListener(dialog -> ExitActivity.this.finish()) .setOnDismissListener(dialog -> ExitActivity.this.finish())
.show(); .show();
} }

View File

@ -22,6 +22,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
@ -967,4 +968,19 @@ public final class Tools {
} }
return runtime; return runtime;
} }
/** Triggers the share intent chooser, with the latestlog file attached to it */
public static void shareLog(Context context){
Uri contentUri = DocumentsContract.buildDocumentUri(context.getString(R.string.storageProviderAuthorities), Tools.DIR_GAME_HOME + "/latestlog.txt");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("text/plain");
Intent sendIntent = Intent.createChooser(shareIntent, "latestlog.txt");
context.startActivity(sendIntent);
}
} }

View File

@ -1,5 +1,7 @@
package net.kdt.pojavlaunch.fragments; package net.kdt.pojavlaunch.fragments;
import static net.kdt.pojavlaunch.Tools.shareLog;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -49,19 +51,7 @@ public class MainMenuFragment extends Fragment {
mPlayButton.setOnClickListener(v -> ExtraCore.setValue(ExtraConstants.LAUNCH_GAME, true)); mPlayButton.setOnClickListener(v -> ExtraCore.setValue(ExtraConstants.LAUNCH_GAME, true));
mShareLogsButton.setOnClickListener((v) -> { mShareLogsButton.setOnClickListener((v) -> shareLog(requireContext()));
Uri contentUri = DocumentsContract.buildDocumentUri(getString(R.string.storageProviderAuthorities), Tools.DIR_GAME_HOME + "/latestlog.txt");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("text/plain");
Intent sendIntent = Intent.createChooser(shareIntent, "latestlog.txt");
startActivity(sendIntent);
});
} }
private void runInstallerWithConfirmation(boolean isCustomArgs) { private void runInstallerWithConfirmation(boolean isCustomArgs) {
if (ProgressKeeper.getTaskCount() == 0) if (ProgressKeeper.getTaskCount() == 0)

View File

@ -5,6 +5,7 @@ import static net.kdt.pojavlaunch.Architecture.is64BitsDevice;
import static net.kdt.pojavlaunch.Tools.LOCAL_RENDERER; import static net.kdt.pojavlaunch.Tools.LOCAL_RENDERER;
import static net.kdt.pojavlaunch.Tools.NATIVE_LIB_DIR; import static net.kdt.pojavlaunch.Tools.NATIVE_LIB_DIR;
import static net.kdt.pojavlaunch.Tools.currentDisplayMetrics; import static net.kdt.pojavlaunch.Tools.currentDisplayMetrics;
import static net.kdt.pojavlaunch.Tools.shareLog;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_DUMP_SHADERS; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_DUMP_SHADERS;
import android.app.*; import android.app.*;
@ -303,7 +304,10 @@ public class JREUtils {
AlertDialog.Builder dialog = new AlertDialog.Builder(activity); AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
dialog.setMessage(activity.getString(R.string.mcn_exit_title, exitCode)); dialog.setMessage(activity.getString(R.string.mcn_exit_title, exitCode));
dialog.setPositiveButton(android.R.string.ok, (p1, p2) -> MainActivity.fullyExit()); dialog.setPositiveButton(R.string.main_share_logs, (p1, p2) -> {
shareLog(activity);
MainActivity.fullyExit();
});
dialog.show(); dialog.show();
}); });
} }