mirror of https://github.com/readrops/Readrops.git
Put some requests in the abstract repository for a better abstract model
This commit is contained in:
parent
20ba537670
commit
f462933c8d
|
@ -42,15 +42,40 @@ public abstract class ARepository {
|
|||
|
||||
public abstract Single<List<FeedInsertionResult>> addFeeds(List<ParsingResult> results);
|
||||
|
||||
public abstract Completable updateFeed(Feed feed);
|
||||
public Completable updateFeed(Feed feed) {
|
||||
return Completable.create(emitter -> {
|
||||
database.feedDao().updateFeedFields(feed.getId(), feed.getName(), feed.getUrl(), feed.getFolderId());
|
||||
emitter.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
public abstract Completable deleteFeed(Feed feed);
|
||||
public Completable deleteFeed(Feed feed) {
|
||||
return Completable.create(emitter -> {
|
||||
database.feedDao().delete(feed.getId());
|
||||
emitter.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
public abstract Completable addFolder(Folder folder);
|
||||
public Completable addFolder(Folder folder) {
|
||||
return Completable.create(emitter -> {
|
||||
database.folderDao().insert(folder);
|
||||
emitter.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
public abstract Completable updateFolder(Folder folder);
|
||||
public Completable updateFolder(Folder folder) {
|
||||
return Completable.create(emitter -> {
|
||||
database.folderDao().update(folder);
|
||||
emitter.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
public abstract Completable deleteFolder(Folder folder);
|
||||
public Completable deleteFolder(Folder folder) {
|
||||
return Completable.create(emitter -> {
|
||||
database.folderDao().delete(folder);
|
||||
emitter.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
public Completable setItemReadState(Item item, boolean read) {
|
||||
return Completable.create(emitter -> {
|
||||
|
|
|
@ -110,10 +110,7 @@ public class FreshRSSRepository extends ARepository {
|
|||
FreshRSSAPI api = new FreshRSSAPI(account.toCredentials());
|
||||
|
||||
return api.deleteFeed(account.getWriteToken(), feed.getUrl())
|
||||
.andThen(Completable.create(emitter -> {
|
||||
database.feedDao().delete(feed.getId());
|
||||
emitter.onComplete();
|
||||
}));
|
||||
.andThen(super.deleteFeed(feed));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -145,7 +142,7 @@ public class FreshRSSRepository extends ARepository {
|
|||
});
|
||||
} else {
|
||||
return api.markItemReadUnread(read, item.getRemoteId(), account.getWriteToken())
|
||||
.concatWith(super.setItemReadState(item, read));
|
||||
.andThen(super.setItemReadState(item, read));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import androidx.annotation.Nullable;
|
|||
|
||||
import com.readrops.app.database.entities.Account;
|
||||
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.utils.FeedInsertionResult;
|
||||
import com.readrops.app.utils.HtmlParser;
|
||||
|
@ -33,7 +32,6 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
|
||||
|
@ -145,46 +143,6 @@ public class LocalFeedRepository extends ARepository {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable updateFeed(Feed feed) {
|
||||
return Completable.create(emitter -> {
|
||||
database.feedDao().updateFeedFields(feed.getId(), feed.getName(), feed.getUrl(), feed.getFolderId());
|
||||
emitter.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable deleteFeed(Feed feed) {
|
||||
return Completable.create(emitter -> {
|
||||
database.feedDao().delete(feed.getId());
|
||||
emitter.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable addFolder(Folder folder) {
|
||||
return Completable.create(emitter -> {
|
||||
database.folderDao().insert(folder);
|
||||
emitter.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable updateFolder(Folder folder) {
|
||||
return Completable.create(emitter -> {
|
||||
database.folderDao().update(folder);
|
||||
emitter.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable deleteFolder(Folder folder) {
|
||||
return Completable.create(emitter -> {
|
||||
database.folderDao().delete(folder);
|
||||
emitter.onComplete();
|
||||
});
|
||||
}
|
||||
|
||||
private void insertNewItems(AFeed feed, RSSQuery.RSSType type) throws ParseException {
|
||||
Feed dbFeed = null;
|
||||
List<Item> items = null;
|
||||
|
@ -284,8 +242,4 @@ public class LocalFeedRepository extends ARepository {
|
|||
else
|
||||
return FeedInsertionResult.FeedInsertionError.UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -162,7 +162,6 @@ public class NextNewsRepository extends ARepository {
|
|||
NextNewsAPI api = new NextNewsAPI(account.toCredentials());
|
||||
|
||||
Folder folder = feed.getFolderId() == null ? null : database.folderDao().select(feed.getFolderId());
|
||||
|
||||
NextNewsRenameFeed newsRenameFeed = new NextNewsRenameFeed(Integer.parseInt(feed.getRemoteId()), feed.getName());
|
||||
|
||||
NextNewsFeed newsFeed;
|
||||
|
@ -173,18 +172,13 @@ public class NextNewsRepository extends ARepository {
|
|||
|
||||
try {
|
||||
if (api.renameFeed(newsRenameFeed) && api.changeFeedFolder(newsFeed)) {
|
||||
if (folder != null)
|
||||
database.feedDao().updateFeedFields(feed.getId(), feed.getName(), feed.getUrl(), folder.getId());
|
||||
else
|
||||
database.feedDao().updateFeedFields(feed.getId(), feed.getName(), feed.getUrl(), null);
|
||||
emitter.onComplete();
|
||||
} else
|
||||
emitter.onError(new Exception("Unknown error"));
|
||||
emitter.onError(new Exception("Unknown error when updating feed"));
|
||||
} catch (Exception e) {
|
||||
emitter.onError(e);
|
||||
}
|
||||
|
||||
emitter.onComplete();
|
||||
});
|
||||
}).andThen(super.updateFeed(feed));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -194,7 +188,6 @@ public class NextNewsRepository extends ARepository {
|
|||
|
||||
try {
|
||||
if (api.deleteFeed(Integer.parseInt(feed.getRemoteId()))) {
|
||||
database.feedDao().delete(feed.getId());
|
||||
emitter.onComplete();
|
||||
} else
|
||||
emitter.onError(new Exception("Unknown error"));
|
||||
|
@ -203,7 +196,7 @@ public class NextNewsRepository extends ARepository {
|
|||
}
|
||||
|
||||
emitter.onComplete();
|
||||
});
|
||||
}).andThen(super.deleteFeed(feed));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -233,7 +226,6 @@ public class NextNewsRepository extends ARepository {
|
|||
|
||||
try {
|
||||
if (api.renameFolder(new NextNewsFolder(Integer.parseInt(folder.getRemoteId()), folder.getName()))) {
|
||||
database.folderDao().update(folder);
|
||||
emitter.onComplete();
|
||||
} else
|
||||
emitter.onError(new Exception("Unknown error"));
|
||||
|
@ -243,7 +235,7 @@ public class NextNewsRepository extends ARepository {
|
|||
}
|
||||
|
||||
emitter.onComplete();
|
||||
});
|
||||
}).andThen(super.updateFolder(folder));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -253,7 +245,6 @@ public class NextNewsRepository extends ARepository {
|
|||
|
||||
try {
|
||||
if (api.deleteFolder(new NextNewsFolder(Integer.parseInt(folder.getRemoteId()), folder.getName()))) {
|
||||
database.folderDao().delete(folder);
|
||||
emitter.onComplete();
|
||||
} else
|
||||
emitter.onError(new Exception("Unknown error"));
|
||||
|
@ -263,7 +254,7 @@ public class NextNewsRepository extends ARepository {
|
|||
}
|
||||
|
||||
emitter.onComplete();
|
||||
});
|
||||
}).andThen(super.deleteFolder(folder));
|
||||
}
|
||||
|
||||
private List<Feed> insertFeeds(List<NextNewsFeed> nextNewsFeeds) {
|
||||
|
|
Loading…
Reference in New Issue