diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-09-29 01:49:30 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-09-29 01:49:30 +0000 |
commit | 3227e43fc4bc914f8bde1d06017ae16ced3fe278 (patch) | |
tree | 4a73e51c771fee9fdb150965990d4400d493f192 /app/src/main/java/User | |
parent | 47832e1e91db7e355b8122e1b533966c8df5ddba (diff) | |
download | infinity-for-reddit-3227e43fc4bc914f8bde1d06017ae16ced3fe278.tar infinity-for-reddit-3227e43fc4bc914f8bde1d06017ae16ced3fe278.tar.gz infinity-for-reddit-3227e43fc4bc914f8bde1d06017ae16ced3fe278.tar.bz2 infinity-for-reddit-3227e43fc4bc914f8bde1d06017ae16ced3fe278.tar.lz infinity-for-reddit-3227e43fc4bc914f8bde1d06017ae16ced3fe278.tar.xz infinity-for-reddit-3227e43fc4bc914f8bde1d06017ae16ced3fe278.tar.zst infinity-for-reddit-3227e43fc4bc914f8bde1d06017ae16ced3fe278.zip |
Change project structures.
Diffstat (limited to 'app/src/main/java/User')
-rw-r--r-- | app/src/main/java/User/UserDao.java | 22 | ||||
-rw-r--r-- | app/src/main/java/User/UserData.java | 65 | ||||
-rw-r--r-- | app/src/main/java/User/UserRepository.java | 40 | ||||
-rw-r--r-- | app/src/main/java/User/UserViewModel.java | 49 |
4 files changed, 0 insertions, 176 deletions
diff --git a/app/src/main/java/User/UserDao.java b/app/src/main/java/User/UserDao.java deleted file mode 100644 index 2bf7b824..00000000 --- a/app/src/main/java/User/UserDao.java +++ /dev/null @@ -1,22 +0,0 @@ -package User; - -import androidx.lifecycle.LiveData; -import androidx.room.Dao; -import androidx.room.Insert; -import androidx.room.OnConflictStrategy; -import androidx.room.Query; - -@Dao -public interface UserDao { - @Insert(onConflict = OnConflictStrategy.REPLACE) - void insert(UserData userData); - - @Query("DELETE FROM users") - void deleteAllUsers(); - - @Query("SELECT * FROM users WHERE name = :userName COLLATE NOCASE LIMIT 1") - LiveData<UserData> getUserLiveData(String userName); - - @Query("SELECT * FROM users WHERE name = :userName COLLATE NOCASE LIMIT 1") - UserData getUserData(String userName); -} diff --git a/app/src/main/java/User/UserData.java b/app/src/main/java/User/UserData.java deleted file mode 100644 index b3f71029..00000000 --- a/app/src/main/java/User/UserData.java +++ /dev/null @@ -1,65 +0,0 @@ -package User; - -import androidx.annotation.NonNull; -import androidx.room.ColumnInfo; -import androidx.room.Entity; -import androidx.room.PrimaryKey; - -@Entity(tableName = "users") -public class UserData { - @PrimaryKey - @NonNull - @ColumnInfo(name = "name") - private String name; - @ColumnInfo(name = "icon") - private String iconUrl; - @ColumnInfo(name = "banner") - private String banner; - @ColumnInfo(name = "karma") - private int karma; - @ColumnInfo(name = "is_gold") - private boolean isGold; - @ColumnInfo(name = "is_friend") - private boolean isFriend; - @ColumnInfo(name = "can_be_followed") - private boolean canBeFollowed; - - public UserData(@NonNull String name, String iconUrl, String banner, int karma, boolean isGold, boolean isFriend, boolean canBeFollowed) { - this.name = name; - this.iconUrl = iconUrl; - this.banner = banner; - this.karma = karma; - this.isGold = isGold; - this.isFriend = isFriend; - this.canBeFollowed = canBeFollowed; - } - - @NonNull - public String getName() { - return name; - } - - public String getIconUrl() { - return iconUrl; - } - - public String getBanner() { - return banner; - } - - public int getKarma() { - return karma; - } - - public boolean isGold() { - return isGold; - } - - public boolean isFriend() { - return isFriend; - } - - public boolean isCanBeFollowed() { - return canBeFollowed; - } -} diff --git a/app/src/main/java/User/UserRepository.java b/app/src/main/java/User/UserRepository.java deleted file mode 100644 index d781a694..00000000 --- a/app/src/main/java/User/UserRepository.java +++ /dev/null @@ -1,40 +0,0 @@ -package User; - -import android.os.AsyncTask; - -import androidx.lifecycle.LiveData; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class UserRepository { - private UserDao mUserDao; - private LiveData<UserData> mUserLiveData; - - UserRepository(RedditDataRoomDatabase redditDataRoomDatabase, String userName) { - mUserDao = redditDataRoomDatabase.userDao(); - mUserLiveData = mUserDao.getUserLiveData(userName); - } - - LiveData<UserData> getUserLiveData() { - return mUserLiveData; - } - - public void insert(UserData userData) { - new InsertAsyncTask(mUserDao).execute(userData); - } - - private static class InsertAsyncTask extends AsyncTask<UserData, Void, Void> { - - private UserDao mAsyncTaskDao; - - InsertAsyncTask(UserDao dao) { - mAsyncTaskDao = dao; - } - - @Override - protected Void doInBackground(final UserData... params) { - mAsyncTaskDao.insert(params[0]); - return null; - } - } -} diff --git a/app/src/main/java/User/UserViewModel.java b/app/src/main/java/User/UserViewModel.java deleted file mode 100644 index 2c746cad..00000000 --- a/app/src/main/java/User/UserViewModel.java +++ /dev/null @@ -1,49 +0,0 @@ -package User; - -import android.app.Application; -import androidx.lifecycle.AndroidViewModel; -import androidx.lifecycle.LiveData; -import androidx.lifecycle.ViewModel; -import androidx.lifecycle.ViewModelProvider; -import androidx.annotation.NonNull; - -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; - -public class UserViewModel extends AndroidViewModel { - private UserRepository mSubredditRepository; - private LiveData<UserData> mUserLiveData; - - public UserViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) { - super(application); - mSubredditRepository = new UserRepository(redditDataRoomDatabase, id); - mUserLiveData = mSubredditRepository.getUserLiveData(); - } - - public LiveData<UserData> getUserLiveData() { - return mUserLiveData; - } - - public void insert(UserData userData) { - mSubredditRepository.insert(userData); - } - - public static class Factory extends ViewModelProvider.NewInstanceFactory { - - @NonNull - private final Application mApplication; - private final RedditDataRoomDatabase mRedditDataRoomDatabase; - private final String mUsername; - - public Factory(@NonNull Application application, RedditDataRoomDatabase redditDataRoomDatabase, String username) { - mApplication = application; - mRedditDataRoomDatabase = redditDataRoomDatabase; - mUsername = username; - } - - @Override - public <T extends ViewModel> T create(Class<T> modelClass) { - //noinspection unchecked - return (T) new UserViewModel(mApplication, mRedditDataRoomDatabase, mUsername); - } - } -} |