Skip to content

Commit

Permalink
Move popup messages of the main screen to cover the bottom app bar
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Jan 23, 2024
1 parent db1450e commit 2d7c125
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Move the popup messages of the main screen to the absolute bottom of the screen, now covering the
bottom app bar. Avoids covering the bottom row of number buttons when checking if there are errors.

### Deprecated

### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
Expand Down Expand Up @@ -381,8 +382,22 @@ class MainActivity : AppCompatActivity(), GridCreationListener {
}

val snackbar =
Snackbar.make(binding.hintOrNewGame, text, duration)
.setAnchorView(binding.hintOrNewGame)
Snackbar.make(binding.root, text, duration)

val params = snackbar.view.layoutParams as ViewGroup.MarginLayoutParams

val startMarginOfBottomAppBar =
(binding.mainBottomAppBar.layoutParams as ViewGroup.MarginLayoutParams)
.marginStart

params.setMargins(
params.leftMargin + startMarginOfBottomAppBar,
params.topMargin,
params.rightMargin,
params.bottomMargin,
)

snackbar.view.layoutParams = params

if (mistakes > 0 && game.undoManager.isUndoPossible()) {
snackbar.setAction(resources.getText(R.string.hint_as_toast_undo_last_step)) {
Expand All @@ -396,17 +411,15 @@ class MainActivity : AppCompatActivity(), GridCreationListener {

private fun showSnackbar(string: String): Snackbar {
val snackbar =
Snackbar.make(binding.hintOrNewGame, string, Snackbar.LENGTH_LONG)
.setAnchorView(binding.hintOrNewGame)
Snackbar.make(binding.root, string, Snackbar.LENGTH_LONG)

snackbar.show()

return snackbar
}

fun gameSaved() {
Snackbar.make(binding.hintOrNewGame, resources.getText(R.string.main_activity_current_game_saved), Snackbar.LENGTH_LONG)
.setAnchorView(binding.hintOrNewGame)
Snackbar.make(binding.root, resources.getText(R.string.main_activity_current_game_saved), Snackbar.LENGTH_LONG)
.show()
}

Expand Down
2 changes: 1 addition & 1 deletion gauguin-app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="48dp"
android:layout_marginBottom="72dp"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@id/gridview"
app:layout_constraintTop_toBottomOf="@id/gameTopFrame"
Expand Down
2 changes: 1 addition & 1 deletion gauguin-app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:id="@+id/mainConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="48dp">
android:layout_marginBottom="72dp">

<FrameLayout
android:id="@+id/gameTopFrame"
Expand Down

0 comments on commit 2d7c125

Please sign in to comment.