mirror of https://github.com/readrops/Readrops.git
Change the way a feed is deleted, we are now using a swipe
This commit is contained in:
parent
54b4aa15a7
commit
5df6e1ed27
|
@ -5,12 +5,15 @@ import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.util.DiffUtil;
|
import android.support.v7.util.DiffUtil;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
@ -55,11 +58,6 @@ public class ManageFeedsActivity extends AppCompatActivity {
|
||||||
openEditFeedDialog(feedWithFolder);
|
openEditFeedDialog(feedWithFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDelete(FeedWithFolder feedWithFolder) {
|
|
||||||
deleteFolder(feedWithFolder.getFeed().getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpenLink(FeedWithFolder feedWithFolder) {
|
public void onOpenLink(FeedWithFolder feedWithFolder) {
|
||||||
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
|
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
|
||||||
|
@ -72,13 +70,40 @@ public class ManageFeedsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
|
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
|
||||||
|
@Override
|
||||||
|
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
|
||||||
|
int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
|
||||||
|
|
||||||
|
return makeMovementFlags(0, swipeFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder viewHolder1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
||||||
|
deleteFolder(adapter.getItemAt(viewHolder.getAdapterPosition()).getFeed().getId(),
|
||||||
|
viewHolder.getAdapterPosition());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItemViewSwipeEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}).attachToRecyclerView(recyclerView);
|
||||||
|
|
||||||
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(ManageFeedsViewModel.class);
|
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(ManageFeedsViewModel.class);
|
||||||
viewModel.getFeedsWithFolder().observe(this, feedWithFolders -> {
|
viewModel.getFeedsWithFolder().observe(this, feedWithFolders -> {
|
||||||
adapter.submitList(feedWithFolders);
|
adapter.submitList(feedWithFolders);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteFolder(int feedId) {
|
private void deleteFolder(int feedId, int position) {
|
||||||
new MaterialDialog.Builder(this)
|
new MaterialDialog.Builder(this)
|
||||||
.title(getString(R.string.delete_feed))
|
.title(getString(R.string.delete_feed))
|
||||||
.positiveText(getString(R.string.validate))
|
.positiveText(getString(R.string.validate))
|
||||||
|
@ -97,6 +122,7 @@ public class ManageFeedsActivity extends AppCompatActivity {
|
||||||
Toast.makeText(getApplication(), "error on feed deletion", Toast.LENGTH_LONG).show();
|
Toast.makeText(getApplication(), "error on feed deletion", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
.onNegative(((dialog, which) -> adapter.notifyItemChanged(position)))
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,9 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FeedWithFolder getItemAt(int position) {
|
||||||
|
return getItem(position);
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,7 +107,6 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||||
listener.onOpenLink(getItem(i));
|
listener.onOpenLink(getItem(i));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
viewHolder.deleteFeed.setOnClickListener(v -> listener.onDelete(getItem(i)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,11 +129,9 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||||
public interface ManageFeedsListener {
|
public interface ManageFeedsListener {
|
||||||
void onOpenLink(FeedWithFolder feedWithFolder);
|
void onOpenLink(FeedWithFolder feedWithFolder);
|
||||||
void onEdit(FeedWithFolder feedWithFolder);
|
void onEdit(FeedWithFolder feedWithFolder);
|
||||||
void onDelete(FeedWithFolder feedWithFolder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected class ViewHolder extends RecyclerView.ViewHolder {
|
protected class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
private ImageView feedIcon;
|
private ImageView feedIcon;
|
||||||
|
@ -141,8 +139,6 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||||
private TextView feedDescription;
|
private TextView feedDescription;
|
||||||
private TextView folderName;
|
private TextView folderName;
|
||||||
|
|
||||||
private ImageView deleteFeed;
|
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|
||||||
|
@ -150,7 +146,6 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||||
feedName = itemView.findViewById(R.id.feed_layout_name);
|
feedName = itemView.findViewById(R.id.feed_layout_name);
|
||||||
feedDescription = itemView.findViewById(R.id.feed_layout_description);
|
feedDescription = itemView.findViewById(R.id.feed_layout_description);
|
||||||
folderName = itemView.findViewById(R.id.feed_layout_folder);
|
folderName = itemView.findViewById(R.id.feed_layout_folder);
|
||||||
deleteFeed = itemView.findViewById(R.id.feed_layout_delete);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
style="@style/Base.TextAppearance.AppCompat.Subhead"
|
style="@style/Base.TextAppearance.AppCompat.Subhead"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_toStartOf="@id/feed_layout_delete"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_toEndOf="@id/feed_layout_icon"
|
android:layout_toEndOf="@id/feed_layout_icon"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="2"
|
android:maxLines="2"
|
||||||
|
@ -53,16 +53,8 @@
|
||||||
android:maxLines="3"
|
android:maxLines="3"
|
||||||
android:minLines="1"
|
android:minLines="1"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
tools:text="This is a feed description"
|
tools:text="This is a feed description" />
|
||||||
tools:visibility="visible" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/feed_layout_delete"
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="24dp"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_marginStart="8dp"
|
|
||||||
android:src="@drawable/ic_delete_grey" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
@ -84,10 +76,10 @@
|
||||||
style="@style/Base.TextAppearance.AppCompat.Body1"
|
style="@style/Base.TextAppearance.AppCompat.Body1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_toEndOf="@id/feed_layout_folder_icon"
|
|
||||||
android:layout_toRightOf="@id/feed_layout_folder_icon"
|
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_marginStart="6dp"
|
android:layout_marginStart="6dp"
|
||||||
|
android:layout_toEndOf="@id/feed_layout_folder_icon"
|
||||||
|
android:layout_toRightOf="@id/feed_layout_folder_icon"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
tools:text="Folder 1" />
|
tools:text="Folder 1" />
|
||||||
|
|
Loading…
Reference in New Issue