From a2390b72d5041a8fd314fcdedf6c66eb1dcaed1f Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 8 Sep 2024 18:23:08 -0400 Subject: Reset FAB position option in ViewPostDetailActivity. --- .../activities/ViewPostDetailActivity.java | 15 +++++++++--- .../customviews/MovableFloatingActionButton.java | 27 ++++++++++++++++++++-- .../main/res/menu/view_post_detail_activity.xml | 9 ++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/menu/view_post_detail_activity.xml (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index e0ee0210..0668a892 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -12,6 +12,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.view.KeyEvent; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewTreeObserver; @@ -287,9 +288,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } public void setTitle(String title) { - if (binding.toolbarViewPostDetailActivity != null) { - binding.toolbarViewPostDetailActivity.setTitle(title); - } + binding.toolbarViewPostDetailActivity.setTitle(title); } public void showFab() { @@ -737,11 +736,21 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele } } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.view_post_detail_activity, menu); + applyMenuItemTheme(menu); + return true; + } + @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); return true; + } else if (item.getItemId() == R.id.action_reset_fab_position_view_post_detail_activity) { + binding.fabViewPostDetailActivity.resetCoordinates(); + return true; } return false; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MovableFloatingActionButton.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MovableFloatingActionButton.java index 1a279ab7..edf28c60 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MovableFloatingActionButton.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/MovableFloatingActionButton.java @@ -102,13 +102,13 @@ public class MovableFloatingActionButton extends FloatingActionButton implements newY = Math.max(layoutParams.topMargin, newY); // Don't allow the FAB past the top of the parent newY = Math.min(parentHeight - viewHeight - layoutParams.bottomMargin, newY); // Don't allow the FAB past the bottom of the parent + saveCoordinates(newX, newY); + view.animate() .x(newX) .y(newY) .setDuration(0) .start(); - - saveCoordinates(newX, newY); return true; } else if (action == MotionEvent.ACTION_UP) { if (longClicked) { @@ -177,6 +177,29 @@ public class MovableFloatingActionButton extends FloatingActionButton implements } } + public void resetCoordinates() { + if (portrait) { + if (postDetailsSharedPreferences != null) { + postDetailsSharedPreferences + .edit() + .remove(SharedPreferencesUtils.getPostDetailFabPortraitX(display)) + .remove(SharedPreferencesUtils.getPostDetailFabPortraitY(display)) + .apply(); + } + } else { + if (postDetailsSharedPreferences != null) { + postDetailsSharedPreferences + .edit() + .remove(SharedPreferencesUtils.getPostDetailFabLandscapeX(display)) + .remove(SharedPreferencesUtils.getPostDetailFabLandscapeY(display)) + .apply(); + } + } + + setTranslationX(0); + setTranslationY(0); + } + private void saveCoordinates(float x, float y) { if (postDetailsSharedPreferences == null) { return; diff --git a/app/src/main/res/menu/view_post_detail_activity.xml b/app/src/main/res/menu/view_post_detail_activity.xml new file mode 100644 index 00000000..3abf5b56 --- /dev/null +++ b/app/src/main/res/menu/view_post_detail_activity.xml @@ -0,0 +1,9 @@ + +
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9b8a026a..ffc28bf4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -98,6 +98,7 @@