-
-
Notifications
You must be signed in to change notification settings - Fork 392
4083 limit dialog sizes #4084
base: develop
Are you sure you want to change the base?
4083 limit dialog sizes #4084
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package com.keylesspalace.tusky.view | ||
|
|
||
| import android.util.Size | ||
| import android.view.ViewGroup | ||
| import android.view.Window | ||
| import android.view.WindowInsets | ||
| import androidx.fragment.app.DialogFragment | ||
| import com.keylesspalace.tusky.R | ||
| import com.keylesspalace.tusky.util.dpToPx | ||
|
|
||
| open class FullScreenDialogFragment : DialogFragment() { | ||
| /** | ||
| * Make sure the dialog window is full screen (minus normal insets like a device status bar). | ||
| * | ||
| * However the size is bounded to a maximum of `max_dialog_width_dp` and `max_dialog_height_dp` from the resources. | ||
| * So for example on tablet it does not fill the whole space. | ||
| */ | ||
| override fun onStart() { | ||
| super.onStart() | ||
| dialog?.apply { | ||
| window?.apply { | ||
| // On smaller devices this is -1 which is MATCH_PARENT | ||
| val maxWidthDp = resources.getInteger(R.integer.max_dialog_width_dp) | ||
| val maxHeightDp = resources.getInteger(R.integer.max_dialog_height_dp) | ||
|
|
||
| if (maxWidthDp == ViewGroup.LayoutParams.MATCH_PARENT && maxHeightDp == ViewGroup.LayoutParams.MATCH_PARENT) { | ||
| this.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) | ||
| } else { | ||
| val maxAvailablePixels = getAvailableScreenPixels(this) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway: I have the feeling this could be a one-line configuration somewhere. E. g. defining the right variable in a style and use that for dialogs? |
||
|
|
||
| var maxWidthSpec = if (maxWidthDp == -1) maxWidthDp else maxWidthDp.dpToPx(this.context.resources) | ||
| if (maxWidthSpec > maxAvailablePixels.width) { | ||
| maxWidthSpec = maxAvailablePixels.width | ||
| } | ||
| var maxHeightSpec = if (maxHeightDp == -1) maxHeightDp else maxHeightDp.dpToPx(this.context.resources) | ||
| if (maxHeightSpec > maxAvailablePixels.height) { | ||
| maxHeightSpec = maxAvailablePixels.height | ||
| } | ||
|
|
||
| this.setLayout(maxWidthSpec, maxHeightSpec) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Draft.. However this leads to this size being fixed. I. e. SOFT_INPUT_ADJUST_RESIZE not working anymore: Once the keyboard is visible half the (caption) dialog is covered and not scrollable... |
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun getAvailableScreenPixels(window: Window): Size { | ||
| val windowInsets = window.windowManager.maximumWindowMetrics.windowInsets | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Draft Unfortunately all methods and fields in this method are api level 30 (and not 24). The task should be simple: Get size available to / used by app window. |
||
| val insets = windowInsets.getInsets(WindowInsets.Type.captionBar() or WindowInsets.Type.systemBars() or | ||
| WindowInsets.Type.navigationBars() or WindowInsets.Type.statusBars()) | ||
| val maxAvailableDeviceWidth = window.context.resources.displayMetrics.widthPixels - insets.left - insets.right | ||
| val maxAvailableDeviceHeight = window.context.resources.displayMetrics.heightPixels - insets.top - insets.bottom | ||
|
|
||
| return Size(maxAvailableDeviceWidth, maxAvailableDeviceHeight) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <integer name="max_dialog_width_dp">800</integer> | ||
| <integer name="max_dialog_height_dp">1000</integer> | ||
| </resources> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <integer name="max_dialog_width_dp">600</integer> | ||
| <integer name="max_dialog_height_dp">1200</integer> | ||
| </resources> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <integer name="max_dialog_width_dp">-1</integer> | ||
| <integer name="max_dialog_height_dp">-1</integer> | ||
| <integer name="profile_media_column_count">3</integer> | ||
|
|
||
| <integer name="trending_column_count">1</integer> | ||
| </resources> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't have those, yet?