Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 55
ADFA-77 Enable landscape mode#993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
ec06e7a0c7e3ad15e6479ff6aa6b987eb7ad9b803be32a3c587772d72ab670995ad905c779355a7ba879234fc0517b0964File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -84,24 +84,37 @@ | ||
| </activity> | ||
| <activity | ||
| android:name=".activities.OnboardingActivity" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize" | ||
| android:exported="false" /> | ||
| <activity | ||
| android:name=".activities.MainActivity" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize" | ||
| android:exported="false" | ||
| android:theme="@style/Theme.AndroidIDE" /> | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| <activity | ||
| android:name=".activities.editor.EditorActivityKt" | ||
| android:configChanges="orientation|screenSize" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize" | ||
| android:launchMode="singleTask" | ||
| android:windowSoftInputMode="adjustResize" /> | ||
| <activity android:name=".activities.PreferencesActivity" /> | ||
| <activity android:name=".activities.PluginManagerActivity" /> | ||
| <activity | ||
| android:name=".activities.PreferencesActivity" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize" /> | ||
| <activity | ||
| android:name=".activities.PluginManagerActivity" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize" /> | ||
| <activity android:name=".activities.AboutActivity" /> | ||
| <activity android:name=".activities.editor.FAQActivity" /> | ||
| <activity android:name=".activities.editor.HelpActivity" /> | ||
| <activity android:name=".activities.ContributorsActivity" /> | ||
| <activity | ||
| android:name=".activities.editor.FAQActivity" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize" /> | ||
| <activity | ||
| android:name=".activities.editor.HelpActivity" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize" /> | ||
| <activity | ||
| android:name=".activities.ContributorsActivity" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize" /> | ||
| <activity | ||
| android:name=".activities.TerminalActivity" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize" | ||
| android:windowSoftInputMode="adjustResize" /> | ||
| <!-- Required: set your sentry.io project identifier (DSN) --> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,6 +18,7 @@ | ||
| package com.itsaky.androidide.activities | ||
| import android.content.Intent | ||
| import android.content.res.Configuration | ||
| import android.os.Bundle | ||
| import android.view.View | ||
| import androidx.activity.OnBackPressedCallback | ||
| @@ -47,6 +48,8 @@ import com.itsaky.androidide.utils.FeatureFlags | ||
| import com.itsaky.androidide.utils.UrlManager | ||
| import com.itsaky.androidide.utils.findValidProjects | ||
| import com.itsaky.androidide.utils.flashInfo | ||
| import com.itsaky.androidide.fragments.MainFragment | ||
| import com.itsaky.androidide.fragments.RecentProjectsFragment | ||
| import com.itsaky.androidide.viewmodel.MainViewModel | ||
| import com.itsaky.androidide.viewmodel.MainViewModel.Companion.SCREEN_DELETE_PROJECTS | ||
| import com.itsaky.androidide.viewmodel.MainViewModel.Companion.SCREEN_MAIN | ||
| @@ -168,22 +171,53 @@ class MainActivity : EdgeToEdgeIDEActivity() { | ||
| builder.show() | ||
| } | ||
| override fun onConfigurationChanged(newConfig: Configuration) { | ||
| super.onConfigurationChanged(newConfig) | ||
| recreateVisibleFragmentView() | ||
| } | ||
hal-eisen-adfa marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| override fun onResume() { | ||
| super.onResume() | ||
| feedbackButtonManager?.loadFabPosition() | ||
| } | ||
| /** | ||
| * With configChanges="orientation|screenSize", the activity is not recreated on rotation, | ||
| * so fragment views stay inflated with the initial layout. Replace the visible fragment | ||
| * with a new instance so it re-inflates and picks up layout-land when in landscape. | ||
| */ | ||
| private fun recreateVisibleFragmentView() { | ||
| when (viewModel.currentScreen.value) { | ||
| SCREEN_MAIN -> | ||
| supportFragmentManager.beginTransaction() | ||
| .setReorderingAllowed(true) | ||
| .replace(R.id.main, MainFragment()) | ||
| .commitNow() | ||
| SCREEN_SAVED_PROJECTS -> | ||
| supportFragmentManager.beginTransaction() | ||
| .setReorderingAllowed(true) | ||
| .replace(R.id.saved_projects_view, RecentProjectsFragment()) | ||
| .commitNow() | ||
| else -> { } | ||
| } | ||
| } | ||
| override fun onApplySystemBarInsets(insets: Insets) { | ||
| // onApplySystemBarInsets can be called before bindLayout() sets _binding | ||
| // Use 0 for bottom so fragment content stretches to the screen bottom (no white bar). | ||
| _binding?.fragmentContainersParent?.setPadding( | ||
| insets.left, | ||
| 0, | ||
| insets.right, | ||
| insets.bottom, | ||
| 0, | ||
| ) | ||
hal-eisen-adfa marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| private fun onScreenChanged(screen: Int?) { | ||
| // When navigating to main (e.g. Exit from saved projects), replace the fragment so it | ||
| // inflates with the current configuration (landscape -> 3 columns, portrait -> 1 column). | ||
| if (screen == SCREEN_MAIN) recreateVisibleFragmentView() | ||
| val previous = viewModel.previousScreen | ||
| if (previous != -1) { | ||
| closeKeyboard() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,6 +18,7 @@ | ||
| package com.itsaky.androidide.activities.editor | ||
| import android.content.ComponentName | ||
| import android.content.res.Configuration | ||
| import android.content.Intent | ||
| import android.content.ServiceConnection | ||
| import android.graphics.Color | ||
| @@ -40,6 +41,8 @@ import android.view.MotionEvent | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import android.view.ViewTreeObserver.OnGlobalLayoutListener | ||
| import android.widget.LinearLayout | ||
| import android.widget.TextView | ||
| import androidx.activity.OnBackPressedCallback | ||
| import androidx.activity.result.ActivityResult | ||
| import androidx.activity.result.ActivityResultLauncher | ||
| @@ -596,6 +599,7 @@ abstract class BaseEditorActivity : | ||
| } | ||
| setupToolbar() | ||
| syncProjectToolbarRowForOrientation(resources.configuration.orientation) | ||
| setupDrawers() | ||
| content.tabs.addOnTabSelectedListener(this) | ||
| @@ -631,6 +635,11 @@ abstract class BaseEditorActivity : | ||
| setupGestureDetector() | ||
| } | ||
| override fun onConfigurationChanged(newConfig: Configuration) { | ||
| super.onConfigurationChanged(newConfig) | ||
| syncProjectToolbarRowForOrientation(newConfig.orientation) | ||
| } | ||
| private fun setupToolbar() { | ||
| // Set the project name in the title TextView | ||
| content.root.findViewById<android.widget.TextView>(R.id.title_text)?.apply { | ||
| @@ -682,6 +691,88 @@ abstract class BaseEditorActivity : | ||
| } | ||
| } | ||
| private fun syncProjectToolbarRowForOrientation(currentOrientation: Int) { | ||
| val appBar = content.editorAppBarLayout | ||
| val titleToolbar = content.titleToolbar | ||
| val actionsToolbar = content.projectActionsToolbar | ||
| val titleParent = titleToolbar.parent as? ViewGroup ?: return | ||
| val actionsParent = actionsToolbar.parent as? ViewGroup ?: return | ||
| if (titleParent != actionsParent) return | ||
| val isLandscape = currentOrientation == Configuration.ORIENTATION_LANDSCAPE | ||
| if (isLandscape && titleParent === appBar) { | ||
| val insertAt = | ||
| minOf( | ||
| appBar.indexOfChild(titleToolbar), | ||
| appBar.indexOfChild(actionsToolbar), | ||
| ).coerceAtLeast(0) | ||
| val row = | ||
| LinearLayout(this).apply { | ||
| orientation = LinearLayout.HORIZONTAL | ||
| gravity = Gravity.CENTER_VERTICAL | ||
| layoutParams = | ||
| com.google.android.material.appbar.AppBarLayout.LayoutParams( | ||
| ViewGroup.LayoutParams.MATCH_PARENT, | ||
| ViewGroup.LayoutParams.WRAP_CONTENT, | ||
| ) | ||
| } | ||
| appBar.removeView(titleToolbar) | ||
| appBar.removeView(actionsToolbar) | ||
| titleToolbar.layoutParams = | ||
| LinearLayout.LayoutParams( | ||
| 0, | ||
| ViewGroup.LayoutParams.WRAP_CONTENT, | ||
| 1f, | ||
| ) | ||
| actionsToolbar.layoutParams = | ||
| LinearLayout.LayoutParams( | ||
| ViewGroup.LayoutParams.WRAP_CONTENT, | ||
| ViewGroup.LayoutParams.WRAP_CONTENT, | ||
| ).apply { marginEnd = SizeUtils.dp2px(8f) } | ||
| content.root.findViewById<TextView>(R.id.title_text)?.updateLayoutParams<ViewGroup.MarginLayoutParams> { | ||
| marginEnd = SizeUtils.dp2px(8f) | ||
| } | ||
| row.addView(titleToolbar) | ||
| row.addView(actionsToolbar) | ||
| appBar.addView(row, insertAt) | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| return | ||
| } | ||
| if (!isLandscape && titleParent is LinearLayout && titleParent.parent === appBar) { | ||
| val row = titleParent | ||
| val insertAt = appBar.indexOfChild(row).coerceAtLeast(0) | ||
| row.removeView(titleToolbar) | ||
| row.removeView(actionsToolbar) | ||
| appBar.removeView(row) | ||
| titleToolbar.layoutParams = | ||
| com.google.android.material.appbar.AppBarLayout.LayoutParams( | ||
| ViewGroup.LayoutParams.MATCH_PARENT, | ||
| ViewGroup.LayoutParams.WRAP_CONTENT, | ||
| ) | ||
| actionsToolbar.layoutParams = | ||
| com.google.android.material.appbar.AppBarLayout.LayoutParams( | ||
| ViewGroup.LayoutParams.MATCH_PARENT, | ||
| ViewGroup.LayoutParams.WRAP_CONTENT, | ||
| ).apply { | ||
| topMargin = SizeUtils.dp2px(4f) | ||
| } | ||
| content.root.findViewById<TextView>(R.id.title_text)?.updateLayoutParams<ViewGroup.MarginLayoutParams> { | ||
| marginEnd = SizeUtils.dp2px(16f) | ||
| } | ||
| appBar.addView(titleToolbar, insertAt) | ||
| appBar.addView(actionsToolbar, insertAt + 1) | ||
| } | ||
| } | ||
| private fun onSwipeRevealDragProgress(progress: Float) { | ||
| _binding?.apply { | ||
| contentCard.progress = progress | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.