Add feed deletion

This commit is contained in:
Shinokuni 2019-03-07 16:43:25 +01:00
parent ef7e1a9b12
commit 767139d1ce
7 changed files with 49 additions and 16 deletions

View File

@ -8,8 +8,6 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.InputType;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
@ -18,7 +16,6 @@ import com.afollestad.materialdialogs.MaterialDialog;
import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.adapters.ModelAdapter;
import com.mikepenz.fastadapter.commons.utils.DiffCallback;
import com.mikepenz.fastadapter.commons.utils.DiffCallbackImpl;
import com.mikepenz.fastadapter.commons.utils.FastAdapterDiffUtil;
import com.readrops.app.database.entities.Folder;
import com.readrops.app.views.EditFeedDialog;
@ -29,9 +26,7 @@ import com.readrops.app.database.pojo.FeedWithFolder;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DisposableCompletableObserver;
import io.reactivex.schedulers.Schedulers;
@ -61,7 +56,20 @@ public class ManageFeedsActivity extends AppCompatActivity {
@Override
public void onDelete(FeedWithFolder feedWithFolder) {
viewModel.deleteFeed(feedWithFolder.getFeed().getId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableCompletableObserver() {
@Override
public void onComplete() {
Toast.makeText(getApplication(), "feed deleted", Toast.LENGTH_LONG).show();
}
@Override
public void onError(Throwable e) {
Toast.makeText(getApplication(), "error on feed deletion", Toast.LENGTH_LONG).show();
}
});
}
});
@ -85,7 +93,20 @@ public class ManageFeedsActivity extends AppCompatActivity {
@Override
public void onDelete(FeedWithFolder feedWithFolder) {
viewModel.deleteFeed(feedWithFolder.getFeed().getId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableCompletableObserver() {
@Override
public void onComplete() {
Toast.makeText(getApplication(), "feed deleted", Toast.LENGTH_LONG).show();
}
@Override
public void onError(Throwable e) {
Toast.makeText(getApplication(), "error on feed deletion", Toast.LENGTH_LONG).show();
}
});
}
});
@ -104,9 +125,9 @@ public class ManageFeedsActivity extends AppCompatActivity {
FeedWithFolder feedWithFolder1 = oldItem.getModel();
FeedWithFolder feedWithFolder2 = newItem.getModel();
return feedWithFolder1.getFeed().getName().equals(feedWithFolder2.getFeed().getName()) &&
feedWithFolder1.getFeed().getUrl().equals(feedWithFolder2.getFeed().getUrl()) &&
feedWithFolder1.getFolder().getName().equals(feedWithFolder2.getFolder().getName());
return feedWithFolder1.getFolder().getName().equals(feedWithFolder2.getFolder().getName()) &&
feedWithFolder1.getFeed().getName().equals(feedWithFolder2.getFeed().getName()) &&
feedWithFolder1.getFeed().getUrl().equals(feedWithFolder2.getFeed().getUrl());
}
@Nullable

View File

@ -24,6 +24,9 @@ public interface FeedDao {
@Update
void update(Feed feed);
@Query("Delete From Feed Where id = :feedId")
void delete(int feedId);
@Query("Select count(*) from Feed")
int getFeedCount();

View File

@ -12,7 +12,9 @@ import com.readrops.readropslibrary.localfeed.json.JSONFeed;
import com.readrops.readropslibrary.localfeed.rss.RSSChannel;
import com.readrops.readropslibrary.localfeed.rss.RSSFeed;
@Entity(foreignKeys = @ForeignKey(entity = Folder.class, parentColumns = "id", childColumns = "folder_id"))
import static android.arch.persistence.room.ForeignKey.NO_ACTION;
@Entity(foreignKeys = @ForeignKey(entity = Folder.class, parentColumns = "id", childColumns = "folder_id", onDelete = ForeignKey.SET_NULL))
public class Feed implements Parcelable {
@PrimaryKey(autoGenerate = true)
@ -42,7 +44,7 @@ public class Feed implements Parcelable {
@ColumnInfo(name = "last_modified")
private String lastModified;
@ColumnInfo(name = "folder_id", index = true)
@ColumnInfo(name = "folder_id")
private int folderId;
public Feed() {

View File

@ -17,9 +17,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import static android.arch.persistence.room.ForeignKey.CASCADE;
@Entity
(foreignKeys = @ForeignKey(entity = Feed.class, parentColumns = "id", childColumns = "feed_id"))
(foreignKeys = @ForeignKey(entity = Feed.class, parentColumns = "id", childColumns = "feed_id", onDelete = CASCADE))
public class Item {
@PrimaryKey(autoGenerate = true)
@ -44,7 +46,7 @@ public class Item {
private String content;
@ColumnInfo(name = "feed_id", index = true)
@ColumnInfo(name = "feed_id")
private int feedId;
@ColumnInfo(index = true)

View File

@ -40,7 +40,7 @@ public abstract class ARepository {
public abstract void updateFeedWithFolder(FeedWithFolder feedWithFolder);
public abstract void deleteFeed(Feed feed);
public abstract Completable deleteFeed(int feedId);
public abstract Completable addFolder(Folder folder);

View File

@ -109,9 +109,10 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
}
@Override
public void deleteFeed(Feed feed) {
executor.execute(() -> {
public Completable deleteFeed(int feedId) {
return Completable.create(emitter -> {
database.feedDao().delete(feedId);
emitter.onComplete();
});
}

View File

@ -45,4 +45,8 @@ public class ManageFeedsViewModel extends AndroidViewModel {
public Completable addFolder(Folder folder) {
return repository.addFolder(folder);
}
public Completable deleteFeed(int feedId) {
return repository.deleteFeed(feedId);
}
}