mirror of https://github.com/readrops/Readrops.git
Replace application by context in repositories
This commit is contained in:
parent
c50c8a96e8
commit
2e29ef2509
|
@ -1,21 +1,21 @@
|
|||
package com.readrops.app.repositories;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.readrops.app.utils.FeedInsertionResult;
|
||||
import com.readrops.app.utils.ParsingResult;
|
||||
import com.readrops.app.utils.feedscolors.FeedColorsKt;
|
||||
import com.readrops.app.utils.feedscolors.FeedsColorsIntentService;
|
||||
import com.readrops.readropsdb.Database;
|
||||
import com.readrops.readropsdb.entities.Feed;
|
||||
import com.readrops.readropsdb.entities.Folder;
|
||||
import com.readrops.readropsdb.entities.Item;
|
||||
import com.readrops.readropsdb.entities.account.Account;
|
||||
import com.readrops.readropsdb.entities.account.AccountType;
|
||||
import com.readrops.app.utils.FeedInsertionResult;
|
||||
import com.readrops.app.utils.ParsingResult;
|
||||
import com.readrops.app.utils.feedscolors.FeedColorsKt;
|
||||
import com.readrops.app.utils.feedscolors.FeedsColorsIntentService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -30,15 +30,15 @@ import static com.readrops.app.utils.ReadropsKeys.FEEDS;
|
|||
|
||||
public abstract class ARepository<T> {
|
||||
|
||||
protected Application application;
|
||||
protected Context context;
|
||||
protected Database database;
|
||||
protected Account account;
|
||||
|
||||
protected T api;
|
||||
|
||||
protected ARepository(@NonNull Application application, @Nullable Account account) {
|
||||
this.application = application;
|
||||
this.database = Database.getInstance(application);
|
||||
protected ARepository(@NonNull Context context, @Nullable Account account) {
|
||||
this.context = context;
|
||||
this.database = Database.getInstance(context);
|
||||
this.account = account;
|
||||
|
||||
api = createAPI();
|
||||
|
@ -157,26 +157,26 @@ public abstract class ARepository<T> {
|
|||
}
|
||||
|
||||
protected void setFeedsColors(List<Feed> feeds) {
|
||||
Intent intent = new Intent(application, FeedsColorsIntentService.class);
|
||||
Intent intent = new Intent(context, FeedsColorsIntentService.class);
|
||||
intent.putParcelableArrayListExtra(FEEDS, new ArrayList<>(feeds));
|
||||
|
||||
application.startService(intent);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
public static ARepository repositoryFactory(Account account, AccountType accountType, Application application) throws Exception {
|
||||
public static ARepository repositoryFactory(Account account, AccountType accountType, Context context) throws Exception {
|
||||
switch (accountType) {
|
||||
case LOCAL:
|
||||
return new LocalFeedRepository(application, account);
|
||||
return new LocalFeedRepository(context, account);
|
||||
case NEXTCLOUD_NEWS:
|
||||
return new NextNewsRepository(application, account);
|
||||
return new NextNewsRepository(context, account);
|
||||
case FRESHRSS:
|
||||
return new FreshRSSRepository(application, account);
|
||||
return new FreshRSSRepository(context, account);
|
||||
default:
|
||||
throw new Exception("account type not supported");
|
||||
}
|
||||
}
|
||||
|
||||
public static ARepository repositoryFactory(Account account, Application application) throws Exception {
|
||||
return ARepository.repositoryFactory(account, account.getAccountType(), application);
|
||||
public static ARepository repositoryFactory(Account account, Context context) throws Exception {
|
||||
return ARepository.repositoryFactory(account, account.getAccountType(), context);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.readrops.app.repositories;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.util.TimingLogger;
|
||||
|
||||
|
@ -34,8 +34,8 @@ public class FreshRSSRepository extends ARepository<FreshRSSAPI> {
|
|||
|
||||
private static final String TAG = FreshRSSRepository.class.getSimpleName();
|
||||
|
||||
public FreshRSSRepository(@NonNull Application application, @Nullable Account account) {
|
||||
super(application, account);
|
||||
public FreshRSSRepository(@NonNull Context context, @Nullable Account account) {
|
||||
super(context, account);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.readrops.app.repositories;
|
||||
|
||||
import android.accounts.NetworkErrorException;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -42,8 +42,8 @@ public class LocalFeedRepository extends ARepository<Void> {
|
|||
|
||||
private static final String TAG = LocalFeedRepository.class.getSimpleName();
|
||||
|
||||
public LocalFeedRepository(@NonNull Application application, @Nullable Account account) {
|
||||
super(application, account);
|
||||
public LocalFeedRepository(@NonNull Context context, @Nullable Account account) {
|
||||
super(context, account);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -173,7 +173,7 @@ public class LocalFeedRepository extends ARepository<Void> {
|
|||
database.feedDao().updateHeaders(dbFeed.getEtag(), dbFeed.getLastModified(), dbFeed.getId());
|
||||
Collections.sort(items, Item::compareTo);
|
||||
|
||||
int maxItems = Integer.parseInt(SharedPreferencesManager.readString(application, SharedPreferencesManager.SharedPrefKey.ITEMS_TO_PARSE_MAX_NB));
|
||||
int maxItems = Integer.parseInt(SharedPreferencesManager.readString(context, SharedPreferencesManager.SharedPrefKey.ITEMS_TO_PARSE_MAX_NB));
|
||||
if (maxItems > 0 && items.size() > maxItems)
|
||||
items = items.subList(items.size() - maxItems, items.size());
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.readrops.app.repositories;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteConstraintException;
|
||||
import android.util.TimingLogger;
|
||||
|
||||
|
@ -37,8 +37,8 @@ public class NextNewsRepository extends ARepository<NextNewsAPI> {
|
|||
|
||||
private static final String TAG = NextNewsRepository.class.getSimpleName();
|
||||
|
||||
public NextNewsRepository(@NonNull Application application, @Nullable Account account) {
|
||||
super(application, account);
|
||||
public NextNewsRepository(@NonNull Context context, @Nullable Account account) {
|
||||
super(context, account);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue