Fix issue #524 - List cannot be removed from "Manage timelines"
This commit is contained in:
parent
80023219b3
commit
4f8377d9d9
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<RecyclerView.
|
|||
|
||||
@Override
|
||||
public void onItemDismiss(int position) {
|
||||
notifyItemChanged(position);
|
||||
Toasty.info(context, context.getString(R.string.warning_main_timeline), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,14 +21,17 @@ import android.view.LayoutInflater;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelStoreOwner;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import app.fedilab.android.BaseMainActivity;
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.activities.ReorderTimelinesActivity;
|
||||
import app.fedilab.android.client.entities.app.Pinned;
|
||||
|
@ -36,11 +39,11 @@ import app.fedilab.android.client.entities.app.PinnedTimeline;
|
|||
import app.fedilab.android.client.entities.app.Timeline;
|
||||
import app.fedilab.android.databinding.DrawerReorderBinding;
|
||||
import app.fedilab.android.exception.DBException;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.itemtouchhelper.ItemTouchHelperAdapter;
|
||||
import app.fedilab.android.helper.itemtouchhelper.ItemTouchHelperViewHolder;
|
||||
import app.fedilab.android.helper.itemtouchhelper.OnStartDragListener;
|
||||
import app.fedilab.android.helper.itemtouchhelper.OnUndoListener;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -52,13 +55,11 @@ import es.dmoral.toasty.Toasty;
|
|||
public class ReorderTabAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> 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<RecyclerView.ViewHol
|
|||
}
|
||||
holder.binding.delete.setOnClickListener(v -> {
|
||||
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
|
||||
|
|
|
@ -1911,4 +1911,7 @@
|
|||
<string name="no_blocked_domains">You have not blocked domains</string>
|
||||
<string name="unblock_domain_confirm">Are you sure to unblock %1$s?</string>
|
||||
<string name="action_privacy_policy">Privacy policy</string>
|
||||
<string name="unpin_timeline">Remove pinned timeline?</string>
|
||||
<string name="unpin_timeline_description">Are you sure to unpin that timeline?</string>
|
||||
<string name="action_pinned_delete">Delete the pinned timelines?</string>
|
||||
</resources>
|
Loading…
Reference in New Issue