mirror of
https://github.com/izzy2lost/PSX2.git
synced 2026-07-05 15:18:36 -07:00
fixed orientation changing problems
This commit is contained in:
@@ -99,6 +99,21 @@ public class GamesCoverDialogFragment extends DialogFragment {
|
||||
if (rv != null) applyCoverflowTransforms(rv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull android.content.res.Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
// The layout file is cached when dialog is created, so we need to recreate the dialog
|
||||
// to get the correct layout for the new orientation
|
||||
dismiss();
|
||||
|
||||
// Recreate the dialog with the correct layout for new orientation
|
||||
if (getParentFragmentManager() != null) {
|
||||
GamesCoverDialogFragment newDialog = GamesCoverDialogFragment.newInstance(origTitles, origUris);
|
||||
newDialog.show(getParentFragmentManager(), getTag());
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
@@ -290,10 +305,15 @@ public class GamesCoverDialogFragment extends DialogFragment {
|
||||
rv.post(() -> {
|
||||
if (!isAdded()) return;
|
||||
boolean landscape = getResources().getConfiguration().orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE;
|
||||
|
||||
// Recalculate padding based on current orientation - this was the issue!
|
||||
float density = getResources().getDisplayMetrics().density;
|
||||
int currentSidePad = (int) (48 * density);
|
||||
int currentVertPad = (int) ((landscape ? 12 : 24) * density);
|
||||
|
||||
int titleDp = 36;
|
||||
int extraDp = 16;
|
||||
float density = getResources().getDisplayMetrics().density;
|
||||
int reservedH = (int) ((titleDp + extraDp) * density) + (vertPad * 2);
|
||||
int reservedH = (int) ((titleDp + extraDp) * density) + (currentVertPad * 2);
|
||||
int availableH = Math.max(0, rvH - reservedH);
|
||||
float ratio = 567f / 878f;
|
||||
int widthFromHeight = (int) (availableH * ratio);
|
||||
@@ -301,15 +321,16 @@ public class GamesCoverDialogFragment extends DialogFragment {
|
||||
int itemWidth = Math.max(160, Math.min(widthFromHeight, widthFromWidth));
|
||||
lastItemWidthPx = itemWidth;
|
||||
adapter.setItemWidthPx(itemWidth);
|
||||
|
||||
// Center vertically in portrait by adjusting top/bottom padding
|
||||
if (!landscape) {
|
||||
int imageH = (int) (itemWidth / (567f / 878f));
|
||||
int titlePx = (int) ((titleDp + extraDp) * density);
|
||||
int contentH = imageH + titlePx;
|
||||
int desiredPad = Math.max(vertPad, Math.max(0, (rvH - contentH) / 2));
|
||||
rv.setPadding(sidePad, desiredPad, sidePad, desiredPad);
|
||||
int desiredPad = Math.max(currentVertPad, Math.max(0, (rvH - contentH) / 2));
|
||||
rv.setPadding(currentSidePad, desiredPad, currentSidePad, desiredPad);
|
||||
} else {
|
||||
rv.setPadding(sidePad, vertPad, sidePad, vertPad);
|
||||
rv.setPadding(currentSidePad, currentVertPad, currentSidePad, currentVertPad);
|
||||
}
|
||||
// If user is scrolling, defer resnap until idle to avoid fighting gesture
|
||||
if (rv.getScrollState() == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
@@ -972,6 +993,8 @@ public class GamesCoverDialogFragment extends DialogFragment {
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -72,48 +72,61 @@
|
||||
android:layout_weight="1"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="0dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:clipToPadding="false" />
|
||||
|
||||
<!-- Hint below covers grid: yellow bulb right next to text -->
|
||||
<!-- Bottom row: Hint and Download button side by side in landscape -->
|
||||
<LinearLayout
|
||||
android:id="@+id/hint_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:id="@+id/img_hint_bulb"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:tint="@color/covers_hint_yellow"
|
||||
android:src="@drawable/lightbulb_2_24px"
|
||||
android:layout_marginEnd="4dp"/>
|
||||
<TextView
|
||||
android:id="@+id/tv_covers_hint"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp">
|
||||
|
||||
<!-- Hint on the left -->
|
||||
<LinearLayout
|
||||
android:id="@+id/hint_row"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="start|center_vertical"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:id="@+id/img_hint_bulb"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:tint="@color/covers_hint_yellow"
|
||||
android:src="@drawable/lightbulb_2_24px"
|
||||
android:layout_marginEnd="4dp"/>
|
||||
<TextView
|
||||
android:id="@+id/tv_covers_hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/covers_hint_long_press"
|
||||
android:textColor="@color/brand_primary"
|
||||
android:textStyle="bold"
|
||||
android:textSize="11sp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Download button on the right -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_download"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/covers_hint_long_press"
|
||||
android:textColor="@color/brand_primary"
|
||||
android:textStyle="bold"
|
||||
android:textSize="12sp"/>
|
||||
</LinearLayout>
|
||||
android:text="COVERS"
|
||||
android:contentDescription="Download Covers"
|
||||
app:icon="@drawable/download_24px"
|
||||
app:iconTint="@color/brand_primary"
|
||||
app:iconGravity="textStart"
|
||||
app:iconPadding="12dp"
|
||||
app:iconSize="20dp" />
|
||||
|
||||
<!-- Download button below covers, centered with COVERS text -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btn_download"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="COVERS"
|
||||
android:contentDescription="Download Covers"
|
||||
app:icon="@drawable/download_24px"
|
||||
app:iconTint="@color/brand_primary"
|
||||
app:iconGravity="textStart"
|
||||
app:iconPadding="20dp"
|
||||
app:iconSize="24dp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user