Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2017 Andrew Dawson
/* Copyright 2023 Tusky contributors
*
* This file is a part of Tusky.
*
Expand All @@ -20,9 +20,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.appcompat.widget.SearchView
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
Expand All @@ -43,14 +41,15 @@ import com.keylesspalace.tusky.util.loadAvatar
import com.keylesspalace.tusky.util.show
import com.keylesspalace.tusky.util.unsafeLazy
import com.keylesspalace.tusky.util.viewBinding
import com.keylesspalace.tusky.view.FullScreenDialogFragment
import com.keylesspalace.tusky.viewmodel.AccountsInListViewModel
import com.keylesspalace.tusky.viewmodel.State
import kotlinx.coroutines.launch
import javax.inject.Inject

private typealias AccountInfo = Pair<TimelineAccount, Boolean>

class AccountsInListFragment : DialogFragment(), Injectable {
class AccountsInListFragment : FullScreenDialogFragment(), Injectable {

@Inject
lateinit var viewModelFactory: ViewModelFactory
Expand Down Expand Up @@ -78,14 +77,6 @@ class AccountsInListFragment : DialogFragment(), Injectable {
viewModel.load(listId)
}

override fun onStart() {
super.onStart()
dialog?.apply {
// Stretch dialog to the window
window?.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_accounts_in_list, container, false)
}
Expand Down Expand Up @@ -257,3 +248,4 @@ class AccountsInListFragment : DialogFragment(), Injectable {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DiffUtil
Expand All @@ -38,11 +36,12 @@ import com.keylesspalace.tusky.util.hide
import com.keylesspalace.tusky.util.show
import com.keylesspalace.tusky.util.viewBinding
import com.keylesspalace.tusky.util.visible
import com.keylesspalace.tusky.view.FullScreenDialogFragment
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import javax.inject.Inject

class ListsForAccountFragment : DialogFragment(), Injectable {
class ListsForAccountFragment : FullScreenDialogFragment(), Injectable {

@Inject
lateinit var viewModelFactory: ViewModelFactory
Expand All @@ -59,16 +58,6 @@ class ListsForAccountFragment : DialogFragment(), Injectable {
viewModel.setup(requireArguments().getString(ARG_ACCOUNT_ID)!!)
}

override fun onStart() {
super.onStart()
dialog?.apply {
window?.setLayout(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
)
}
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.EditText
import android.widget.LinearLayout
import androidx.core.os.BundleCompat
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy
import com.bumptech.glide.request.target.CustomTarget
Expand All @@ -37,11 +35,12 @@ import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.databinding.DialogImageDescriptionBinding
import com.keylesspalace.tusky.util.hide
import com.keylesspalace.tusky.util.viewBinding
import com.keylesspalace.tusky.view.FullScreenDialogFragment

// https://github.com/tootsuite/mastodon/blob/c6904c0d3766a2ea8a81ab025c127169ecb51373/app/models/media_attachment.rb#L32
private const val MEDIA_DESCRIPTION_CHARACTER_LIMIT = 1500

class CaptionDialog : DialogFragment() {
class CaptionDialog : FullScreenDialogFragment() {
private lateinit var listener: Listener
private lateinit var input: EditText

Expand Down Expand Up @@ -116,10 +115,6 @@ class CaptionDialog : DialogFragment() {
override fun onStart() {
super.onStart()
dialog?.apply {
window?.setLayout(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
)
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
}
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/keylesspalace/tusky/util/ViewExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

package com.keylesspalace.tusky.util

import android.content.res.Resources
import android.util.Log
import android.util.TypedValue
import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import kotlin.math.roundToInt

fun View.show() {
this.visibility = View.VISIBLE
Expand Down Expand Up @@ -78,3 +81,15 @@ fun TextView.fixTextSelection() {
setTextIsSelectable(false)
post { setTextIsSelectable(true) }
}

fun Float.dpToPx(resource: Resources): Float {
Copy link
Collaborator Author

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?

return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this,
resource.displayMetrics
)
}

fun Int.dpToPx(resource: Resources): Int {
return this.toFloat().dpToPx(resource).roundToInt()
}
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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Copy link
Collaborator Author

@Lakoja Lakoja Jan 3, 2024

Choose a reason for hiding this comment

The 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)
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/values-large-land/integers.xml
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>
5 changes: 5 additions & 0 deletions app/src/main/res/values-large/integers.xml
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>
3 changes: 2 additions & 1 deletion app/src/main/res/values/integers.xml
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>