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.content.SharedPreferences;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
@ -43,8 +42,6 @@ import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.TimeUnit;
|
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.Helper;
|
||||||
import app.fedilab.android.helper.ThemeHelper;
|
import app.fedilab.android.helper.ThemeHelper;
|
||||||
import app.fedilab.android.helper.itemtouchhelper.OnStartDragListener;
|
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.helper.itemtouchhelper.SimpleItemTouchHelperCallback;
|
||||||
import app.fedilab.android.ui.drawer.ReorderBottomMenuAdapter;
|
import app.fedilab.android.ui.drawer.ReorderBottomMenuAdapter;
|
||||||
import app.fedilab.android.ui.drawer.ReorderTabAdapter;
|
import app.fedilab.android.ui.drawer.ReorderTabAdapter;
|
||||||
|
@ -78,7 +74,7 @@ import okhttp3.RequestBody;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
|
||||||
public class ReorderTimelinesActivity extends BaseActivity implements OnStartDragListener, OnUndoListener {
|
public class ReorderTimelinesActivity extends BaseActivity implements OnStartDragListener {
|
||||||
|
|
||||||
|
|
||||||
private ItemTouchHelper touchHelper;
|
private ItemTouchHelper touchHelper;
|
||||||
|
@ -132,7 +128,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
|
||||||
update = false;
|
update = false;
|
||||||
}
|
}
|
||||||
sortPositionAsc(this.pinned.pinnedTimelines);
|
sortPositionAsc(this.pinned.pinnedTimelines);
|
||||||
reorderTabAdapter = new ReorderTabAdapter(this.pinned, ReorderTimelinesActivity.this, ReorderTimelinesActivity.this);
|
reorderTabAdapter = new ReorderTabAdapter(this.pinned, ReorderTimelinesActivity.this);
|
||||||
ItemTouchHelper.Callback callback =
|
ItemTouchHelper.Callback callback =
|
||||||
new SimpleItemTouchHelperCallback(reorderTabAdapter);
|
new SimpleItemTouchHelperCallback(reorderTabAdapter);
|
||||||
touchHelper = new ItemTouchHelper(callback);
|
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
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback {
|
||||||
return makeMovementFlags(dragFlags, swipeFlags);
|
return makeMovementFlags(dragFlags, swipeFlags);
|
||||||
} else {
|
} else {
|
||||||
final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
|
final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
|
||||||
final int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
|
final int swipeFlags = 0;
|
||||||
return makeMovementFlags(dragFlags, swipeFlags);
|
return makeMovementFlags(dragFlags, swipeFlags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ import android.content.Context;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
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.ItemTouchHelperAdapter;
|
||||||
import app.fedilab.android.helper.itemtouchhelper.ItemTouchHelperViewHolder;
|
import app.fedilab.android.helper.itemtouchhelper.ItemTouchHelperViewHolder;
|
||||||
import app.fedilab.android.helper.itemtouchhelper.OnStartDragListener;
|
import app.fedilab.android.helper.itemtouchhelper.OnStartDragListener;
|
||||||
import es.dmoral.toasty.Toasty;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,8 +128,6 @@ public class ReorderBottomMenuAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemDismiss(int position) {
|
public void onItemDismiss(int position) {
|
||||||
notifyItemChanged(position);
|
|
||||||
Toasty.info(context, context.getString(R.string.warning_main_timeline), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,14 +21,17 @@ import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
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 androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import app.fedilab.android.BaseMainActivity;
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
import app.fedilab.android.activities.ReorderTimelinesActivity;
|
import app.fedilab.android.activities.ReorderTimelinesActivity;
|
||||||
import app.fedilab.android.client.entities.app.Pinned;
|
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.client.entities.app.Timeline;
|
||||||
import app.fedilab.android.databinding.DrawerReorderBinding;
|
import app.fedilab.android.databinding.DrawerReorderBinding;
|
||||||
import app.fedilab.android.exception.DBException;
|
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.ItemTouchHelperAdapter;
|
||||||
import app.fedilab.android.helper.itemtouchhelper.ItemTouchHelperViewHolder;
|
import app.fedilab.android.helper.itemtouchhelper.ItemTouchHelperViewHolder;
|
||||||
import app.fedilab.android.helper.itemtouchhelper.OnStartDragListener;
|
import app.fedilab.android.helper.itemtouchhelper.OnStartDragListener;
|
||||||
import app.fedilab.android.helper.itemtouchhelper.OnUndoListener;
|
import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
|
||||||
import es.dmoral.toasty.Toasty;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,13 +55,11 @@ import es.dmoral.toasty.Toasty;
|
||||||
public class ReorderTabAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements ItemTouchHelperAdapter {
|
public class ReorderTabAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements ItemTouchHelperAdapter {
|
||||||
|
|
||||||
private final OnStartDragListener mDragStartListener;
|
private final OnStartDragListener mDragStartListener;
|
||||||
private final OnUndoListener mUndoListener;
|
|
||||||
private final Pinned pinned;
|
private final Pinned pinned;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
public ReorderTabAdapter(Pinned pinned, OnStartDragListener dragStartListener, OnUndoListener undoListener) {
|
public ReorderTabAdapter(Pinned pinned, OnStartDragListener dragStartListener) {
|
||||||
this.mDragStartListener = dragStartListener;
|
this.mDragStartListener = dragStartListener;
|
||||||
this.mUndoListener = undoListener;
|
|
||||||
this.pinned = pinned;
|
this.pinned = pinned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,26 +170,61 @@ public class ReorderTabAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||||
}
|
}
|
||||||
holder.binding.delete.setOnClickListener(v -> {
|
holder.binding.delete.setOnClickListener(v -> {
|
||||||
if (item.type == Timeline.TimeLineEnum.TAG || item.type == Timeline.TimeLineEnum.REMOTE || item.type == Timeline.TimeLineEnum.LIST) {
|
if (item.type == Timeline.TimeLineEnum.TAG || item.type == Timeline.TimeLineEnum.REMOTE || item.type == Timeline.TimeLineEnum.LIST) {
|
||||||
mUndoListener.onUndo(item, position);
|
AlertDialog.Builder alt_bld = new AlertDialog.Builder(context, Helper.dialogStyle());
|
||||||
if (position < pinned.pinnedTimelines.size()) {
|
String title = "";
|
||||||
pinned.pinnedTimelines.remove(position);
|
String message = "";
|
||||||
notifyItemRemoved(position);
|
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
|
@Override
|
||||||
public void onItemDismiss(int position) {
|
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
|
@Override
|
||||||
|
|
|
@ -1911,4 +1911,7 @@
|
||||||
<string name="no_blocked_domains">You have not blocked domains</string>
|
<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="unblock_domain_confirm">Are you sure to unblock %1$s?</string>
|
||||||
<string name="action_privacy_policy">Privacy policy</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>
|
</resources>
|
Loading…
Reference in New Issue