mirror of
https://github.com/izzy2lost/Starship.git
synced 2026-07-05 15:19:42 -07:00
fix portrait mode crash - hopefully
This commit is contained in:
@@ -17,7 +17,7 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: sudo apt-get install gcc g++ git cmake ninja-build lsb-release
|
||||
- name: ccache
|
||||
uses: hendrikmuhs/ccache-action@v1.2.13
|
||||
uses: hendrikmuhs/ccache-action@v1.2.18
|
||||
with:
|
||||
key: ${{ runner.os }}-o2r-ccache-${{ github.ref }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
|
||||
@@ -25,7 +25,7 @@ android {
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments "-DSDL_SHARED=ON", "-DANDROID_STL=c++_static", "-DHAVE_LD_VERSION_SCRIPT=OFF",'-DUSE_OPENGLES=ON'
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
|
||||
abiFilters 'armeabi-v7a', 'arm64-v8a'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,13 @@
|
||||
</intent-filter>
|
||||
-->
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".DialogActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/RoundedDialog"
|
||||
android:exported="false" />
|
||||
</application>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.starship.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class DialogActivity extends Activity {
|
||||
public static final String EXTRA_TITLE = "title";
|
||||
public static final String EXTRA_MESSAGE = "message";
|
||||
public static final String EXTRA_POSITIVE_BUTTON = "positive_button";
|
||||
public static final String EXTRA_NEGATIVE_BUTTON = "negative_button";
|
||||
public static final String EXTRA_CANCELABLE = "cancelable";
|
||||
public static final String EXTRA_DIALOG_TYPE = "dialog_type";
|
||||
|
||||
public static final int DIALOG_TYPE_FOLDER_PROMPT = 1;
|
||||
public static final int DIALOG_TYPE_FILE_NOT_FOUND = 2;
|
||||
public static final int DIALOG_TYPE_COPY_COMPLETE = 3;
|
||||
public static final int DIALOG_TYPE_FILE_READY = 4;
|
||||
|
||||
public static final int RESULT_POSITIVE = RESULT_OK;
|
||||
public static final int RESULT_NEGATIVE = RESULT_CANCELED;
|
||||
public static final int RESULT_FOLDER_PICKER = 100;
|
||||
public static final int RESULT_TORCH_DOWNLOAD = 101;
|
||||
public static final int RESULT_FILE_PICKER = 102;
|
||||
public static final int RESULT_RESTART = 103;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getIntent();
|
||||
String title = intent.getStringExtra(EXTRA_TITLE);
|
||||
String message = intent.getStringExtra(EXTRA_MESSAGE);
|
||||
String positiveButton = intent.getStringExtra(EXTRA_POSITIVE_BUTTON);
|
||||
String negativeButton = intent.getStringExtra(EXTRA_NEGATIVE_BUTTON);
|
||||
boolean cancelable = intent.getBooleanExtra(EXTRA_CANCELABLE, true);
|
||||
int dialogType = intent.getIntExtra(EXTRA_DIALOG_TYPE, 0);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.RoundedDialog);
|
||||
builder.setTitle(title);
|
||||
builder.setMessage(message);
|
||||
builder.setCancelable(cancelable);
|
||||
|
||||
// Set up buttons based on dialog type
|
||||
switch (dialogType) {
|
||||
case DIALOG_TYPE_FOLDER_PROMPT:
|
||||
builder.setPositiveButton(positiveButton, (d, w) -> {
|
||||
setResult(RESULT_FOLDER_PICKER);
|
||||
finish();
|
||||
});
|
||||
break;
|
||||
|
||||
case DIALOG_TYPE_FILE_NOT_FOUND:
|
||||
builder.setPositiveButton("Download Torch App", (d, w) -> {
|
||||
setResult(RESULT_TORCH_DOWNLOAD);
|
||||
finish();
|
||||
});
|
||||
builder.setNegativeButton("Select sf64.o2r File", (d, w) -> {
|
||||
setResult(RESULT_FILE_PICKER);
|
||||
finish();
|
||||
});
|
||||
break;
|
||||
|
||||
case DIALOG_TYPE_COPY_COMPLETE:
|
||||
builder.setPositiveButton("Restart", (d, w) -> {
|
||||
setResult(RESULT_RESTART);
|
||||
finish();
|
||||
});
|
||||
builder.setNegativeButton("Later", (d, w) -> {
|
||||
setResult(RESULT_NEGATIVE);
|
||||
finish();
|
||||
});
|
||||
break;
|
||||
|
||||
case DIALOG_TYPE_FILE_READY:
|
||||
builder.setPositiveButton("Restart", (d, w) -> {
|
||||
setResult(RESULT_RESTART);
|
||||
finish();
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
builder.setPositiveButton(positiveButton != null ? positiveButton : "OK", (d, w) -> {
|
||||
setResult(RESULT_POSITIVE);
|
||||
finish();
|
||||
});
|
||||
if (negativeButton != null) {
|
||||
builder.setNegativeButton(negativeButton, (d, w) -> {
|
||||
setResult(RESULT_NEGATIVE);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.setOnDismissListener(d -> finish());
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
@@ -340,11 +340,13 @@ private void copyAssetFolderRecursive(String assetDir, File destDir) {
|
||||
}
|
||||
|
||||
// ===== UI helpers =====
|
||||
private AlertDialog.Builder createPortraitDialog() {
|
||||
setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(this, R.style.RoundedDialog);
|
||||
b.setOnDismissListener(d -> setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE));
|
||||
return b;
|
||||
private void showPortraitDialog(String title, String message, int dialogType) {
|
||||
Intent intent = new Intent(this, DialogActivity.class);
|
||||
intent.putExtra(DialogActivity.EXTRA_TITLE, title);
|
||||
intent.putExtra(DialogActivity.EXTRA_MESSAGE, message);
|
||||
intent.putExtra(DialogActivity.EXTRA_DIALOG_TYPE, dialogType);
|
||||
intent.putExtra(DialogActivity.EXTRA_CANCELABLE, false);
|
||||
startActivityForResult(intent, dialogType);
|
||||
}
|
||||
|
||||
private void showToast(String msg) {
|
||||
@@ -368,12 +370,9 @@ private void restartApp() {
|
||||
|
||||
// ===== Folder / File pickers =====
|
||||
private void promptForUserFolder() {
|
||||
runOnUiThread(() -> createPortraitDialog()
|
||||
.setTitle("Choose Your Folder")
|
||||
.setMessage("Select a folder for your sf64.o2r file and mods location. This will be your main Starship folder where you can add mods and manage game files.")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("Select Folder", (d, w) -> openFolderPicker())
|
||||
.show());
|
||||
showPortraitDialog("Choose Your Folder",
|
||||
"Select a folder for your sf64.o2r file and mods location. This will be your main Starship folder where you can add mods and manage game files.",
|
||||
DialogActivity.DIALOG_TYPE_FOLDER_PROMPT);
|
||||
}
|
||||
|
||||
public void openFolderPicker() {
|
||||
@@ -417,6 +416,27 @@ private void openTorchDownload() {
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
// Handle DialogActivity results
|
||||
if (requestCode == DialogActivity.DIALOG_TYPE_FOLDER_PROMPT && resultCode == DialogActivity.RESULT_FOLDER_PICKER) {
|
||||
openFolderPicker();
|
||||
return;
|
||||
}
|
||||
if (requestCode == DialogActivity.DIALOG_TYPE_FILE_NOT_FOUND) {
|
||||
if (resultCode == DialogActivity.RESULT_TORCH_DOWNLOAD) {
|
||||
openTorchDownload();
|
||||
} else if (resultCode == DialogActivity.RESULT_FILE_PICKER) {
|
||||
openFilePickerForSf64();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ((requestCode == DialogActivity.DIALOG_TYPE_COPY_COMPLETE || requestCode == DialogActivity.DIALOG_TYPE_FILE_READY)
|
||||
&& resultCode == DialogActivity.RESULT_RESTART) {
|
||||
restartApp();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle file/folder picker results
|
||||
if (resultCode != RESULT_OK || data == null) return;
|
||||
|
||||
if (requestCode == REQ_PICK_FOLDER) {
|
||||
@@ -467,22 +487,13 @@ private void handleFolderSelection(Uri treeUri, int returnedFlags) {
|
||||
// Check if sf64.o2r exists in the user's chosen folder
|
||||
DocumentFile sf64InUserFolder = userRoot.findFile("sf64.o2r");
|
||||
if (sf64InUserFolder == null || !sf64InUserFolder.exists()) {
|
||||
runOnUiThread(() -> createPortraitDialog()
|
||||
.setTitle("sf64.o2r not found in selected folder")
|
||||
.setMessage("Pick an existing sf64.o2r file or use Torch to create one. It will be copied to your selected folder.")
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("Download Torch App", (d, w) -> openTorchDownload())
|
||||
.setNegativeButton("Select sf64.o2r File", (d, w) -> openFilePickerForSf64())
|
||||
.show());
|
||||
runOnUiThread(() -> showPortraitDialog("sf64.o2r not found in selected folder",
|
||||
"Pick an existing sf64.o2r file or use Torch to create one. It will be copied to your selected folder.",
|
||||
DialogActivity.DIALOG_TYPE_FILE_NOT_FOUND));
|
||||
} else {
|
||||
final String msg = anyCopied ? "Files copied. Restart to load the game."
|
||||
: "Nothing copied (sources not found).";
|
||||
runOnUiThread(() -> createPortraitDialog()
|
||||
.setTitle("Copy complete")
|
||||
.setMessage(msg)
|
||||
.setPositiveButton("Restart", (d, w) -> restartApp())
|
||||
.setNegativeButton("Later", null)
|
||||
.show());
|
||||
runOnUiThread(() -> showPortraitDialog("Copy complete", msg, DialogActivity.DIALOG_TYPE_COPY_COMPLETE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,11 +598,9 @@ private void handleRomFileSelection(Uri selectedFileUri) {
|
||||
out.getFD().sync();
|
||||
Log.i(TAG, "sf64.o2r copied to internal (" + total + " bytes): " + dest.getAbsolutePath());
|
||||
|
||||
runOnUiThread(() -> createPortraitDialog()
|
||||
.setTitle("sf64.o2r ready")
|
||||
.setMessage("sf64.o2r copied. Restart to load the game.")
|
||||
.setPositiveButton("Restart", (d, w) -> restartApp())
|
||||
.show());
|
||||
runOnUiThread(() -> showPortraitDialog("sf64.o2r ready",
|
||||
"sf64.o2r copied. Restart to load the game.",
|
||||
DialogActivity.DIALOG_TYPE_FILE_READY));
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "handleRomFileSelection", e);
|
||||
showToast("Failed to copy sf64.o2r: " + e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user