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 e0ee021061..0668a892fc 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.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 void onGlobalLayout() { } 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 void onProvidePostListToViewPostDetailActivityEvent(ProvidePostListToView } } + @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 1a279ab721..edf28c6072 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 boolean onTouch(View view, MotionEvent motionEvent) { 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 void setCoordinates() { } } + 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 0000000000..3abf5b56f7 --- /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 9b8a026a86..ffc28bf474 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -98,6 +98,7 @@