Skip to content

Commit

Permalink
Improve custom layouts in different form factors
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelvcaetano committed Nov 28, 2024
1 parent 5a45d2c commit 5a5ccb9
Show file tree
Hide file tree
Showing 70 changed files with 1,109 additions and 694 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ dependencies {
implementation(libs.androidx.room.rxjava)
implementation(libs.androidx.splashscreen)
implementation(libs.androidx.swiperefreshlayout)
implementation(libs.androidx.window)
implementation(libs.androidx.work)
implementation(libs.android.material)

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
<activity
android:name=".ui.layouteditor.LayoutEditorActivity"
android:theme="@style/EmulatorTheme"
android:label="@string/layout_editor">
android:label="@string/layout_editor"
android:configChanges="orientation|screenSize|screenSize">
</activity>
<activity
android:name=".ui.backgrounds.BackgroundsActivity"
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/me/magnum/melonds/di/MelonModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import me.magnum.melonds.domain.services.ConfigurationDirectoryVerifier
import me.magnum.melonds.domain.services.DSiNandManager
import me.magnum.melonds.impl.AndroidDSiNandManager
import me.magnum.melonds.impl.*
import me.magnum.melonds.impl.layout.UILayoutProvider
import me.magnum.melonds.impl.romprocessors.Api24RomFileProcessorFactory
import me.magnum.melonds.impl.romprocessors.OldRomFileProcessorFactory
import me.magnum.melonds.ui.romdetails.RomDetailsUiMapper
Expand Down Expand Up @@ -150,8 +151,13 @@ object MelonModule {

@Provides
@Singleton
fun provideDefaultLayoutBuilder(@ApplicationContext context: Context, screenUnitsConverter: ScreenUnitsConverter): DefaultLayoutProvider {
return DefaultLayoutProvider(context, screenUnitsConverter)
fun provideDefaultLayoutBuilder(screenUnitsConverter: ScreenUnitsConverter): DefaultLayoutProvider {
return DefaultLayoutProvider(screenUnitsConverter)
}

@Provides
fun provideUILayoutProvider(defaultLayoutProvider: DefaultLayoutProvider): UILayoutProvider {
return UILayoutProvider(defaultLayoutProvider)
}

@Provides
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/me/magnum/melonds/di/MigrationModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ object MigrationModule {
registerMigration(Migration24to25(genericJsonArrayMigrationHelper, context))
registerMigration(Migration25to26(genericJsonArrayMigrationHelper))
registerMigration(Migration30to31(genericJsonArrayMigrationHelper))
registerMigration(Migration31to32(context, genericJsonArrayMigrationHelper))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.magnum.melonds.domain.model

import android.net.Uri
import me.magnum.melonds.domain.model.ui.Orientation
import java.util.*

data class Background(val id: UUID?, val name: String, val orientation: Orientation, val uri: Uri)
15 changes: 0 additions & 15 deletions app/src/main/java/me/magnum/melonds/domain/model/BackgroundMode.kt

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/java/me/magnum/melonds/domain/model/Point.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package me.magnum.melonds.domain.model

class Point(var x: Int, var y: Int) {
data class Point(var x: Int, var y: Int) {
constructor() : this(0, 0)
}

This file was deleted.

7 changes: 6 additions & 1 deletion app/src/main/java/me/magnum/melonds/domain/model/Rect.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package me.magnum.melonds.domain.model

data class Rect(val x: Int, val y: Int, val width: Int, val height: Int)
data class Rect(val x: Int, val y: Int, val width: Int, val height: Int) {

val bottom get() = y + height

val right get() = x + width
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.magnum.melonds.domain.model

import me.magnum.melonds.domain.model.layout.BackgroundMode

data class RuntimeBackground(val background: Background?, val mode: BackgroundMode) {

companion object {
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/java/me/magnum/melonds/domain/model/UILayout.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.magnum.melonds.domain.model.layout

enum class BackgroundMode {
STRETCH,
FIT_CENTER,
FIT_TOP,
FIT_LEFT,
FIT_BOTTOM,
FIT_RIGHT;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.magnum.melonds.domain.model
package me.magnum.melonds.domain.model.layout

enum class LayoutComponent {
TOP_SCREEN,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.magnum.melonds.domain.model
package me.magnum.melonds.domain.model.layout

import java.util.UUID

Expand All @@ -9,20 +9,27 @@ data class LayoutConfiguration(
val orientation: LayoutOrientation,
val useCustomOpacity: Boolean,
val opacity: Int,
val portraitLayout: UILayout,
val landscapeLayout: UILayout
val layoutVariants: Map<UILayoutVariant, UILayout>,
) {

companion object {
val DEFAULT_ID = UUID(0, 0)

fun newCustom(portraitLayout: UILayout, landscapeLayout: UILayout): LayoutConfiguration {
return LayoutConfiguration(null, null, LayoutType.CUSTOM, LayoutOrientation.FOLLOW_SYSTEM, false, 50, portraitLayout, landscapeLayout)
fun newCustom(): LayoutConfiguration {
return LayoutConfiguration(
id = null,
name = null,
type = LayoutType.CUSTOM,
orientation = LayoutOrientation.FOLLOW_SYSTEM,
useCustomOpacity = false,
opacity = 50,
layoutVariants = emptyMap(),
)
}
}

// Empty constructor to include defaults that help in migrations
constructor() : this(null, null, LayoutType.CUSTOM, LayoutOrientation.FOLLOW_SYSTEM, false, 50, UILayout(), UILayout())
constructor() : this(null, null, LayoutType.CUSTOM, LayoutOrientation.FOLLOW_SYSTEM, false, 50, emptyMap())

enum class LayoutType {
DEFAULT,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package me.magnum.melonds.domain.model.layout

import me.magnum.melonds.domain.model.Rect

data class PositionedLayoutComponent(val rect: Rect, val component: LayoutComponent) {
fun isScreen(): Boolean {
return component.isScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.magnum.melonds.domain.model.layout

import me.magnum.melonds.domain.model.Rect
import me.magnum.melonds.domain.model.ui.Orientation

data class ScreenFold(
val orientation: Orientation,
val type: FoldType,
val foldBounds: Rect,
) {

enum class FoldType {
SEAMLESS,
GAP,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.magnum.melonds.domain.model.layout

import java.util.UUID

data class UILayout(
val backgroundId: UUID?,
val backgroundMode: BackgroundMode,
val components: List<PositionedLayoutComponent>?,
) {
// Empty constructor allow parsing after new data is added to the class
constructor() : this(null)

constructor(components: List<PositionedLayoutComponent>?): this(null, BackgroundMode.FIT_CENTER, components)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.magnum.melonds.domain.model.layout

import me.magnum.melonds.domain.model.Point
import me.magnum.melonds.domain.model.ui.Orientation

data class UILayoutVariant(
val uiSize: Point,
val orientation: Orientation,
val folds: List<ScreenFold>,
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.magnum.melonds.domain.model
package me.magnum.melonds.domain.model.ui

enum class Orientation {
PORTRAIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package me.magnum.melonds.domain.repositories
import io.reactivex.Completable
import io.reactivex.Maybe
import io.reactivex.Observable
import me.magnum.melonds.domain.model.LayoutConfiguration
import me.magnum.melonds.domain.model.layout.LayoutConfiguration
import java.util.*

interface LayoutsRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package me.magnum.melonds.extensions

import android.app.Activity
import android.content.pm.ActivityInfo
import me.magnum.melonds.domain.model.LayoutConfiguration
import me.magnum.melonds.domain.model.layout.LayoutConfiguration

/**
* Requests the best activity orientation that satisfies the given [layoutOrientation].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.view.children
import me.magnum.melonds.domain.model.BackgroundMode
import me.magnum.melonds.domain.model.layout.BackgroundMode

fun View.setViewEnabledRecursive(enabled: Boolean) {
this.isEnabled = enabled
Expand Down
Loading

0 comments on commit 5a5ccb9

Please sign in to comment.