Clean code
This commit is contained in:
parent
470bedd669
commit
5b5534be48
@ -2,11 +2,9 @@ package com.readrops.app.database;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
import androidx.room.TypeConverters;
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
|
||||
import com.readrops.app.database.dao.AccountDao;
|
||||
import com.readrops.app.database.dao.FeedDao;
|
||||
@ -35,22 +33,8 @@ public abstract class Database extends RoomDatabase {
|
||||
public static Database getInstance(Context context) {
|
||||
if (database == null)
|
||||
database = Room.databaseBuilder(context, Database.class, "readrops-db")
|
||||
.addCallback(roomCallback)
|
||||
.build();
|
||||
|
||||
return database;
|
||||
}
|
||||
|
||||
public static RoomDatabase.Callback roomCallback = new RoomDatabase.Callback() {
|
||||
@Override
|
||||
public void onCreate(@NonNull SupportSQLiteDatabase db) {
|
||||
super.onCreate(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(@NonNull SupportSQLiteDatabase db) {
|
||||
super.onOpen(db);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@ -35,14 +35,14 @@ public class ItemsListQueryBuilder {
|
||||
private String buildWhereClause() {
|
||||
StringBuilder stringBuilder = new StringBuilder(80);
|
||||
|
||||
stringBuilder.append("Feed.account_id = " + accountId + " And ");
|
||||
stringBuilder.append("Feed.account_id = ").append(accountId).append(" And ");
|
||||
|
||||
if (!showReadItems)
|
||||
stringBuilder.append("read = 0 And ");
|
||||
|
||||
switch (filterType) {
|
||||
case FEED_FILTER:
|
||||
stringBuilder.append("feed_id = " + filterFeedId + " And read_it_later = 0");
|
||||
stringBuilder.append("feed_id = ").append(filterFeedId).append(" And read_it_later = 0");
|
||||
break;
|
||||
case READ_IT_LATER_FILTER:
|
||||
stringBuilder.append("read_it_later = 1");
|
||||
|
@ -17,8 +17,6 @@ import com.readrops.app.utils.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Observable;
|
||||
@ -27,12 +25,9 @@ import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public abstract class ARepository {
|
||||
|
||||
protected Executor executor;
|
||||
|
||||
protected Database database;
|
||||
|
||||
protected ARepository(Application application) {
|
||||
executor = Executors.newSingleThreadExecutor();
|
||||
this.database = Database.getInstance(application);
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public final class SharedPreferencesManager {
|
||||
|
||||
public static String readString(Context context, String key) {
|
||||
SharedPreferences sharedPreferences = getSharedPreferences(context);
|
||||
return sharedPreferences.getString(key.toString(), null);
|
||||
return sharedPreferences.getString(key, null);
|
||||
}
|
||||
|
||||
public enum SharedPrefKey {
|
||||
|
@ -52,7 +52,6 @@ public class MainViewModel extends AndroidViewModel {
|
||||
queryBuilder.setFilterType(FilterType.NO_FILTER);
|
||||
queryBuilder.setSortType(MainActivity.ListSortType.NEWEST_TO_OLDEST);
|
||||
|
||||
repository = new NextNewsRepository(application);
|
||||
db = Database.getInstance(application);
|
||||
|
||||
itemsWithFeed = new MediatorLiveData<>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user