diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-09-08 22:23:08 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-09-08 22:23:08 +0000 |
commit | a2390b72d5041a8fd314fcdedf6c66eb1dcaed1f (patch) | |
tree | 47e0860613a1024c4f6f8d07759d2c314988f383 /app/src | |
parent | 72036e4744f206d505cb6b8cc67ceb7ab39f9440 (diff) | |
download | infinity-for-reddit-a2390b72d5041a8fd314fcdedf6c66eb1dcaed1f.tar infinity-for-reddit-a2390b72d5041a8fd314fcdedf6c66eb1dcaed1f.tar.gz infinity-for-reddit-a2390b72d5041a8fd314fcdedf6c66eb1dcaed1f.tar.bz2 infinity-for-reddit-a2390b72d5041a8fd314fcdedf6c66eb1dcaed1f.tar.lz infinity-for-reddit-a2390b72d5041a8fd314fcdedf6c66eb1dcaed1f.tar.xz infinity-for-reddit-a2390b72d5041a8fd314fcdedf6c66eb1dcaed1f.tar.zst infinity-for-reddit-a2390b72d5041a8fd314fcdedf6c66eb1dcaed1f.zip |
Reset FAB position option in ViewPostDetailActivity.
Diffstat (limited to 'app/src')
4 files changed, 47 insertions, 5 deletions
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() { @@ -738,10 +737,20 @@ 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + <item + android:id="@+id/action_reset_fab_position_view_post_detail_activity" + android:orderInCategory="100" + android:title="@string/action_reset_fab_position" + app:showAsAction="never" /> +</menu>
\ 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 @@ <string name="action_contact_mods">Contact Mods</string> <string name="action_more_options">More Options</string> <string name="action_add_to_home_screen">Add to Home screen</string> + <string name="action_reset_fab_position">Reset FAB position</string> <string name="parse_json_response_error">Error occurred when parsing the JSON response</string> <string name="retrieve_token_error">Error Retrieving the token</string> |