Add folder creation, deletion and feed folder change with rxandroid

This commit is contained in:
Shinokuni 2019-02-19 11:02:50 +00:00
parent d76d2e356f
commit d0b5fa6866
7 changed files with 43 additions and 22 deletions

Binary file not shown.

View File

@ -32,7 +32,6 @@ dependencies {
implementation 'com.android.support:palette-v7:28.0.0' implementation 'com.android.support:palette-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
@ -57,5 +56,5 @@ dependencies {
implementation "joda-time:joda-time:2.9.9" implementation "joda-time:joda-time:2.9.9"
implementation 'org.jsoup:jsoup:1.11.3' implementation 'org.jsoup:jsoup:1.11.3'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
} }

View File

@ -5,13 +5,23 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import com.readrops.app.database.Database; import com.readrops.app.database.Database;
import com.readrops.app.database.entities.Feed;
import com.readrops.app.database.entities.Folder;
import com.readrops.app.database.entities.Item; import com.readrops.app.database.entities.Item;
import com.readrops.readropslibrary.ParsingResult; import com.readrops.readropslibrary.ParsingResult;
import com.readrops.readropslibrary.localfeed.RSSNetwork;
import org.reactivestreams.Subscriber;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import io.reactivex.Completable;
import io.reactivex.CompletableEmitter;
import io.reactivex.CompletableObserver;
import io.reactivex.CompletableOnSubscribe;
import io.reactivex.Flowable;
public abstract class ARepository { public abstract class ARepository {
protected Executor executor; protected Executor executor;
@ -32,9 +42,31 @@ public abstract class ARepository {
public abstract void addFeed(ParsingResult result); public abstract void addFeed(ParsingResult result);
public abstract void deleteFeed(Item item); public abstract void deleteFeed(Feed feed);
public abstract void moveFeed(Item item); public Completable addFolder(String name) {
return Completable.create(emitter -> {
Folder folder = new Folder(name);
database.folderDao().insert(folder);
emitter.onComplete();
});
}
public Completable deleteFolder(Folder folder) {
return Completable.create(emitter -> {
database.folderDao().delete(folder);
emitter.onComplete();
});
}
public Completable changeFeedFolder(Feed feed, Folder newFolder) {
return Completable.create(emitter -> {
database.feedDao().updateFeedFolder(feed.getId(), newFolder.getId());
emitter.onComplete();
});
}
protected void failureCallBackInMainThread(Exception e) { protected void failureCallBackInMainThread(Exception e) {
Handler handler = new Handler(Looper.getMainLooper()); Handler handler = new Handler(Looper.getMainLooper());

View File

@ -4,6 +4,7 @@ import android.app.Application;
import android.arch.lifecycle.LiveData; import android.arch.lifecycle.LiveData;
import com.readrops.app.database.ItemWithFeed; import com.readrops.app.database.ItemWithFeed;
import com.readrops.app.database.entities.Feed;
import com.readrops.app.database.entities.Item; import com.readrops.app.database.entities.Item;
import com.readrops.readropslibrary.ParsingResult; import com.readrops.readropslibrary.ParsingResult;
@ -29,14 +30,7 @@ public class BasedRepository extends ARepository {
} }
@Override @Override
public void deleteFeed(Item item) { public void deleteFeed(Feed feed) {
} }
@Override
public void moveFeed(Item item) {
}
} }

View File

@ -3,9 +3,7 @@ package com.readrops.app;
import android.app.Application; import android.app.Application;
import android.arch.lifecycle.LiveData; import android.arch.lifecycle.LiveData;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.support.annotation.ColorInt;
import android.support.v7.graphics.Palette; import android.support.v7.graphics.Palette;
import android.util.Log;
import android.util.Patterns; import android.util.Patterns;
import com.readrops.app.database.ItemWithFeed; import com.readrops.app.database.ItemWithFeed;
@ -88,18 +86,12 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
} }
@Override @Override
public void deleteFeed(Item item) { public void deleteFeed(Feed feed) {
executor.execute(() -> { executor.execute(() -> {
}); });
} }
@Override
public void moveFeed(Item item) {
}
@Override @Override
public void onSyncSuccess(AFeed feed, RSSNetwork.RSSType type) { public void onSyncSuccess(AFeed feed, RSSNetwork.RSSType type) {
switch (type) { switch (type) {

View File

@ -2,6 +2,7 @@ package com.readrops.app.database.dao;
import android.arch.lifecycle.LiveData; import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao; import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert; import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query; import android.arch.persistence.room.Query;
@ -17,4 +18,7 @@ public interface FolderDao {
@Insert @Insert
long insert(Folder folder); long insert(Folder folder);
@Delete
void delete(Folder folder);
} }