Issue #903 - Undo action

This commit is contained in:
tom79 2019-04-27 18:01:13 +02:00
parent 20c66087a7
commit 96fb867740
6 changed files with 40 additions and 13 deletions

View File

@ -42,6 +42,8 @@ import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.OnStartDragListener;
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.OnUndoListener;
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.SimpleItemTouchHelperCallback;
import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.TimelinesDAO;
@ -63,7 +65,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
private TextView undo_action;
private List<ManageTimelines> timelines;
private ReorderTabAdapter adapter;
private boolean actionCanBeApplied;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -138,19 +140,35 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
public void onUndo(ManageTimelines manageTimelines, int position) {
undo_container.setVisibility(View.VISIBLE);
undo_action.setPaintFlags(undo_action.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
actionCanBeApplied = true;
undo_action.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
timelines.add(position, manageTimelines);
adapter.notifyItemInserted(position);
undo_container.setVisibility(View.GONE);
actionCanBeApplied = false;
}
});
final Handler handler = new Handler();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
undo_container.setVisibility(View.GONE);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
if( actionCanBeApplied){
switch (manageTimelines.getType()){
case TAG:
new SearchDAO(getApplicationContext(), db).remove(manageTimelines.getTagTimeline().getName());
new TimelinesDAO(getApplicationContext(), db).remove(manageTimelines);
break;
case INSTANCE:
new InstancesDAO(getApplicationContext(), db).remove(manageTimelines.getRemoteInstance().getId());
new TimelinesDAO(getApplicationContext(), db).remove(manageTimelines);
break;
}
updated = true;
}
}
}, 2000);

View File

@ -539,7 +539,7 @@ public class ManageTimelines {
final boolean[] show_nsfw = {sharedpreferences.getBoolean(Helper.SET_ART_WITH_NSFW, false)};
final MenuItem itemShowNSFW = menu.findItem(R.id.action_show_nsfw);
final MenuItem itemMedia = menu.findItem(R.id.action_show_media_only);
final MenuItem itemDelete = menu.findItem(R.id.action_delete);
//final MenuItem itemDelete = menu.findItem(R.id.action_delete);
final MenuItem itemAny = menu.findItem(R.id.action_any);
final MenuItem itemAll = menu.findItem(R.id.action_all);
@ -550,7 +550,7 @@ public class ManageTimelines {
itemNone.setVisible(false);
action_displayname.setVisible(false);
itemMedia.setVisible(false);
itemDelete.setVisible(false);
// itemDelete.setVisible(false);
itemShowNSFW.setChecked(show_nsfw[0]);
final boolean[] changes = {false};
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
@ -941,7 +941,7 @@ public class ManageTimelines {
alertDialog = dialogBuilder.create();
alertDialog.show();
break;
case R.id.action_delete:
/*case R.id.action_delete:
dialogBuilder = new AlertDialog.Builder(context, style);
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
@ -971,7 +971,7 @@ public class ManageTimelines {
if( alertDialog.getWindow() != null )
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
return false;
return false;*/
}
return false;
}

View File

@ -21,7 +21,6 @@ import android.database.sqlite.SQLiteDatabase;
import android.graphics.PorterDuff;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -205,9 +204,18 @@ public class ReorderTabAdapter extends RecyclerView.Adapter<ReorderTabAdapter.It
@Override
public void onItemDismiss(int position) {
ManageTimelines item = mItems.get(position);
mUndoListener.onUndo(item, position);
mItems.remove(position);
notifyItemRemoved(position);
if( item.getType() == ManageTimelines.Type.TAG || item.getType() == ManageTimelines.Type.INSTANCE ) {
mUndoListener.onUndo(item, position);
mItems.remove(position);
notifyItemRemoved(position);
}else{
notifyItemChanged(position);
if( item.getType() == ManageTimelines.Type.LIST ){
Toasty.info(context, context.getString(R.string.warning_list_deletion), Toast.LENGTH_SHORT).show();
}else{
Toasty.info(context, context.getString(R.string.warning_main_timeline), Toast.LENGTH_SHORT).show();
}
}
}
@Override

View File

@ -24,7 +24,6 @@
android:id="@+id/lv_reorder_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="?attr/actionBarSize"
android:scrollbars="none"
>
</android.support.v7.widget.RecyclerView>

View File

@ -31,8 +31,8 @@
android:id="@+id/action_none"
app:showAsAction="always"
android:title="@string/none_tags" />
<item
<!-- <item
android:id="@+id/action_delete"
app:showAsAction="always"
android:title="@string/delete" />
android:title="@string/delete" /> -->
</menu>

View File

@ -930,6 +930,8 @@
<string name="undo">Undo</string>
<string name="visible_tabs_needed">You need to keep two visible tabs!</string>
<string name="action_reorder_timeline">Reorder timelines</string>
<string name="warning_list_deletion">Use the list entry for deleting this list!</string>
<string name="warning_main_timeline">Main timelines can only be hidden!</string>
<plurals name="number_of_vote">
<item quantity="one">%d vote</item>