From 807ddf5a6e595d2368579008bb8132296be54ea2 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 27 Dec 2018 13:54:19 +0800 Subject: Move several classes to other packages. --- .../main/java/SubredditDatabase/SubredditDao.java | 25 +++++++++ .../main/java/SubredditDatabase/SubredditData.java | 63 ++++++++++++++++++++++ .../SubredditDatabase/SubredditRepository.java | 43 +++++++++++++++ .../SubredditDatabase/SubredditRoomDatabase.java | 26 +++++++++ .../java/SubredditDatabase/SubredditViewModel.java | 48 +++++++++++++++++ .../SubscribedSubredditDao.java | 21 ++++++++ .../SubscribedSubredditData.java | 38 +++++++++++++ .../SubscribedSubredditRepository.java | 41 ++++++++++++++ .../SubscribedSubredditRoomDatabase.java | 26 +++++++++ .../SubscribedSubredditViewModel.java | 26 +++++++++ .../SubscribedUserDatabase/SubscribedUserDao.java | 21 ++++++++ .../SubscribedUserDatabase/SubscribedUserData.java | 37 +++++++++++++ .../SubscribedUserRepository.java | 41 ++++++++++++++ .../SubscribedUserRoomDatabase.java | 26 +++++++++ .../SubscribedUserViewModel.java | 26 +++++++++ .../infinityforreddit/FetchSubscribedThing.java | 3 ++ .../LoadSubredditIconAsyncTask.java | 2 + .../infinityforreddit/MainActivity.java | 11 ++++ .../infinityforreddit/ParseSubredditData.java | 2 + .../infinityforreddit/ParseSubscribedThing.java | 4 ++ .../infinityforreddit/PostRecyclerViewAdapter.java | 2 + .../infinityforreddit/SubredditDao.java | 25 --------- .../infinityforreddit/SubredditData.java | 63 ---------------------- .../infinityforreddit/SubredditRepository.java | 43 --------------- .../infinityforreddit/SubredditRoomDatabase.java | 26 --------- .../infinityforreddit/SubredditViewModel.java | 48 ----------------- .../infinityforreddit/SubscribedSubredditDao.java | 21 -------- .../infinityforreddit/SubscribedSubredditData.java | 38 ------------- .../SubscribedSubredditRecyclerViewAdapter.java | 1 + .../SubscribedSubredditRepository.java | 41 -------------- .../SubscribedSubredditRoomDatabase.java | 26 --------- .../SubscribedSubredditViewModel.java | 26 --------- .../infinityforreddit/SubscribedUserDao.java | 21 -------- .../infinityforreddit/SubscribedUserData.java | 37 ------------- .../SubscribedUserRecyclerViewAdapter.java | 5 +- .../SubscribedUserRepository.java | 41 -------------- .../SubscribedUserRoomDatabase.java | 26 --------- .../infinityforreddit/SubscribedUserViewModel.java | 26 --------- .../infinityforreddit/ViewPostDetailActivity.java | 1 + .../ViewSubredditDetailActivity.java | 4 ++ 40 files changed, 541 insertions(+), 510 deletions(-) create mode 100644 app/src/main/java/SubredditDatabase/SubredditDao.java create mode 100644 app/src/main/java/SubredditDatabase/SubredditData.java create mode 100644 app/src/main/java/SubredditDatabase/SubredditRepository.java create mode 100644 app/src/main/java/SubredditDatabase/SubredditRoomDatabase.java create mode 100644 app/src/main/java/SubredditDatabase/SubredditViewModel.java create mode 100644 app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditDao.java create mode 100644 app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditData.java create mode 100644 app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRepository.java create mode 100644 app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRoomDatabase.java create mode 100644 app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditViewModel.java create mode 100644 app/src/main/java/SubscribedUserDatabase/SubscribedUserDao.java create mode 100644 app/src/main/java/SubscribedUserDatabase/SubscribedUserData.java create mode 100644 app/src/main/java/SubscribedUserDatabase/SubscribedUserRepository.java create mode 100644 app/src/main/java/SubscribedUserDatabase/SubscribedUserRoomDatabase.java create mode 100644 app/src/main/java/SubscribedUserDatabase/SubscribedUserViewModel.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubredditDao.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubredditData.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubredditRepository.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubredditRoomDatabase.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubredditViewModel.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditDao.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditData.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRepository.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRoomDatabase.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditViewModel.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserDao.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserData.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRepository.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRoomDatabase.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserViewModel.java (limited to 'app/src/main/java') diff --git a/app/src/main/java/SubredditDatabase/SubredditDao.java b/app/src/main/java/SubredditDatabase/SubredditDao.java new file mode 100644 index 00000000..9b2fcabb --- /dev/null +++ b/app/src/main/java/SubredditDatabase/SubredditDao.java @@ -0,0 +1,25 @@ +package SubredditDatabase; + +import android.arch.lifecycle.LiveData; +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.OnConflictStrategy; +import android.arch.persistence.room.Query; + +@Dao +public interface SubredditDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insert(SubredditData SubredditData); + + @Query("DELETE FROM subreddits") + void deleteAllSubreddits(); + + @Query("SELECT * from subreddits WHERE id = :id") + LiveData getSubredditLiveDataById(String id); + + @Query("SELECT * from subreddits WHERE name = :namePrefixed") + LiveData getSubredditLiveDataByNamePrefixed(String namePrefixed); + + @Query("SELECT * from subreddits WHERE name = :namePrefixed") + SubredditData getSubredditData(String namePrefixed); +} diff --git a/app/src/main/java/SubredditDatabase/SubredditData.java b/app/src/main/java/SubredditDatabase/SubredditData.java new file mode 100644 index 00000000..bbd9f7d8 --- /dev/null +++ b/app/src/main/java/SubredditDatabase/SubredditData.java @@ -0,0 +1,63 @@ +package SubredditDatabase; + +import android.arch.persistence.room.ColumnInfo; +import android.arch.persistence.room.Entity; +import android.arch.persistence.room.PrimaryKey; +import android.support.annotation.NonNull; + +@Entity(tableName = "subreddits") +public class SubredditData { + @PrimaryKey + @NonNull + @ColumnInfo(name = "id") + private String id; + + @ColumnInfo(name = "name") + private String name; + + @ColumnInfo(name = "icon_url") + private String iconUrl; + + @ColumnInfo(name = "banner_url") + private String bannerUrl; + + @ColumnInfo(name = "description") + private String description; + + @ColumnInfo(name = "subscribers_count") + private int nSubscribers; + + public SubredditData(@NonNull String id, String name, String iconUrl, String bannerUrl, String description, int nSubscribers) { + this.id = id; + this.name = name; + this.iconUrl = iconUrl; + this.bannerUrl = bannerUrl; + this.description = description; + this.nSubscribers = nSubscribers; + } + + @NonNull + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getIconUrl() { + return iconUrl; + } + + public String getBannerUrl() { + return bannerUrl; + } + + public String getDescription() { + return description; + } + + public int getNSubscribers() { + return nSubscribers; + } +} diff --git a/app/src/main/java/SubredditDatabase/SubredditRepository.java b/app/src/main/java/SubredditDatabase/SubredditRepository.java new file mode 100644 index 00000000..20eb617a --- /dev/null +++ b/app/src/main/java/SubredditDatabase/SubredditRepository.java @@ -0,0 +1,43 @@ +package SubredditDatabase; + +import android.app.Application; +import android.arch.lifecycle.LiveData; +import android.os.AsyncTask; + +public class SubredditRepository { + private SubredditDao mSubredditDao; + private LiveData mSubredditLiveData; + + SubredditRepository(Application application, String value, boolean isId) { + SubredditRoomDatabase db = SubredditRoomDatabase.getDatabase(application); + mSubredditDao = db.subredditDao(); + if(isId) { + mSubredditLiveData = mSubredditDao.getSubredditLiveDataById(value); + } else { + mSubredditLiveData = mSubredditDao.getSubredditLiveDataByNamePrefixed(value); + } + } + + LiveData getSubredditLiveData() { + return mSubredditLiveData; + } + + public void insert(SubredditData subredditData) { + new SubredditRepository.insertAsyncTask(mSubredditDao).execute(subredditData); + } + + private static class insertAsyncTask extends AsyncTask { + + private SubredditDao mAsyncTaskDao; + + insertAsyncTask(SubredditDao dao) { + mAsyncTaskDao = dao; + } + + @Override + protected Void doInBackground(final SubredditData... params) { + mAsyncTaskDao.insert(params[0]); + return null; + } + } +} diff --git a/app/src/main/java/SubredditDatabase/SubredditRoomDatabase.java b/app/src/main/java/SubredditDatabase/SubredditRoomDatabase.java new file mode 100644 index 00000000..764a3741 --- /dev/null +++ b/app/src/main/java/SubredditDatabase/SubredditRoomDatabase.java @@ -0,0 +1,26 @@ +package SubredditDatabase; + +import android.arch.persistence.room.Database; +import android.arch.persistence.room.Room; +import android.arch.persistence.room.RoomDatabase; +import android.content.Context; + +@Database(entities = {SubredditData.class}, version = 1) +public abstract class SubredditRoomDatabase extends RoomDatabase{ + private static SubredditRoomDatabase INSTANCE; + + public abstract SubredditDao subredditDao(); + + public static SubredditRoomDatabase getDatabase(final Context context) { + if(INSTANCE == null) { + synchronized (SubredditRoomDatabase.class) { + if(INSTANCE == null) { + INSTANCE = Room.databaseBuilder(context.getApplicationContext(), + SubredditRoomDatabase.class, "subreddits") + .build(); + } + } + } + return INSTANCE; + } +} diff --git a/app/src/main/java/SubredditDatabase/SubredditViewModel.java b/app/src/main/java/SubredditDatabase/SubredditViewModel.java new file mode 100644 index 00000000..10135401 --- /dev/null +++ b/app/src/main/java/SubredditDatabase/SubredditViewModel.java @@ -0,0 +1,48 @@ +package SubredditDatabase; + +import android.app.Application; +import android.arch.lifecycle.AndroidViewModel; +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.ViewModel; +import android.arch.lifecycle.ViewModelProvider; +import android.support.annotation.NonNull; + +public class SubredditViewModel extends AndroidViewModel { + private SubredditRepository mSubredditRepository; + private LiveData mSubredditLiveData; + + SubredditViewModel(Application application, String id, boolean isId) { + super(application); + mSubredditRepository = new SubredditRepository(application, id, isId); + mSubredditLiveData = mSubredditRepository.getSubredditLiveData(); + } + + public LiveData getSubredditLiveData() { + return mSubredditLiveData; + } + + public void insert(SubredditData subredditData) { + mSubredditRepository.insert(subredditData); + } + + public static class Factory extends ViewModelProvider.NewInstanceFactory { + + @NonNull + private final Application mApplication; + + private final String value; + private final boolean isId; + + public Factory(@NonNull Application application, String value, boolean isId) { + mApplication = application; + this.value = value; + this.isId = isId; + } + + @Override + public T create(Class modelClass) { + //noinspection unchecked + return (T) new SubredditViewModel(mApplication, value, isId); + } + } +} diff --git a/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditDao.java b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditDao.java new file mode 100644 index 00000000..7837aa42 --- /dev/null +++ b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditDao.java @@ -0,0 +1,21 @@ +package SubscribedSubredditDatabase; + +import android.arch.lifecycle.LiveData; +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.OnConflictStrategy; +import android.arch.persistence.room.Query; + +import java.util.List; + +@Dao +public interface SubscribedSubredditDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insert(SubscribedSubredditData subscribedSubredditData); + + @Query("DELETE FROM subscribed_subreddits") + void deleteAllSubscribedSubreddits(); + + @Query("SELECT * from subscribed_subreddits ORDER BY name COLLATE NOCASE ASC") + LiveData> getAllSubscribedSubreddits(); +} diff --git a/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditData.java b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditData.java new file mode 100644 index 00000000..c6812768 --- /dev/null +++ b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditData.java @@ -0,0 +1,38 @@ +package SubscribedSubredditDatabase; + +import android.arch.persistence.room.ColumnInfo; +import android.arch.persistence.room.Entity; +import android.arch.persistence.room.PrimaryKey; +import android.support.annotation.NonNull; + +@Entity(tableName = "subscribed_subreddits") +public class SubscribedSubredditData { + + @PrimaryKey + @NonNull + @ColumnInfo(name = "id") + private String id; + @ColumnInfo(name = "name") + private String name; + @ColumnInfo(name = "icon") + private String iconUrl; + + public SubscribedSubredditData(@NonNull String id, String name, String iconUrl) { + this.id = id; + this.name = name; + this.iconUrl = iconUrl; + } + + @NonNull + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getIconUrl() { + return iconUrl; + } +} diff --git a/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRepository.java b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRepository.java new file mode 100644 index 00000000..54b2ddfa --- /dev/null +++ b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRepository.java @@ -0,0 +1,41 @@ +package SubscribedSubredditDatabase; + +import android.app.Application; +import android.arch.lifecycle.LiveData; +import android.os.AsyncTask; + +import java.util.List; + +public class SubscribedSubredditRepository { + private SubscribedSubredditDao mSubscribedSubredditDao; + private LiveData> mAllSubscribedSubreddits; + + SubscribedSubredditRepository(Application application) { + SubscribedSubredditRoomDatabase db = SubscribedSubredditRoomDatabase.getDatabase(application); + mSubscribedSubredditDao = db.subscribedSubredditDao(); + mAllSubscribedSubreddits = mSubscribedSubredditDao.getAllSubscribedSubreddits(); + } + + LiveData> getAllSubscribedSubreddits() { + return mAllSubscribedSubreddits; + } + + public void insert(SubscribedSubredditData subscribedSubredditData) { + new insertAsyncTask(mSubscribedSubredditDao).execute(subscribedSubredditData); + } + + private static class insertAsyncTask extends AsyncTask { + + private SubscribedSubredditDao mAsyncTaskDao; + + insertAsyncTask(SubscribedSubredditDao dao) { + mAsyncTaskDao = dao; + } + + @Override + protected Void doInBackground(final SubscribedSubredditData... params) { + mAsyncTaskDao.insert(params[0]); + return null; + } + } +} diff --git a/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRoomDatabase.java b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRoomDatabase.java new file mode 100644 index 00000000..abde79b4 --- /dev/null +++ b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditRoomDatabase.java @@ -0,0 +1,26 @@ +package SubscribedSubredditDatabase; + +import android.arch.persistence.room.Database; +import android.arch.persistence.room.Room; +import android.arch.persistence.room.RoomDatabase; +import android.content.Context; + +@Database(entities = {SubscribedSubredditData.class}, version = 1) +public abstract class SubscribedSubredditRoomDatabase extends RoomDatabase { + private static SubscribedSubredditRoomDatabase INSTANCE; + + public abstract SubscribedSubredditDao subscribedSubredditDao(); + + public static SubscribedSubredditRoomDatabase getDatabase(final Context context) { + if(INSTANCE == null) { + synchronized (SubscribedSubredditRoomDatabase.class) { + if(INSTANCE == null) { + INSTANCE = Room.databaseBuilder(context.getApplicationContext(), + SubscribedSubredditRoomDatabase.class, "subscribed_subreddits") + .build(); + } + } + } + return INSTANCE; + } +} diff --git a/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditViewModel.java b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditViewModel.java new file mode 100644 index 00000000..8598dd55 --- /dev/null +++ b/app/src/main/java/SubscribedSubredditDatabase/SubscribedSubredditViewModel.java @@ -0,0 +1,26 @@ +package SubscribedSubredditDatabase; + +import android.app.Application; +import android.arch.lifecycle.AndroidViewModel; +import android.arch.lifecycle.LiveData; + +import java.util.List; + +public class SubscribedSubredditViewModel extends AndroidViewModel { + private SubscribedSubredditRepository mSubscribedSubredditRepository; + private LiveData> mAllSubscribedSubreddits; + + public SubscribedSubredditViewModel(Application application) { + super(application); + mSubscribedSubredditRepository = new SubscribedSubredditRepository(application); + mAllSubscribedSubreddits = mSubscribedSubredditRepository.getAllSubscribedSubreddits(); + } + + public LiveData> getAllSubscribedSubreddits() { + return mAllSubscribedSubreddits; + } + + public void insert(SubscribedSubredditData subscribedSubredditData) { + mSubscribedSubredditRepository.insert(subscribedSubredditData); + } +} diff --git a/app/src/main/java/SubscribedUserDatabase/SubscribedUserDao.java b/app/src/main/java/SubscribedUserDatabase/SubscribedUserDao.java new file mode 100644 index 00000000..2b61a666 --- /dev/null +++ b/app/src/main/java/SubscribedUserDatabase/SubscribedUserDao.java @@ -0,0 +1,21 @@ +package SubscribedUserDatabase; + +import android.arch.lifecycle.LiveData; +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.OnConflictStrategy; +import android.arch.persistence.room.Query; + +import java.util.List; + +@Dao +public interface SubscribedUserDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insert(SubscribedUserData subscribedUserData); + + @Query("DELETE FROM subscribed_users") + void deleteAllSubscribedUsers(); + + @Query("SELECT * from subscribed_users ORDER BY name COLLATE NOCASE ASC") + LiveData> getAllSubscribedUsers(); +} diff --git a/app/src/main/java/SubscribedUserDatabase/SubscribedUserData.java b/app/src/main/java/SubscribedUserDatabase/SubscribedUserData.java new file mode 100644 index 00000000..8494e784 --- /dev/null +++ b/app/src/main/java/SubscribedUserDatabase/SubscribedUserData.java @@ -0,0 +1,37 @@ +package SubscribedUserDatabase; + +import android.arch.persistence.room.ColumnInfo; +import android.arch.persistence.room.Entity; +import android.arch.persistence.room.PrimaryKey; +import android.support.annotation.NonNull; + +@Entity(tableName = "subscribed_users") +public class SubscribedUserData { + @PrimaryKey + @NonNull + @ColumnInfo(name = "id") + private String id; + @ColumnInfo(name = "name") + private String name; + @ColumnInfo(name = "icon") + private String iconUrl; + + public SubscribedUserData(@NonNull String id, String name, String iconUrl) { + this.id = id; + this.name = name; + this.iconUrl = iconUrl; + } + + @NonNull + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public String getIconUrl() { + return iconUrl; + } +} diff --git a/app/src/main/java/SubscribedUserDatabase/SubscribedUserRepository.java b/app/src/main/java/SubscribedUserDatabase/SubscribedUserRepository.java new file mode 100644 index 00000000..5cab5fa8 --- /dev/null +++ b/app/src/main/java/SubscribedUserDatabase/SubscribedUserRepository.java @@ -0,0 +1,41 @@ +package SubscribedUserDatabase; + +import android.app.Application; +import android.arch.lifecycle.LiveData; +import android.os.AsyncTask; + +import java.util.List; + +public class SubscribedUserRepository { + private SubscribedUserDao mSubscribedUserDao; + private LiveData> mAllSubscribedUsers; + + SubscribedUserRepository(Application application) { + SubscribedUserRoomDatabase db = SubscribedUserRoomDatabase.getDatabase(application); + mSubscribedUserDao = db.subscribedUserDao(); + mAllSubscribedUsers = mSubscribedUserDao.getAllSubscribedUsers(); + } + + LiveData> getAllSubscribedSubreddits() { + return mAllSubscribedUsers; + } + + public void insert(SubscribedUserData subscribedUserData) { + new SubscribedUserRepository.insertAsyncTask(mSubscribedUserDao).execute(subscribedUserData); + } + + private static class insertAsyncTask extends AsyncTask { + + private SubscribedUserDao mAsyncTaskDao; + + insertAsyncTask(SubscribedUserDao dao) { + mAsyncTaskDao = dao; + } + + @Override + protected Void doInBackground(final SubscribedUserData... params) { + mAsyncTaskDao.insert(params[0]); + return null; + } + } +} diff --git a/app/src/main/java/SubscribedUserDatabase/SubscribedUserRoomDatabase.java b/app/src/main/java/SubscribedUserDatabase/SubscribedUserRoomDatabase.java new file mode 100644 index 00000000..cf3ea59d --- /dev/null +++ b/app/src/main/java/SubscribedUserDatabase/SubscribedUserRoomDatabase.java @@ -0,0 +1,26 @@ +package SubscribedUserDatabase; + +import android.arch.persistence.room.Database; +import android.arch.persistence.room.Room; +import android.arch.persistence.room.RoomDatabase; +import android.content.Context; + +@Database(entities = {SubscribedUserData.class}, version = 1) +public abstract class SubscribedUserRoomDatabase extends RoomDatabase { + private static SubscribedUserRoomDatabase INSTANCE; + + public abstract SubscribedUserDao subscribedUserDao(); + + public static SubscribedUserRoomDatabase getDatabase(final Context context) { + if(INSTANCE == null) { + synchronized (SubscribedUserRoomDatabase.class) { + if(INSTANCE == null) { + INSTANCE = Room.databaseBuilder(context.getApplicationContext(), + SubscribedUserRoomDatabase.class, "subscribed_users") + .build(); + } + } + } + return INSTANCE; + } +} diff --git a/app/src/main/java/SubscribedUserDatabase/SubscribedUserViewModel.java b/app/src/main/java/SubscribedUserDatabase/SubscribedUserViewModel.java new file mode 100644 index 00000000..858fac48 --- /dev/null +++ b/app/src/main/java/SubscribedUserDatabase/SubscribedUserViewModel.java @@ -0,0 +1,26 @@ +package SubscribedUserDatabase; + +import android.app.Application; +import android.arch.lifecycle.AndroidViewModel; +import android.arch.lifecycle.LiveData; + +import java.util.List; + +public class SubscribedUserViewModel extends AndroidViewModel { + private SubscribedUserRepository mSubscribedUserRepository; + private LiveData> mAllSubscribedUsers; + + public SubscribedUserViewModel(Application application) { + super(application); + mSubscribedUserRepository = new SubscribedUserRepository(application); + mAllSubscribedUsers = mSubscribedUserRepository.getAllSubscribedSubreddits(); + } + + public LiveData> getAllSubscribedUsers() { + return mAllSubscribedUsers; + } + + public void insert(SubscribedUserData subscribedUserData) { + mSubscribedUserRepository.insert(subscribedUserData); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java index cfda92de..691d170b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchSubscribedThing.java @@ -6,6 +6,9 @@ import android.util.Log; import java.util.ArrayList; +import SubredditDatabase.SubredditData; +import SubscribedSubredditDatabase.SubscribedSubredditData; +import SubscribedUserDatabase.SubscribedUserData; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java index 957e52ab..f7f0fdcd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java @@ -2,6 +2,8 @@ package ml.docilealligator.infinityforreddit; import android.os.AsyncTask; +import SubredditDatabase.SubredditDao; + class LoadSubredditIconAsyncTask extends AsyncTask { interface LoadSubredditIconAsyncTaskListener { void loadIconSuccess(String iconImageUrl); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index 5f559aa1..00ca7f15 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -31,6 +31,17 @@ import java.util.List; import javax.inject.Inject; import javax.inject.Named; +import SubredditDatabase.SubredditDao; +import SubredditDatabase.SubredditData; +import SubredditDatabase.SubredditRoomDatabase; +import SubscribedSubredditDatabase.SubscribedSubredditDao; +import SubscribedSubredditDatabase.SubscribedSubredditData; +import SubscribedSubredditDatabase.SubscribedSubredditRoomDatabase; +import SubscribedSubredditDatabase.SubscribedSubredditViewModel; +import SubscribedUserDatabase.SubscribedUserDao; +import SubscribedUserDatabase.SubscribedUserData; +import SubscribedUserDatabase.SubscribedUserRoomDatabase; +import SubscribedUserDatabase.SubscribedUserViewModel; import butterknife.BindView; import butterknife.ButterKnife; import de.hdodenhof.circleimageview.CircleImageView; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java index 1f9b4a9e..5292a976 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java @@ -6,6 +6,8 @@ import android.util.Log; import org.json.JSONException; import org.json.JSONObject; +import SubredditDatabase.SubredditData; + class ParseSubredditData { interface ParseSubredditDataListener { void onParseSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java index 2cddfc2f..a69d0c22 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubscribedThing.java @@ -9,6 +9,10 @@ import org.json.JSONObject; import java.util.ArrayList; +import SubredditDatabase.SubredditData; +import SubscribedSubredditDatabase.SubscribedSubredditData; +import SubscribedUserDatabase.SubscribedUserData; + class ParseSubscribedThing { interface ParseSubscribedSubredditsListener { void onParseSubscribedSubredditsSuccess(ArrayList subscribedSubredditData, diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 2d6f54aa..9ec8b83b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -39,6 +39,8 @@ import com.bumptech.glide.request.target.Target; import java.util.List; import CustomView.AspectRatioGifImageView; +import SubredditDatabase.SubredditDao; +import SubredditDatabase.SubredditRoomDatabase; import butterknife.BindView; import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.BlurTransformation; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditDao.java deleted file mode 100644 index 2e1b0bb7..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditDao.java +++ /dev/null @@ -1,25 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.arch.lifecycle.LiveData; -import android.arch.persistence.room.Dao; -import android.arch.persistence.room.Insert; -import android.arch.persistence.room.OnConflictStrategy; -import android.arch.persistence.room.Query; - -@Dao -public interface SubredditDao { - @Insert(onConflict = OnConflictStrategy.REPLACE) - void insert(SubredditData SubredditData); - - @Query("DELETE FROM subreddits") - void deleteAllSubreddits(); - - @Query("SELECT * from subreddits WHERE id = :id") - LiveData getSubredditLiveDataById(String id); - - @Query("SELECT * from subreddits WHERE name = :namePrefixed") - LiveData getSubredditLiveDataByNamePrefixed(String namePrefixed); - - @Query("SELECT * from subreddits WHERE name = :namePrefixed") - SubredditData getSubredditData(String namePrefixed); -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditData.java deleted file mode 100644 index 59b8e6b8..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditData.java +++ /dev/null @@ -1,63 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.arch.persistence.room.ColumnInfo; -import android.arch.persistence.room.Entity; -import android.arch.persistence.room.PrimaryKey; -import android.support.annotation.NonNull; - -@Entity(tableName = "subreddits") -class SubredditData { - @PrimaryKey - @NonNull - @ColumnInfo(name = "id") - private String id; - - @ColumnInfo(name = "name") - private String name; - - @ColumnInfo(name = "icon_url") - private String iconUrl; - - @ColumnInfo(name = "banner_url") - private String bannerUrl; - - @ColumnInfo(name = "description") - private String description; - - @ColumnInfo(name = "subscribers_count") - private int nSubscribers; - - SubredditData(@NonNull String id, String name, String iconUrl, String bannerUrl, String description, int nSubscribers) { - this.id = id; - this.name = name; - this.iconUrl = iconUrl; - this.bannerUrl = bannerUrl; - this.description = description; - this.nSubscribers = nSubscribers; - } - - @NonNull - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public String getIconUrl() { - return iconUrl; - } - - public String getBannerUrl() { - return bannerUrl; - } - - public String getDescription() { - return description; - } - - public int getNSubscribers() { - return nSubscribers; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditRepository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditRepository.java deleted file mode 100644 index deb68806..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditRepository.java +++ /dev/null @@ -1,43 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.app.Application; -import android.arch.lifecycle.LiveData; -import android.os.AsyncTask; - -public class SubredditRepository { - private SubredditDao mSubredditDao; - private LiveData mSubredditLiveData; - - SubredditRepository(Application application, String value, boolean isId) { - SubredditRoomDatabase db = SubredditRoomDatabase.getDatabase(application); - mSubredditDao = db.subredditDao(); - if(isId) { - mSubredditLiveData = mSubredditDao.getSubredditLiveDataById(value); - } else { - mSubredditLiveData = mSubredditDao.getSubredditLiveDataByNamePrefixed(value); - } - } - - LiveData getSubredditLiveData() { - return mSubredditLiveData; - } - - public void insert(SubredditData subredditData) { - new SubredditRepository.insertAsyncTask(mSubredditDao).execute(subredditData); - } - - private static class insertAsyncTask extends AsyncTask { - - private SubredditDao mAsyncTaskDao; - - insertAsyncTask(SubredditDao dao) { - mAsyncTaskDao = dao; - } - - @Override - protected Void doInBackground(final SubredditData... params) { - mAsyncTaskDao.insert(params[0]); - return null; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditRoomDatabase.java deleted file mode 100644 index 16affad3..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditRoomDatabase.java +++ /dev/null @@ -1,26 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.arch.persistence.room.Database; -import android.arch.persistence.room.Room; -import android.arch.persistence.room.RoomDatabase; -import android.content.Context; - -@Database(entities = {SubredditData.class}, version = 1) -public abstract class SubredditRoomDatabase extends RoomDatabase{ - private static SubredditRoomDatabase INSTANCE; - - public abstract SubredditDao subredditDao(); - - public static SubredditRoomDatabase getDatabase(final Context context) { - if(INSTANCE == null) { - synchronized (SubredditRoomDatabase.class) { - if(INSTANCE == null) { - INSTANCE = Room.databaseBuilder(context.getApplicationContext(), - SubredditRoomDatabase.class, "subreddits") - .build(); - } - } - } - return INSTANCE; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditViewModel.java deleted file mode 100644 index ee636b43..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditViewModel.java +++ /dev/null @@ -1,48 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.app.Application; -import android.arch.lifecycle.AndroidViewModel; -import android.arch.lifecycle.LiveData; -import android.arch.lifecycle.ViewModel; -import android.arch.lifecycle.ViewModelProvider; -import android.support.annotation.NonNull; - -public class SubredditViewModel extends AndroidViewModel { - private SubredditRepository mSubredditRepository; - private LiveData mSubredditLiveData; - - SubredditViewModel(Application application, String id, boolean isId) { - super(application); - mSubredditRepository = new SubredditRepository(application, id, isId); - mSubredditLiveData = mSubredditRepository.getSubredditLiveData(); - } - - public LiveData getSubredditLiveData() { - return mSubredditLiveData; - } - - public void insert(SubredditData subredditData) { - mSubredditRepository.insert(subredditData); - } - - public static class Factory extends ViewModelProvider.NewInstanceFactory { - - @NonNull - private final Application mApplication; - - private final String value; - private final boolean isId; - - public Factory(@NonNull Application application, String value, boolean isId) { - mApplication = application; - this.value = value; - this.isId = isId; - } - - @Override - public T create(Class modelClass) { - //noinspection unchecked - return (T) new SubredditViewModel(mApplication, value, isId); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditDao.java deleted file mode 100644 index 9ced85c1..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditDao.java +++ /dev/null @@ -1,21 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.arch.lifecycle.LiveData; -import android.arch.persistence.room.Dao; -import android.arch.persistence.room.Insert; -import android.arch.persistence.room.OnConflictStrategy; -import android.arch.persistence.room.Query; - -import java.util.List; - -@Dao -public interface SubscribedSubredditDao { - @Insert(onConflict = OnConflictStrategy.REPLACE) - void insert(SubscribedSubredditData subscribedSubredditData); - - @Query("DELETE FROM subscribed_subreddits") - void deleteAllSubscribedSubreddits(); - - @Query("SELECT * from subscribed_subreddits ORDER BY name COLLATE NOCASE ASC") - LiveData> getAllSubscribedSubreddits(); -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditData.java deleted file mode 100644 index 10b2c8e0..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditData.java +++ /dev/null @@ -1,38 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.arch.persistence.room.ColumnInfo; -import android.arch.persistence.room.Entity; -import android.arch.persistence.room.PrimaryKey; -import android.support.annotation.NonNull; - -@Entity(tableName = "subscribed_subreddits") -class SubscribedSubredditData { - - @PrimaryKey - @NonNull - @ColumnInfo(name = "id") - private String id; - @ColumnInfo(name = "name") - private String name; - @ColumnInfo(name = "icon") - private String iconUrl; - - SubscribedSubredditData(@NonNull String id, String name, String iconUrl) { - this.id = id; - this.name = name; - this.iconUrl = iconUrl; - } - - @NonNull - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public String getIconUrl() { - return iconUrl; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java index 87c679cd..9bc4f5e7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRecyclerViewAdapter.java @@ -23,6 +23,7 @@ import com.felipecsl.gifimageview.library.GifImageView; import java.util.List; +import SubscribedSubredditDatabase.SubscribedSubredditData; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRepository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRepository.java deleted file mode 100644 index 3173bba4..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRepository.java +++ /dev/null @@ -1,41 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.app.Application; -import android.arch.lifecycle.LiveData; -import android.os.AsyncTask; - -import java.util.List; - -public class SubscribedSubredditRepository { - private SubscribedSubredditDao mSubscribedSubredditDao; - private LiveData> mAllSubscribedSubreddits; - - SubscribedSubredditRepository(Application application) { - SubscribedSubredditRoomDatabase db = SubscribedSubredditRoomDatabase.getDatabase(application); - mSubscribedSubredditDao = db.subscribedSubredditDao(); - mAllSubscribedSubreddits = mSubscribedSubredditDao.getAllSubscribedSubreddits(); - } - - LiveData> getAllSubscribedSubreddits() { - return mAllSubscribedSubreddits; - } - - public void insert(SubscribedSubredditData subscribedSubredditData) { - new insertAsyncTask(mSubscribedSubredditDao).execute(subscribedSubredditData); - } - - private static class insertAsyncTask extends AsyncTask { - - private SubscribedSubredditDao mAsyncTaskDao; - - insertAsyncTask(SubscribedSubredditDao dao) { - mAsyncTaskDao = dao; - } - - @Override - protected Void doInBackground(final SubscribedSubredditData... params) { - mAsyncTaskDao.insert(params[0]); - return null; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRoomDatabase.java deleted file mode 100644 index d4b1f710..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditRoomDatabase.java +++ /dev/null @@ -1,26 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.arch.persistence.room.Database; -import android.arch.persistence.room.Room; -import android.arch.persistence.room.RoomDatabase; -import android.content.Context; - -@Database(entities = {SubscribedSubredditData.class}, version = 1) -public abstract class SubscribedSubredditRoomDatabase extends RoomDatabase { - private static SubscribedSubredditRoomDatabase INSTANCE; - - public abstract SubscribedSubredditDao subscribedSubredditDao(); - - public static SubscribedSubredditRoomDatabase getDatabase(final Context context) { - if(INSTANCE == null) { - synchronized (SubscribedSubredditRoomDatabase.class) { - if(INSTANCE == null) { - INSTANCE = Room.databaseBuilder(context.getApplicationContext(), - SubscribedSubredditRoomDatabase.class, "subscribed_subreddits") - .build(); - } - } - } - return INSTANCE; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditViewModel.java deleted file mode 100644 index bd092640..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedSubredditViewModel.java +++ /dev/null @@ -1,26 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.app.Application; -import android.arch.lifecycle.AndroidViewModel; -import android.arch.lifecycle.LiveData; - -import java.util.List; - -public class SubscribedSubredditViewModel extends AndroidViewModel { - private SubscribedSubredditRepository mSubscribedSubredditRepository; - private LiveData> mAllSubscribedSubreddits; - - public SubscribedSubredditViewModel(Application application) { - super(application); - mSubscribedSubredditRepository = new SubscribedSubredditRepository(application); - mAllSubscribedSubreddits = mSubscribedSubredditRepository.getAllSubscribedSubreddits(); - } - - public LiveData> getAllSubscribedSubreddits() { - return mAllSubscribedSubreddits; - } - - public void insert(SubscribedSubredditData subscribedSubredditData) { - mSubscribedSubredditRepository.insert(subscribedSubredditData); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserDao.java deleted file mode 100644 index a2979dcd..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserDao.java +++ /dev/null @@ -1,21 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.arch.lifecycle.LiveData; -import android.arch.persistence.room.Dao; -import android.arch.persistence.room.Insert; -import android.arch.persistence.room.OnConflictStrategy; -import android.arch.persistence.room.Query; - -import java.util.List; - -@Dao -public interface SubscribedUserDao { - @Insert(onConflict = OnConflictStrategy.REPLACE) - void insert(SubscribedUserData subscribedUserData); - - @Query("DELETE FROM subscribed_users") - void deleteAllSubscribedUsers(); - - @Query("SELECT * from subscribed_users ORDER BY name COLLATE NOCASE ASC") - LiveData> getAllSubscribedUsers(); -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserData.java deleted file mode 100644 index 9bf58700..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserData.java +++ /dev/null @@ -1,37 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.arch.persistence.room.ColumnInfo; -import android.arch.persistence.room.Entity; -import android.arch.persistence.room.PrimaryKey; -import android.support.annotation.NonNull; - -@Entity(tableName = "subscribed_users") -class SubscribedUserData { - @PrimaryKey - @NonNull - @ColumnInfo(name = "id") - private String id; - @ColumnInfo(name = "name") - private String name; - @ColumnInfo(name = "icon") - private String iconUrl; - - SubscribedUserData(@NonNull String id, String name, String iconUrl) { - this.id = id; - this.name = name; - this.iconUrl = iconUrl; - } - - @NonNull - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public String getIconUrl() { - return iconUrl; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java index e36dea17..013d75c1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRecyclerViewAdapter.java @@ -22,14 +22,15 @@ import com.felipecsl.gifimageview.library.GifImageView; import java.util.List; +import SubscribedUserDatabase.SubscribedUserData; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter { +public class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter { private List mSubscribedUserData; private RequestManager glide; private OnItemClickListener mOnItemClickListener; - interface OnItemClickListener { + public interface OnItemClickListener { void onClick(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRepository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRepository.java deleted file mode 100644 index 8dfc4204..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRepository.java +++ /dev/null @@ -1,41 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.app.Application; -import android.arch.lifecycle.LiveData; -import android.os.AsyncTask; - -import java.util.List; - -public class SubscribedUserRepository { - private SubscribedUserDao mSubscribedUserDao; - private LiveData> mAllSubscribedUsers; - - SubscribedUserRepository(Application application) { - SubscribedUserRoomDatabase db = SubscribedUserRoomDatabase.getDatabase(application); - mSubscribedUserDao = db.subscribedUserDao(); - mAllSubscribedUsers = mSubscribedUserDao.getAllSubscribedUsers(); - } - - LiveData> getAllSubscribedSubreddits() { - return mAllSubscribedUsers; - } - - public void insert(SubscribedUserData subscribedUserData) { - new SubscribedUserRepository.insertAsyncTask(mSubscribedUserDao).execute(subscribedUserData); - } - - private static class insertAsyncTask extends AsyncTask { - - private SubscribedUserDao mAsyncTaskDao; - - insertAsyncTask(SubscribedUserDao dao) { - mAsyncTaskDao = dao; - } - - @Override - protected Void doInBackground(final SubscribedUserData... params) { - mAsyncTaskDao.insert(params[0]); - return null; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRoomDatabase.java deleted file mode 100644 index 0f6575d7..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserRoomDatabase.java +++ /dev/null @@ -1,26 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.arch.persistence.room.Database; -import android.arch.persistence.room.Room; -import android.arch.persistence.room.RoomDatabase; -import android.content.Context; - -@Database(entities = {SubscribedUserData.class}, version = 1) -public abstract class SubscribedUserRoomDatabase extends RoomDatabase { - private static SubscribedUserRoomDatabase INSTANCE; - - public abstract SubscribedUserDao subscribedUserDao(); - - public static SubscribedUserRoomDatabase getDatabase(final Context context) { - if(INSTANCE == null) { - synchronized (SubscribedUserRoomDatabase.class) { - if(INSTANCE == null) { - INSTANCE = Room.databaseBuilder(context.getApplicationContext(), - SubscribedUserRoomDatabase.class, "subscribed_users") - .build(); - } - } - } - return INSTANCE; - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserViewModel.java deleted file mode 100644 index 44e40fe5..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubscribedUserViewModel.java +++ /dev/null @@ -1,26 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -import android.app.Application; -import android.arch.lifecycle.AndroidViewModel; -import android.arch.lifecycle.LiveData; - -import java.util.List; - -public class SubscribedUserViewModel extends AndroidViewModel { - private SubscribedUserRepository mSubscribedUserRepository; - private LiveData> mAllSubscribedUsers; - - public SubscribedUserViewModel(Application application) { - super(application); - mSubscribedUserRepository = new SubscribedUserRepository(application); - mAllSubscribedUsers = mSubscribedUserRepository.getAllSubscribedSubreddits(); - } - - public LiveData> getAllSubscribedUsers() { - return mAllSubscribedUsers; - } - - public void insert(SubscribedUserData subscribedUserData) { - mSubscribedUserRepository.insert(subscribedUserData); - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 6c8f209e..5140ac94 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -42,6 +42,7 @@ import java.util.List; import javax.inject.Inject; import javax.inject.Named; +import SubredditDatabase.SubredditRoomDatabase; import butterknife.BindView; import butterknife.ButterKnife; import de.hdodenhof.circleimageview.CircleImageView; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java index cc7bb742..1c63ffac 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java @@ -33,6 +33,10 @@ import com.felipecsl.gifimageview.library.GifImageView; import javax.inject.Inject; import javax.inject.Named; +import SubredditDatabase.SubredditDao; +import SubredditDatabase.SubredditData; +import SubredditDatabase.SubredditRoomDatabase; +import SubredditDatabase.SubredditViewModel; import butterknife.BindView; import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; -- cgit v1.2.3