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