mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 03:07:26 +01:00
Refactored all the other classes to support multi user. Clearing the app data is required before launching the app.
This commit is contained in:
parent
7f2bc01180
commit
425bc857cf
@ -58,6 +58,10 @@ public class Account {
|
|||||||
return accessToken;
|
return accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAccessToken(String accessToken) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
public String getRefreshToken() {
|
public String getRefreshToken() {
|
||||||
return refreshToken;
|
return refreshToken;
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,19 @@ import androidx.room.Insert;
|
|||||||
import androidx.room.OnConflictStrategy;
|
import androidx.room.OnConflictStrategy;
|
||||||
import androidx.room.Query;
|
import androidx.room.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public interface AccountDao {
|
public interface AccountDao {
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
void insert(Account account);
|
void insert(Account account);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM accounts WHERE is_current_user = 0")
|
||||||
|
List<Account> getAllNonCurrentAccounts();
|
||||||
|
|
||||||
|
@Query("UPDATE accounts SET is_current_user = 0 WHERE is_current_user = 1")
|
||||||
|
void markAllAccountsNonCurrent();
|
||||||
|
|
||||||
@Query("DELETE FROM accounts")
|
@Query("DELETE FROM accounts")
|
||||||
void deleteAllAccounts();
|
void deleteAllAccounts();
|
||||||
|
|
||||||
@ -19,4 +27,7 @@ public interface AccountDao {
|
|||||||
|
|
||||||
@Query("SELECT * FROM accounts WHERE username = :userName COLLATE NOCASE LIMIT 1")
|
@Query("SELECT * FROM accounts WHERE username = :userName COLLATE NOCASE LIMIT 1")
|
||||||
Account getAccountData(String userName);
|
Account getAccountData(String userName);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM accounts WHERE is_current_user = 1 LIMIT 1")
|
||||||
|
Account getCurrentAccount();
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package Account;
|
package Account;
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
public class AccountRepository {
|
public class AccountRepository {
|
||||||
private AccountDao mAccountDao;
|
private AccountDao mAccountDao;
|
||||||
private LiveData<Account> mAccountLiveData;
|
private LiveData<Account> mAccountLiveData;
|
||||||
|
|
||||||
AccountRepository(Application application, String username) {
|
AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
||||||
mAccountDao = AccountRoomDatabase.getDatabase(application).accountDao();
|
mAccountDao = redditDataRoomDatabase.accountDao();
|
||||||
|
|
||||||
mAccountLiveData = mAccountDao.getAccountLiveData(username);
|
mAccountLiveData = mAccountDao.getAccountLiveData(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
package Account;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import androidx.room.Database;
|
|
||||||
import androidx.room.Room;
|
|
||||||
import androidx.room.RoomDatabase;
|
|
||||||
|
|
||||||
@Database(entities = {Account.class}, version = 1)
|
|
||||||
public abstract class AccountRoomDatabase extends RoomDatabase {
|
|
||||||
private static AccountRoomDatabase INSTANCE;
|
|
||||||
|
|
||||||
public abstract AccountDao accountDao();
|
|
||||||
|
|
||||||
public static AccountRoomDatabase getDatabase(final Context context) {
|
|
||||||
if(INSTANCE == null) {
|
|
||||||
synchronized (AccountRoomDatabase.class) {
|
|
||||||
if(INSTANCE == null) {
|
|
||||||
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
|
|
||||||
AccountRoomDatabase.class, "accounts")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,13 +8,15 @@ import androidx.lifecycle.LiveData;
|
|||||||
import androidx.lifecycle.ViewModel;
|
import androidx.lifecycle.ViewModel;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
public class AccountViewModel extends AndroidViewModel {
|
public class AccountViewModel extends AndroidViewModel {
|
||||||
private AccountRepository mAccountRepository;
|
private AccountRepository mAccountRepository;
|
||||||
private LiveData<Account> mAccountLiveData;
|
private LiveData<Account> mAccountLiveData;
|
||||||
|
|
||||||
public AccountViewModel(Application application, String id) {
|
public AccountViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) {
|
||||||
super(application);
|
super(application);
|
||||||
mAccountRepository = new AccountRepository(application, id);
|
mAccountRepository = new AccountRepository(redditDataRoomDatabase, id);
|
||||||
mAccountLiveData = mAccountRepository.getAccountLiveData();
|
mAccountLiveData = mAccountRepository.getAccountLiveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,18 +32,19 @@ public class AccountViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Application mApplication;
|
private final Application mApplication;
|
||||||
|
private final RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
private final String mUsername;
|
||||||
|
|
||||||
private final String userName;
|
public Factory(@NonNull Application application, RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
||||||
|
|
||||||
public Factory(@NonNull Application application, String userName) {
|
|
||||||
mApplication = application;
|
mApplication = application;
|
||||||
this.userName = userName;
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
|
mUsername = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(Class<T> modelClass) {
|
public <T extends ViewModel> T create(Class<T> modelClass) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return (T) new AccountViewModel(mApplication, userName);
|
return (T) new AccountViewModel(mApplication, mRedditDataRoomDatabase, mUsername);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,49 @@
|
|||||||
package SubredditDatabase;
|
package SubredditDatabase;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.room.ColumnInfo;
|
import androidx.room.ColumnInfo;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
import SubscribedSubredditDatabase.SubscribedSubredditData;
|
|
||||||
|
|
||||||
@Entity(tableName = "subreddits")
|
@Entity(tableName = "subreddits")
|
||||||
public class SubredditData extends SubscribedSubredditData {
|
public class SubredditData {
|
||||||
|
@PrimaryKey
|
||||||
|
@NonNull
|
||||||
|
@ColumnInfo(name = "id")
|
||||||
|
private String id;
|
||||||
|
@ColumnInfo(name = "name")
|
||||||
|
private String name;
|
||||||
|
@ColumnInfo(name = "icon")
|
||||||
|
private String iconUrl;
|
||||||
@ColumnInfo(name = "banner")
|
@ColumnInfo(name = "banner")
|
||||||
private String bannerUrl;
|
private String bannerUrl;
|
||||||
|
|
||||||
@ColumnInfo(name = "description")
|
@ColumnInfo(name = "description")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@ColumnInfo(name = "subscribers_count")
|
@ColumnInfo(name = "subscribers_count")
|
||||||
private int nSubscribers;
|
private int nSubscribers;
|
||||||
|
|
||||||
public SubredditData(@NonNull String id, String name, String iconUrl, String bannerUrl, String description, int nSubscribers) {
|
public SubredditData(@NonNull String id, String name, String iconUrl, String bannerUrl, String description, int nSubscribers) {
|
||||||
super(id, name, iconUrl);
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.iconUrl = iconUrl;
|
||||||
this.bannerUrl = bannerUrl;
|
this.bannerUrl = bannerUrl;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.nSubscribers = nSubscribers;
|
this.nSubscribers = nSubscribers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIconUrl() {
|
||||||
|
return iconUrl;
|
||||||
|
}
|
||||||
|
|
||||||
public String getBannerUrl() {
|
public String getBannerUrl() {
|
||||||
return bannerUrl;
|
return bannerUrl;
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package SubredditDatabase;
|
package SubredditDatabase;
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
public class SubredditRepository {
|
public class SubredditRepository {
|
||||||
private SubredditDao mSubredditDao;
|
private SubredditDao mSubredditDao;
|
||||||
private LiveData<SubredditData> mSubredditLiveData;
|
private LiveData<SubredditData> mSubredditLiveData;
|
||||||
|
|
||||||
SubredditRepository(Application application, String subredditName) {
|
SubredditRepository(RedditDataRoomDatabase redditDataRoomDatabase, String subredditName) {
|
||||||
SubredditRoomDatabase db = SubredditRoomDatabase.getDatabase(application);
|
mSubredditDao = redditDataRoomDatabase.subredditDao();
|
||||||
mSubredditDao = db.subredditDao();
|
|
||||||
|
|
||||||
mSubredditLiveData = mSubredditDao.getSubredditLiveDataByName(subredditName);
|
mSubredditLiveData = mSubredditDao.getSubredditLiveDataByName(subredditName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
package SubredditDatabase;
|
|
||||||
|
|
||||||
import androidx.room.Database;
|
|
||||||
import androidx.room.Room;
|
|
||||||
import androidx.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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,13 +7,15 @@ import androidx.lifecycle.ViewModel;
|
|||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
public class SubredditViewModel extends AndroidViewModel {
|
public class SubredditViewModel extends AndroidViewModel {
|
||||||
private SubredditRepository mSubredditRepository;
|
private SubredditRepository mSubredditRepository;
|
||||||
private LiveData<SubredditData> mSubredditLiveData;
|
private LiveData<SubredditData> mSubredditLiveData;
|
||||||
|
|
||||||
public SubredditViewModel(Application application, String id) {
|
public SubredditViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) {
|
||||||
super(application);
|
super(application);
|
||||||
mSubredditRepository = new SubredditRepository(application, id);
|
mSubredditRepository = new SubredditRepository(redditDataRoomDatabase, id);
|
||||||
mSubredditLiveData = mSubredditRepository.getSubredditLiveData();
|
mSubredditLiveData = mSubredditRepository.getSubredditLiveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,19 +31,20 @@ public class SubredditViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Application mApplication;
|
private final Application mApplication;
|
||||||
|
private final RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
private final String mSubredditName;
|
||||||
|
|
||||||
private final String subredditName;
|
public Factory(@NonNull Application application, RedditDataRoomDatabase redditDataRoomDatabase, String subredditname) {
|
||||||
|
|
||||||
public Factory(@NonNull Application application, String subredditName) {
|
|
||||||
mApplication = application;
|
mApplication = application;
|
||||||
this.subredditName = subredditName;
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
|
mSubredditName = subredditname;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return (T) new SubredditViewModel(mApplication, subredditName);
|
return (T) new SubredditViewModel(mApplication, mRedditDataRoomDatabase, mSubredditName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,12 @@ public interface SubscribedSubredditDao {
|
|||||||
@Query("DELETE FROM subscribed_subreddits")
|
@Query("DELETE FROM subscribed_subreddits")
|
||||||
void deleteAllSubscribedSubreddits();
|
void deleteAllSubscribedSubreddits();
|
||||||
|
|
||||||
@Query("SELECT * from subscribed_subreddits ORDER BY name COLLATE NOCASE ASC")
|
@Query("SELECT * from subscribed_subreddits WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
|
||||||
LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits();
|
LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits(String accountName);
|
||||||
|
|
||||||
@Query("SELECT * from subscribed_subreddits WHERE name = :subredditName COLLATE NOCASE LIMIT 1")
|
@Query("SELECT * from subscribed_subreddits WHERE name = :subredditName AND username = :accountName COLLATE NOCASE LIMIT 1")
|
||||||
SubscribedSubredditData getSubscribedSubreddit(String subredditName);
|
SubscribedSubredditData getSubscribedSubreddit(String subredditName, String accountName);
|
||||||
|
|
||||||
@Query("DELETE FROM subscribed_subreddits WHERE name = :subredditName")
|
@Query("DELETE FROM subscribed_subreddits WHERE name = :subredditName AND username = :accountName")
|
||||||
void deleteSubscribedSubreddit(String subredditName);
|
void deleteSubscribedSubreddit(String subredditName, String accountName);
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,14 @@ package SubscribedSubredditDatabase;
|
|||||||
|
|
||||||
import androidx.room.ColumnInfo;
|
import androidx.room.ColumnInfo;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
|
import androidx.room.ForeignKey;
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
@Entity(tableName = "subscribed_subreddits")
|
import Account.Account;
|
||||||
|
|
||||||
|
@Entity(tableName = "subscribed_subreddits", foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username",
|
||||||
|
childColumns = "username", onDelete = ForeignKey.CASCADE))
|
||||||
public class SubscribedSubredditData {
|
public class SubscribedSubredditData {
|
||||||
|
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
@ -16,11 +20,14 @@ public class SubscribedSubredditData {
|
|||||||
private String name;
|
private String name;
|
||||||
@ColumnInfo(name = "icon")
|
@ColumnInfo(name = "icon")
|
||||||
private String iconUrl;
|
private String iconUrl;
|
||||||
|
@ColumnInfo(name = "username")
|
||||||
|
private String username;
|
||||||
|
|
||||||
public SubscribedSubredditData(@NonNull String id, String name, String iconUrl) {
|
public SubscribedSubredditData(@NonNull String id, String name, String iconUrl, String username) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.iconUrl = iconUrl;
|
this.iconUrl = iconUrl;
|
||||||
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -35,4 +42,12 @@ public class SubscribedSubredditData {
|
|||||||
public String getIconUrl() {
|
public String getIconUrl() {
|
||||||
return iconUrl;
|
return iconUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
package SubscribedSubredditDatabase;
|
package SubscribedSubredditDatabase;
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
public class SubscribedSubredditRepository {
|
public class SubscribedSubredditRepository {
|
||||||
private SubscribedSubredditDao mSubscribedSubredditDao;
|
private SubscribedSubredditDao mSubscribedSubredditDao;
|
||||||
private LiveData<List<SubscribedSubredditData>> mAllSubscribedSubreddits;
|
private LiveData<List<SubscribedSubredditData>> mAllSubscribedSubreddits;
|
||||||
|
|
||||||
SubscribedSubredditRepository(Application application) {
|
SubscribedSubredditRepository(RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
|
||||||
SubscribedSubredditRoomDatabase db = SubscribedSubredditRoomDatabase.getDatabase(application);
|
mSubscribedSubredditDao = redditDataRoomDatabase.subscribedSubredditDao();
|
||||||
mSubscribedSubredditDao = db.subscribedSubredditDao();
|
mAllSubscribedSubreddits = mSubscribedSubredditDao.getAllSubscribedSubreddits(accountName);
|
||||||
mAllSubscribedSubreddits = mSubscribedSubredditDao.getAllSubscribedSubreddits();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits() {
|
LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits() {
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
package SubscribedSubredditDatabase;
|
|
||||||
|
|
||||||
import androidx.room.Database;
|
|
||||||
import androidx.room.Room;
|
|
||||||
import androidx.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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +1,24 @@
|
|||||||
package SubscribedSubredditDatabase;
|
package SubscribedSubredditDatabase;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
public class SubscribedSubredditViewModel extends AndroidViewModel {
|
public class SubscribedSubredditViewModel extends AndroidViewModel {
|
||||||
private SubscribedSubredditRepository mSubscribedSubredditRepository;
|
private SubscribedSubredditRepository mSubscribedSubredditRepository;
|
||||||
private LiveData<List<SubscribedSubredditData>> mAllSubscribedSubreddits;
|
private LiveData<List<SubscribedSubredditData>> mAllSubscribedSubreddits;
|
||||||
|
|
||||||
public SubscribedSubredditViewModel(Application application) {
|
public SubscribedSubredditViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
|
||||||
super(application);
|
super(application);
|
||||||
mSubscribedSubredditRepository = new SubscribedSubredditRepository(application);
|
mSubscribedSubredditRepository = new SubscribedSubredditRepository(redditDataRoomDatabase, accountName);
|
||||||
mAllSubscribedSubreddits = mSubscribedSubredditRepository.getAllSubscribedSubreddits();
|
mAllSubscribedSubreddits = mSubscribedSubredditRepository.getAllSubscribedSubreddits();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,4 +29,22 @@ public class SubscribedSubredditViewModel extends AndroidViewModel {
|
|||||||
public void insert(SubscribedSubredditData subscribedSubredditData) {
|
public void insert(SubscribedSubredditData subscribedSubredditData) {
|
||||||
mSubscribedSubredditRepository.insert(subscribedSubredditData);
|
mSubscribedSubredditRepository.insert(subscribedSubredditData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||||
|
private Application mApplication;
|
||||||
|
private RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
private String mAccountName;
|
||||||
|
|
||||||
|
public Factory(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
|
||||||
|
this.mApplication = application;
|
||||||
|
this.mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
|
this.mAccountName = accountName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
|
return (T) new SubscribedSubredditViewModel(mApplication, mRedditDataRoomDatabase, mAccountName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,12 @@ public interface SubscribedUserDao {
|
|||||||
@Query("DELETE FROM subscribed_users")
|
@Query("DELETE FROM subscribed_users")
|
||||||
void deleteAllSubscribedUsers();
|
void deleteAllSubscribedUsers();
|
||||||
|
|
||||||
@Query("SELECT * FROM subscribed_users ORDER BY name COLLATE NOCASE ASC")
|
@Query("SELECT * FROM subscribed_users WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
|
||||||
LiveData<List<SubscribedUserData>> getAllSubscribedUsers();
|
LiveData<List<SubscribedUserData>> getAllSubscribedUsers(String accountName);
|
||||||
|
|
||||||
@Query("SELECT * FROM subscribed_users WHERE name = :userName COLLATE NOCASE LIMIT 1")
|
@Query("SELECT * FROM subscribed_users WHERE name = :name AND username = :accountName COLLATE NOCASE LIMIT 1")
|
||||||
SubscribedUserData getSubscribedUser(String userName);
|
SubscribedUserData getSubscribedUser(String name, String accountName);
|
||||||
|
|
||||||
@Query("DELETE FROM subscribed_users WHERE name = :userName")
|
@Query("DELETE FROM subscribed_users WHERE name = :name AND username = :accountName")
|
||||||
void deleteSubscribedUser(String userName);
|
void deleteSubscribedUser(String name, String accountName);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package SubscribedUserDatabase;
|
package SubscribedUserDatabase;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.room.ColumnInfo;
|
import androidx.room.ColumnInfo;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
|
import androidx.room.ForeignKey;
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
@Entity(tableName = "subscribed_users")
|
import Account.Account;
|
||||||
|
|
||||||
|
@Entity(tableName = "subscribed_users", foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username",
|
||||||
|
childColumns = "username", onDelete = ForeignKey.CASCADE))
|
||||||
public class SubscribedUserData {
|
public class SubscribedUserData {
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -13,10 +17,13 @@ public class SubscribedUserData {
|
|||||||
private String name;
|
private String name;
|
||||||
@ColumnInfo(name = "icon")
|
@ColumnInfo(name = "icon")
|
||||||
private String iconUrl;
|
private String iconUrl;
|
||||||
|
@ColumnInfo(name = "username")
|
||||||
|
private String username;
|
||||||
|
|
||||||
public SubscribedUserData(@NonNull String name, String iconUrl) {
|
public SubscribedUserData(@NonNull String name, String iconUrl, String username) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.iconUrl = iconUrl;
|
this.iconUrl = iconUrl;
|
||||||
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -27,4 +34,12 @@ public class SubscribedUserData {
|
|||||||
public String getIconUrl() {
|
public String getIconUrl() {
|
||||||
return iconUrl;
|
return iconUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
package SubscribedUserDatabase;
|
package SubscribedUserDatabase;
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
public class SubscribedUserRepository {
|
public class SubscribedUserRepository {
|
||||||
private SubscribedUserDao mSubscribedUserDao;
|
private SubscribedUserDao mSubscribedUserDao;
|
||||||
private LiveData<List<SubscribedUserData>> mAllSubscribedUsers;
|
private LiveData<List<SubscribedUserData>> mAllSubscribedUsers;
|
||||||
|
|
||||||
SubscribedUserRepository(Application application) {
|
SubscribedUserRepository(RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
|
||||||
SubscribedUserRoomDatabase db = SubscribedUserRoomDatabase.getDatabase(application);
|
mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
|
||||||
mSubscribedUserDao = db.subscribedUserDao();
|
mAllSubscribedUsers = mSubscribedUserDao.getAllSubscribedUsers(accountName);
|
||||||
mAllSubscribedUsers = mSubscribedUserDao.getAllSubscribedUsers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveData<List<SubscribedUserData>> getAllSubscribedSubreddits() {
|
LiveData<List<SubscribedUserData>> getAllSubscribedSubreddits() {
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
package SubscribedUserDatabase;
|
|
||||||
|
|
||||||
import androidx.room.Database;
|
|
||||||
import androidx.room.Room;
|
|
||||||
import androidx.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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +1,24 @@
|
|||||||
package SubscribedUserDatabase;
|
package SubscribedUserDatabase;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
public class SubscribedUserViewModel extends AndroidViewModel {
|
public class SubscribedUserViewModel extends AndroidViewModel {
|
||||||
private SubscribedUserRepository mSubscribedUserRepository;
|
private SubscribedUserRepository mSubscribedUserRepository;
|
||||||
private LiveData<List<SubscribedUserData>> mAllSubscribedUsers;
|
private LiveData<List<SubscribedUserData>> mAllSubscribedUsers;
|
||||||
|
|
||||||
public SubscribedUserViewModel(Application application) {
|
public SubscribedUserViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
|
||||||
super(application);
|
super(application);
|
||||||
mSubscribedUserRepository = new SubscribedUserRepository(application);
|
mSubscribedUserRepository = new SubscribedUserRepository(redditDataRoomDatabase, accountName);
|
||||||
mAllSubscribedUsers = mSubscribedUserRepository.getAllSubscribedSubreddits();
|
mAllSubscribedUsers = mSubscribedUserRepository.getAllSubscribedSubreddits();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,4 +29,22 @@ public class SubscribedUserViewModel extends AndroidViewModel {
|
|||||||
public void insert(SubscribedUserData subscribedUserData) {
|
public void insert(SubscribedUserData subscribedUserData) {
|
||||||
mSubscribedUserRepository.insert(subscribedUserData);
|
mSubscribedUserRepository.insert(subscribedUserData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||||
|
private Application mApplication;
|
||||||
|
private RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
private String mAccountName;
|
||||||
|
|
||||||
|
public Factory(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
|
||||||
|
mApplication = application;
|
||||||
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
|
mAccountName = accountName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
|
return (T) new SubscribedUserViewModel(mApplication, mRedditDataRoomDatabase, mAccountName);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
package User;
|
package User;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.room.ColumnInfo;
|
import androidx.room.ColumnInfo;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
import SubscribedUserDatabase.SubscribedUserData;
|
|
||||||
|
|
||||||
@Entity(tableName = "users")
|
@Entity(tableName = "users")
|
||||||
public class UserData extends SubscribedUserData {
|
public class UserData {
|
||||||
|
@PrimaryKey
|
||||||
|
@NonNull
|
||||||
|
@ColumnInfo(name = "name")
|
||||||
|
private String name;
|
||||||
|
@ColumnInfo(name = "icon")
|
||||||
|
private String iconUrl;
|
||||||
@ColumnInfo(name = "banner")
|
@ColumnInfo(name = "banner")
|
||||||
private String banner;
|
private String banner;
|
||||||
@ColumnInfo(name = "karma")
|
@ColumnInfo(name = "karma")
|
||||||
@ -20,7 +25,8 @@ public class UserData extends SubscribedUserData {
|
|||||||
private boolean canBeFollowed;
|
private boolean canBeFollowed;
|
||||||
|
|
||||||
public UserData(@NonNull String name, String iconUrl, String banner, int karma, boolean isGold, boolean isFriend, boolean canBeFollowed) {
|
public UserData(@NonNull String name, String iconUrl, String banner, int karma, boolean isGold, boolean isFriend, boolean canBeFollowed) {
|
||||||
super(name, iconUrl);
|
this.name = name;
|
||||||
|
this.iconUrl = iconUrl;
|
||||||
this.banner = banner;
|
this.banner = banner;
|
||||||
this.karma = karma;
|
this.karma = karma;
|
||||||
this.isGold = isGold;
|
this.isGold = isGold;
|
||||||
@ -28,6 +34,15 @@ public class UserData extends SubscribedUserData {
|
|||||||
this.canBeFollowed = canBeFollowed;
|
this.canBeFollowed = canBeFollowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIconUrl() {
|
||||||
|
return iconUrl;
|
||||||
|
}
|
||||||
|
|
||||||
public String getBanner() {
|
public String getBanner() {
|
||||||
return banner;
|
return banner;
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
package User;
|
package User;
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
public class UserRepository {
|
public class UserRepository {
|
||||||
private UserDao mUserDao;
|
private UserDao mUserDao;
|
||||||
private LiveData<UserData> mUserLiveData;
|
private LiveData<UserData> mUserLiveData;
|
||||||
|
|
||||||
UserRepository(Application application, String userName) {
|
UserRepository(RedditDataRoomDatabase redditDataRoomDatabase, String userName) {
|
||||||
mUserDao = UserRoomDatabase.getDatabase(application).userDao();
|
mUserDao = redditDataRoomDatabase.userDao();
|
||||||
|
|
||||||
mUserLiveData = mUserDao.getUserLiveData(userName);
|
mUserLiveData = mUserDao.getUserLiveData(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
package User;
|
|
||||||
|
|
||||||
import androidx.room.Database;
|
|
||||||
import androidx.room.Room;
|
|
||||||
import androidx.room.RoomDatabase;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
@Database(entities = {UserData.class}, version = 1)
|
|
||||||
public abstract class UserRoomDatabase extends RoomDatabase {
|
|
||||||
private static UserRoomDatabase INSTANCE;
|
|
||||||
|
|
||||||
public abstract UserDao userDao();
|
|
||||||
|
|
||||||
public static UserRoomDatabase getDatabase(final Context context) {
|
|
||||||
if(INSTANCE == null) {
|
|
||||||
synchronized (UserRoomDatabase.class) {
|
|
||||||
if(INSTANCE == null) {
|
|
||||||
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
|
|
||||||
UserRoomDatabase.class, "users")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,13 +7,15 @@ import androidx.lifecycle.ViewModel;
|
|||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
|
||||||
public class UserViewModel extends AndroidViewModel {
|
public class UserViewModel extends AndroidViewModel {
|
||||||
private UserRepository mSubredditRepository;
|
private UserRepository mSubredditRepository;
|
||||||
private LiveData<UserData> mUserLiveData;
|
private LiveData<UserData> mUserLiveData;
|
||||||
|
|
||||||
public UserViewModel(Application application, String id) {
|
public UserViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) {
|
||||||
super(application);
|
super(application);
|
||||||
mSubredditRepository = new UserRepository(application, id);
|
mSubredditRepository = new UserRepository(redditDataRoomDatabase, id);
|
||||||
mUserLiveData = mSubredditRepository.getUserLiveData();
|
mUserLiveData = mSubredditRepository.getUserLiveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,18 +31,19 @@ public class UserViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Application mApplication;
|
private final Application mApplication;
|
||||||
|
private final RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
private final String mUsername;
|
||||||
|
|
||||||
private final String userName;
|
public Factory(@NonNull Application application, RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
||||||
|
|
||||||
public Factory(@NonNull Application application, String userName) {
|
|
||||||
mApplication = application;
|
mApplication = application;
|
||||||
this.userName = userName;
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
|
mUsername = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(Class<T> modelClass) {
|
public <T extends ViewModel> T create(Class<T> modelClass) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return (T) new UserViewModel(mApplication, userName);
|
return (T) new UserViewModel(mApplication, mRedditDataRoomDatabase, mUsername);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -10,8 +12,7 @@ import java.io.IOException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import Account.Account;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import okhttp3.Authenticator;
|
import okhttp3.Authenticator;
|
||||||
import okhttp3.Headers;
|
import okhttp3.Headers;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
@ -22,37 +23,38 @@ import retrofit2.Retrofit;
|
|||||||
|
|
||||||
class AccessTokenAuthenticator implements Authenticator {
|
class AccessTokenAuthenticator implements Authenticator {
|
||||||
private Retrofit mRetrofit;
|
private Retrofit mRetrofit;
|
||||||
private SharedPreferences mAuthInfoSharedPreferences;
|
private RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
AccessTokenAuthenticator(Retrofit retrofit, SharedPreferences authInfoSharedPreferences) {
|
AccessTokenAuthenticator(Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) {
|
||||||
mRetrofit = retrofit;
|
mRetrofit = retrofit;
|
||||||
mAuthInfoSharedPreferences = authInfoSharedPreferences;
|
mRedditDataRoomDatabase = accountRoomDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Request authenticate(@NonNull Route route, @NonNull Response response) {
|
public Request authenticate(Route route, @NonNull Response response) {
|
||||||
if (response.code() == 401) {
|
if (response.code() == 401) {
|
||||||
String accessToken = response.request().header(RedditUtils.AUTHORIZATION_KEY).substring(RedditUtils.AUTHORIZATION_BASE.length());
|
String accessToken = response.request().header(RedditUtils.AUTHORIZATION_KEY).substring(RedditUtils.AUTHORIZATION_BASE.length());
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
String accessTokenFromSharedPreferences = mAuthInfoSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount();
|
||||||
if (accessToken.equals(accessTokenFromSharedPreferences)) {
|
String accessTokenFromDatabase = account.getAccessToken();
|
||||||
String newAccessToken = refreshAccessToken();
|
if (accessToken.equals(accessTokenFromDatabase)) {
|
||||||
|
String newAccessToken = refreshAccessToken(account);
|
||||||
if (!newAccessToken.equals("")) {
|
if (!newAccessToken.equals("")) {
|
||||||
return response.request().newBuilder().headers(Headers.of(RedditUtils.getOAuthHeader(newAccessToken))).build();
|
return response.request().newBuilder().headers(Headers.of(RedditUtils.getOAuthHeader(newAccessToken))).build();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return response.request().newBuilder().headers(Headers.of(RedditUtils.getOAuthHeader(accessTokenFromSharedPreferences))).build();
|
return response.request().newBuilder().headers(Headers.of(RedditUtils.getOAuthHeader(accessTokenFromDatabase))).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String refreshAccessToken() {
|
private String refreshAccessToken(Account account) {
|
||||||
String refreshToken = mAuthInfoSharedPreferences.getString(SharedPreferencesUtils.REFRESH_TOKEN_KEY, "");
|
String refreshToken = mRedditDataRoomDatabase.accountDao().getCurrentAccount().getRefreshToken();
|
||||||
|
|
||||||
RedditAPI api = mRetrofit.create(RedditAPI.class);
|
RedditAPI api = mRetrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
@ -63,11 +65,14 @@ class AccessTokenAuthenticator implements Authenticator {
|
|||||||
Call<String> accessTokenCall = api.getAccessToken(RedditUtils.getHttpBasicAuthHeader(), params);
|
Call<String> accessTokenCall = api.getAccessToken(RedditUtils.getHttpBasicAuthHeader(), params);
|
||||||
try {
|
try {
|
||||||
retrofit2.Response response = accessTokenCall.execute();
|
retrofit2.Response response = accessTokenCall.execute();
|
||||||
|
if(response.body() == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject((String) response.body());
|
JSONObject jsonObject = new JSONObject((String) response.body());
|
||||||
|
|
||||||
String newAccessToken = jsonObject.getString(RedditUtils.ACCESS_TOKEN_KEY);
|
String newAccessToken = jsonObject.getString(RedditUtils.ACCESS_TOKEN_KEY);
|
||||||
|
account.setAccessToken(newAccessToken);
|
||||||
mAuthInfoSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, newAccessToken).apply();
|
mRedditDataRoomDatabase.accountDao().insert(account);
|
||||||
|
|
||||||
Log.i("access token", newAccessToken);
|
Log.i("access token", newAccessToken);
|
||||||
return newAccessToken;
|
return newAccessToken;
|
||||||
|
@ -26,4 +26,8 @@ interface AppComponent {
|
|||||||
void inject(RulesActivity rulesActivity);
|
void inject(RulesActivity rulesActivity);
|
||||||
void inject(CommentsListingFragment commentsListingFragment);
|
void inject(CommentsListingFragment commentsListingFragment);
|
||||||
void inject(SubmitPostService submitPostService);
|
void inject(SubmitPostService submitPostService);
|
||||||
|
void inject(FilteredPostsActivity filteredPostsActivity);
|
||||||
|
void inject(SearchResultActivity searchResultActivity);
|
||||||
|
void inject(SearchSubredditsResultActivity searchSubredditsResultActivity);
|
||||||
|
void inject(FollowedUsersListingFragment followedUsersListingFragment);
|
||||||
}
|
}
|
||||||
|
@ -60,9 +60,9 @@ class AppModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, @Named("auth_info") SharedPreferences sharedPreferences) {
|
OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) {
|
||||||
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
|
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
|
||||||
okHttpClientBuilder.authenticator(new AccessTokenAuthenticator(retrofit, sharedPreferences));
|
okHttpClientBuilder.authenticator(new AccessTokenAuthenticator(retrofit, accountRoomDatabase));
|
||||||
return okHttpClientBuilder.build();
|
return okHttpClientBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,4 +76,10 @@ class AppModule {
|
|||||||
SharedPreferences provideUserInfoSharedPreferences() {
|
SharedPreferences provideUserInfoSharedPreferences() {
|
||||||
return mApplication.getSharedPreferences(SharedPreferencesUtils.USER_INFO_FILE_KEY, Context.MODE_PRIVATE);
|
return mApplication.getSharedPreferences(SharedPreferencesUtils.USER_INFO_FILE_KEY, Context.MODE_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
RedditDataRoomDatabase provideRedditDataRoomDatabase() {
|
||||||
|
return RedditDataRoomDatabase.getDatabase(mApplication);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@ import SubscribedUserDatabase.SubscribedUserData;
|
|||||||
|
|
||||||
public class CheckIsFollowingUserAsyncTask extends AsyncTask<Void, Void, Void> {
|
public class CheckIsFollowingUserAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
private SubscribedUserDao subscribedUserDao;
|
private SubscribedUserDao subscribedUserDao;
|
||||||
private String userName;
|
private String username;
|
||||||
|
private String accountName;
|
||||||
private SubscribedUserData subscribedUserData;
|
private SubscribedUserData subscribedUserData;
|
||||||
private CheckIsFollowingUserListener checkIsFollowingUserListener;
|
private CheckIsFollowingUserListener checkIsFollowingUserListener;
|
||||||
|
|
||||||
@ -16,16 +17,17 @@ public class CheckIsFollowingUserAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||||||
void isNotSubscribed();
|
void isNotSubscribed();
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckIsFollowingUserAsyncTask(SubscribedUserDao subscribedUserDao, String userName,
|
CheckIsFollowingUserAsyncTask(SubscribedUserDao subscribedUserDao, String username, String accountName,
|
||||||
CheckIsFollowingUserListener checkIsFollowingUserListener) {
|
CheckIsFollowingUserListener checkIsFollowingUserListener) {
|
||||||
this.subscribedUserDao = subscribedUserDao;
|
this.subscribedUserDao = subscribedUserDao;
|
||||||
this.userName = userName;
|
this.username = username;
|
||||||
|
this.accountName = accountName;
|
||||||
this.checkIsFollowingUserListener = checkIsFollowingUserListener;
|
this.checkIsFollowingUserListener = checkIsFollowingUserListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
subscribedUserData = subscribedUserDao.getSubscribedUser(userName);
|
subscribedUserData = subscribedUserDao.getSubscribedUser(username, accountName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ class CheckIsSubscribedToSubredditAsyncTask extends AsyncTask<Void, Void, Void>
|
|||||||
|
|
||||||
private SubscribedSubredditDao subscribedSubredditDao;
|
private SubscribedSubredditDao subscribedSubredditDao;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
|
private String accountName;
|
||||||
private SubscribedSubredditData subscribedSubredditData;
|
private SubscribedSubredditData subscribedSubredditData;
|
||||||
private CheckIsSubscribedToSubredditListener checkIsSubscribedToSubredditListener;
|
private CheckIsSubscribedToSubredditListener checkIsSubscribedToSubredditListener;
|
||||||
|
|
||||||
@ -17,16 +18,18 @@ class CheckIsSubscribedToSubredditAsyncTask extends AsyncTask<Void, Void, Void>
|
|||||||
void isNotSubscribed();
|
void isNotSubscribed();
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckIsSubscribedToSubredditAsyncTask(SubscribedSubredditDao subscribedSubredditDao, String subredditName,
|
CheckIsSubscribedToSubredditAsyncTask(SubscribedSubredditDao subscribedSubredditDao,
|
||||||
|
String subredditName, String accountName,
|
||||||
CheckIsSubscribedToSubredditListener checkIsSubscribedToSubredditListener) {
|
CheckIsSubscribedToSubredditListener checkIsSubscribedToSubredditListener) {
|
||||||
this.subscribedSubredditDao = subscribedSubredditDao;
|
this.subscribedSubredditDao = subscribedSubredditDao;
|
||||||
this.subredditName =subredditName;
|
this.subredditName =subredditName;
|
||||||
|
this.accountName = accountName;
|
||||||
this.checkIsSubscribedToSubredditListener = checkIsSubscribedToSubredditListener;
|
this.checkIsSubscribedToSubredditListener = checkIsSubscribedToSubredditListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
subscribedSubredditData = subscribedSubredditDao.getSubscribedSubreddit(subredditName);
|
subscribedSubredditData = subscribedSubredditDao.getSubscribedSubreddit(subredditName, accountName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
@ -40,8 +39,6 @@ import java.util.Locale;
|
|||||||
|
|
||||||
import CustomView.AspectRatioGifImageView;
|
import CustomView.AspectRatioGifImageView;
|
||||||
import CustomView.CustomMarkwonView;
|
import CustomView.CustomMarkwonView;
|
||||||
import SubredditDatabase.SubredditRoomDatabase;
|
|
||||||
import User.UserRoomDatabase;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||||
@ -61,8 +58,9 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private Retrofit mRetrofit;
|
private Retrofit mRetrofit;
|
||||||
private Retrofit mOauthRetrofit;
|
private Retrofit mOauthRetrofit;
|
||||||
|
private RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
private SharedPreferences mSharedPreferences;
|
private String mAccessToken;
|
||||||
private Post mPost;
|
private Post mPost;
|
||||||
private ArrayList<CommentData> mVisibleComments;
|
private ArrayList<CommentData> mVisibleComments;
|
||||||
private String mSubredditNamePrefixed;
|
private String mSubredditNamePrefixed;
|
||||||
@ -79,15 +77,17 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
void retryFetchingMoreComments();
|
void retryFetchingMoreComments();
|
||||||
}
|
}
|
||||||
|
|
||||||
CommentAndPostRecyclerViewAdapter(Activity activity, Retrofit retrofit, Retrofit oauthRetrofit, RequestManager glide,
|
CommentAndPostRecyclerViewAdapter(Activity activity, Retrofit retrofit, Retrofit oauthRetrofit,
|
||||||
SharedPreferences sharedPreferences, Post post, String subredditNamePrefixed,
|
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
|
||||||
|
String accessToken, Post post, String subredditNamePrefixed,
|
||||||
Locale locale, LoadSubredditIconAsyncTask loadSubredditIconAsyncTask,
|
Locale locale, LoadSubredditIconAsyncTask loadSubredditIconAsyncTask,
|
||||||
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
|
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mRetrofit = retrofit;
|
mRetrofit = retrofit;
|
||||||
mOauthRetrofit = oauthRetrofit;
|
mOauthRetrofit = oauthRetrofit;
|
||||||
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
mGlide = glide;
|
mGlide = glide;
|
||||||
mSharedPreferences = sharedPreferences;
|
mAccessToken = accessToken;
|
||||||
mPost = post;
|
mPost = post;
|
||||||
mVisibleComments = new ArrayList<>();
|
mVisibleComments = new ArrayList<>();
|
||||||
mSubredditNamePrefixed = subredditNamePrefixed;
|
mSubredditNamePrefixed = subredditNamePrefixed;
|
||||||
@ -164,7 +164,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
|
|
||||||
if(mPost.getSubredditNamePrefixed().equals("u/" + mPost.getAuthor())) {
|
if(mPost.getSubredditNamePrefixed().equals("u/" + mPost.getAuthor())) {
|
||||||
if(mPost.getAuthorIconUrl() == null) {
|
if(mPost.getAuthorIconUrl() == null) {
|
||||||
new LoadUserDataAsyncTask(UserRoomDatabase.getDatabase(mActivity).userDao(), mPost.getAuthor(), mOauthRetrofit, iconImageUrl -> {
|
new LoadUserDataAsyncTask(mRedditDataRoomDatabase.userDao(), mPost.getAuthor(), mOauthRetrofit, iconImageUrl -> {
|
||||||
if(mActivity != null && getItemCount() > 0) {
|
if(mActivity != null && getItemCount() > 0) {
|
||||||
if(iconImageUrl == null || iconImageUrl.equals("")) {
|
if(iconImageUrl == null || iconImageUrl.equals("")) {
|
||||||
mGlide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
@ -200,7 +200,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
mLoadSubredditIconAsyncTask.cancel(true);
|
mLoadSubredditIconAsyncTask.cancel(true);
|
||||||
}
|
}
|
||||||
mLoadSubredditIconAsyncTask = new LoadSubredditIconAsyncTask(
|
mLoadSubredditIconAsyncTask = new LoadSubredditIconAsyncTask(
|
||||||
SubredditRoomDatabase.getDatabase(mActivity).subredditDao(), mPost.getSubredditNamePrefixed().substring(2),
|
mRedditDataRoomDatabase.subredditDao(), mPost.getSubredditNamePrefixed().substring(2),
|
||||||
mRetrofit, iconImageUrl -> {
|
mRetrofit, iconImageUrl -> {
|
||||||
if(iconImageUrl == null || iconImageUrl.equals("")) {
|
if(iconImageUrl == null || iconImageUrl.equals("")) {
|
||||||
mGlide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
@ -749,7 +749,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
|
|
||||||
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
|
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingWithoutPositionListener() {
|
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess() {
|
public void onVoteThingSuccess() {
|
||||||
if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
||||||
@ -808,7 +808,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
|
|
||||||
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
|
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingWithoutPositionListener() {
|
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess() {
|
public void onVoteThingSuccess() {
|
||||||
if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
||||||
@ -911,7 +911,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
|
|
||||||
scoreTextView.setText(Integer.toString(mVisibleComments.get(getAdapterPosition() - 1).getScore() + mVisibleComments.get(getAdapterPosition() - 1).getVoteType()));
|
scoreTextView.setText(Integer.toString(mVisibleComments.get(getAdapterPosition() - 1).getScore() + mVisibleComments.get(getAdapterPosition() - 1).getVoteType()));
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position) {
|
public void onVoteThingSuccess(int position) {
|
||||||
if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
||||||
@ -951,7 +951,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
|
|
||||||
scoreTextView.setText(Integer.toString(mVisibleComments.get(getAdapterPosition() - 1).getScore() + mVisibleComments.get(getAdapterPosition() - 1).getVoteType()));
|
scoreTextView.setText(Integer.toString(mVisibleComments.get(getAdapterPosition() - 1).getScore() + mVisibleComments.get(getAdapterPosition() - 1).getVoteType()));
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
||||||
|
@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -37,6 +36,7 @@ import retrofit2.Retrofit;
|
|||||||
public class CommentsListingFragment extends Fragment implements FragmentCommunicator {
|
public class CommentsListingFragment extends Fragment implements FragmentCommunicator {
|
||||||
|
|
||||||
static final String EXTRA_USERNAME_KEY = "ENK";
|
static final String EXTRA_USERNAME_KEY = "ENK";
|
||||||
|
static final String EXTRA_ACCESS_TOKEN = "EAT";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_comments_listing_fragment) CoordinatorLayout mCoordinatorLayout;
|
@BindView(R.id.coordinator_layout_comments_listing_fragment) CoordinatorLayout mCoordinatorLayout;
|
||||||
@BindView(R.id.recycler_view_comments_listing_fragment) RecyclerView mCommentRecyclerView;
|
@BindView(R.id.recycler_view_comments_listing_fragment) RecyclerView mCommentRecyclerView;
|
||||||
@ -60,9 +60,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
|||||||
@Inject @Named("oauth")
|
@Inject @Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
@Inject @Named("auth_info")
|
|
||||||
SharedPreferences mSharedPreferences;
|
|
||||||
|
|
||||||
public CommentsListingFragment() {
|
public CommentsListingFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
@ -83,7 +80,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
|||||||
|
|
||||||
CommentViewModel.Factory factory;
|
CommentViewModel.Factory factory;
|
||||||
mAdapter = new CommentsListingRecyclerViewAdapter(activity, mOauthRetrofit,
|
mAdapter = new CommentsListingRecyclerViewAdapter(activity, mOauthRetrofit,
|
||||||
mSharedPreferences, () -> mCommentViewModel.retryLoadingMore());
|
getArguments().getString(EXTRA_ACCESS_TOKEN), () -> mCommentViewModel.retryLoadingMore());
|
||||||
|
|
||||||
String username = getArguments().getString(EXTRA_USERNAME_KEY);
|
String username = getArguments().getString(EXTRA_USERNAME_KEY);
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -28,9 +27,9 @@ import retrofit2.Retrofit;
|
|||||||
class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, RecyclerView.ViewHolder> {
|
class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, RecyclerView.ViewHolder> {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Retrofit mOauthRetrofit;
|
private Retrofit mOauthRetrofit;
|
||||||
private SharedPreferences mSharedPreferences;
|
private String mAccessToken;
|
||||||
private int textColorPrimaryDark;
|
private int mTextColorPrimaryDark;
|
||||||
private int colorAccent;
|
private int mColorAccent;
|
||||||
|
|
||||||
private static final int VIEW_TYPE_DATA = 0;
|
private static final int VIEW_TYPE_DATA = 0;
|
||||||
private static final int VIEW_TYPE_ERROR = 1;
|
private static final int VIEW_TYPE_ERROR = 1;
|
||||||
@ -43,15 +42,15 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
|
|||||||
void retryLoadingMore();
|
void retryLoadingMore();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, SharedPreferences sharedPreferences,
|
protected CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, String accessToken,
|
||||||
RetryLoadingMoreCallback retryLoadingMoreCallback) {
|
RetryLoadingMoreCallback retryLoadingMoreCallback) {
|
||||||
super(DIFF_CALLBACK);
|
super(DIFF_CALLBACK);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mOauthRetrofit = oauthRetrofit;
|
mOauthRetrofit = oauthRetrofit;
|
||||||
mSharedPreferences = sharedPreferences;
|
mAccessToken = accessToken;
|
||||||
mRetryLoadingMoreCallback = retryLoadingMoreCallback;
|
mRetryLoadingMoreCallback = retryLoadingMoreCallback;
|
||||||
textColorPrimaryDark = mContext.getResources().getColor(R.color.textColorPrimaryDark);
|
mTextColorPrimaryDark = mContext.getResources().getColor(R.color.textColorPrimaryDark);
|
||||||
colorAccent = mContext.getResources().getColor(R.color.colorAccent);
|
mColorAccent = mContext.getResources().getColor(R.color.colorAccent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final DiffUtil.ItemCallback<CommentData> DIFF_CALLBACK = new DiffUtil.ItemCallback<CommentData>() {
|
private static final DiffUtil.ItemCallback<CommentData> DIFF_CALLBACK = new DiffUtil.ItemCallback<CommentData>() {
|
||||||
@ -88,7 +87,7 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
|
|||||||
|
|
||||||
if(comment.getAuthor().equals(comment.getSubredditName().substring(2))) {
|
if(comment.getAuthor().equals(comment.getSubredditName().substring(2))) {
|
||||||
((DataViewHolder) holder).authorTextView.setText("u/" + comment.getAuthor());
|
((DataViewHolder) holder).authorTextView.setText("u/" + comment.getAuthor());
|
||||||
((DataViewHolder) holder).authorTextView.setTextColor(textColorPrimaryDark);
|
((DataViewHolder) holder).authorTextView.setTextColor(mTextColorPrimaryDark);
|
||||||
((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
|
((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
|
||||||
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
||||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, comment.getAuthor());
|
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, comment.getAuthor());
|
||||||
@ -96,7 +95,7 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
((DataViewHolder) holder).authorTextView.setText("r/" + comment.getSubredditName());
|
((DataViewHolder) holder).authorTextView.setText("r/" + comment.getSubredditName());
|
||||||
((DataViewHolder) holder).authorTextView.setTextColor(colorAccent);
|
((DataViewHolder) holder).authorTextView.setTextColor(mColorAccent);
|
||||||
((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
|
((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
|
||||||
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
|
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
|
||||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, comment.getSubredditName());
|
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, comment.getSubredditName());
|
||||||
@ -225,7 +224,7 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
|
|||||||
|
|
||||||
scoreTextView.setText(Integer.toString(getItem(getAdapterPosition()).getScore() + getItem(getAdapterPosition()).getVoteType()));
|
scoreTextView.setText(Integer.toString(getItem(getAdapterPosition()).getScore() + getItem(getAdapterPosition()).getVoteType()));
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position) {
|
public void onVoteThingSuccess(int position) {
|
||||||
if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
||||||
@ -265,7 +264,7 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
|
|||||||
|
|
||||||
scoreTextView.setText(Integer.toString(getItem(getAdapterPosition()).getScore() + getItem(getAdapterPosition()).getVoteType()));
|
scoreTextView.setText(Integer.toString(getItem(getAdapterPosition()).getScore() + getItem(getAdapterPosition()).getVoteType()));
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -16,31 +15,6 @@ class FetchMyInfo {
|
|||||||
void onFetchMyInfoFail();
|
void onFetchMyInfoFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fetchMyInfo(final Retrofit retrofit, SharedPreferences authInfoSharedPreferences,
|
|
||||||
final FetchUserMyListener fetchUserMyListener) {
|
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
|
||||||
|
|
||||||
String accessToken = authInfoSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
|
||||||
Call<String> userInfo = api.getMyInfo(RedditUtils.getOAuthHeader(accessToken));
|
|
||||||
userInfo.enqueue(new Callback<String>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
|
||||||
if(response.isSuccessful()) {
|
|
||||||
fetchUserMyListener.onFetchMyInfoSuccess(response.body());
|
|
||||||
} else {
|
|
||||||
Log.i("call failed", response.message());
|
|
||||||
fetchUserMyListener.onFetchMyInfoFail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
|
||||||
Log.i("call failed", t.getMessage());
|
|
||||||
fetchUserMyListener.onFetchMyInfoFail();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fetchMyInfo(final Retrofit retrofit, String accessToken,
|
static void fetchMyInfo(final Retrofit retrofit, String accessToken,
|
||||||
final FetchUserMyListener fetchUserMyListener) {
|
final FetchUserMyListener fetchUserMyListener) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import SubredditDatabase.SubredditData;
|
import SubredditDatabase.SubredditData;
|
||||||
@ -22,23 +22,20 @@ class FetchSubscribedThing {
|
|||||||
void onFetchSubscribedThingFail();
|
void onFetchSubscribedThingFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fetchSubscribedThing(final Retrofit retrofit, final SharedPreferences sharedPreferences,
|
static void fetchSubscribedThing(final Retrofit retrofit, String accessToken, String accountName,
|
||||||
final String lastItem,
|
final String lastItem, final ArrayList<SubscribedSubredditData> subscribedSubredditData,
|
||||||
final ArrayList<SubscribedSubredditData> subscribedSubredditData,
|
|
||||||
final ArrayList<SubscribedUserData> subscribedUserData,
|
final ArrayList<SubscribedUserData> subscribedUserData,
|
||||||
final ArrayList<SubredditData> subredditData,
|
final ArrayList<SubredditData> subredditData,
|
||||||
final FetchSubscribedThingListener fetchSubscribedThingListener) {
|
final FetchSubscribedThingListener fetchSubscribedThingListener) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
String accessToken = sharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
|
||||||
|
|
||||||
Call<String> subredditDataCall = api.getSubscribedThing(lastItem, RedditUtils.getOAuthHeader(accessToken));
|
Call<String> subredditDataCall = api.getSubscribedThing(lastItem, RedditUtils.getOAuthHeader(accessToken));
|
||||||
subredditDataCall.enqueue(new Callback<String>() {
|
subredditDataCall.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
ParseSubscribedThing.parseSubscribedSubreddits(response.body(), subscribedSubredditData,
|
ParseSubscribedThing.parseSubscribedSubreddits(response.body(), accountName,
|
||||||
subscribedUserData, subredditData,
|
subscribedSubredditData, subscribedUserData, subredditData,
|
||||||
new ParseSubscribedThing.ParseSubscribedSubredditsListener() {
|
new ParseSubscribedThing.ParseSubscribedSubredditsListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,8 +47,8 @@ class FetchSubscribedThing {
|
|||||||
fetchSubscribedThingListener.onFetchSubscribedThingSuccess(
|
fetchSubscribedThingListener.onFetchSubscribedThingSuccess(
|
||||||
subscribedSubredditData, subscribedUserData, subredditData);
|
subscribedSubredditData, subscribedUserData, subredditData);
|
||||||
} else {
|
} else {
|
||||||
fetchSubscribedThing(retrofit, sharedPreferences, lastItem, subscribedSubredditData,
|
fetchSubscribedThing(retrofit, accessToken, accountName, lastItem,
|
||||||
subscribedUserData, subredditData,
|
subscribedSubredditData, subscribedUserData, subredditData,
|
||||||
fetchSubscribedThingListener);
|
fetchSubscribedThingListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
@ -21,10 +23,14 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType
|
|||||||
static final String EXTRA_POST_TYPE = "EPT";
|
static final String EXTRA_POST_TYPE = "EPT";
|
||||||
static final String EXTRA_SORT_TYPE = "EST";
|
static final String EXTRA_SORT_TYPE = "EST";
|
||||||
|
|
||||||
|
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
||||||
|
private static final String ACCESS_TOKEN_STATE = "ATS";
|
||||||
private static final String FRAGMENT_OUT_STATE = "FOS";
|
private static final String FRAGMENT_OUT_STATE = "FOS";
|
||||||
|
|
||||||
@BindView(R.id.toolbar_filtered_posts_activity) Toolbar toolbar;
|
@BindView(R.id.toolbar_filtered_posts_activity) Toolbar toolbar;
|
||||||
|
|
||||||
|
private boolean mNullAccessToken = false;
|
||||||
|
private String mAccessToken;
|
||||||
private String name;
|
private String name;
|
||||||
private int postType;
|
private int postType;
|
||||||
|
|
||||||
@ -35,6 +41,9 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType
|
|||||||
private SortTypeBottomSheetFragment subredditSortTypeBottomSheetFragment;
|
private SortTypeBottomSheetFragment subredditSortTypeBottomSheetFragment;
|
||||||
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
|
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -42,14 +51,43 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType
|
|||||||
|
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
((Infinity) getApplication()).getmAppComponent().inject(this);
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
name = getIntent().getExtras().getString(EXTRA_NAME);
|
name = getIntent().getExtras().getString(EXTRA_NAME);
|
||||||
int filter = getIntent().getExtras().getInt(EXTRA_FILTER);
|
|
||||||
postType = getIntent().getExtras().getInt(EXTRA_POST_TYPE);
|
postType = getIntent().getExtras().getInt(EXTRA_POST_TYPE);
|
||||||
|
int filter = getIntent().getExtras().getInt(EXTRA_FILTER);
|
||||||
String sortType = getIntent().getExtras().getString(EXTRA_SORT_TYPE);
|
String sortType = getIntent().getExtras().getString(EXTRA_SORT_TYPE);
|
||||||
|
|
||||||
|
if(savedInstanceState != null) {
|
||||||
|
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
||||||
|
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
||||||
|
if(!mNullAccessToken && mAccessToken == null) {
|
||||||
|
getCurrentAccountAndBindView(filter, sortType);
|
||||||
|
} else {
|
||||||
|
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
|
||||||
|
bindView(filter, sortType, false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getCurrentAccountAndBindView(filter, sortType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getCurrentAccountAndBindView(int filter, String sortType) {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if(account == null) {
|
||||||
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
}
|
||||||
|
bindView(filter, sortType, true);
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindView(int filter, String sortType, boolean initializeFragment) {
|
||||||
switch (postType) {
|
switch (postType) {
|
||||||
case PostDataSource.TYPE_FRONT_PAGE:
|
case PostDataSource.TYPE_FRONT_PAGE:
|
||||||
getSupportActionBar().setTitle(name);
|
getSupportActionBar().setTitle(name);
|
||||||
@ -108,21 +146,19 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType
|
|||||||
toolbar.setSubtitle(R.string.gif);
|
toolbar.setSubtitle(R.string.gif);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(savedInstanceState == null) {
|
if(initializeFragment) {
|
||||||
mFragment = new PostFragment();
|
mFragment = new PostFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, name);
|
bundle.putString(PostFragment.EXTRA_NAME, name);
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, postType);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, postType);
|
||||||
bundle.putString(PostFragment.EXTRA_SORT_TYPE, sortType);
|
bundle.putString(PostFragment.EXTRA_SORT_TYPE, sortType);
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, filter);
|
bundle.putInt(PostFragment.EXTRA_FILTER, filter);
|
||||||
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
if(postType == PostDataSource.TYPE_SEARCH) {
|
if(postType == PostDataSource.TYPE_SEARCH) {
|
||||||
bundle.putString(PostFragment.EXTRA_QUERY, getIntent().getExtras().getString(EXTRA_QUERY));
|
bundle.putString(PostFragment.EXTRA_QUERY, getIntent().getExtras().getString(EXTRA_QUERY));
|
||||||
}
|
}
|
||||||
mFragment.setArguments(bundle);
|
mFragment.setArguments(bundle);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
|
||||||
} else {
|
|
||||||
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,6 +206,7 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType
|
|||||||
if (mFragment != null) {
|
if (mFragment != null) {
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
||||||
}
|
}
|
||||||
|
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,6 +17,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.RequestManager;
|
import com.bumptech.glide.RequestManager;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import SubscribedUserDatabase.SubscribedUserViewModel;
|
import SubscribedUserDatabase.SubscribedUserViewModel;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -27,6 +29,8 @@ import butterknife.ButterKnife;
|
|||||||
*/
|
*/
|
||||||
public class FollowedUsersListingFragment extends Fragment {
|
public class FollowedUsersListingFragment extends Fragment {
|
||||||
|
|
||||||
|
static final String EXTRA_ACCOUNT_NAME = "EAN";
|
||||||
|
|
||||||
@BindView(R.id.recycler_view_followed_users_listing_fragment) RecyclerView mRecyclerView;
|
@BindView(R.id.recycler_view_followed_users_listing_fragment) RecyclerView mRecyclerView;
|
||||||
@BindView(R.id.no_subscriptions_linear_layout_followed_users_listing_fragment) LinearLayout mLinearLayout;
|
@BindView(R.id.no_subscriptions_linear_layout_followed_users_listing_fragment) LinearLayout mLinearLayout;
|
||||||
@BindView(R.id.no_subscriptions_image_view_followed_users_listing_fragment) ImageView mImageView;
|
@BindView(R.id.no_subscriptions_image_view_followed_users_listing_fragment) ImageView mImageView;
|
||||||
@ -41,6 +45,8 @@ public class FollowedUsersListingFragment extends Fragment {
|
|||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
@ -51,13 +57,17 @@ public class FollowedUsersListingFragment extends Fragment {
|
|||||||
|
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
|
|
||||||
|
((Infinity) mActivity.getApplication()).getmAppComponent().inject(this);
|
||||||
|
|
||||||
mGlide = Glide.with(this);
|
mGlide = Glide.with(this);
|
||||||
|
|
||||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
|
mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
|
||||||
FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity);
|
FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity);
|
||||||
mRecyclerView.setAdapter(adapter);
|
mRecyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
mSubscribedUserViewModel = ViewModelProviders.of(this).get(SubscribedUserViewModel.class);
|
mSubscribedUserViewModel = ViewModelProviders.of(this,
|
||||||
|
new SubscribedUserViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, getArguments().getString(EXTRA_ACCOUNT_NAME)))
|
||||||
|
.get(SubscribedUserViewModel.class);
|
||||||
mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, subscribedUserData -> {
|
mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, subscribedUserData -> {
|
||||||
if (subscribedUserData == null || subscribedUserData.size() == 0) {
|
if (subscribedUserData == null || subscribedUserData.size() == 0) {
|
||||||
mRecyclerView.setVisibility(View.GONE);
|
mRecyclerView.setVisibility(View.GONE);
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import Account.Account;
|
||||||
|
import Account.AccountDao;
|
||||||
|
|
||||||
|
class GetCurrentAccountAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
|
interface GetCurrentAccountAsyncTaskListener {
|
||||||
|
void success(Account account);
|
||||||
|
}
|
||||||
|
|
||||||
|
Account account;
|
||||||
|
AccountDao accountDao;
|
||||||
|
GetCurrentAccountAsyncTaskListener getCurrentAccountAsyncTaskListener;
|
||||||
|
|
||||||
|
GetCurrentAccountAsyncTask(AccountDao accountDao, GetCurrentAccountAsyncTaskListener getCurrentAccountAsyncTaskListener) {
|
||||||
|
this.accountDao = accountDao;
|
||||||
|
this.getCurrentAccountAsyncTaskListener = getCurrentAccountAsyncTaskListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... voids) {
|
||||||
|
account = accountDao.getCurrentAccount();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid) {
|
||||||
|
getCurrentAccountAsyncTaskListener.success(account);
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,7 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -24,7 +22,6 @@ import java.util.Map;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import Account.AccountRoomDatabase;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
@ -42,6 +39,9 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
@Named("oauth")
|
@Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -75,10 +75,6 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
if(state.equals(RedditUtils.STATE)) {
|
if(state.equals(RedditUtils.STATE)) {
|
||||||
authCode = uri.getQueryParameter("code");
|
authCode = uri.getQueryParameter("code");
|
||||||
|
|
||||||
SharedPreferences.Editor editor = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE).edit();
|
|
||||||
editor.putString(SharedPreferencesUtils.AUTH_CODE_KEY, authCode);
|
|
||||||
editor.apply();
|
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put(RedditUtils.GRANT_TYPE_KEY, "authorization_code");
|
params.put(RedditUtils.GRANT_TYPE_KEY, "authorization_code");
|
||||||
params.put("code", authCode);
|
params.put("code", authCode);
|
||||||
@ -107,8 +103,8 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
ParseMyInfo.parseMyInfo(response, new ParseMyInfo.ParseMyInfoListener() {
|
ParseMyInfo.parseMyInfo(response, new ParseMyInfo.ParseMyInfoListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
|
public void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
|
||||||
new ParseAndInsertAccount(name, accessToken, refreshToken, profileImageUrl, bannerImageUrl,
|
new ParseAndInsertNewAccountAsyncTask(name, accessToken, refreshToken, profileImageUrl, bannerImageUrl,
|
||||||
karma, authCode, AccountRoomDatabase.getDatabase(LoginActivity.this).accountDao(),
|
karma, authCode, mRedditDataRoomDatabase.accountDao(),
|
||||||
() -> {
|
() -> {
|
||||||
Intent resultIntent = new Intent();
|
Intent resultIntent = new Intent();
|
||||||
setResult(Activity.RESULT_OK, resultIntent);
|
setResult(Activity.RESULT_OK, resultIntent);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -48,6 +47,8 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
|
|
||||||
private static final String FETCH_USER_INFO_STATE = "FUIS";
|
private static final String FETCH_USER_INFO_STATE = "FUIS";
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
||||||
|
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
||||||
|
private static final String ACCESS_TOKEN_STATE = "ATS";
|
||||||
|
|
||||||
private static final int LOGIN_ACTIVITY_REQUEST_CODE = 0;
|
private static final int LOGIN_ACTIVITY_REQUEST_CODE = 0;
|
||||||
|
|
||||||
@ -73,6 +74,8 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment;
|
private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment;
|
||||||
private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment;
|
private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment;
|
||||||
|
|
||||||
|
private boolean mNullAccessToken = false;
|
||||||
|
private String mAccessToken;
|
||||||
private String mName;
|
private String mName;
|
||||||
private String mProfileImageUrl;
|
private String mProfileImageUrl;
|
||||||
private String mBannerImageUrl;
|
private String mBannerImageUrl;
|
||||||
@ -87,14 +90,13 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
@Named("user_info")
|
@Named("user_info")
|
||||||
SharedPreferences mUserInfoSharedPreferences;
|
SharedPreferences mUserInfoSharedPreferences;
|
||||||
|
|
||||||
@Inject
|
|
||||||
@Named("auth_info")
|
|
||||||
SharedPreferences mAuthInfoSharedPreferences;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("oauth")
|
@Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -127,85 +129,105 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
|
|
||||||
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
||||||
|
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
if(savedInstanceState != null) {
|
||||||
viewPager.setAdapter(sectionsPagerAdapter);
|
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
|
||||||
viewPager.setOffscreenPageLimit(2);
|
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
||||||
|
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
||||||
String accessToken = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE).getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
if(!mNullAccessToken && mAccessToken == null) {
|
||||||
if (accessToken.equals("")) {
|
getCurrentAccountAndBindView();
|
||||||
Intent loginIntent = new Intent(this, LoginActivity.class);
|
} else {
|
||||||
startActivityForResult(loginIntent, LOGIN_ACTIVITY_REQUEST_CODE);
|
bindView();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (savedInstanceState != null) {
|
getCurrentAccountAndBindView();
|
||||||
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
|
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
|
||||||
} else {
|
|
||||||
if(getIntent().hasExtra(EXTRA_POST_TYPE)) {
|
|
||||||
if(getIntent().getExtras().getString(EXTRA_POST_TYPE).equals("popular")) {
|
|
||||||
viewPager.setCurrentItem(1);
|
|
||||||
} else {
|
|
||||||
viewPager.setCurrentItem(2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
glide = Glide.with(this);
|
|
||||||
|
|
||||||
View header = findViewById(R.id.nav_header_main_activity);
|
|
||||||
mNameTextView = header.findViewById(R.id.name_text_view_nav_header_main);
|
|
||||||
mKarmaTextView = header.findViewById(R.id.karma_text_view_nav_header_main);
|
|
||||||
mProfileImageView = header.findViewById(R.id.profile_image_view_nav_header_main);
|
|
||||||
mBannerImageView = header.findViewById(R.id.banner_image_view_nav_header_main);
|
|
||||||
|
|
||||||
loadUserData();
|
|
||||||
|
|
||||||
mName = mUserInfoSharedPreferences.getString(SharedPreferencesUtils.USER_KEY, "");
|
|
||||||
mProfileImageUrl = mUserInfoSharedPreferences.getString(SharedPreferencesUtils.PROFILE_IMAGE_URL_KEY, "");
|
|
||||||
mBannerImageUrl = mUserInfoSharedPreferences.getString(SharedPreferencesUtils.BANNER_IMAGE_URL_KEY, "");
|
|
||||||
mKarma = mUserInfoSharedPreferences.getString(SharedPreferencesUtils.KARMA_KEY, "");
|
|
||||||
|
|
||||||
mNameTextView.setText(mName);
|
|
||||||
mKarmaTextView.setText(mKarma);
|
|
||||||
|
|
||||||
if (!mProfileImageUrl.equals("")) {
|
|
||||||
glide.load(mProfileImageUrl)
|
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
|
|
||||||
.error(glide.load(R.drawable.subreddit_default_icon)
|
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))))
|
|
||||||
.into(mProfileImageView);
|
|
||||||
} else {
|
|
||||||
glide.load(R.drawable.subreddit_default_icon)
|
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
|
|
||||||
.into(mProfileImageView);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mBannerImageUrl.equals("")) {
|
|
||||||
glide.load(mBannerImageUrl).into(mBannerImageView);
|
|
||||||
}
|
|
||||||
|
|
||||||
profileLinearLayout.setOnClickListener(view -> {
|
|
||||||
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
|
||||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mName);
|
|
||||||
startActivity(intent);
|
|
||||||
});
|
|
||||||
|
|
||||||
subscriptionLinearLayout.setOnClickListener(view -> {
|
|
||||||
Intent intent = new Intent(this, SubscribedThingListingActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
});
|
|
||||||
|
|
||||||
settingsLinearLayout.setOnClickListener(view -> {
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()));
|
fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadUserData() {
|
private void getCurrentAccountAndBindView() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if(account == null) {
|
||||||
|
Intent loginIntent = new Intent(this, LoginActivity.class);
|
||||||
|
startActivityForResult(loginIntent, LOGIN_ACTIVITY_REQUEST_CODE);
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
if(mAccessToken == null) {
|
||||||
|
mNullAccessToken = true;
|
||||||
|
}
|
||||||
|
bindView();
|
||||||
|
}
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindView() {
|
||||||
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||||
|
viewPager.setAdapter(sectionsPagerAdapter);
|
||||||
|
viewPager.setOffscreenPageLimit(2);
|
||||||
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
|
||||||
|
if(getIntent().hasExtra(EXTRA_POST_TYPE)) {
|
||||||
|
if(getIntent().getExtras().getString(EXTRA_POST_TYPE).equals("popular")) {
|
||||||
|
viewPager.setCurrentItem(1);
|
||||||
|
} else {
|
||||||
|
viewPager.setCurrentItem(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glide = Glide.with(this);
|
||||||
|
|
||||||
|
View header = findViewById(R.id.nav_header_main_activity);
|
||||||
|
mNameTextView = header.findViewById(R.id.name_text_view_nav_header_main);
|
||||||
|
mKarmaTextView = header.findViewById(R.id.karma_text_view_nav_header_main);
|
||||||
|
mProfileImageView = header.findViewById(R.id.profile_image_view_nav_header_main);
|
||||||
|
mBannerImageView = header.findViewById(R.id.banner_image_view_nav_header_main);
|
||||||
|
|
||||||
|
loadUserData(mAccessToken);
|
||||||
|
|
||||||
|
mName = mUserInfoSharedPreferences.getString(SharedPreferencesUtils.USER_KEY, "");
|
||||||
|
mProfileImageUrl = mUserInfoSharedPreferences.getString(SharedPreferencesUtils.PROFILE_IMAGE_URL_KEY, "");
|
||||||
|
mBannerImageUrl = mUserInfoSharedPreferences.getString(SharedPreferencesUtils.BANNER_IMAGE_URL_KEY, "");
|
||||||
|
mKarma = mUserInfoSharedPreferences.getString(SharedPreferencesUtils.KARMA_KEY, "");
|
||||||
|
|
||||||
|
mNameTextView.setText(mName);
|
||||||
|
mKarmaTextView.setText(mKarma);
|
||||||
|
|
||||||
|
if (!mProfileImageUrl.equals("")) {
|
||||||
|
glide.load(mProfileImageUrl)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
|
||||||
|
.error(glide.load(R.drawable.subreddit_default_icon)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0))))
|
||||||
|
.into(mProfileImageView);
|
||||||
|
} else {
|
||||||
|
glide.load(R.drawable.subreddit_default_icon)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(144, 0)))
|
||||||
|
.into(mProfileImageView);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mBannerImageUrl.equals("")) {
|
||||||
|
glide.load(mBannerImageUrl).into(mBannerImageView);
|
||||||
|
}
|
||||||
|
|
||||||
|
profileLinearLayout.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
||||||
|
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mName);
|
||||||
|
startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
subscriptionLinearLayout.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(this, SubscribedThingListingActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
settingsLinearLayout.setOnClickListener(view -> {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadUserData(String accessToken) {
|
||||||
if (!mFetchUserInfoSuccess) {
|
if (!mFetchUserInfoSuccess) {
|
||||||
FetchMyInfo.fetchMyInfo(mOauthRetrofit, mAuthInfoSharedPreferences, new FetchMyInfo.FetchUserMyListener() {
|
FetchMyInfo.fetchMyInfo(mOauthRetrofit, accessToken, new FetchMyInfo.FetchUserMyListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchMyInfoSuccess(String response) {
|
public void onFetchMyInfoSuccess(String response) {
|
||||||
ParseMyInfo.parseMyInfo(response, new ParseMyInfo.ParseMyInfoListener() {
|
ParseMyInfo.parseMyInfo(response, new ParseMyInfo.ParseMyInfoListener() {
|
||||||
@ -306,7 +328,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
case R.id.action_refresh_main_activity:
|
case R.id.action_refresh_main_activity:
|
||||||
sectionsPagerAdapter.refresh(viewPager.getCurrentItem());
|
sectionsPagerAdapter.refresh(viewPager.getCurrentItem());
|
||||||
mFetchUserInfoSuccess = false;
|
mFetchUserInfoSuccess = false;
|
||||||
loadUserData();
|
loadUserData(mAccessToken);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_lazy_mode_main_activity:
|
case R.id.action_lazy_mode_main_activity:
|
||||||
/*MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_main_activity);
|
/*MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_main_activity);
|
||||||
@ -343,6 +365,8 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
|
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
|
||||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
||||||
|
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
||||||
|
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -390,6 +414,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
|
||||||
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
|
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
} else if(position == 1) {
|
} else if(position == 1) {
|
||||||
@ -399,6 +424,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
bundle.putString(PostFragment.EXTRA_NAME, "popular");
|
bundle.putString(PostFragment.EXTRA_NAME, "popular");
|
||||||
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
|
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
} else {
|
} else {
|
||||||
@ -408,6 +434,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
bundle.putString(PostFragment.EXTRA_NAME, "all");
|
bundle.putString(PostFragment.EXTRA_NAME, "all");
|
||||||
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
|
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import android.os.AsyncTask;
|
|||||||
import Account.Account;
|
import Account.Account;
|
||||||
import Account.AccountDao;
|
import Account.AccountDao;
|
||||||
|
|
||||||
class ParseAndInsertAccount extends AsyncTask<Void, Void, Void> {
|
class ParseAndInsertNewAccountAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
interface ParseAndInsertAccountListener {
|
interface ParseAndInsertAccountListener {
|
||||||
void success();
|
void success();
|
||||||
@ -21,9 +21,9 @@ class ParseAndInsertAccount extends AsyncTask<Void, Void, Void> {
|
|||||||
private AccountDao accountDao;
|
private AccountDao accountDao;
|
||||||
private ParseAndInsertAccountListener parseAndInsertAccountListener;
|
private ParseAndInsertAccountListener parseAndInsertAccountListener;
|
||||||
|
|
||||||
ParseAndInsertAccount(String username, String accessToken, String refreshToken, String profileImageUrl, String bannerImageUrl,
|
ParseAndInsertNewAccountAsyncTask(String username, String accessToken, String refreshToken, String profileImageUrl, String bannerImageUrl,
|
||||||
int karma, String code, AccountDao accountDao,
|
int karma, String code, AccountDao accountDao,
|
||||||
ParseAndInsertAccountListener parseAndInsertAccountListener) {
|
ParseAndInsertAccountListener parseAndInsertAccountListener) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.refreshToken = refreshToken;
|
this.refreshToken = refreshToken;
|
||||||
@ -39,6 +39,7 @@ class ParseAndInsertAccount extends AsyncTask<Void, Void, Void> {
|
|||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
Account account = new Account(username, accessToken, refreshToken, code, profileImageUrl,
|
Account account = new Account(username, accessToken, refreshToken, code, profileImageUrl,
|
||||||
bannerImageUrl, karma, true);
|
bannerImageUrl, karma, true);
|
||||||
|
accountDao.markAllAccountsNonCurrent();
|
||||||
accountDao.insert(account);
|
accountDao.insert(account);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
@ -22,16 +22,18 @@ class ParseSubscribedThing {
|
|||||||
void onParseSubscribedSubredditsFail();
|
void onParseSubscribedSubredditsFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseSubscribedSubreddits(String response, ArrayList<SubscribedSubredditData> subscribedSubredditData,
|
static void parseSubscribedSubreddits(String response, String accountName,
|
||||||
ArrayList<SubscribedUserData> subscribedUserData,
|
ArrayList<SubscribedSubredditData> subscribedSubredditData,
|
||||||
ArrayList<SubredditData> subredditData,
|
ArrayList<SubscribedUserData> subscribedUserData,
|
||||||
ParseSubscribedSubredditsListener parseSubscribedSubredditsListener) {
|
ArrayList<SubredditData> subredditData,
|
||||||
new ParseSubscribedSubredditsAsyncTask(response, subscribedSubredditData, subscribedUserData, subredditData,
|
ParseSubscribedSubredditsListener parseSubscribedSubredditsListener) {
|
||||||
|
new ParseSubscribedSubredditsAsyncTask(response, accountName, subscribedSubredditData, subscribedUserData, subredditData,
|
||||||
parseSubscribedSubredditsListener).execute();
|
parseSubscribedSubredditsListener).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ParseSubscribedSubredditsAsyncTask extends AsyncTask<Void, Void, Void> {
|
private static class ParseSubscribedSubredditsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
private JSONObject jsonResponse;
|
private JSONObject jsonResponse;
|
||||||
|
private String accountName;
|
||||||
private boolean parseFailed;
|
private boolean parseFailed;
|
||||||
private String lastItem;
|
private String lastItem;
|
||||||
private ArrayList<SubscribedSubredditData> subscribedSubredditData;
|
private ArrayList<SubscribedSubredditData> subscribedSubredditData;
|
||||||
@ -42,12 +44,13 @@ class ParseSubscribedThing {
|
|||||||
private ArrayList<SubredditData> newSubredditData;
|
private ArrayList<SubredditData> newSubredditData;
|
||||||
private ParseSubscribedSubredditsListener parseSubscribedSubredditsListener;
|
private ParseSubscribedSubredditsListener parseSubscribedSubredditsListener;
|
||||||
|
|
||||||
ParseSubscribedSubredditsAsyncTask(String response, ArrayList<SubscribedSubredditData> subscribedSubredditData,
|
ParseSubscribedSubredditsAsyncTask(String response, String accountName, ArrayList<SubscribedSubredditData> subscribedSubredditData,
|
||||||
ArrayList<SubscribedUserData> subscribedUserData,
|
ArrayList<SubscribedUserData> subscribedUserData,
|
||||||
ArrayList<SubredditData> subredditData,
|
ArrayList<SubredditData> subredditData,
|
||||||
ParseSubscribedSubredditsListener parseSubscribedSubredditsListener){
|
ParseSubscribedSubredditsListener parseSubscribedSubredditsListener){
|
||||||
try {
|
try {
|
||||||
jsonResponse = new JSONObject(response);
|
jsonResponse = new JSONObject(response);
|
||||||
|
this.accountName = accountName;
|
||||||
parseFailed = false;
|
parseFailed = false;
|
||||||
this.subscribedSubredditData = subscribedSubredditData;
|
this.subscribedSubredditData = subscribedSubredditData;
|
||||||
this.subscribedUserData = subscribedUserData;
|
this.subscribedUserData = subscribedUserData;
|
||||||
@ -94,12 +97,12 @@ class ParseSubscribedThing {
|
|||||||
if(data.getString(JSONUtils.SUBREDDIT_TYPE_KEY)
|
if(data.getString(JSONUtils.SUBREDDIT_TYPE_KEY)
|
||||||
.equals(JSONUtils.SUBREDDIT_TYPE_VALUE_USER)) {
|
.equals(JSONUtils.SUBREDDIT_TYPE_VALUE_USER)) {
|
||||||
//It's a user
|
//It's a user
|
||||||
newSubscribedUserData.add(new SubscribedUserData(name.substring(2), iconUrl));
|
newSubscribedUserData.add(new SubscribedUserData(name.substring(2), iconUrl, accountName));
|
||||||
} else {
|
} else {
|
||||||
String subredditFullName = data.getString(JSONUtils.DISPLAY_NAME);
|
String subredditFullName = data.getString(JSONUtils.DISPLAY_NAME);
|
||||||
String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
|
String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
|
||||||
int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY);
|
int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY);
|
||||||
newSubscribedSubredditData.add(new SubscribedSubredditData(id, name, iconUrl));
|
newSubscribedSubredditData.add(new SubscribedSubredditData(id, name, iconUrl, accountName));
|
||||||
newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description, nSubscribers));
|
newSubredditData.add(new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description, nSubscribers));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -53,6 +52,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
static final String EXTRA_SORT_TYPE = "EST";
|
static final String EXTRA_SORT_TYPE = "EST";
|
||||||
static final String EXTRA_FILTER = "EF";
|
static final String EXTRA_FILTER = "EF";
|
||||||
static final int EXTRA_NO_FILTER = -1;
|
static final int EXTRA_NO_FILTER = -1;
|
||||||
|
static final String EXTRA_ACCESS_TOKEN = "EAT";
|
||||||
|
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
||||||
|
|
||||||
@ -87,8 +87,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
@Inject @Named("oauth")
|
@Inject @Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
@Inject @Named("auth_info")
|
@Inject
|
||||||
SharedPreferences mSharedPreferences;
|
RedditDataRoomDatabase redditDataRoomDatabase;
|
||||||
|
|
||||||
public PostFragment() {
|
public PostFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
@ -173,9 +173,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
int postType = getArguments().getInt(EXTRA_POST_TYPE);
|
int postType = getArguments().getInt(EXTRA_POST_TYPE);
|
||||||
String sortType = getArguments().getString(EXTRA_SORT_TYPE);
|
String sortType = getArguments().getString(EXTRA_SORT_TYPE);
|
||||||
int filter = getArguments().getInt(EXTRA_FILTER);
|
int filter = getArguments().getInt(EXTRA_FILTER);
|
||||||
|
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||||
String accessToken = activity.getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE)
|
|
||||||
.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
|
||||||
|
|
||||||
PostViewModel.Factory factory;
|
PostViewModel.Factory factory;
|
||||||
|
|
||||||
@ -183,8 +181,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
String subredditName = getArguments().getString(EXTRA_NAME);
|
String subredditName = getArguments().getString(EXTRA_NAME);
|
||||||
String query = getArguments().getString(EXTRA_QUERY);
|
String query = getArguments().getString(EXTRA_QUERY);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, redditDataRoomDatabase,
|
||||||
mSharedPreferences, postType, true, new PostRecyclerViewAdapter.Callback() {
|
accessToken, postType, true, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
mPostViewModel.retryLoadingMore();
|
mPostViewModel.retryLoadingMore();
|
||||||
@ -221,8 +219,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
String subredditName = getArguments().getString(EXTRA_NAME);
|
String subredditName = getArguments().getString(EXTRA_NAME);
|
||||||
|
|
||||||
boolean displaySubredditName = subredditName.equals("popular") || subredditName.equals("all");
|
boolean displaySubredditName = subredditName.equals("popular") || subredditName.equals("all");
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, redditDataRoomDatabase,
|
||||||
mSharedPreferences, postType, displaySubredditName, new PostRecyclerViewAdapter.Callback() {
|
accessToken, postType, displaySubredditName, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
mPostViewModel.retryLoadingMore();
|
mPostViewModel.retryLoadingMore();
|
||||||
@ -261,8 +259,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
String username = getArguments().getString(EXTRA_USER_NAME);
|
String username = getArguments().getString(EXTRA_USER_NAME);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, redditDataRoomDatabase,
|
||||||
mSharedPreferences, postType, true, new PostRecyclerViewAdapter.Callback() {
|
accessToken, postType, true, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
mPostViewModel.retryLoadingMore();
|
mPostViewModel.retryLoadingMore();
|
||||||
@ -296,8 +294,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, redditDataRoomDatabase,
|
||||||
mSharedPreferences, postType, true, new PostRecyclerViewAdapter.Callback() {
|
accessToken, postType, true, new PostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
mPostViewModel.retryLoadingMore();
|
mPostViewModel.retryLoadingMore();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -39,7 +38,6 @@ import java.io.IOException;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import SubredditDatabase.SubredditRoomDatabase;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
@ -110,12 +108,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
Retrofit mUploadMediaRetrofit;
|
Retrofit mUploadMediaRetrofit;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("user_info")
|
RedditDataRoomDatabase redditDataRoomDatabase;
|
||||||
SharedPreferences mUserInfoSharedPreferences;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
@Named("auth_info")
|
|
||||||
SharedPreferences sharedPreferences;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -299,7 +292,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadSubredditIcon() {
|
private void loadSubredditIcon() {
|
||||||
new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
|
new LoadSubredditIconAsyncTask(redditDataRoomDatabase.subredditDao(),
|
||||||
subredditName, mRetrofit, iconImageUrl -> {
|
subredditName, mRetrofit, iconImageUrl -> {
|
||||||
iconUrl = iconImageUrl;
|
iconUrl = iconImageUrl;
|
||||||
displaySubredditIcon();
|
displaySubredditIcon();
|
||||||
@ -441,11 +434,13 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
public void onSubmitImagePostEvent(SubmitImagePostEvent submitImagePostEvent) {
|
public void onSubmitImagePostEvent(SubmitImagePostEvent submitImagePostEvent) {
|
||||||
isPosting = false;
|
isPosting = false;
|
||||||
if(submitImagePostEvent.postSuccess) {
|
if(submitImagePostEvent.postSuccess) {
|
||||||
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
new GetCurrentAccountAsyncTask(redditDataRoomDatabase.accountDao(), account -> {
|
||||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY,
|
Intent intent = new Intent(PostImageActivity.this, ViewUserDetailActivity.class);
|
||||||
mUserInfoSharedPreferences.getString(SharedPreferencesUtils.USER_KEY, ""));
|
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY,
|
||||||
startActivity(intent);
|
account.getUsername());
|
||||||
finish();
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}).execute();
|
||||||
} else {
|
} else {
|
||||||
mPostingSnackbar.dismiss();
|
mPostingSnackbar.dismiss();
|
||||||
mMemu.getItem(R.id.action_send_post_image_activity).setEnabled(true);
|
mMemu.getItem(R.id.action_send_post_image_activity).setEnabled(true);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -28,7 +27,6 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import SubredditDatabase.SubredditRoomDatabase;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
@ -48,6 +46,8 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
private static final String FLAIR_STATE = "FS";
|
private static final String FLAIR_STATE = "FS";
|
||||||
private static final String IS_SPOILER_STATE = "ISS";
|
private static final String IS_SPOILER_STATE = "ISS";
|
||||||
private static final String IS_NSFW_STATE = "INS";
|
private static final String IS_NSFW_STATE = "INS";
|
||||||
|
private static final String NULL_ACCOUNT_NAME_STATE = "NATS";
|
||||||
|
private static final String ACCOUNT_NAME_STATE = "ANS";
|
||||||
|
|
||||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||||
|
|
||||||
@ -62,6 +62,8 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
@BindView(R.id.post_title_edit_text_post_link_activity) EditText titleEditText;
|
@BindView(R.id.post_title_edit_text_post_link_activity) EditText titleEditText;
|
||||||
@BindView(R.id.post_link_edit_text_post_link_activity) EditText contentEditText;
|
@BindView(R.id.post_link_edit_text_post_link_activity) EditText contentEditText;
|
||||||
|
|
||||||
|
private boolean mNullAccountName = false;
|
||||||
|
private String mAccountName;
|
||||||
private String iconUrl;
|
private String iconUrl;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
private boolean subredditSelected = false;
|
private boolean subredditSelected = false;
|
||||||
@ -87,8 +89,7 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("auth_info")
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
SharedPreferences sharedPreferences;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -215,6 +216,16 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getCurrentAccountName() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if(account == null) {
|
||||||
|
mNullAccountName = true;
|
||||||
|
} else {
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
}
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
private void displaySubredditIcon() {
|
private void displaySubredditIcon() {
|
||||||
if(iconUrl != null && !iconUrl.equals("")) {
|
if(iconUrl != null && !iconUrl.equals("")) {
|
||||||
mGlide.load(iconUrl)
|
mGlide.load(iconUrl)
|
||||||
@ -230,7 +241,7 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadSubredditIcon() {
|
private void loadSubredditIcon() {
|
||||||
new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
|
new LoadSubredditIconAsyncTask(mRedditDataRoomDatabase.subredditDao(),
|
||||||
subredditName, mRetrofit, iconImageUrl -> {
|
subredditName, mRetrofit, iconImageUrl -> {
|
||||||
iconUrl = iconImageUrl;
|
iconUrl = iconImageUrl;
|
||||||
displaySubredditIcon();
|
displaySubredditIcon();
|
||||||
@ -304,6 +315,8 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
outState.putString(FLAIR_STATE, flair);
|
outState.putString(FLAIR_STATE, flair);
|
||||||
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
||||||
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
||||||
|
outState.putBoolean(NULL_ACCOUNT_NAME_STATE, mNullAccountName);
|
||||||
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -43,9 +42,7 @@ import org.greenrobot.eventbus.EventBus;
|
|||||||
|
|
||||||
import CustomView.AspectRatioGifImageView;
|
import CustomView.AspectRatioGifImageView;
|
||||||
import SubredditDatabase.SubredditDao;
|
import SubredditDatabase.SubredditDao;
|
||||||
import SubredditDatabase.SubredditRoomDatabase;
|
|
||||||
import User.UserDao;
|
import User.UserDao;
|
||||||
import User.UserRoomDatabase;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||||
@ -60,20 +57,20 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Retrofit mOauthRetrofit;
|
private Retrofit mOauthRetrofit;
|
||||||
private Retrofit mRetrofit;
|
private Retrofit mRetrofit;
|
||||||
private SharedPreferences mSharedPreferences;
|
private String mAccessToken;
|
||||||
private RequestManager glide;
|
private RequestManager mGlide;
|
||||||
private SubredditDao subredditDao;
|
private SubredditDao mSubredditDao;
|
||||||
private UserDao userDao;
|
private UserDao mUserDao;
|
||||||
private boolean canStartActivity = true;
|
private boolean canStartActivity = true;
|
||||||
private int postType;
|
private int mPostType;
|
||||||
private boolean displaySubredditName;
|
private boolean mDisplaySubredditName;
|
||||||
|
|
||||||
private static final int VIEW_TYPE_DATA = 0;
|
private static final int VIEW_TYPE_DATA = 0;
|
||||||
private static final int VIEW_TYPE_ERROR = 1;
|
private static final int VIEW_TYPE_ERROR = 1;
|
||||||
private static final int VIEW_TYPE_LOADING = 2;
|
private static final int VIEW_TYPE_LOADING = 2;
|
||||||
|
|
||||||
private NetworkState networkState;
|
private NetworkState networkState;
|
||||||
private Callback callback;
|
private Callback mCallback;
|
||||||
|
|
||||||
interface Callback {
|
interface Callback {
|
||||||
void retryLoadingMore();
|
void retryLoadingMore();
|
||||||
@ -81,20 +78,21 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
}
|
}
|
||||||
|
|
||||||
PostRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, Retrofit retrofit,
|
PostRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, Retrofit retrofit,
|
||||||
SharedPreferences sharedPreferences, int postType,
|
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
|
String accessToken, int postType,
|
||||||
boolean displaySubredditName, Callback callback) {
|
boolean displaySubredditName, Callback callback) {
|
||||||
super(DIFF_CALLBACK);
|
super(DIFF_CALLBACK);
|
||||||
if(context != null) {
|
if(context != null) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mOauthRetrofit = oauthRetrofit;
|
mOauthRetrofit = oauthRetrofit;
|
||||||
mRetrofit = retrofit;
|
mRetrofit = retrofit;
|
||||||
mSharedPreferences = sharedPreferences;
|
mAccessToken = accessToken;
|
||||||
this.postType = postType;
|
mPostType = postType;
|
||||||
this.displaySubredditName = displaySubredditName;
|
mDisplaySubredditName = displaySubredditName;
|
||||||
glide = Glide.with(mContext.getApplicationContext());
|
mGlide = Glide.with(mContext.getApplicationContext());
|
||||||
subredditDao = SubredditRoomDatabase.getDatabase(mContext.getApplicationContext()).subredditDao();
|
mSubredditDao = redditDataRoomDatabase.subredditDao();
|
||||||
userDao = UserRoomDatabase.getDatabase(mContext.getApplicationContext()).userDao();
|
mUserDao = redditDataRoomDatabase.userDao();
|
||||||
this.callback = callback;
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,19 +159,19 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(displaySubredditName) {
|
if(mDisplaySubredditName) {
|
||||||
if(authorPrefixed.equals(subredditNamePrefixed)) {
|
if(authorPrefixed.equals(subredditNamePrefixed)) {
|
||||||
if(post.getAuthorIconUrl() == null) {
|
if(post.getAuthorIconUrl() == null) {
|
||||||
new LoadUserDataAsyncTask(userDao, post.getAuthor(), mRetrofit, iconImageUrl -> {
|
new LoadUserDataAsyncTask(mUserDao, post.getAuthor(), mRetrofit, iconImageUrl -> {
|
||||||
if(mContext != null && getItemCount() > 0) {
|
if(mContext != null && getItemCount() > 0) {
|
||||||
if(iconImageUrl == null || iconImageUrl.equals("")) {
|
if(iconImageUrl == null || iconImageUrl.equals("")) {
|
||||||
glide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
glide.load(iconImageUrl)
|
mGlide.load(iconImageUrl)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(glide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
}
|
}
|
||||||
@ -184,29 +182,29 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
}
|
}
|
||||||
}).execute();
|
}).execute();
|
||||||
} else if(!post.getAuthorIconUrl().equals("")) {
|
} else if(!post.getAuthorIconUrl().equals("")) {
|
||||||
glide.load(post.getAuthorIconUrl())
|
mGlide.load(post.getAuthorIconUrl())
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(glide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
glide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(post.getSubredditIconUrl() == null) {
|
if(post.getSubredditIconUrl() == null) {
|
||||||
new LoadSubredditIconAsyncTask(subredditDao, subredditName, mRetrofit,
|
new LoadSubredditIconAsyncTask(mSubredditDao, subredditName, mRetrofit,
|
||||||
iconImageUrl -> {
|
iconImageUrl -> {
|
||||||
if(mContext != null && getItemCount() > 0) {
|
if(mContext != null && getItemCount() > 0) {
|
||||||
if(iconImageUrl == null || iconImageUrl.equals("")) {
|
if(iconImageUrl == null || iconImageUrl.equals("")) {
|
||||||
glide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
glide.load(iconImageUrl)
|
mGlide.load(iconImageUrl)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(glide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
}
|
}
|
||||||
@ -217,13 +215,13 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
}
|
}
|
||||||
}).execute();
|
}).execute();
|
||||||
} else if(!post.getSubredditIconUrl().equals("")) {
|
} else if(!post.getSubredditIconUrl().equals("")) {
|
||||||
glide.load(post.getSubredditIconUrl())
|
mGlide.load(post.getSubredditIconUrl())
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(glide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
glide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
}
|
}
|
||||||
@ -250,16 +248,16 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if(post.getAuthorIconUrl() == null) {
|
if(post.getAuthorIconUrl() == null) {
|
||||||
new LoadUserDataAsyncTask(userDao, post.getAuthor(), mRetrofit, iconImageUrl -> {
|
new LoadUserDataAsyncTask(mUserDao, post.getAuthor(), mRetrofit, iconImageUrl -> {
|
||||||
if(mContext != null && getItemCount() > 0) {
|
if(mContext != null && getItemCount() > 0) {
|
||||||
if(iconImageUrl == null || iconImageUrl.equals("")) {
|
if(iconImageUrl == null || iconImageUrl.equals("")) {
|
||||||
glide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
glide.load(iconImageUrl)
|
mGlide.load(iconImageUrl)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(glide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
}
|
}
|
||||||
@ -270,13 +268,13 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
}
|
}
|
||||||
}).execute();
|
}).execute();
|
||||||
} else if(!post.getAuthorIconUrl().equals("")) {
|
} else if(!post.getAuthorIconUrl().equals("")) {
|
||||||
glide.load(post.getAuthorIconUrl())
|
mGlide.load(post.getAuthorIconUrl())
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.error(glide.load(R.drawable.subreddit_default_icon)
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
glide.load(R.drawable.subreddit_default_icon)
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.into(((DataViewHolder) holder).iconGifImageView);
|
.into(((DataViewHolder) holder).iconGifImageView);
|
||||||
}
|
}
|
||||||
@ -300,7 +298,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
|
|
||||||
if(gilded > 0) {
|
if(gilded > 0) {
|
||||||
((DataViewHolder) holder).gildedImageView.setVisibility(View.VISIBLE);
|
((DataViewHolder) holder).gildedImageView.setVisibility(View.VISIBLE);
|
||||||
glide.load(R.drawable.gold).into(((DataViewHolder) holder).gildedImageView);
|
mGlide.load(R.drawable.gold).into(((DataViewHolder) holder).gildedImageView);
|
||||||
((DataViewHolder) holder).gildedNumberTextView.setVisibility(View.VISIBLE);
|
((DataViewHolder) holder).gildedNumberTextView.setVisibility(View.VISIBLE);
|
||||||
String gildedNumber = mContext.getResources().getString(R.string.gilded, gilded);
|
String gildedNumber = mContext.getResources().getString(R.string.gilded, gilded);
|
||||||
((DataViewHolder) holder).gildedNumberTextView.setText(gildedNumber);
|
((DataViewHolder) holder).gildedNumberTextView.setText(gildedNumber);
|
||||||
@ -345,9 +343,9 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
loadImage(holder, post);
|
loadImage(holder, post);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(postType == PostDataSource.TYPE_SUBREDDIT && post.isStickied()) {
|
if(mPostType == PostDataSource.TYPE_SUBREDDIT && post.isStickied()) {
|
||||||
((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE);
|
((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE);
|
||||||
glide.load(R.drawable.thumbtack).into(((DataViewHolder) holder).stickiedPostImageView);
|
mGlide.load(R.drawable.thumbtack).into(((DataViewHolder) holder).stickiedPostImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isArchived) {
|
if(isArchived) {
|
||||||
@ -362,7 +360,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!(mContext instanceof FilteredPostsActivity)) {
|
if(!(mContext instanceof FilteredPostsActivity)) {
|
||||||
((DataViewHolder) holder).typeChip.setOnClickListener(view -> callback.typeChipClicked(post.getPostType()));
|
((DataViewHolder) holder).typeChip.setOnClickListener(view -> mCallback.typeChipClicked(post.getPostType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (post.getPostType()) {
|
switch (post.getPostType()) {
|
||||||
@ -481,7 +479,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
|
|
||||||
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
|
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
||||||
@ -541,7 +539,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
|
|
||||||
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
|
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
||||||
@ -584,7 +582,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadImage(final RecyclerView.ViewHolder holder, final Post post) {
|
private void loadImage(final RecyclerView.ViewHolder holder, final Post post) {
|
||||||
RequestBuilder imageRequestBuilder = glide.load(post.getPreviewUrl()).listener(new RequestListener<Drawable>() {
|
RequestBuilder imageRequestBuilder = mGlide.load(post.getPreviewUrl()).listener(new RequestListener<Drawable>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||||
((DataViewHolder) holder).progressBar.setVisibility(View.GONE);
|
((DataViewHolder) holder).progressBar.setVisibility(View.GONE);
|
||||||
@ -699,7 +697,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
super(itemView);
|
super(itemView);
|
||||||
ButterKnife.bind(this, itemView);
|
ButterKnife.bind(this, itemView);
|
||||||
errorTextView.setText(R.string.load_posts_error);
|
errorTextView.setText(R.string.load_posts_error);
|
||||||
retryButton.setOnClickListener(view -> callback.retryLoadingMore());
|
retryButton.setOnClickListener(view -> mCallback.retryLoadingMore());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,8 +711,8 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
@Override
|
@Override
|
||||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||||
if(holder instanceof DataViewHolder) {
|
if(holder instanceof DataViewHolder) {
|
||||||
glide.clear(((DataViewHolder) holder).imageView);
|
mGlide.clear(((DataViewHolder) holder).imageView);
|
||||||
glide.clear(((DataViewHolder) holder).iconGifImageView);
|
mGlide.clear(((DataViewHolder) holder).iconGifImageView);
|
||||||
((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE);
|
((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE);
|
||||||
((DataViewHolder) holder).relativeLayout.setVisibility(View.GONE);
|
((DataViewHolder) holder).relativeLayout.setVisibility(View.GONE);
|
||||||
((DataViewHolder) holder).gildedImageView.setVisibility(View.GONE);
|
((DataViewHolder) holder).gildedImageView.setVisibility(View.GONE);
|
||||||
|
@ -28,7 +28,6 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import SubredditDatabase.SubredditRoomDatabase;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
@ -48,6 +47,8 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
private static final String FLAIR_STATE = "FS";
|
private static final String FLAIR_STATE = "FS";
|
||||||
private static final String IS_SPOILER_STATE = "ISS";
|
private static final String IS_SPOILER_STATE = "ISS";
|
||||||
private static final String IS_NSFW_STATE = "INS";
|
private static final String IS_NSFW_STATE = "INS";
|
||||||
|
private static final String NULL_ACCOUNT_NAME_STATE = "NATS";
|
||||||
|
private static final String ACCOUNT_NAME_STATE = "ANS";
|
||||||
|
|
||||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||||
|
|
||||||
@ -62,6 +63,8 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
@BindView(R.id.post_title_edit_text_post_text_activity) EditText titleEditText;
|
@BindView(R.id.post_title_edit_text_post_text_activity) EditText titleEditText;
|
||||||
@BindView(R.id.post_text_content_edit_text_post_text_activity) EditText contentEditText;
|
@BindView(R.id.post_text_content_edit_text_post_text_activity) EditText contentEditText;
|
||||||
|
|
||||||
|
private boolean mNullAccountName = false;
|
||||||
|
private String mAccountName;
|
||||||
private String iconUrl;
|
private String iconUrl;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
private boolean subredditSelected = false;
|
private boolean subredditSelected = false;
|
||||||
@ -90,6 +93,9 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
@Named("auth_info")
|
@Named("auth_info")
|
||||||
SharedPreferences sharedPreferences;
|
SharedPreferences sharedPreferences;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -220,6 +226,16 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getCurrentAccountName() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if(account == null) {
|
||||||
|
mNullAccountName = true;
|
||||||
|
} else {
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
}
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
private void displaySubredditIcon() {
|
private void displaySubredditIcon() {
|
||||||
if(iconUrl != null && !iconUrl.equals("")) {
|
if(iconUrl != null && !iconUrl.equals("")) {
|
||||||
mGlide.load(iconUrl)
|
mGlide.load(iconUrl)
|
||||||
@ -235,7 +251,7 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadSubredditIcon() {
|
private void loadSubredditIcon() {
|
||||||
new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
|
new LoadSubredditIconAsyncTask(mRedditDataRoomDatabase.subredditDao(),
|
||||||
subredditName, mRetrofit, iconImageUrl -> {
|
subredditName, mRetrofit, iconImageUrl -> {
|
||||||
iconUrl = iconImageUrl;
|
iconUrl = iconImageUrl;
|
||||||
displaySubredditIcon();
|
displaySubredditIcon();
|
||||||
@ -309,6 +325,8 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh
|
|||||||
outState.putString(FLAIR_STATE, flair);
|
outState.putString(FLAIR_STATE, flair);
|
||||||
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
||||||
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
||||||
|
outState.putBoolean(NULL_ACCOUNT_NAME_STATE, mNullAccountName);
|
||||||
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -34,7 +33,6 @@ import org.greenrobot.eventbus.Subscribe;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import SubredditDatabase.SubredditRoomDatabase;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
@ -55,6 +53,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
private static final String FLAIR_STATE = "FS";
|
private static final String FLAIR_STATE = "FS";
|
||||||
private static final String IS_SPOILER_STATE = "ISS";
|
private static final String IS_SPOILER_STATE = "ISS";
|
||||||
private static final String IS_NSFW_STATE = "INS";
|
private static final String IS_NSFW_STATE = "INS";
|
||||||
|
private static final String NULL_ACCOUNT_NAME_STATE = "NATS";
|
||||||
|
private static final String ACCOUNT_NAME_STATE = "ANS";
|
||||||
|
|
||||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||||
private static final int PICK_VIDEO_REQUEST_CODE = 1;
|
private static final int PICK_VIDEO_REQUEST_CODE = 1;
|
||||||
@ -75,6 +75,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
@BindView(R.id.select_again_text_view_post_video_activity) TextView selectAgainTextView;
|
@BindView(R.id.select_again_text_view_post_video_activity) TextView selectAgainTextView;
|
||||||
@BindView(R.id.video_view_post_video_activity) VideoView videoView;
|
@BindView(R.id.video_view_post_video_activity) VideoView videoView;
|
||||||
|
|
||||||
|
private boolean mNullAccountName = false;
|
||||||
|
private String mAccountName;
|
||||||
private String iconUrl;
|
private String iconUrl;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
private boolean subredditSelected = false;
|
private boolean subredditSelected = false;
|
||||||
@ -109,12 +111,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
Retrofit mUploadVideoRetrofit;
|
Retrofit mUploadVideoRetrofit;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("user_info")
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
SharedPreferences mUserInfoSharedPreferences;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
@Named("auth_info")
|
|
||||||
SharedPreferences sharedPreferences;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -142,6 +139,12 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
flair = savedInstanceState.getString(FLAIR_STATE);
|
flair = savedInstanceState.getString(FLAIR_STATE);
|
||||||
isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE);
|
isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE);
|
||||||
isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE);
|
isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE);
|
||||||
|
mNullAccountName = savedInstanceState.getBoolean(NULL_ACCOUNT_NAME_STATE);
|
||||||
|
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
||||||
|
|
||||||
|
if(!mNullAccountName && mAccountName == null) {
|
||||||
|
getCurrentAccountName();
|
||||||
|
}
|
||||||
|
|
||||||
if(savedInstanceState.getString(VIDEO_URI_STATE) != null) {
|
if(savedInstanceState.getString(VIDEO_URI_STATE) != null) {
|
||||||
videoUri = Uri.parse(savedInstanceState.getString(VIDEO_URI_STATE));
|
videoUri = Uri.parse(savedInstanceState.getString(VIDEO_URI_STATE));
|
||||||
@ -173,6 +176,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent));
|
nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
getCurrentAccountName();
|
||||||
|
|
||||||
isPosting = false;
|
isPosting = false;
|
||||||
|
|
||||||
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||||
@ -272,6 +277,16 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getCurrentAccountName() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if(account == null) {
|
||||||
|
mNullAccountName = true;
|
||||||
|
} else {
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
}
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
private void loadVideo() {
|
private void loadVideo() {
|
||||||
constraintLayout.setVisibility(View.GONE);
|
constraintLayout.setVisibility(View.GONE);
|
||||||
videoView.setVisibility(View.VISIBLE);
|
videoView.setVisibility(View.VISIBLE);
|
||||||
@ -295,7 +310,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadSubredditIcon() {
|
private void loadSubredditIcon() {
|
||||||
new LoadSubredditIconAsyncTask(SubredditRoomDatabase.getDatabase(this).subredditDao(),
|
new LoadSubredditIconAsyncTask(mRedditDataRoomDatabase.subredditDao(),
|
||||||
subredditName, mRetrofit, iconImageUrl -> {
|
subredditName, mRetrofit, iconImageUrl -> {
|
||||||
iconUrl = iconImageUrl;
|
iconUrl = iconImageUrl;
|
||||||
displaySubredditIcon();
|
displaySubredditIcon();
|
||||||
@ -387,6 +402,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
outState.putString(FLAIR_STATE, flair);
|
outState.putString(FLAIR_STATE, flair);
|
||||||
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
|
||||||
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
outState.putBoolean(IS_NSFW_STATE, isNSFW);
|
||||||
|
outState.putBoolean(NULL_ACCOUNT_NAME_STATE, mNullAccountName);
|
||||||
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -444,7 +461,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
|
|||||||
if(submitVideoPostEvent.postSuccess) {
|
if(submitVideoPostEvent.postSuccess) {
|
||||||
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
||||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY,
|
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY,
|
||||||
mUserInfoSharedPreferences.getString(SharedPreferencesUtils.USER_KEY, ""));
|
mAccountName);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
} else if(submitVideoPostEvent.errorProcessingVideo) {
|
} else if(submitVideoPostEvent.errorProcessingVideo) {
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.room.Database;
|
||||||
|
import androidx.room.Room;
|
||||||
|
import androidx.room.RoomDatabase;
|
||||||
|
|
||||||
|
import Account.Account;
|
||||||
|
import Account.AccountDao;
|
||||||
|
import SubredditDatabase.SubredditDao;
|
||||||
|
import SubredditDatabase.SubredditData;
|
||||||
|
import SubscribedSubredditDatabase.SubscribedSubredditDao;
|
||||||
|
import SubscribedSubredditDatabase.SubscribedSubredditData;
|
||||||
|
import SubscribedUserDatabase.SubscribedUserDao;
|
||||||
|
import SubscribedUserDatabase.SubscribedUserData;
|
||||||
|
import User.UserDao;
|
||||||
|
import User.UserData;
|
||||||
|
|
||||||
|
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class, SubscribedUserData.class}, version = 1)
|
||||||
|
public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||||
|
private static RedditDataRoomDatabase INSTANCE;
|
||||||
|
|
||||||
|
public abstract AccountDao accountDao();
|
||||||
|
public abstract SubredditDao subredditDao();
|
||||||
|
public abstract SubscribedSubredditDao subscribedSubredditDao();
|
||||||
|
public abstract UserDao userDao();
|
||||||
|
public abstract SubscribedUserDao subscribedUserDao();
|
||||||
|
|
||||||
|
public static RedditDataRoomDatabase getDatabase(final Context context) {
|
||||||
|
if(INSTANCE == null) {
|
||||||
|
synchronized (RedditDataRoomDatabase.class) {
|
||||||
|
if(INSTANCE == null) {
|
||||||
|
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
|
||||||
|
RedditDataRoomDatabase.class, "reddit_data")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,8 @@ import androidx.viewpager.widget.ViewPager;
|
|||||||
|
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
@ -24,6 +26,13 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
|
|||||||
static final String EXTRA_QUERY = "QK";
|
static final String EXTRA_QUERY = "QK";
|
||||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||||
|
|
||||||
|
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
||||||
|
private static final String ACCESS_TOKEN_STATE = "ATS";
|
||||||
|
private static final String ACCOUNT_NAME_STATE = "ANS";
|
||||||
|
|
||||||
|
private boolean mNullAccessToken = false;
|
||||||
|
private String mAccessToken;
|
||||||
|
private String mAccountName;
|
||||||
private String mQuery;
|
private String mQuery;
|
||||||
private String mSubredditName;
|
private String mSubredditName;
|
||||||
|
|
||||||
@ -36,6 +45,9 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
|
|||||||
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
|
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
|
||||||
private SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment;
|
private SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -43,14 +55,23 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
|
|||||||
|
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
((Infinity) getApplication()).getmAppComponent().inject(this);
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
if(savedInstanceState == null) {
|
||||||
viewPager.setAdapter(sectionsPagerAdapter);
|
getCurrentAccountAndInitializeViewPager();
|
||||||
viewPager.setOffscreenPageLimit(2);
|
} else {
|
||||||
|
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
||||||
|
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
||||||
|
if(!mNullAccessToken && mAccessToken == null) {
|
||||||
|
getCurrentAccountAndInitializeViewPager();
|
||||||
|
} else {
|
||||||
|
initializeViewPager();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment();
|
searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
@ -72,6 +93,25 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getCurrentAccountAndInitializeViewPager() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if(account == null) {
|
||||||
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
}
|
||||||
|
initializeViewPager();
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeViewPager() {
|
||||||
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||||
|
viewPager.setAdapter(sectionsPagerAdapter);
|
||||||
|
viewPager.setOffscreenPageLimit(2);
|
||||||
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.search_result_activity, menu);
|
getMenuInflater().inflate(R.menu.search_result_activity, menu);
|
||||||
@ -112,6 +152,14 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
||||||
|
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
||||||
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void searchSortTypeSelected(String sortType) {
|
public void searchSortTypeSelected(String sortType) {
|
||||||
sectionsPagerAdapter.changeSortType(sortType, 0);
|
sectionsPagerAdapter.changeSortType(sortType, 0);
|
||||||
@ -144,21 +192,26 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
|
|||||||
bundle.putString(PostFragment.EXTRA_NAME, mSubredditName);
|
bundle.putString(PostFragment.EXTRA_NAME, mSubredditName);
|
||||||
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
|
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
mFragment.setArguments(bundle);
|
mFragment.setArguments(bundle);
|
||||||
return mFragment;
|
return mFragment;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
SubredditListingFragment mFragment = new SubredditListingFragment();
|
SubredditListingFragment mFragment = new SubredditListingFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(SubredditListingFragment.EXTRA_QUERY_KEY, mQuery);
|
bundle.putString(SubredditListingFragment.EXTRA_QUERY, mQuery);
|
||||||
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_POSTING, false);
|
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_POSTING, false);
|
||||||
|
bundle.putString(SubredditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
|
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
mFragment.setArguments(bundle);
|
mFragment.setArguments(bundle);
|
||||||
return mFragment;
|
return mFragment;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
UserListingFragment mFragment = new UserListingFragment();
|
UserListingFragment mFragment = new UserListingFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(UserListingFragment.QUERY_KEY, mQuery);
|
bundle.putString(UserListingFragment.EXTRA_QUERY, mQuery);
|
||||||
|
bundle.putString(UserListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
|
bundle.putString(UserListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
mFragment.setArguments(bundle);
|
mFragment.setArguments(bundle);
|
||||||
return mFragment;
|
return mFragment;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
@ -19,12 +21,22 @@ public class SearchSubredditsResultActivity extends AppCompatActivity {
|
|||||||
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
|
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
|
||||||
static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL";
|
static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL";
|
||||||
|
|
||||||
|
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
||||||
|
private static final String ACCESS_TOKEN_STATE = "ATS";
|
||||||
|
private static final String ACCOUNT_NAME_STATE = "ANS";
|
||||||
private static final String FRAGMENT_OUT_STATE = "FOS";
|
private static final String FRAGMENT_OUT_STATE = "FOS";
|
||||||
|
|
||||||
@BindView(R.id.toolbar_search_subreddits_result_activity) Toolbar toolbar;
|
@BindView(R.id.toolbar_search_subreddits_result_activity) Toolbar toolbar;
|
||||||
|
|
||||||
|
private boolean mNullAccessToken = false;
|
||||||
|
private String mAccessToken;
|
||||||
|
private String mAccountName;
|
||||||
|
|
||||||
Fragment mFragment;
|
Fragment mFragment;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -32,23 +44,46 @@ public class SearchSubredditsResultActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|
||||||
|
((Infinity) getApplication()).getmAppComponent().inject(this);
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
String query = getIntent().getExtras().getString(EXTRA_QUERY);
|
String query = getIntent().getExtras().getString(EXTRA_QUERY);
|
||||||
|
|
||||||
if(savedInstanceState == null) {
|
if(savedInstanceState == null) {
|
||||||
|
getCurrentAccountAndInitializeFragment(query);
|
||||||
|
} else {
|
||||||
|
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
||||||
|
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
||||||
|
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
||||||
|
if(!mNullAccessToken && mAccessToken == null) {
|
||||||
|
getCurrentAccountAndInitializeFragment(query);
|
||||||
|
} else {
|
||||||
|
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_subreddits_result_activity, mFragment).commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getCurrentAccountAndInitializeFragment(String query) {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if(account == null) {
|
||||||
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
mFragment = new SubredditListingFragment();
|
mFragment = new SubredditListingFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(SubredditListingFragment.EXTRA_QUERY_KEY, query);
|
bundle.putString(SubredditListingFragment.EXTRA_QUERY, query);
|
||||||
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_POSTING, true);
|
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_POSTING, true);
|
||||||
|
bundle.putString(SubredditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
|
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
mFragment.setArguments(bundle);
|
mFragment.setArguments(bundle);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_subreddits_result_activity, mFragment).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_subreddits_result_activity, mFragment).commit();
|
||||||
} else {
|
}).execute();
|
||||||
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_subreddits_result_activity, mFragment).commit();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void getSelectedSubreddit(String name, String iconUrl) {
|
void getSelectedSubreddit(String name, String iconUrl) {
|
||||||
@ -74,5 +109,8 @@ public class SearchSubredditsResultActivity extends AppCompatActivity {
|
|||||||
if (mFragment != null) {
|
if (mFragment != null) {
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
||||||
}
|
}
|
||||||
|
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
||||||
|
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
||||||
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import android.widget.ImageView;
|
|||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProviders;
|
import androidx.lifecycle.ViewModelProviders;
|
||||||
@ -24,7 +25,6 @@ import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import SubscribedSubredditDatabase.SubscribedSubredditRoomDatabase;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
@ -35,8 +35,10 @@ import retrofit2.Retrofit;
|
|||||||
*/
|
*/
|
||||||
public class SubredditListingFragment extends Fragment implements FragmentCommunicator {
|
public class SubredditListingFragment extends Fragment implements FragmentCommunicator {
|
||||||
|
|
||||||
static final String EXTRA_QUERY_KEY = "EQK";
|
static final String EXTRA_QUERY = "EQ";
|
||||||
static final String EXTRA_IS_POSTING = "EIP";
|
static final String EXTRA_IS_POSTING = "EIP";
|
||||||
|
static final String EXTRA_ACCESS_TOKEN = "EAT";
|
||||||
|
static final String EXTRA_ACCOUNT_NAME = "EAN";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_subreddit_listing_fragment) CoordinatorLayout mCoordinatorLayout;
|
@BindView(R.id.coordinator_layout_subreddit_listing_fragment) CoordinatorLayout mCoordinatorLayout;
|
||||||
@BindView(R.id.recycler_view_subreddit_listing_fragment) RecyclerView mSubredditListingRecyclerView;
|
@BindView(R.id.recycler_view_subreddit_listing_fragment) RecyclerView mSubredditListingRecyclerView;
|
||||||
@ -60,13 +62,16 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
|
|||||||
@Inject @Named("oauth")
|
@Inject @Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase redditDataRoomDatabase;
|
||||||
|
|
||||||
public SubredditListingFragment() {
|
public SubredditListingFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View rootView = inflater.inflate(R.layout.fragment_subreddit_listing, container, false);
|
View rootView = inflater.inflate(R.layout.fragment_subreddit_listing, container, false);
|
||||||
@ -80,8 +85,10 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
|
|||||||
mLinearLayoutManager = new LinearLayoutManager(getActivity());
|
mLinearLayoutManager = new LinearLayoutManager(getActivity());
|
||||||
mSubredditListingRecyclerView.setLayoutManager(mLinearLayoutManager);
|
mSubredditListingRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||||
|
|
||||||
String query = getArguments().getString(EXTRA_QUERY_KEY);
|
String query = getArguments().getString(EXTRA_QUERY);
|
||||||
boolean isPosting = getArguments().getBoolean(EXTRA_IS_POSTING);
|
boolean isPosting = getArguments().getBoolean(EXTRA_IS_POSTING);
|
||||||
|
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||||
|
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
||||||
|
|
||||||
SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, query,
|
SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, query,
|
||||||
PostDataSource.SORT_TYPE_RELEVANCE, new SubredditListingDataSource.OnSubredditListingDataFetchedCallback() {
|
PostDataSource.SORT_TYPE_RELEVANCE, new SubredditListingDataSource.OnSubredditListingDataFetchedCallback() {
|
||||||
@ -99,9 +106,8 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mAdapter = new SubredditListingRecyclerViewAdapter(getActivity(), mOauthRetrofit, mRetrofit,
|
mAdapter = new SubredditListingRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
|
||||||
mAuthInfoSharedPreferences,
|
accessToken, accountName, redditDataRoomDatabase.subscribedSubredditDao(),
|
||||||
SubscribedSubredditRoomDatabase.getDatabase(getContext()).subscribedSubredditDao(),
|
|
||||||
new SubredditListingRecyclerViewAdapter.Callback() {
|
new SubredditListingRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void retryLoadingMore() {
|
public void retryLoadingMore() {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -44,21 +43,23 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
|||||||
private Context context;
|
private Context context;
|
||||||
private Retrofit oauthRetrofit;
|
private Retrofit oauthRetrofit;
|
||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private SharedPreferences authInfoSharedPreferences;
|
private String accessToken;
|
||||||
|
private String accountName;
|
||||||
private SubscribedSubredditDao subscribedSubredditDao;
|
private SubscribedSubredditDao subscribedSubredditDao;
|
||||||
|
|
||||||
private NetworkState networkState;
|
private NetworkState networkState;
|
||||||
private Callback callback;
|
private Callback callback;
|
||||||
|
|
||||||
SubredditListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, Retrofit retrofit,
|
SubredditListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, Retrofit retrofit,
|
||||||
SharedPreferences authInfoSharedPreferences,
|
String accessToken, String accountName,
|
||||||
SubscribedSubredditDao subscribedSubredditDao,
|
SubscribedSubredditDao subscribedSubredditDao,
|
||||||
Callback callback) {
|
Callback callback) {
|
||||||
super(DIFF_CALLBACK);
|
super(DIFF_CALLBACK);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.oauthRetrofit = oauthRetrofit;
|
this.oauthRetrofit = oauthRetrofit;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.authInfoSharedPreferences = authInfoSharedPreferences;
|
this.accessToken = accessToken;
|
||||||
|
this.accountName = accountName;
|
||||||
this.subscribedSubredditDao = subscribedSubredditDao;
|
this.subscribedSubredditDao = subscribedSubredditDao;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
glide = Glide.with(context.getApplicationContext());
|
glide = Glide.with(context.getApplicationContext());
|
||||||
@ -112,7 +113,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
|||||||
|
|
||||||
((DataViewHolder) holder).subredditNameTextView.setText(subredditData.getName());
|
((DataViewHolder) holder).subredditNameTextView.setText(subredditData.getName());
|
||||||
|
|
||||||
new CheckIsSubscribedToSubredditAsyncTask(subscribedSubredditDao, subredditData.getName(),
|
new CheckIsSubscribedToSubredditAsyncTask(subscribedSubredditDao, subredditData.getName(), accountName,
|
||||||
new CheckIsSubscribedToSubredditAsyncTask.CheckIsSubscribedToSubredditListener() {
|
new CheckIsSubscribedToSubredditAsyncTask.CheckIsSubscribedToSubredditListener() {
|
||||||
@Override
|
@Override
|
||||||
public void isSubscribed() {
|
public void isSubscribed() {
|
||||||
@ -124,7 +125,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
|||||||
((DataViewHolder) holder).subscribeButton.setVisibility(View.VISIBLE);
|
((DataViewHolder) holder).subscribeButton.setVisibility(View.VISIBLE);
|
||||||
((DataViewHolder) holder).subscribeButton.setOnClickListener(view -> {
|
((DataViewHolder) holder).subscribeButton.setOnClickListener(view -> {
|
||||||
SubredditSubscription.subscribeToSubreddit(oauthRetrofit, retrofit,
|
SubredditSubscription.subscribeToSubreddit(oauthRetrofit, retrofit,
|
||||||
authInfoSharedPreferences, subredditData.getName(), subscribedSubredditDao,
|
accessToken, accountName, subredditData.getName(), subscribedSubredditDao,
|
||||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSubredditSubscriptionSuccess() {
|
public void onSubredditSubscriptionSuccess() {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import SubredditDatabase.SubredditData;
|
import SubredditDatabase.SubredditData;
|
||||||
import SubscribedSubredditDatabase.SubscribedSubredditDao;
|
import SubscribedSubredditDatabase.SubscribedSubredditDao;
|
||||||
import SubscribedSubredditDatabase.SubscribedSubredditData;
|
import SubscribedSubredditDatabase.SubscribedSubredditData;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
@ -22,27 +22,27 @@ class SubredditSubscription {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void subscribeToSubreddit(Retrofit oauthRetrofit, Retrofit retrofit,
|
static void subscribeToSubreddit(Retrofit oauthRetrofit, Retrofit retrofit,
|
||||||
SharedPreferences authInfoSharedPreferences, String subredditName,
|
String accessToken, String subredditName, String accountName,
|
||||||
SubscribedSubredditDao subscribedSubredditDao,
|
SubscribedSubredditDao subscribedSubredditDao,
|
||||||
SubredditSubscriptionListener subredditSubscriptionListener) {
|
SubredditSubscriptionListener subredditSubscriptionListener) {
|
||||||
subredditSubscription(oauthRetrofit, retrofit, authInfoSharedPreferences, subredditName, "sub",
|
subredditSubscription(oauthRetrofit, retrofit, accessToken, subredditName, accountName, "sub",
|
||||||
subscribedSubredditDao, subredditSubscriptionListener);
|
subscribedSubredditDao, subredditSubscriptionListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unsubscribeToSubreddit(Retrofit oauthRetrofit, SharedPreferences authInfoSharedPreferences,
|
static void unsubscribeToSubreddit(Retrofit oauthRetrofit, String accessToken,
|
||||||
String subredditName, SubscribedSubredditDao subscribedSubredditDao,
|
String subredditName, String accountName,
|
||||||
|
SubscribedSubredditDao subscribedSubredditDao,
|
||||||
SubredditSubscriptionListener subredditSubscriptionListener) {
|
SubredditSubscriptionListener subredditSubscriptionListener) {
|
||||||
subredditSubscription(oauthRetrofit, null, authInfoSharedPreferences, subredditName, "unsub",
|
subredditSubscription(oauthRetrofit, null, accessToken, subredditName, accountName, "unsub",
|
||||||
subscribedSubredditDao,subredditSubscriptionListener);
|
subscribedSubredditDao,subredditSubscriptionListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void subredditSubscription(Retrofit oauthRetrofit, Retrofit retrofit, SharedPreferences authInfoSharedPreferences,
|
private static void subredditSubscription(Retrofit oauthRetrofit, Retrofit retrofit, String accessToken,
|
||||||
String subredditName, String action, SubscribedSubredditDao subscribedSubredditDao,
|
String subredditName, String accountName, String action,
|
||||||
|
SubscribedSubredditDao subscribedSubredditDao,
|
||||||
SubredditSubscriptionListener subredditSubscriptionListener) {
|
SubredditSubscriptionListener subredditSubscriptionListener) {
|
||||||
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
|
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
String accessToken = authInfoSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put(RedditUtils.ACTION_KEY, action);
|
params.put(RedditUtils.ACTION_KEY, action);
|
||||||
params.put(RedditUtils.SR_NAME_KEY, subredditName);
|
params.put(RedditUtils.SR_NAME_KEY, subredditName);
|
||||||
@ -57,7 +57,7 @@ class SubredditSubscription {
|
|||||||
@Override
|
@Override
|
||||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||||
new UpdateSubscriptionAsyncTask(subscribedSubredditDao,
|
new UpdateSubscriptionAsyncTask(subscribedSubredditDao,
|
||||||
subredditData, true).execute();
|
subredditData, accountName, true).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -66,7 +66,7 @@ class SubredditSubscription {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
new UpdateSubscriptionAsyncTask(subscribedSubredditDao, subredditName, false).execute();
|
new UpdateSubscriptionAsyncTask(subscribedSubredditDao, subredditName, accountName, false).execute();
|
||||||
}
|
}
|
||||||
subredditSubscriptionListener.onSubredditSubscriptionSuccess();
|
subredditSubscriptionListener.onSubredditSubscriptionSuccess();
|
||||||
} else {
|
} else {
|
||||||
@ -87,20 +87,24 @@ class SubredditSubscription {
|
|||||||
|
|
||||||
private SubscribedSubredditDao subscribedSubredditDao;
|
private SubscribedSubredditDao subscribedSubredditDao;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
|
private String accountName;
|
||||||
private SubscribedSubredditData subscribedSubredditData;
|
private SubscribedSubredditData subscribedSubredditData;
|
||||||
private boolean isSubscribing;
|
private boolean isSubscribing;
|
||||||
|
|
||||||
UpdateSubscriptionAsyncTask(SubscribedSubredditDao subscribedSubredditDao, String subredditName,
|
UpdateSubscriptionAsyncTask(SubscribedSubredditDao subscribedSubredditDao, String subredditName,
|
||||||
boolean isSubscribing) {
|
String accountName, boolean isSubscribing) {
|
||||||
this.subscribedSubredditDao = subscribedSubredditDao;
|
this.subscribedSubredditDao = subscribedSubredditDao;
|
||||||
this.subredditName = subredditName;
|
this.subredditName = subredditName;
|
||||||
|
this.accountName = accountName;
|
||||||
this.isSubscribing = isSubscribing;
|
this.isSubscribing = isSubscribing;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateSubscriptionAsyncTask(SubscribedSubredditDao subscribedSubredditDao, SubscribedSubredditData subscribedSubredditData,
|
UpdateSubscriptionAsyncTask(SubscribedSubredditDao subscribedSubredditDao, SubredditData subredditData,
|
||||||
boolean isSubscribing) {
|
String accountName, boolean isSubscribing) {
|
||||||
this.subscribedSubredditDao = subscribedSubredditDao;
|
this.subscribedSubredditDao = subscribedSubredditDao;
|
||||||
this.subscribedSubredditData = subscribedSubredditData;
|
this.subscribedSubredditData = new SubscribedSubredditData(subredditData.getId(), subredditData.getName(),
|
||||||
|
subredditData.getIconUrl(), accountName);
|
||||||
|
this.accountName = accountName;
|
||||||
this.isSubscribing = isSubscribing;
|
this.isSubscribing = isSubscribing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +113,7 @@ class SubredditSubscription {
|
|||||||
if(isSubscribing) {
|
if(isSubscribing) {
|
||||||
subscribedSubredditDao.insert(subscribedSubredditData);
|
subscribedSubredditDao.insert(subscribedSubredditData);
|
||||||
} else {
|
} else {
|
||||||
subscribedSubredditDao.deleteSubscribedSubreddit(subredditName);;
|
subscribedSubredditDao.deleteSubscribedSubreddit(subredditName, accountName);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -10,6 +9,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProviders;
|
import androidx.lifecycle.ViewModelProviders;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
@ -19,7 +19,6 @@ import com.bumptech.glide.Glide;
|
|||||||
import com.bumptech.glide.RequestManager;
|
import com.bumptech.glide.RequestManager;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
import SubscribedSubredditDatabase.SubscribedSubredditViewModel;
|
import SubscribedSubredditDatabase.SubscribedSubredditViewModel;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@ -31,6 +30,8 @@ import butterknife.ButterKnife;
|
|||||||
*/
|
*/
|
||||||
public class SubscribedSubredditsListingFragment extends Fragment {
|
public class SubscribedSubredditsListingFragment extends Fragment {
|
||||||
|
|
||||||
|
static final String EXTRA_ACCOUNT_NAME = "EAT";
|
||||||
|
static final String EXTRA_ACCOUNT_PROFILE_IMAGE_URL = "EAPIU";
|
||||||
static final String EXTRA_IS_SUBREDDIT_SELECTION = "EISS";
|
static final String EXTRA_IS_SUBREDDIT_SELECTION = "EISS";
|
||||||
static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
|
static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
|
||||||
|
|
||||||
@ -45,15 +46,14 @@ public class SubscribedSubredditsListingFragment extends Fragment {
|
|||||||
private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
|
private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("user_info")
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
SharedPreferences sharedPreferences;
|
|
||||||
|
|
||||||
public SubscribedSubredditsListingFragment() {
|
public SubscribedSubredditsListingFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View rootView = inflater.inflate(R.layout.fragment_subscribed_subreddits_listing, container, false);
|
View rootView = inflater.inflate(R.layout.fragment_subscribed_subreddits_listing, container, false);
|
||||||
|
|
||||||
@ -63,8 +63,7 @@ public class SubscribedSubredditsListingFragment extends Fragment {
|
|||||||
|
|
||||||
((Infinity) mActivity.getApplication()).getmAppComponent().inject(this);
|
((Infinity) mActivity.getApplication()).getmAppComponent().inject(this);
|
||||||
|
|
||||||
String username = sharedPreferences.getString(SharedPreferencesUtils.USER_KEY, "");
|
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
||||||
String userIconUrl = sharedPreferences.getString(SharedPreferencesUtils.PROFILE_IMAGE_URL_KEY, "");
|
|
||||||
|
|
||||||
mGlide = Glide.with(this);
|
mGlide = Glide.with(this);
|
||||||
|
|
||||||
@ -80,7 +79,9 @@ public class SubscribedSubredditsListingFragment extends Fragment {
|
|||||||
|
|
||||||
mRecyclerView.setAdapter(adapter);
|
mRecyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
mSubscribedSubredditViewModel = ViewModelProviders.of(this).get(SubscribedSubredditViewModel.class);
|
mSubscribedSubredditViewModel = ViewModelProviders.of(this,
|
||||||
|
new SubscribedSubredditViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, accountName))
|
||||||
|
.get(SubscribedSubredditViewModel.class);
|
||||||
mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, subscribedSubredditData -> {
|
mSubscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, subscribedSubredditData -> {
|
||||||
if (subscribedSubredditData == null || subscribedSubredditData.size() == 0) {
|
if (subscribedSubredditData == null || subscribedSubredditData.size() == 0) {
|
||||||
mRecyclerView.setVisibility(View.GONE);
|
mRecyclerView.setVisibility(View.GONE);
|
||||||
@ -91,7 +92,7 @@ public class SubscribedSubredditsListingFragment extends Fragment {
|
|||||||
mRecyclerView.setVisibility(View.VISIBLE);
|
mRecyclerView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter.addUser(username, userIconUrl);
|
adapter.addUser(accountName, getArguments().getString(EXTRA_ACCOUNT_PROFILE_IMAGE_URL));
|
||||||
adapter.setSubscribedSubreddits(subscribedSubredditData);
|
adapter.setSubscribedSubreddits(subscribedSubredditData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -21,11 +20,8 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import SubredditDatabase.SubredditData;
|
import SubredditDatabase.SubredditData;
|
||||||
import SubredditDatabase.SubredditRoomDatabase;
|
|
||||||
import SubscribedSubredditDatabase.SubscribedSubredditData;
|
import SubscribedSubredditDatabase.SubscribedSubredditData;
|
||||||
import SubscribedSubredditDatabase.SubscribedSubredditRoomDatabase;
|
|
||||||
import SubscribedUserDatabase.SubscribedUserData;
|
import SubscribedUserDatabase.SubscribedUserData;
|
||||||
import SubscribedUserDatabase.SubscribedUserRoomDatabase;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
@ -34,22 +30,28 @@ public class SubscribedThingListingActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
|
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
|
||||||
|
|
||||||
|
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
||||||
|
private static final String ACCESS_TOKEN_STATE = "ATS";
|
||||||
|
private static final String ACCOUNT_NAME_STATE = "ANS";
|
||||||
|
|
||||||
@BindView(R.id.toolbar_subscribed_thing_listing_activity) Toolbar toolbar;
|
@BindView(R.id.toolbar_subscribed_thing_listing_activity) Toolbar toolbar;
|
||||||
@BindView(R.id.tab_layout_subscribed_thing_listing_activity) TabLayout tabLayout;
|
@BindView(R.id.tab_layout_subscribed_thing_listing_activity) TabLayout tabLayout;
|
||||||
@BindView(R.id.view_pager_subscribed_thing_listing_activity) ViewPager viewPager;
|
@BindView(R.id.view_pager_subscribed_thing_listing_activity) ViewPager viewPager;
|
||||||
|
|
||||||
|
private boolean mNullAccessToken = false;
|
||||||
|
private String mAccessToken;
|
||||||
|
private String mAccountName;
|
||||||
private boolean mInsertSuccess = false;
|
private boolean mInsertSuccess = false;
|
||||||
|
|
||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
|
|
||||||
@Inject
|
|
||||||
@Named("auth_info")
|
|
||||||
SharedPreferences mAuthInfoSharedPreferences;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("oauth")
|
@Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -62,15 +64,39 @@ public class SubscribedThingListingActivity extends AppCompatActivity {
|
|||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
if(savedInstanceState != null) {
|
||||||
|
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
|
||||||
|
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
||||||
|
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
||||||
|
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
||||||
|
if(!mNullAccessToken && mAccessToken == null) {
|
||||||
|
getCurrentAccountAndInitializeViewPager();
|
||||||
|
} else {
|
||||||
|
initializeViewPagerAndLoadSubscriptions();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
getCurrentAccountAndInitializeViewPager();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getCurrentAccountAndInitializeViewPager() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if(account == null) {
|
||||||
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
}
|
||||||
|
initializeViewPagerAndLoadSubscriptions();
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initializeViewPagerAndLoadSubscriptions() {
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||||
viewPager.setAdapter(sectionsPagerAdapter);
|
viewPager.setAdapter(sectionsPagerAdapter);
|
||||||
viewPager.setOffscreenPageLimit(2);
|
viewPager.setOffscreenPageLimit(2);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
|
||||||
if(savedInstanceState != null) {
|
|
||||||
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
loadSubscriptions();
|
loadSubscriptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,11 +114,14 @@ public class SubscribedThingListingActivity extends AppCompatActivity {
|
|||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
|
outState.putBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE, mInsertSuccess);
|
||||||
|
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
||||||
|
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
||||||
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSubscriptions() {
|
private void loadSubscriptions() {
|
||||||
if (!mInsertSuccess) {
|
if (!mInsertSuccess) {
|
||||||
FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAuthInfoSharedPreferences, null,
|
FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAccessToken, mAccountName, null,
|
||||||
new ArrayList<>(), new ArrayList<>(),
|
new ArrayList<>(), new ArrayList<>(),
|
||||||
new ArrayList<>(),
|
new ArrayList<>(),
|
||||||
new FetchSubscribedThing.FetchSubscribedThingListener() {
|
new FetchSubscribedThing.FetchSubscribedThingListener() {
|
||||||
@ -101,9 +130,9 @@ public class SubscribedThingListingActivity extends AppCompatActivity {
|
|||||||
ArrayList<SubscribedUserData> subscribedUserData,
|
ArrayList<SubscribedUserData> subscribedUserData,
|
||||||
ArrayList<SubredditData> subredditData) {
|
ArrayList<SubredditData> subredditData) {
|
||||||
new InsertSubscribedThingsAsyncTask(
|
new InsertSubscribedThingsAsyncTask(
|
||||||
SubscribedSubredditRoomDatabase.getDatabase(SubscribedThingListingActivity.this).subscribedSubredditDao(),
|
mRedditDataRoomDatabase.subscribedSubredditDao(),
|
||||||
SubscribedUserRoomDatabase.getDatabase(SubscribedThingListingActivity.this).subscribedUserDao(),
|
mRedditDataRoomDatabase.subscribedUserDao(),
|
||||||
SubredditRoomDatabase.getDatabase(SubscribedThingListingActivity.this).subredditDao(),
|
mRedditDataRoomDatabase.subredditDao(),
|
||||||
subscribedSubredditData,
|
subscribedSubredditData,
|
||||||
subscribedUserData,
|
subscribedUserData,
|
||||||
subredditData,
|
subredditData,
|
||||||
@ -132,12 +161,17 @@ public class SubscribedThingListingActivity extends AppCompatActivity {
|
|||||||
SubscribedSubredditsListingFragment fragment = new SubscribedSubredditsListingFragment();
|
SubscribedSubredditsListingFragment fragment = new SubscribedSubredditsListingFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, false);
|
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, false);
|
||||||
|
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
return new FollowedUsersListingFragment();
|
FollowedUsersListingFragment fragment = new FollowedUsersListingFragment();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString(FollowedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
|
fragment.setArguments(bundle);
|
||||||
|
return fragment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -23,31 +22,29 @@ class UserFollowing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void followUser(Retrofit oauthRetrofit, Retrofit retrofit,
|
static void followUser(Retrofit oauthRetrofit, Retrofit retrofit,
|
||||||
SharedPreferences authInfoSharedPreferences, String userName,
|
String accessToken, String username, String accountName,
|
||||||
SubscribedUserDao subscribedUserDao,
|
SubscribedUserDao subscribedUserDao,
|
||||||
UserFollowingListener userFollowingListener) {
|
UserFollowingListener userFollowingListener) {
|
||||||
userFollowing(oauthRetrofit, retrofit, authInfoSharedPreferences, userName, "sub",
|
userFollowing(oauthRetrofit, retrofit, accessToken, username, accountName, "sub",
|
||||||
subscribedUserDao, userFollowingListener);
|
subscribedUserDao, userFollowingListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unfollowUser(Retrofit oauthRetrofit, Retrofit retrofit,
|
static void unfollowUser(Retrofit oauthRetrofit, Retrofit retrofit,
|
||||||
SharedPreferences authInfoSharedPreferences, String userName,
|
String accessToken, String username, String accountName,
|
||||||
SubscribedUserDao subscribedUserDao,
|
SubscribedUserDao subscribedUserDao,
|
||||||
UserFollowingListener userFollowingListener) {
|
UserFollowingListener userFollowingListener) {
|
||||||
userFollowing(oauthRetrofit, retrofit, authInfoSharedPreferences, userName, "unsub",
|
userFollowing(oauthRetrofit, retrofit, accessToken, username, accountName, "unsub",
|
||||||
subscribedUserDao, userFollowingListener);
|
subscribedUserDao, userFollowingListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void userFollowing(Retrofit oauthRetrofit, Retrofit retrofit, SharedPreferences authInfoSharedPreferences,
|
private static void userFollowing(Retrofit oauthRetrofit, Retrofit retrofit, String accessToken,
|
||||||
String userName, String action, SubscribedUserDao subscribedUserDao,
|
String username, String accountName, String action, SubscribedUserDao subscribedUserDao,
|
||||||
UserFollowingListener userFollowingListener) {
|
UserFollowingListener userFollowingListener) {
|
||||||
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
|
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
String accessToken = authInfoSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put(RedditUtils.ACTION_KEY, action);
|
params.put(RedditUtils.ACTION_KEY, action);
|
||||||
params.put(RedditUtils.SR_NAME_KEY, "u_" + userName);
|
params.put(RedditUtils.SR_NAME_KEY, "u_" + username);
|
||||||
|
|
||||||
Call<String> subredditSubscriptionCall = api.subredditSubscription(RedditUtils.getOAuthHeader(accessToken), params);
|
Call<String> subredditSubscriptionCall = api.subredditSubscription(RedditUtils.getOAuthHeader(accessToken), params);
|
||||||
subredditSubscriptionCall.enqueue(new Callback<String>() {
|
subredditSubscriptionCall.enqueue(new Callback<String>() {
|
||||||
@ -55,10 +52,10 @@ class UserFollowing {
|
|||||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
if(action.equals("sub")) {
|
if(action.equals("sub")) {
|
||||||
FetchUserData.fetchUserData(retrofit, userName, new FetchUserData.FetchUserDataListener() {
|
FetchUserData.fetchUserData(retrofit, username, new FetchUserData.FetchUserDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchUserDataSuccess(UserData userData) {
|
public void onFetchUserDataSuccess(UserData userData) {
|
||||||
new UpdateSubscriptionAsyncTask(subscribedUserDao, userData, true).execute();
|
new UpdateSubscriptionAsyncTask(subscribedUserDao, userData, accountName, true).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,7 +64,7 @@ class UserFollowing {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
new UpdateSubscriptionAsyncTask(subscribedUserDao, userName, false).execute();
|
new UpdateSubscriptionAsyncTask(subscribedUserDao, username, accountName, false).execute();
|
||||||
}
|
}
|
||||||
userFollowingListener.onUserFollowingSuccess();
|
userFollowingListener.onUserFollowingSuccess();
|
||||||
} else {
|
} else {
|
||||||
@ -87,21 +84,25 @@ class UserFollowing {
|
|||||||
private static class UpdateSubscriptionAsyncTask extends AsyncTask<Void, Void, Void> {
|
private static class UpdateSubscriptionAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
private SubscribedUserDao subscribedUserDao;
|
private SubscribedUserDao subscribedUserDao;
|
||||||
private String userName;
|
private String username;
|
||||||
|
private String accountName;
|
||||||
private SubscribedUserData subscribedUserData;
|
private SubscribedUserData subscribedUserData;
|
||||||
private boolean isSubscribing;
|
private boolean isSubscribing;
|
||||||
|
|
||||||
UpdateSubscriptionAsyncTask(SubscribedUserDao subscribedUserDao, String userName,
|
UpdateSubscriptionAsyncTask(SubscribedUserDao subscribedUserDao, String username,
|
||||||
boolean isSubscribing) {
|
String accountName, boolean isSubscribing) {
|
||||||
this.subscribedUserDao = subscribedUserDao;
|
this.subscribedUserDao = subscribedUserDao;
|
||||||
this.userName = userName;
|
this.username = username;
|
||||||
|
this.accountName = accountName;
|
||||||
this.isSubscribing = isSubscribing;
|
this.isSubscribing = isSubscribing;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateSubscriptionAsyncTask(SubscribedUserDao subscribedUserDao, SubscribedUserData subscribedUserData,
|
UpdateSubscriptionAsyncTask(SubscribedUserDao subscribedUserDao, UserData userData,
|
||||||
boolean isSubscribing) {
|
String accountName, boolean isSubscribing) {
|
||||||
this.subscribedUserDao = subscribedUserDao;
|
this.subscribedUserDao = subscribedUserDao;
|
||||||
this.subscribedUserData = subscribedUserData;
|
this.subscribedUserData = new SubscribedUserData(userData.getName(), userData.getIconUrl(),
|
||||||
|
userData.getName());
|
||||||
|
this.accountName = accountName;
|
||||||
this.isSubscribing = isSubscribing;
|
this.isSubscribing = isSubscribing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ class UserFollowing {
|
|||||||
if(isSubscribing) {
|
if(isSubscribing) {
|
||||||
subscribedUserDao.insert(subscribedUserData);
|
subscribedUserDao.insert(subscribedUserData);
|
||||||
} else {
|
} else {
|
||||||
subscribedUserDao.deleteSubscribedUser(userName);
|
subscribedUserDao.deleteSubscribedUser(username, accountName);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import SubscribedUserDatabase.SubscribedUserRoomDatabase;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
@ -32,20 +31,17 @@ import retrofit2.Retrofit;
|
|||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
*/
|
*/
|
||||||
public class UserListingFragment extends Fragment implements FragmentCommunicator {
|
public class UserListingFragment extends Fragment implements FragmentCommunicator {
|
||||||
static final String QUERY_KEY = "QK";
|
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_user_listing_fragment)
|
static final String EXTRA_QUERY = "EQ";
|
||||||
CoordinatorLayout mCoordinatorLayout;
|
static final String EXTRA_ACCESS_TOKEN = "EAT";
|
||||||
@BindView(R.id.recycler_view_user_listing_fragment)
|
static final String EXTRA_ACCOUNT_NAME = "EAN";
|
||||||
RecyclerView mUserListingRecyclerView;
|
|
||||||
@BindView(R.id.progress_bar_user_listing_fragment)
|
@BindView(R.id.coordinator_layout_user_listing_fragment) CoordinatorLayout mCoordinatorLayout;
|
||||||
CircleProgressBar mProgressBar;
|
@BindView(R.id.recycler_view_user_listing_fragment) RecyclerView mUserListingRecyclerView;
|
||||||
@BindView(R.id.fetch_user_listing_info_linear_layout_user_listing_fragment)
|
@BindView(R.id.progress_bar_user_listing_fragment) CircleProgressBar mProgressBar;
|
||||||
LinearLayout mFetchUserListingInfoLinearLayout;
|
@BindView(R.id.fetch_user_listing_info_linear_layout_user_listing_fragment) LinearLayout mFetchUserListingInfoLinearLayout;
|
||||||
@BindView(R.id.fetch_user_listing_info_image_view_user_listing_fragment)
|
@BindView(R.id.fetch_user_listing_info_image_view_user_listing_fragment) ImageView mFetchUserListingInfoImageView;
|
||||||
ImageView mFetchUserListingInfoImageView;
|
@BindView(R.id.fetch_user_listing_info_text_view_user_listing_fragment) TextView mFetchUserListingInfoTextView;
|
||||||
@BindView(R.id.fetch_user_listing_info_text_view_user_listing_fragment)
|
|
||||||
TextView mFetchUserListingInfoTextView;
|
|
||||||
|
|
||||||
private LinearLayoutManager mLinearLayoutManager;
|
private LinearLayoutManager mLinearLayoutManager;
|
||||||
|
|
||||||
@ -65,6 +61,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
|
|||||||
@Inject @Named("oauth")
|
@Inject @Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
RedditDataRoomDatabase redditDataRoomDatabase;
|
||||||
|
|
||||||
public UserListingFragment() {
|
public UserListingFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
@ -83,7 +82,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
|
|||||||
mLinearLayoutManager = new LinearLayoutManager(getActivity());
|
mLinearLayoutManager = new LinearLayoutManager(getActivity());
|
||||||
mUserListingRecyclerView.setLayoutManager(mLinearLayoutManager);
|
mUserListingRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||||
|
|
||||||
mQuery = getArguments().getString(QUERY_KEY);
|
mQuery = getArguments().getString(EXTRA_QUERY);
|
||||||
|
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||||
|
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
||||||
|
|
||||||
UserListingViewModel.Factory factory = new UserListingViewModel.Factory(mRetrofit, mQuery,
|
UserListingViewModel.Factory factory = new UserListingViewModel.Factory(mRetrofit, mQuery,
|
||||||
PostDataSource.SORT_TYPE_RELEVANCE, new UserListingDataSource.OnUserListingDataFetchedCallback() {
|
PostDataSource.SORT_TYPE_RELEVANCE, new UserListingDataSource.OnUserListingDataFetchedCallback() {
|
||||||
@ -102,8 +103,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
|
|||||||
});
|
});
|
||||||
|
|
||||||
mAdapter = new UserListingRecyclerViewAdapter(getActivity(), mOauthRetrofit, mRetrofit,
|
mAdapter = new UserListingRecyclerViewAdapter(getActivity(), mOauthRetrofit, mRetrofit,
|
||||||
mAuthInfoSharedPreferences,
|
accessToken, accountName, redditDataRoomDatabase.subscribedUserDao(),
|
||||||
SubscribedUserRoomDatabase.getDatabase(getContext()).subscribedUserDao(),
|
|
||||||
() -> mUserListingViewModel.retryLoadingMore());
|
() -> mUserListingViewModel.retryLoadingMore());
|
||||||
|
|
||||||
mUserListingRecyclerView.setAdapter(mAdapter);
|
mUserListingRecyclerView.setAdapter(mAdapter);
|
||||||
|
@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -44,21 +43,22 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R
|
|||||||
private Context context;
|
private Context context;
|
||||||
private Retrofit oauthRetrofit;
|
private Retrofit oauthRetrofit;
|
||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private SharedPreferences authInfoSharedPreferences;
|
private String accessToken;
|
||||||
|
private String accountName;
|
||||||
private SubscribedUserDao subscribedUserDao;
|
private SubscribedUserDao subscribedUserDao;
|
||||||
|
|
||||||
private NetworkState networkState;
|
private NetworkState networkState;
|
||||||
private UserListingRecyclerViewAdapter.RetryLoadingMoreCallback retryLoadingMoreCallback;
|
private UserListingRecyclerViewAdapter.RetryLoadingMoreCallback retryLoadingMoreCallback;
|
||||||
|
|
||||||
UserListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, Retrofit retrofit,
|
UserListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, Retrofit retrofit,
|
||||||
SharedPreferences authInfoSharedPreferences,
|
String accessToken, String accountName, SubscribedUserDao subscribedUserDao,
|
||||||
SubscribedUserDao subscribedUserDao,
|
|
||||||
UserListingRecyclerViewAdapter.RetryLoadingMoreCallback retryLoadingMoreCallback) {
|
UserListingRecyclerViewAdapter.RetryLoadingMoreCallback retryLoadingMoreCallback) {
|
||||||
super(DIFF_CALLBACK);
|
super(DIFF_CALLBACK);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.oauthRetrofit = oauthRetrofit;
|
this.oauthRetrofit = oauthRetrofit;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.authInfoSharedPreferences = authInfoSharedPreferences;
|
this.accessToken = accessToken;
|
||||||
|
this.accountName = accountName;
|
||||||
this.subscribedUserDao = subscribedUserDao;
|
this.subscribedUserDao = subscribedUserDao;
|
||||||
this.retryLoadingMoreCallback = retryLoadingMoreCallback;
|
this.retryLoadingMoreCallback = retryLoadingMoreCallback;
|
||||||
glide = Glide.with(context.getApplicationContext());
|
glide = Glide.with(context.getApplicationContext());
|
||||||
@ -115,7 +115,7 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R
|
|||||||
|
|
||||||
((UserListingRecyclerViewAdapter.DataViewHolder) holder).UserNameTextView.setText(userData.getName());
|
((UserListingRecyclerViewAdapter.DataViewHolder) holder).UserNameTextView.setText(userData.getName());
|
||||||
|
|
||||||
new CheckIsFollowingUserAsyncTask(subscribedUserDao, userData.getName(),
|
new CheckIsFollowingUserAsyncTask(subscribedUserDao, userData.getName(), accountName,
|
||||||
new CheckIsFollowingUserAsyncTask.CheckIsFollowingUserListener() {
|
new CheckIsFollowingUserAsyncTask.CheckIsFollowingUserListener() {
|
||||||
@Override
|
@Override
|
||||||
public void isSubscribed() {
|
public void isSubscribed() {
|
||||||
@ -127,7 +127,7 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R
|
|||||||
((UserListingRecyclerViewAdapter.DataViewHolder) holder).subscribeButton.setVisibility(View.VISIBLE);
|
((UserListingRecyclerViewAdapter.DataViewHolder) holder).subscribeButton.setVisibility(View.VISIBLE);
|
||||||
((UserListingRecyclerViewAdapter.DataViewHolder) holder).subscribeButton.setOnClickListener(view -> {
|
((UserListingRecyclerViewAdapter.DataViewHolder) holder).subscribeButton.setOnClickListener(view -> {
|
||||||
UserFollowing.followUser(oauthRetrofit, retrofit,
|
UserFollowing.followUser(oauthRetrofit, retrofit,
|
||||||
authInfoSharedPreferences, userData.getName(), subscribedUserDao,
|
accessToken, userData.getName(), accountName, subscribedUserDao,
|
||||||
new UserFollowing.UserFollowingListener() {
|
new UserFollowing.UserFollowingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onUserFollowingSuccess() {
|
public void onUserFollowingSuccess() {
|
||||||
|
@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -59,6 +58,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
private int orientation;
|
private int orientation;
|
||||||
private int postListPosition = -1;
|
private int postListPosition = -1;
|
||||||
|
|
||||||
|
@State
|
||||||
|
boolean mNullAccessToken = false;
|
||||||
|
@State
|
||||||
|
String mAccessToken;
|
||||||
@State
|
@State
|
||||||
Post mPost;
|
Post mPost;
|
||||||
@State
|
@State
|
||||||
@ -94,8 +97,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
@Inject @Named("oauth")
|
@Inject @Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
@Inject @Named("auth_info")
|
@Inject
|
||||||
SharedPreferences mSharedPreferences;
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -121,6 +124,30 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
orientation = getResources().getConfiguration().orientation;
|
orientation = getResources().getConfiguration().orientation;
|
||||||
|
|
||||||
|
if(!mNullAccessToken && mAccessToken == null) {
|
||||||
|
getCurrentAccountAndBindView();
|
||||||
|
} else {
|
||||||
|
bindView();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getIntent().hasExtra(EXTRA_POST_LIST_POSITION)) {
|
||||||
|
postListPosition = getIntent().getExtras().getInt(EXTRA_POST_LIST_POSITION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getCurrentAccountAndBindView() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if(account == null) {
|
||||||
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
bindView();
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindView() {
|
||||||
if(mPost == null) {
|
if(mPost == null) {
|
||||||
mPost = getIntent().getExtras().getParcelable(EXTRA_POST_DATA);
|
mPost = getIntent().getExtras().getParcelable(EXTRA_POST_DATA);
|
||||||
}
|
}
|
||||||
@ -130,7 +157,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
fetchPostAndCommentsById(getIntent().getExtras().getString(EXTRA_POST_ID));
|
fetchPostAndCommentsById(getIntent().getExtras().getString(EXTRA_POST_ID));
|
||||||
} else {
|
} else {
|
||||||
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
||||||
mOauthRetrofit, mGlide, mSharedPreferences, mPost,
|
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mPost,
|
||||||
mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
|
mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
|
||||||
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
||||||
@Override
|
@Override
|
||||||
@ -163,12 +190,9 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getIntent().hasExtra(EXTRA_POST_LIST_POSITION)) {
|
|
||||||
postListPosition = getIntent().getExtras().getInt(EXTRA_POST_LIST_POSITION);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void fetchPostAndCommentsById(String subredditId) {
|
private void fetchPostAndCommentsById(String subredditId) {
|
||||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||||
mGlide.clear(mFetchPostInfoImageView);
|
mGlide.clear(mFetchPostInfoImageView);
|
||||||
@ -190,7 +214,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
|||||||
mPost = post;
|
mPost = post;
|
||||||
|
|
||||||
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
|
||||||
mOauthRetrofit, mGlide, mSharedPreferences, mPost,
|
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mPost,
|
||||||
mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
|
mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
|
||||||
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -31,10 +30,8 @@ import javax.inject.Named;
|
|||||||
|
|
||||||
import SubredditDatabase.SubredditDao;
|
import SubredditDatabase.SubredditDao;
|
||||||
import SubredditDatabase.SubredditData;
|
import SubredditDatabase.SubredditData;
|
||||||
import SubredditDatabase.SubredditRoomDatabase;
|
|
||||||
import SubredditDatabase.SubredditViewModel;
|
import SubredditDatabase.SubredditViewModel;
|
||||||
import SubscribedSubredditDatabase.SubscribedSubredditDao;
|
import SubscribedSubredditDatabase.SubscribedSubredditDao;
|
||||||
import SubscribedSubredditDatabase.SubscribedSubredditRoomDatabase;
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
@ -48,6 +45,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
|
|
||||||
private static final String FRAGMENT_OUT_STATE_KEY = "FOSK";
|
private static final String FRAGMENT_OUT_STATE_KEY = "FOSK";
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
||||||
|
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
||||||
|
private static final String ACCESS_TOKEN_STATE = "ATS";
|
||||||
|
private static final String ACCOUNT_NAME_STATE = "ANS";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_view_subreddit_detail_activity) CoordinatorLayout coordinatorLayout;
|
@BindView(R.id.coordinator_layout_view_subreddit_detail_activity) CoordinatorLayout coordinatorLayout;
|
||||||
@BindView(R.id.appbar_layout_view_subreddit_detail) AppBarLayout appBarLayout;
|
@BindView(R.id.appbar_layout_view_subreddit_detail) AppBarLayout appBarLayout;
|
||||||
@ -62,6 +62,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
@BindView(R.id.description_text_view_view_subreddit_detail_activity) TextView descriptionTextView;
|
@BindView(R.id.description_text_view_view_subreddit_detail_activity) TextView descriptionTextView;
|
||||||
@BindView(R.id.fab_view_subreddit_detail_activity) FloatingActionButton fab;
|
@BindView(R.id.fab_view_subreddit_detail_activity) FloatingActionButton fab;
|
||||||
|
|
||||||
|
private boolean mNullAccessToken = false;
|
||||||
|
private String mAccessToken;
|
||||||
|
private String mAccountName;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
private boolean subscriptionReady = false;
|
private boolean subscriptionReady = false;
|
||||||
private boolean isInLazyMode = false;
|
private boolean isInLazyMode = false;
|
||||||
@ -85,8 +88,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("auth_info")
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
SharedPreferences sharedPreferences;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -97,6 +99,23 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
|
|
||||||
((Infinity) getApplication()).getmAppComponent().inject(this);
|
((Infinity) getApplication()).getmAppComponent().inject(this);
|
||||||
|
|
||||||
|
if(savedInstanceState == null) {
|
||||||
|
getCurrentAccountAndBindView();
|
||||||
|
} else {
|
||||||
|
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
||||||
|
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
||||||
|
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
||||||
|
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||||
|
|
||||||
|
if(!mNullAccessToken && mAccessToken == null) {
|
||||||
|
getCurrentAccountAndBindView();
|
||||||
|
} else {
|
||||||
|
bindView(false);
|
||||||
|
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
|
||||||
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
|
postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
|
||||||
|
|
||||||
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
|
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
|
||||||
@ -123,10 +142,11 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
|
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
|
||||||
params.topMargin = statusBarHeight;
|
params.topMargin = statusBarHeight;
|
||||||
|
|
||||||
subscribedSubredditDao = SubscribedSubredditRoomDatabase.getDatabase(this).subscribedSubredditDao();
|
subscribedSubredditDao = mRedditDataRoomDatabase.subscribedSubredditDao();
|
||||||
glide = Glide.with(this);
|
glide = Glide.with(this);
|
||||||
|
|
||||||
mSubredditViewModel = ViewModelProviders.of(this, new SubredditViewModel.Factory(getApplication(), subredditName))
|
mSubredditViewModel = ViewModelProviders.of(this,
|
||||||
|
new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, subredditName))
|
||||||
.get(SubredditViewModel.class);
|
.get(SubredditViewModel.class);
|
||||||
mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
|
mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
|
||||||
if(subredditData != null) {
|
if(subredditData != null) {
|
||||||
@ -183,12 +203,44 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
FetchSubredditData.fetchSubredditData(mRetrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() {
|
||||||
|
@Override
|
||||||
|
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||||
|
new InsertSubredditDataAsyncTask(mRedditDataRoomDatabase, subredditData)
|
||||||
|
.execute();
|
||||||
|
String nOnlineSubscribers = getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers);
|
||||||
|
nOnlineSubscribersTextView.setText(nOnlineSubscribers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFetchSubredditDataFail() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getCurrentAccountAndBindView() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
|
if(account == null) {
|
||||||
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
}
|
||||||
|
bindView(true);
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindView(boolean initializeFragment) {
|
||||||
subscribeSubredditChip.setOnClickListener(view -> {
|
subscribeSubredditChip.setOnClickListener(view -> {
|
||||||
if(subscriptionReady) {
|
if(subscriptionReady) {
|
||||||
subscriptionReady = false;
|
subscriptionReady = false;
|
||||||
if(subscribeSubredditChip.getText().equals(getResources().getString(R.string.subscribe))) {
|
if(subscribeSubredditChip.getText().equals(getResources().getString(R.string.subscribe))) {
|
||||||
SubredditSubscription.subscribeToSubreddit(mOauthRetrofit, mRetrofit, sharedPreferences,
|
SubredditSubscription.subscribeToSubreddit(mOauthRetrofit, mRetrofit, mAccessToken,
|
||||||
subredditName, subscribedSubredditDao, new SubredditSubscription.SubredditSubscriptionListener() {
|
subredditName, mAccountName, subscribedSubredditDao,
|
||||||
|
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSubredditSubscriptionSuccess() {
|
public void onSubredditSubscriptionSuccess() {
|
||||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||||
@ -204,8 +256,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
SubredditSubscription.unsubscribeToSubreddit(mOauthRetrofit, sharedPreferences,
|
SubredditSubscription.unsubscribeToSubreddit(mOauthRetrofit, mAccessToken,
|
||||||
subredditName, subscribedSubredditDao, new SubredditSubscription.SubredditSubscriptionListener() {
|
subredditName, mAccountName, subscribedSubredditDao,
|
||||||
|
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSubredditSubscriptionSuccess() {
|
public void onSubredditSubscriptionSuccess() {
|
||||||
subscribeSubredditChip.setText(R.string.subscribe);
|
subscribeSubredditChip.setText(R.string.subscribe);
|
||||||
@ -224,63 +277,34 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
new CheckIsSubscribedToSubredditAsyncTask(subscribedSubredditDao, subredditName,
|
new CheckIsSubscribedToSubredditAsyncTask(subscribedSubredditDao, subredditName, mAccountName,
|
||||||
new CheckIsSubscribedToSubredditAsyncTask.CheckIsSubscribedToSubredditListener() {
|
new CheckIsSubscribedToSubredditAsyncTask.CheckIsSubscribedToSubredditListener() {
|
||||||
@Override
|
@Override
|
||||||
public void isSubscribed() {
|
public void isSubscribed() {
|
||||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||||
subscribeSubredditChip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorAccent));
|
subscribeSubredditChip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorAccent));
|
||||||
subscriptionReady = true;
|
subscriptionReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void isNotSubscribed() {
|
public void isNotSubscribed() {
|
||||||
subscribeSubredditChip.setText(R.string.subscribe);
|
subscribeSubredditChip.setText(R.string.subscribe);
|
||||||
subscribeSubredditChip.setChipBackgroundColor(getResources().getColorStateList(R.color.backgroundColorPrimaryDark));
|
subscribeSubredditChip.setChipBackgroundColor(getResources().getColorStateList(R.color.backgroundColorPrimaryDark));
|
||||||
subscriptionReady = true;
|
subscriptionReady = true;
|
||||||
}
|
}
|
||||||
}).execute();
|
}).execute();
|
||||||
|
|
||||||
FetchSubredditData.fetchSubredditData(mRetrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() {
|
if(initializeFragment) {
|
||||||
@Override
|
|
||||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
|
||||||
new InsertSubredditDataAsyncTask(SubredditRoomDatabase.getDatabase(ViewSubredditDetailActivity.this), subredditData)
|
|
||||||
.execute();
|
|
||||||
String nOnlineSubscribers = getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers);
|
|
||||||
nOnlineSubscribersTextView.setText(nOnlineSubscribers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFetchSubredditDataFail() {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if(savedInstanceState == null) {
|
|
||||||
mFragment = new PostFragment();
|
mFragment = new PostFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, subredditName);
|
bundle.putString(PostFragment.EXTRA_NAME, subredditName);
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
||||||
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
|
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
mFragment.setArguments(bundle);
|
mFragment.setArguments(bundle);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
|
||||||
} else {
|
|
||||||
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
|
|
||||||
if(mFragment == null) {
|
|
||||||
mFragment = new PostFragment();
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, subredditName);
|
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
|
|
||||||
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
|
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
|
||||||
mFragment.setArguments(bundle);
|
|
||||||
}
|
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -347,6 +371,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
||||||
|
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
||||||
|
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
||||||
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,8 +417,8 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
private SubredditDao mSubredditDao;
|
private SubredditDao mSubredditDao;
|
||||||
private SubredditData subredditData;
|
private SubredditData subredditData;
|
||||||
|
|
||||||
InsertSubredditDataAsyncTask(SubredditRoomDatabase subredditDb, SubredditData subredditData) {
|
InsertSubredditDataAsyncTask(RedditDataRoomDatabase db, SubredditData subredditData) {
|
||||||
mSubredditDao = subredditDb.subredditDao();
|
mSubredditDao = db.subredditDao();
|
||||||
this.subredditData = subredditData;
|
this.subredditData = subredditData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -33,10 +32,8 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import SubscribedUserDatabase.SubscribedUserDao;
|
import SubscribedUserDatabase.SubscribedUserDao;
|
||||||
import SubscribedUserDatabase.SubscribedUserRoomDatabase;
|
|
||||||
import User.UserDao;
|
import User.UserDao;
|
||||||
import User.UserData;
|
import User.UserData;
|
||||||
import User.UserRoomDatabase;
|
|
||||||
import User.UserViewModel;
|
import User.UserViewModel;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -48,6 +45,9 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
public static final String EXTRA_USER_NAME_KEY = "EUNK";
|
public static final String EXTRA_USER_NAME_KEY = "EUNK";
|
||||||
|
|
||||||
|
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
||||||
|
private static final String ACCESS_TOKEN_STATE = "ATS";
|
||||||
|
private static final String ACCOUNT_NAME_STATE = "ANS";
|
||||||
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
private static final String IS_IN_LAZY_MODE_STATE = "IILMS";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_view_user_detail_activity) CoordinatorLayout coordinatorLayout;
|
@BindView(R.id.coordinator_layout_view_user_detail_activity) CoordinatorLayout coordinatorLayout;
|
||||||
@ -69,6 +69,9 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
private Menu mMenu;
|
private Menu mMenu;
|
||||||
private AppBarLayout.LayoutParams params;
|
private AppBarLayout.LayoutParams params;
|
||||||
|
|
||||||
|
private boolean mNullAccessToken = false;
|
||||||
|
private String mAccessToken;
|
||||||
|
private String mAccountName;
|
||||||
private String username;
|
private String username;
|
||||||
private boolean subscriptionReady = false;
|
private boolean subscriptionReady = false;
|
||||||
private boolean isInLazyMode = false;
|
private boolean isInLazyMode = false;
|
||||||
@ -88,8 +91,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("auth_info")
|
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||||
SharedPreferences sharedPreferences;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -100,6 +102,23 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
((Infinity) getApplication()).getmAppComponent().inject(this);
|
((Infinity) getApplication()).getmAppComponent().inject(this);
|
||||||
|
|
||||||
|
if(savedInstanceState == null) {
|
||||||
|
getCurrentAccountAndInitializeViewPager();
|
||||||
|
} else {
|
||||||
|
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
|
||||||
|
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
|
||||||
|
mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
|
||||||
|
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
||||||
|
|
||||||
|
if(!mNullAccessToken && mAccessToken == null) {
|
||||||
|
getCurrentAccountAndInitializeViewPager();
|
||||||
|
} else {
|
||||||
|
initializeViewPager();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentAccountAndInitializeViewPager();
|
||||||
|
|
||||||
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
|
||||||
|
|
||||||
//Get status bar height
|
//Get status bar height
|
||||||
@ -120,11 +139,6 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
|
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
|
||||||
params.topMargin = statusBarHeight;
|
params.topMargin = statusBarHeight;
|
||||||
|
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
|
||||||
viewPager.setAdapter(sectionsPagerAdapter);
|
|
||||||
viewPager.setOffscreenPageLimit(2);
|
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
|
||||||
|
|
||||||
expandedTabTextColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTextColor);
|
expandedTabTextColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTextColor);
|
||||||
expandedTabBackgroundColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabBackground);
|
expandedTabBackgroundColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabBackground);
|
||||||
expandedTabIndicatorColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabIndicator);
|
expandedTabIndicatorColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabIndicator);
|
||||||
@ -148,10 +162,10 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
subscribedUserDao = SubscribedUserRoomDatabase.getDatabase(this).subscribedUserDao();
|
subscribedUserDao = mRedditDataRoomDatabase.subscribedUserDao();
|
||||||
glide = Glide.with(this);
|
glide = Glide.with(this);
|
||||||
|
|
||||||
userViewModel = ViewModelProviders.of(this, new UserViewModel.Factory(getApplication(), username))
|
userViewModel = ViewModelProviders.of(this, new UserViewModel.Factory(getApplication(), mRedditDataRoomDatabase, username))
|
||||||
.get(UserViewModel.class);
|
.get(UserViewModel.class);
|
||||||
userViewModel.getUserLiveData().observe(this, userData -> {
|
userViewModel.getUserLiveData().observe(this, userData -> {
|
||||||
if(userData != null) {
|
if(userData != null) {
|
||||||
@ -199,8 +213,8 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
if(subscriptionReady) {
|
if(subscriptionReady) {
|
||||||
subscriptionReady = false;
|
subscriptionReady = false;
|
||||||
if(subscribeUserChip.getText().equals(getResources().getString(R.string.follow))) {
|
if(subscribeUserChip.getText().equals(getResources().getString(R.string.follow))) {
|
||||||
UserFollowing.followUser(mOauthRetrofit, mRetrofit, sharedPreferences,
|
UserFollowing.followUser(mOauthRetrofit, mRetrofit, mAccessToken,
|
||||||
username, subscribedUserDao, new UserFollowing.UserFollowingListener() {
|
username, mAccountName, subscribedUserDao, new UserFollowing.UserFollowingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onUserFollowingSuccess() {
|
public void onUserFollowingSuccess() {
|
||||||
subscribeUserChip.setText(R.string.unfollow);
|
subscribeUserChip.setText(R.string.unfollow);
|
||||||
@ -216,8 +230,8 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
UserFollowing.unfollowUser(mOauthRetrofit, mRetrofit, sharedPreferences,
|
UserFollowing.unfollowUser(mOauthRetrofit, mRetrofit, mAccessToken,
|
||||||
username, subscribedUserDao, new UserFollowing.UserFollowingListener() {
|
username, mAccountName, subscribedUserDao, new UserFollowing.UserFollowingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onUserFollowingSuccess() {
|
public void onUserFollowingSuccess() {
|
||||||
subscribeUserChip.setText(R.string.follow);
|
subscribeUserChip.setText(R.string.follow);
|
||||||
@ -236,7 +250,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
new CheckIsFollowingUserAsyncTask(subscribedUserDao, username, new CheckIsFollowingUserAsyncTask.CheckIsFollowingUserListener() {
|
new CheckIsFollowingUserAsyncTask(subscribedUserDao, username, mAccountName, new CheckIsFollowingUserAsyncTask.CheckIsFollowingUserListener() {
|
||||||
@Override
|
@Override
|
||||||
public void isSubscribed() {
|
public void isSubscribed() {
|
||||||
subscribeUserChip.setText(R.string.unfollow);
|
subscribeUserChip.setText(R.string.unfollow);
|
||||||
@ -268,7 +282,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
FetchUserData.fetchUserData(mRetrofit, username, new FetchUserData.FetchUserDataListener() {
|
FetchUserData.fetchUserData(mRetrofit, username, new FetchUserData.FetchUserDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchUserDataSuccess(UserData userData) {
|
public void onFetchUserDataSuccess(UserData userData) {
|
||||||
new InsertUserDataAsyncTask(UserRoomDatabase.getDatabase(ViewUserDetailActivity.this).userDao(), userData).execute();
|
new InsertUserDataAsyncTask(mRedditDataRoomDatabase.userDao(), userData).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -276,26 +290,25 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
makeSnackbar(R.string.cannot_fetch_user_info);
|
makeSnackbar(R.string.cannot_fetch_user_info);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if(savedInstanceState == null) {
|
private void getCurrentAccountAndInitializeViewPager() {
|
||||||
/*mFragment = new PostFragment();
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
Bundle bundle = new Bundle();
|
if(account == null) {
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, username);
|
mNullAccessToken = true;
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
} else {
|
||||||
mFragment.setArguments(bundle);
|
mAccessToken = account.getAccessToken();
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_user_detail_activity, mFragment).commit();*/
|
mAccountName = account.getUsername();
|
||||||
} else {
|
}
|
||||||
/*mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
|
initializeViewPager();
|
||||||
if(mFragment == null) {
|
}).execute();
|
||||||
mFragment = new PostFragment();
|
}
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, username);
|
private void initializeViewPager() {
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||||
mFragment.setArguments(bundle);
|
viewPager.setAdapter(sectionsPagerAdapter);
|
||||||
}*/
|
viewPager.setOffscreenPageLimit(2);
|
||||||
isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
//getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_user_detail_activity, mFragment).commit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -318,7 +331,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
finish();
|
finish();
|
||||||
@ -359,7 +372,9 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
outState.putBoolean(IS_IN_LAZY_MODE_STATE, isInLazyMode);
|
||||||
//getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE_KEY, mFragment);
|
outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
|
||||||
|
outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
|
||||||
|
outState.putString(ACCOUNT_NAME_STATE, mAccountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeSnackbar(int resId) {
|
private void makeSnackbar(int resId) {
|
||||||
@ -438,12 +453,14 @@ public class ViewUserDetailActivity extends AppCompatActivity {
|
|||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_USER);
|
||||||
bundle.putString(PostFragment.EXTRA_USER_NAME, username);
|
bundle.putString(PostFragment.EXTRA_USER_NAME, username);
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
CommentsListingFragment fragment = new CommentsListingFragment();
|
CommentsListingFragment fragment = new CommentsListingFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(CommentsListingFragment.EXTRA_USERNAME_KEY, username);
|
bundle.putString(CommentsListingFragment.EXTRA_USERNAME_KEY, username);
|
||||||
|
bundle.putString(CommentsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
fragment.setArguments(bundle);
|
fragment.setArguments(bundle);
|
||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -28,12 +27,11 @@ class VoteThing {
|
|||||||
void onVoteThingFail();
|
void onVoteThingFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void voteThing(final Retrofit retrofit, SharedPreferences authInfoSharedPreferences,
|
static void voteThing(final Retrofit retrofit, String accessToken,
|
||||||
final VoteThingListener voteThingListener, final String fullName,
|
final VoteThingListener voteThingListener, final String fullName,
|
||||||
final String point, final int position) {
|
final String point, final int position) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
String accessToken = authInfoSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put(RedditUtils.DIR_KEY, point);
|
params.put(RedditUtils.DIR_KEY, point);
|
||||||
params.put(RedditUtils.ID_KEY, fullName);
|
params.put(RedditUtils.ID_KEY, fullName);
|
||||||
@ -58,12 +56,11 @@ class VoteThing {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void voteThing(final Retrofit retrofit, SharedPreferences authInfoSharedPreferences,
|
static void voteThing(final Retrofit retrofit, String accessToken,
|
||||||
final VoteThingWithoutPositionListener voteThingWithoutPositionListener,
|
final VoteThingWithoutPositionListener voteThingWithoutPositionListener,
|
||||||
final String fullName, final String point) {
|
final String fullName, final String point) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
|
|
||||||
String accessToken = authInfoSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put(RedditUtils.DIR_KEY, point);
|
params.put(RedditUtils.DIR_KEY, point);
|
||||||
params.put(RedditUtils.ID_KEY, fullName);
|
params.put(RedditUtils.ID_KEY, fullName);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/coordinator_layout_comment_activity"
|
android:id="@+id/coordinator_layout_comment_activity"
|
||||||
tools:context=".CommentActivity">
|
tools:application=".CommentActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".FilteredPostsActivity">
|
tools:application=".FilteredPostsActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.LoginActivity">
|
tools:application="ml.docilealligator.infinityforreddit.LoginActivity">
|
||||||
|
|
||||||
<WebView
|
<WebView
|
||||||
android:id="@+id/webview_login_activity"
|
android:id="@+id/webview_login_activity"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/coordinator_layout_post_image_activity"
|
android:id="@+id/coordinator_layout_post_image_activity"
|
||||||
tools:context=".PostImageActivity">
|
tools:application=".PostImageActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/coordinator_layout_post_link_activity"
|
android:id="@+id/coordinator_layout_post_link_activity"
|
||||||
tools:context=".PostTextActivity">
|
tools:application=".PostTextActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/coordinator_layout_post_text_activity"
|
android:id="@+id/coordinator_layout_post_text_activity"
|
||||||
tools:context=".PostTextActivity">
|
tools:application=".PostTextActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/coordinator_layout_post_video_activity"
|
android:id="@+id/coordinator_layout_post_video_activity"
|
||||||
tools:context=".PostImageActivity">
|
tools:application=".PostImageActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".RulesActivity">
|
tools:application=".RulesActivity">
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progress_bar_rules_activity"
|
android:id="@+id/progress_bar_rules_activity"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".SearchActivity">
|
tools:application=".SearchActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -67,6 +67,6 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
tools:context=".SearchResultActivity" />
|
tools:application=".SearchResultActivity" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".SearchSubredditsResultActivity">
|
tools:application=".SearchSubredditsResultActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".SubredditSelectionActivity">
|
tools:application=".SubredditSelectionActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".SubscribedThingListingActivity">
|
tools:application=".SubscribedThingListingActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/appbar_subscribed_thing_listing_activity"
|
android:id="@+id/appbar_subscribed_thing_listing_activity"
|
||||||
@ -40,6 +40,6 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
tools:context=".SubscribedThingListingActivity" />
|
tools:application=".SubscribedThingListingActivity" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -6,7 +6,7 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/parent_relative_layout_view_image_activity"
|
android:id="@+id/parent_relative_layout_view_image_activity"
|
||||||
android:background="@android:color/black"
|
android:background="@android:color/black"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.ViewImageActivity">
|
tools:application="ml.docilealligator.infinityforreddit.ViewImageActivity">
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progress_bar_view_image_activity"
|
android:id="@+id/progress_bar_view_image_activity"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:id="@+id/coordinator_layout_view_post_detail"
|
android:id="@+id/coordinator_layout_view_post_detail"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".ViewPostDetailActivity">
|
tools:application=".ViewPostDetailActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/coordinator_layout_view_subreddit_detail_activity"
|
android:id="@+id/coordinator_layout_view_subreddit_detail_activity"
|
||||||
tools:context=".ViewSubredditDetailActivity">
|
tools:application=".ViewSubredditDetailActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/appbar_layout_view_subreddit_detail"
|
android:id="@+id/appbar_layout_view_subreddit_detail"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/coordinator_layout_view_user_detail_activity"
|
android:id="@+id/coordinator_layout_view_user_detail_activity"
|
||||||
tools:context=".ViewUserDetailActivity">
|
tools:application=".ViewUserDetailActivity">
|
||||||
|
|
||||||
<androidx.viewpager.widget.ViewPager
|
<androidx.viewpager.widget.ViewPager
|
||||||
android:id="@+id/view_pager_view_user_detail_activity"
|
android:id="@+id/view_pager_view_user_detail_activity"
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
android:background="@android:color/black"
|
android:background="@android:color/black"
|
||||||
android:id="@+id/relative_layout_view_video_activity"
|
android:id="@+id/relative_layout_view_video_activity"
|
||||||
android:keepScreenOn="true"
|
android:keepScreenOn="true"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.ViewVideoActivity">
|
tools:application="ml.docilealligator.infinityforreddit.ViewVideoActivity">
|
||||||
|
|
||||||
<com.google.android.exoplayer2.ui.PlayerView
|
<com.google.android.exoplayer2.ui.PlayerView
|
||||||
android:id="@+id/player_view_view_video_activity"
|
android:id="@+id/player_view_view_video_activity"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.MainActivity">
|
tools:application="ml.docilealligator.infinityforreddit.MainActivity">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.MainActivity"
|
tools:application="ml.docilealligator.infinityforreddit.MainActivity"
|
||||||
tools:showIn="@layout/app_bar_main" />
|
tools:showIn="@layout/app_bar_main" />
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
tools:context=".ViewSubredditDetailActivity"
|
tools:application=".ViewSubredditDetailActivity"
|
||||||
tools:showIn="@layout/activity_view_subreddit_detail" />
|
tools:showIn="@layout/activity_view_subreddit_detail" />
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
tools:context=".ViewUserDetailActivity"
|
tools:application=".ViewUserDetailActivity"
|
||||||
tools:showIn="@layout/activity_view_user_detail" />
|
tools:showIn="@layout/activity_view_user_detail" />
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/coordinator_layout_comments_listing_fragment"
|
android:id="@+id/coordinator_layout_comments_listing_fragment"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.CommentsListingFragment">
|
tools:application="ml.docilealligator.infinityforreddit.CommentsListingFragment">
|
||||||
|
|
||||||
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
|
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
|
||||||
android:id="@+id/progress_bar_comments_listing_fragment"
|
android:id="@+id/progress_bar_comments_listing_fragment"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".FlairBottomSheetFragment">
|
tools:application=".FlairBottomSheetFragment">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".FollowedUsersListingFragment">
|
tools:application=".FollowedUsersListingFragment">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recycler_view_followed_users_listing_fragment"
|
android:id="@+id/recycler_view_followed_users_listing_fragment"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:id="@+id/coordinator_layout_post_fragment"
|
android:id="@+id/coordinator_layout_post_fragment"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.PostFragment">
|
tools:application="ml.docilealligator.infinityforreddit.PostFragment">
|
||||||
|
|
||||||
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
|
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
|
||||||
android:id="@+id/progress_bar_post_fragment"
|
android:id="@+id/progress_bar_post_fragment"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
tools:context=".SubredditListingFragment">
|
tools:application=".SubredditListingFragment">
|
||||||
|
|
||||||
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
|
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
|
||||||
android:id="@+id/progress_bar_subreddit_listing_fragment"
|
android:id="@+id/progress_bar_subreddit_listing_fragment"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".SubscribedSubredditsListingFragment">
|
tools:application=".SubscribedSubredditsListingFragment">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recycler_view_subscribed_subreddits_listing_fragment"
|
android:id="@+id/recycler_view_subscribed_subreddits_listing_fragment"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
tools:context=".UserListingFragment">
|
tools:application=".UserListingFragment">
|
||||||
|
|
||||||
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
|
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
|
||||||
android:id="@+id/progress_bar_user_listing_fragment"
|
android:id="@+id/progress_bar_user_listing_fragment"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.MainActivity">
|
tools:application="ml.docilealligator.infinityforreddit.MainActivity">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_sort_main_activity"
|
android:id="@+id/action_sort_main_activity"
|
||||||
android:orderInCategory="1"
|
android:orderInCategory="1"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.SearchResultActivity">
|
tools:application="ml.docilealligator.infinityforreddit.SearchResultActivity">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_search_search_activity"
|
android:id="@+id/action_search_search_activity"
|
||||||
android:orderInCategory="1"
|
android:orderInCategory="1"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.SearchResultActivity">
|
tools:application="ml.docilealligator.infinityforreddit.SearchResultActivity">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_search_search_activity"
|
android:id="@+id/action_search_search_activity"
|
||||||
android:orderInCategory="1"
|
android:orderInCategory="1"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.ViewSubredditDetailActivity">
|
tools:application="ml.docilealligator.infinityforreddit.ViewSubredditDetailActivity">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_sort_view_subreddit_detail_activity"
|
android:id="@+id/action_sort_view_subreddit_detail_activity"
|
||||||
android:orderInCategory="1"
|
android:orderInCategory="1"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
tools:context="ml.docilealligator.infinityforreddit.ViewUserDetailActivity">
|
tools:application="ml.docilealligator.infinityforreddit.ViewUserDetailActivity">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_search_view_user_detail_activity"
|
android:id="@+id/action_search_view_user_detail_activity"
|
||||||
android:orderInCategory="1"
|
android:orderInCategory="1"
|
||||||
|
Loading…
Reference in New Issue
Block a user