From f0c36819b73fd0a41c6b96340027d1355dd9f9b4 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 18 May 2022 18:35:00 +0200 Subject: [PATCH] Fix issue #56 - Overlap with undo action --- .../activities/ReorderTimelinesActivity.java | 33 ++++++++------- .../main/res/layout/activity_reorder_tabs.xml | 42 +------------------ 2 files changed, 20 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/ReorderTimelinesActivity.java b/app/src/main/java/app/fedilab/android/activities/ReorderTimelinesActivity.java index 53924c51f..e5466ff2a 100644 --- a/app/src/main/java/app/fedilab/android/activities/ReorderTimelinesActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ReorderTimelinesActivity.java @@ -19,7 +19,6 @@ import static app.fedilab.android.helper.PinnedTimelineHelper.sortMenuItem; import static app.fedilab.android.helper.PinnedTimelineHelper.sortPositionAsc; import android.content.Intent; -import android.graphics.Paint; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.os.Handler; @@ -28,7 +27,6 @@ import android.text.InputFilter; import android.text.TextWatcher; import android.view.Menu; import android.view.MenuItem; -import android.view.View; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; @@ -43,6 +41,8 @@ import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.snackbar.Snackbar; + import java.io.IOException; import java.util.ArrayList; import java.util.concurrent.TimeUnit; @@ -346,21 +346,22 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra @Override public void onUndo(PinnedTimeline pinnedTimeline, int position) { - binding.undoContainer.setVisibility(View.VISIBLE); + + String text = ""; switch (pinnedTimeline.type) { case TAG: - binding.undoMessage.setText(R.string.reorder_tag_removed); + text = getString(R.string.reorder_tag_removed); break; case REMOTE: - binding.undoMessage.setText(R.string.reorder_instance_removed); + text = getString(R.string.reorder_instance_removed); break; case LIST: - binding.undoMessage.setText(R.string.reorder_list_deleted); + text = getString(R.string.reorder_list_deleted); break; } - binding.undoAction.setPaintFlags(binding.undoAction.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + + Runnable runnable = () -> { - binding.undoContainer.setVisibility(View.GONE); //change position of pinned that are after the removed item for (int i = pinnedTimeline.position + 1; i < pinned.pinnedTimelines.size(); i++) { pinned.pinnedTimelines.get(i).position -= 1; @@ -376,12 +377,16 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra }; Handler handler = new Handler(); handler.postDelayed(runnable, 4000); - binding.undoAction.setOnClickListener(v -> { - pinned.pinnedTimelines.add(position, pinnedTimeline); - reorderTabAdapter.notifyItemInserted(position); - binding.undoContainer.setVisibility(View.GONE); - handler.removeCallbacks(runnable); - }); + Snackbar.make(binding.getRoot(), text, 4000) + .setAction(getString(R.string.undo), view -> { + pinned.pinnedTimelines.add(position, pinnedTimeline); + reorderTabAdapter.notifyItemInserted(position); + handler.removeCallbacks(runnable); + }) + .setTextColor(ThemeHelper.getAttColor(ReorderTimelinesActivity.this, R.attr.mTextColor)) + .setActionTextColor(ContextCompat.getColor(ReorderTimelinesActivity.this, R.color.cyanea_accent_reference)) + .setBackgroundTint(ContextCompat.getColor(ReorderTimelinesActivity.this, R.color.cyanea_primary_dark_reference)) + .show(); } @Override diff --git a/app/src/main/res/layout/activity_reorder_tabs.xml b/app/src/main/res/layout/activity_reorder_tabs.xml index 7d99742ac..4a9bfc13a 100644 --- a/app/src/main/res/layout/activity_reorder_tabs.xml +++ b/app/src/main/res/layout/activity_reorder_tabs.xml @@ -20,7 +20,7 @@ android:layout_width="match_parent" android:layout_marginStart="@dimen/fab_margin" android:layout_marginEnd="@dimen/fab_margin" - android:layout_height="match_parent"> + android:layout_height="wrap_content"> - - - - - - -