3939import android .util .DisplayMetrics ;
4040import android .util .Log ;
4141import android .view .InputDevice ;
42+ import android .view .LayoutInflater ;
4243import android .view .View ;
4344import android .view .WindowManager ;
4445import android .widget .EditText ;
7374import net .kdt .pojavlaunch .utils .JREUtils ;
7475import net .kdt .pojavlaunch .utils .JSONUtils ;
7576import net .kdt .pojavlaunch .utils .MCOptionUtils ;
77+ import net .kdt .pojavlaunch .utils .McLogsApi ;
7678import net .kdt .pojavlaunch .utils .OldVersionsUtils ;
7779import net .kdt .pojavlaunch .value .DependentLibrary ;
7880import net .kdt .pojavlaunch .value .MinecraftAccount ;
@@ -1578,11 +1580,66 @@ public static void runOnUiThread(Runnable runnable) {
15781580 return runtime ;
15791581 }
15801582
1581- /** Triggers the share intent chooser, with the latestlog file attached to it */
1583+ /** Shows a dialog letting the user pick between uploading the log to mclo.gs or sharing
1584+ * the raw log file directly, like before this dialog existed. */
15821585 public static void shareLog (Context context ){
1586+ View dialogView = LayoutInflater .from (context ).inflate (R .layout .dialog_share_log , null );
1587+
1588+ AlertDialog dialog = new AlertDialog .Builder (context )
1589+ .setTitle (R .string .share_log_dialog_title )
1590+ .setView (dialogView )
1591+ .setNegativeButton (android .R .string .cancel , null )
1592+ .create ();
1593+
1594+ dialogView .findViewById (R .id .share_log_mclogs_button ).setOnClickListener (v -> {
1595+ dialog .dismiss ();
1596+ shareLogToMcLogs (context );
1597+ });
1598+ dialogView .findViewById (R .id .share_log_file_button ).setOnClickListener (v -> {
1599+ dialog .dismiss ();
1600+ shareLogFile (context );
1601+ });
1602+
1603+ dialog .show ();
1604+ }
1605+
1606+ /** Triggers the share intent chooser, with the latestlog file attached to it */
1607+ private static void shareLogFile (Context context ){
15831608 openPath (context , new File (Tools .DIR_GAME_HOME , "latestlog.txt" ), true );
15841609 }
15851610
1611+ /** Uploads the latest log file to mclo.gs and shares the resulting link, copying it to the
1612+ * clipboard as well so it isn't lost if the share sheet gets dismissed. */
1613+ private static void shareLogToMcLogs (Context context ){
1614+ final File logFile = new File (Tools .DIR_GAME_HOME , "latestlog.txt" );
1615+ final ProgressDialog progressDialog = getWaitingDialog (context , R .string .share_log_mclogs_uploading );
1616+
1617+ sExecutorService .execute (() -> {
1618+ try {
1619+ String url = McLogsApi .upload (logFile );
1620+ Tools .runOnUiThread (() -> {
1621+ progressDialog .dismiss ();
1622+
1623+ ClipboardManager clipboardManager = (ClipboardManager ) context .getSystemService (Context .CLIPBOARD_SERVICE );
1624+ if (clipboardManager != null ) clipboardManager .setPrimaryClip (ClipData .newPlainText ("mclo.gs" , url ));
1625+ Toast .makeText (context , R .string .share_log_mclogs_copied , Toast .LENGTH_SHORT ).show ();
1626+
1627+ Intent shareIntent = new Intent (Intent .ACTION_SEND );
1628+ shareIntent .setType ("text/plain" );
1629+ shareIntent .putExtra (Intent .EXTRA_TEXT , url );
1630+ Intent chooserIntent = Intent .createChooser (shareIntent , url );
1631+ chooserIntent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
1632+ context .startActivity (chooserIntent );
1633+ });
1634+ } catch (IOException e ) {
1635+ Tools .runOnUiThread (() -> {
1636+ progressDialog .dismiss ();
1637+ Tools .showError (context , R .string .share_log_mclogs_error , e );
1638+ });
1639+ }
1640+ });
1641+ }
1642+
15861643 /**
15871644 * Determine the MIME type of a File.
15881645 * @param file The file to determine the type of
@@ -1872,4 +1929,4 @@ static class SDL {
18721929 */
18731930 public static native void initializeControllerSubsystems ();
18741931 }
1875- }
1932+ }
0 commit comments