mirror of
https://github.com/readrops/Readrops.git
synced 2025-02-02 11:46:52 +01:00
create API in repositories in a separate method
This commit is contained in:
parent
7487bc7b78
commit
8fba823db7
@ -39,8 +39,12 @@ public abstract class ARepository<T> {
|
||||
this.application = application;
|
||||
this.database = Database.getInstance(application);
|
||||
this.account = account;
|
||||
|
||||
api = createAPI();
|
||||
}
|
||||
|
||||
protected abstract T createAPI();
|
||||
|
||||
public abstract Single<Boolean> login(Account account, boolean insert);
|
||||
|
||||
public abstract Observable<Feed> sync(List<Feed> feeds);
|
||||
@ -75,10 +79,9 @@ public abstract class ARepository<T> {
|
||||
|
||||
public Completable setItemReadState(Item item, boolean read) {
|
||||
return database.itemDao().setReadState(item.getId(), read ? 1 : 0, !item.isReadChanged() ? 1 : 0);
|
||||
|
||||
}
|
||||
|
||||
public Completable setAllItemsReadState(Boolean read) {
|
||||
public Completable setAllItemsReadState(boolean read) {
|
||||
return database.itemDao().setAllItemsReadState(read ? 1 : 0, account.getId());
|
||||
}
|
||||
|
||||
@ -93,7 +96,7 @@ public abstract class ARepository<T> {
|
||||
protected void setFaviconUtils(List<Feed> feeds) {
|
||||
Observable.<Feed>create(emitter -> {
|
||||
for (Feed feed : feeds) {
|
||||
setFavIconUtils(feed);
|
||||
setFaviconUtils(feed);
|
||||
emitter.onNext(feed);
|
||||
}
|
||||
}).subscribeOn(Schedulers.io())
|
||||
@ -103,7 +106,7 @@ public abstract class ARepository<T> {
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
protected void setFavIconUtils(Feed feed) throws IOException {
|
||||
protected void setFaviconUtils(Feed feed) throws IOException {
|
||||
String favUrl;
|
||||
|
||||
if (feed.getIconUrl() != null)
|
||||
@ -130,7 +133,6 @@ public abstract class ARepository<T> {
|
||||
if (palette.getMutedSwatch() != null) {
|
||||
feed.setBackgroundColor(palette.getMutedSwatch().getRgb());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,14 @@ public class FreshRSSRepository extends ARepository<FreshRSSAPI> {
|
||||
|
||||
public FreshRSSRepository(@NonNull Application application, @Nullable Account account) {
|
||||
super(application, account);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FreshRSSAPI createAPI() {
|
||||
if (account != null)
|
||||
api = new FreshRSSAPI(account.toCredentials());
|
||||
return new FreshRSSAPI(account.toCredentials());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,6 +46,11 @@ public class LocalFeedRepository extends ARepository<Void> {
|
||||
super(application, account);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void createAPI() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<Boolean> login(Account account, boolean insert) {
|
||||
return null;
|
||||
@ -128,8 +133,6 @@ public class LocalFeedRepository extends ARepository<Void> {
|
||||
insertionResult.setInsertionError(getErrorFromException(queryResult.getException()));
|
||||
|
||||
insertionResults.add(insertionResult);
|
||||
} else {
|
||||
// error 304
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e instanceof IOException)
|
||||
@ -192,7 +195,7 @@ public class LocalFeedRepository extends ARepository<Void> {
|
||||
if (database.feedDao().feedExists(dbFeed.getUrl(), account.getId()))
|
||||
return null; // feed already inserted
|
||||
|
||||
setFavIconUtils(dbFeed);
|
||||
setFaviconUtils(dbFeed);
|
||||
dbFeed.setAccountId(account.getId());
|
||||
|
||||
// we need empty headers to query the feed just after, without any 304 result
|
||||
|
@ -46,9 +46,14 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
|
||||
|
||||
public NextNewsRepository(@NonNull Application application, @Nullable Account account) {
|
||||
super(application, account);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NextNewsAPI createAPI() {
|
||||
if (account != null)
|
||||
api = new NextNewsAPI(account.toCredentials());
|
||||
return new NextNewsAPI(account.toCredentials());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user