From 2e29ef25092d980367223da7c983fbb6fdd94ff3 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sat, 1 Feb 2020 21:41:31 +0100 Subject: [PATCH] Replace application by context in repositories --- .../app/repositories/ARepository.java | 34 +++++++++---------- .../app/repositories/FreshRSSRepository.java | 6 ++-- .../app/repositories/LocalFeedRepository.java | 8 ++--- .../app/repositories/NextNewsRepository.java | 6 ++-- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/readrops/app/repositories/ARepository.java b/app/src/main/java/com/readrops/app/repositories/ARepository.java index 0f86430e..3bc40054 100644 --- a/app/src/main/java/com/readrops/app/repositories/ARepository.java +++ b/app/src/main/java/com/readrops/app/repositories/ARepository.java @@ -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 { - 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 { } protected void setFeedsColors(List 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); } } diff --git a/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.java b/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.java index b9d9e5fb..93446d0a 100644 --- a/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.java +++ b/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.java @@ -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 { 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 diff --git a/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java b/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java index 48245219..94ad5cba 100644 --- a/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java +++ b/app/src/main/java/com/readrops/app/repositories/LocalFeedRepository.java @@ -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 { 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 { 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()); diff --git a/app/src/main/java/com/readrops/app/repositories/NextNewsRepository.java b/app/src/main/java/com/readrops/app/repositories/NextNewsRepository.java index 3e7fe605..3c1857a2 100644 --- a/app/src/main/java/com/readrops/app/repositories/NextNewsRepository.java +++ b/app/src/main/java/com/readrops/app/repositories/NextNewsRepository.java @@ -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 { 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