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 2a9ff539d..dc1eb145a 100644 --- a/app/src/main/java/app/fedilab/android/activities/ReorderTimelinesActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ReorderTimelinesActivity.java @@ -22,7 +22,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; -import android.os.Handler; import android.text.Editable; import android.text.TextWatcher; import android.view.Menu; @@ -43,8 +42,6 @@ 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; @@ -62,7 +59,6 @@ import app.fedilab.android.exception.DBException; import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.ThemeHelper; import app.fedilab.android.helper.itemtouchhelper.OnStartDragListener; -import app.fedilab.android.helper.itemtouchhelper.OnUndoListener; import app.fedilab.android.helper.itemtouchhelper.SimpleItemTouchHelperCallback; import app.fedilab.android.ui.drawer.ReorderBottomMenuAdapter; import app.fedilab.android.ui.drawer.ReorderTabAdapter; @@ -78,7 +74,7 @@ import okhttp3.RequestBody; import okhttp3.Response; -public class ReorderTimelinesActivity extends BaseActivity implements OnStartDragListener, OnUndoListener { +public class ReorderTimelinesActivity extends BaseActivity implements OnStartDragListener { private ItemTouchHelper touchHelper; @@ -132,7 +128,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra update = false; } sortPositionAsc(this.pinned.pinnedTimelines); - reorderTabAdapter = new ReorderTabAdapter(this.pinned, ReorderTimelinesActivity.this, ReorderTimelinesActivity.this); + reorderTabAdapter = new ReorderTabAdapter(this.pinned, ReorderTimelinesActivity.this); ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(reorderTabAdapter); touchHelper = new ItemTouchHelper(callback); @@ -393,51 +389,6 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra } - @Override - public void onUndo(PinnedTimeline pinnedTimeline, int position) { - - String text = ""; - switch (pinnedTimeline.type) { - case TAG: - text = getString(R.string.reorder_tag_removed); - break; - case REMOTE: - text = getString(R.string.reorder_instance_removed); - break; - case LIST: - text = getString(R.string.reorder_list_deleted); - break; - } - - - Runnable runnable = () -> { - //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; - } - pinned.pinnedTimelines.remove(pinnedTimeline); - reorderTabAdapter.notifyItemRemoved(position); - try { - new Pinned(ReorderTimelinesActivity.this).updatePinned(pinned); - changes = true; - } catch (DBException e) { - e.printStackTrace(); - } - }; - Handler handler = new Handler(); - handler.postDelayed(runnable, 4000); - 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 public void onStop() { super.onStop(); diff --git a/app/src/main/java/app/fedilab/android/helper/itemtouchhelper/SimpleItemTouchHelperCallback.java b/app/src/main/java/app/fedilab/android/helper/itemtouchhelper/SimpleItemTouchHelperCallback.java index f929d9d02..3c42ab280 100644 --- a/app/src/main/java/app/fedilab/android/helper/itemtouchhelper/SimpleItemTouchHelperCallback.java +++ b/app/src/main/java/app/fedilab/android/helper/itemtouchhelper/SimpleItemTouchHelperCallback.java @@ -64,7 +64,7 @@ public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback { return makeMovementFlags(dragFlags, swipeFlags); } else { final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN; - final int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END; + final int swipeFlags = 0; return makeMovementFlags(dragFlags, swipeFlags); } } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ReorderBottomMenuAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ReorderBottomMenuAdapter.java index 5d0e4dd01..052a5c678 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ReorderBottomMenuAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ReorderBottomMenuAdapter.java @@ -20,7 +20,6 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.ViewGroup; -import android.widget.Toast; import androidx.recyclerview.widget.RecyclerView; @@ -36,7 +35,6 @@ import app.fedilab.android.exception.DBException; import app.fedilab.android.helper.itemtouchhelper.ItemTouchHelperAdapter; import app.fedilab.android.helper.itemtouchhelper.ItemTouchHelperViewHolder; import app.fedilab.android.helper.itemtouchhelper.OnStartDragListener; -import es.dmoral.toasty.Toasty; /** @@ -130,8 +128,6 @@ public class ReorderBottomMenuAdapter extends RecyclerView.Adapter implements ItemTouchHelperAdapter { private final OnStartDragListener mDragStartListener; - private final OnUndoListener mUndoListener; private final Pinned pinned; private Context context; - public ReorderTabAdapter(Pinned pinned, OnStartDragListener dragStartListener, OnUndoListener undoListener) { + public ReorderTabAdapter(Pinned pinned, OnStartDragListener dragStartListener) { this.mDragStartListener = dragStartListener; - this.mUndoListener = undoListener; this.pinned = pinned; } @@ -169,26 +170,61 @@ public class ReorderTabAdapter extends RecyclerView.Adapter { if (item.type == Timeline.TimeLineEnum.TAG || item.type == Timeline.TimeLineEnum.REMOTE || item.type == Timeline.TimeLineEnum.LIST) { - mUndoListener.onUndo(item, position); - if (position < pinned.pinnedTimelines.size()) { - pinned.pinnedTimelines.remove(position); - notifyItemRemoved(position); + AlertDialog.Builder alt_bld = new AlertDialog.Builder(context, Helper.dialogStyle()); + String title = ""; + String message = ""; + alt_bld.setTitle(R.string.action_lists_delete); + alt_bld.setMessage(R.string.action_lists_confirm_delete); + switch (item.type) { + case TAG: + case REMOTE: + title = context.getString(R.string.action_pinned_delete); + message = context.getString(R.string.unpin_timeline_description); + break; + case LIST: + title = context.getString(R.string.action_lists_delete); + message = context.getString(R.string.action_lists_confirm_delete); + break; } + alt_bld.setTitle(title); + alt_bld.setMessage(message); + + alt_bld.setPositiveButton(R.string.delete, (dialog, id) -> { + //change position of pinned that are after the removed item + if (position < pinned.pinnedTimelines.size()) { + for (int i = item.position + 1; i < pinned.pinnedTimelines.size(); i++) { + pinned.pinnedTimelines.get(i).position -= 1; + } + pinned.pinnedTimelines.remove(position); + notifyItemRemoved(position); + notifyItemChanged(position, pinned.pinnedTimelines.size() - position); + try { + new Pinned(context).updatePinned(pinned); + } catch (DBException e) { + e.printStackTrace(); + } + } + + if (item.type == Timeline.TimeLineEnum.LIST) { + TimelinesVM timelinesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(TimelinesVM.class); + timelinesVM.deleteList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, item.mastodonList.id); + } + + + ((ReorderTimelinesActivity) context).setChanges(true); + dialog.dismiss(); + + }); + alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); + AlertDialog alert = alt_bld.create(); + alert.show(); + } }); } @Override public void onItemDismiss(int position) { - PinnedTimeline item = pinned.pinnedTimelines.get(position); - if (item.type == Timeline.TimeLineEnum.TAG || item.type == Timeline.TimeLineEnum.REMOTE || item.type == Timeline.TimeLineEnum.LIST) { - mUndoListener.onUndo(item, position); - pinned.pinnedTimelines.remove(position); - notifyItemRemoved(position); - } else { - notifyItemChanged(position); - Toasty.info(context, context.getString(R.string.warning_main_timeline), Toast.LENGTH_SHORT).show(); - } } @Override diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0eec9af99..9d8b5255b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1911,4 +1911,7 @@ You have not blocked domains Are you sure to unblock %1$s? Privacy policy + Remove pinned timeline? + Are you sure to unpin that timeline? + Delete the pinned timelines? \ No newline at end of file