Skip to content
Merged
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
32 changes: 21 additions & 11 deletions app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.core.graphics.Insets
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
Expand Down Expand Up @@ -86,13 +89,13 @@ import org.thoughtcrime.securesms.reviews.ui.InAppReview
import org.thoughtcrime.securesms.reviews.ui.InAppReviewViewModel
import org.thoughtcrime.securesms.showSessionDialog
import org.thoughtcrime.securesms.tokenpage.TokenPageNotificationManager
import org.thoughtcrime.securesms.ui.ObserveAsEvents
import org.thoughtcrime.securesms.ui.UINavigator
import org.thoughtcrime.securesms.ui.components.Avatar
import org.thoughtcrime.securesms.ui.setThemedContent
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
import org.thoughtcrime.securesms.util.AvatarUtils
import org.thoughtcrime.securesms.util.DateUtils
import org.thoughtcrime.securesms.util.applySafeInsetsMargins
import org.thoughtcrime.securesms.util.applySafeInsetsPaddings
import org.thoughtcrime.securesms.util.disableClipping
import org.thoughtcrime.securesms.util.fadeIn
Expand Down Expand Up @@ -415,16 +418,6 @@ class HomeActivity : ScreenLockActionBarActivity(),
}
}

binding.root.applySafeInsetsPaddings(
applyBottom = false,
alsoApply = { insets ->
binding.globalSearchRecycler.updatePadding(bottom = insets.bottom)
binding.newConversationButton.updateLayoutParams<MarginLayoutParams> {
bottomMargin = insets.bottom + resources.getDimensionPixelSize(R.dimen.new_conversation_button_bottom_offset)
}
}
)

// Set up in-app review
binding.inAppReviewView.setThemedContent {
InAppReview(
Expand All @@ -433,6 +426,8 @@ class HomeActivity : ScreenLockActionBarActivity(),
sendCommands = inAppReviewViewModel::sendUiCommand,
)
}

applyViewInsets()
}

override fun onCancelClicked() {
Expand Down Expand Up @@ -893,6 +888,21 @@ class HomeActivity : ScreenLockActionBarActivity(),
private fun showStartConversation() {
homeViewModel.onCommand(HomeViewModel.Commands.ShowStartConversationSheet)
}

private fun applyViewInsets() {
binding.root.applySafeInsetsPaddings(
applyBottom = false,
consumeInsets = false,
alsoApply = { insets ->
binding.globalSearchRecycler.updatePadding(bottom = insets.bottom)
}
)

binding.newConversationButton.applySafeInsetsMargins(
typeMask = WindowInsetsCompat.Type.navigationBars(),
additionalInsets = Insets.of(0,0,0, resources.getDimensionPixelSize(R.dimen.new_conversation_button_bottom_offset))
)
}
}

fun Context.startHomeActivity(isFromOnboarding: Boolean, isNewAccount: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ fun View.applySafeInsetsMargins(
consumeInsets: Boolean = true,
@InsetsType
typeMask: Int = WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.ime(),
additionalInsets : Insets = Insets.NONE // for additional offsets
) {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets ->
// Get system bars insets
Expand All @@ -162,7 +163,7 @@ fun View.applySafeInsetsMargins(
// Update view margins to account for system bars
val lp = view.layoutParams as? MarginLayoutParams
if (lp != null) {
lp.setMargins(systemBarsInsets.left, systemBarsInsets.top, systemBarsInsets.right, systemBarsInsets.bottom)
lp.setMargins(additionalInsets.left + systemBarsInsets.left, additionalInsets.top + systemBarsInsets.top, additionalInsets.right + systemBarsInsets.right, additionalInsets.bottom + systemBarsInsets.bottom)
view.layoutParams = lp

if (consumeInsets) {
Expand Down