Fix the fab in MainActivity shows in wrong places. Put all classes related to Post to Package Post.

This commit is contained in:
Alex Ning 2020-01-04 16:30:16 +08:00
parent 4d6782107d
commit a143501f9f
25 changed files with 70 additions and 58 deletions

View File

@ -35,7 +35,7 @@ import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;

View File

@ -40,7 +40,7 @@ import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;

View File

@ -38,8 +38,8 @@ import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment
import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;

View File

@ -85,7 +85,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.ParseAndSaveAccountInfo; import ml.docilealligator.infinityforreddit.ParseAndSaveAccountInfo;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.PullNotificationWorker; import ml.docilealligator.infinityforreddit.PullNotificationWorker;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.ReadMessage; import ml.docilealligator.infinityforreddit.ReadMessage;
@ -211,6 +211,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private String mNewAccountName; private String mNewAccountName;
private Menu mMenu; private Menu mMenu;
private boolean isInLazyMode = false; private boolean isInLazyMode = false;
private boolean showBottomAppBar;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -310,6 +311,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams(); params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
showBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false);
if (savedInstanceState != null) { if (savedInstanceState != null) {
mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE); mFetchUserInfoSuccess = savedInstanceState.getBoolean(FETCH_USER_INFO_STATE);
mFetchSubscriptionsSuccess = savedInstanceState.getBoolean(FETCH_SUBSCRIPTIONS_STATE); mFetchSubscriptionsSuccess = savedInstanceState.getBoolean(FETCH_SUBSCRIPTIONS_STATE);
@ -454,7 +457,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
bottomNavigationView.setVisibility(View.GONE); bottomNavigationView.setVisibility(View.GONE);
fab.setVisibility(View.GONE); fab.setVisibility(View.GONE);
} else { } else {
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY, false)) { if (showBottomAppBar) {
bottomNavigationView.setVisibility(View.VISIBLE); bottomNavigationView.setVisibility(View.VISIBLE);
} else { } else {
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
@ -489,8 +492,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Override @Override
public void onPageSelected(int position) { public void onPageSelected(int position) {
if (mAccessToken != null && showBottomAppBar) {
bottomNavigationView.performShow(); bottomNavigationView.performShow();
fab.show(); fab.show();
}
if (isInLazyMode) { if (isInLazyMode) {
if (position == sectionsPagerAdapter.getCurrentLazyModeFragmentPosition()) { if (position == sectionsPagerAdapter.getCurrentLazyModeFragmentPosition()) {
sectionsPagerAdapter.resumeLazyMode(); sectionsPagerAdapter.resumeLazyMode();
@ -943,14 +948,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} }
public void postScrollUp() { public void postScrollUp() {
if (mAccessToken != null) { if (mAccessToken != null && showBottomAppBar) {
bottomNavigationView.performShow(); bottomNavigationView.performShow();
fab.show(); fab.show();
} }
} }
public void postScrollDown() { public void postScrollDown() {
if (mAccessToken != null) { if (mAccessToken != null && showBottomAppBar) {
fab.hide(); fab.hide();
bottomNavigationView.performHide(); bottomNavigationView.performHide();
} }

View File

@ -44,7 +44,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment;
import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment; import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;

View File

@ -35,7 +35,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment
import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortType;

View File

@ -72,7 +72,7 @@ import ml.docilealligator.infinityforreddit.HidePost;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.ParseComment; import ml.docilealligator.infinityforreddit.ParseComment;
import ml.docilealligator.infinityforreddit.ParsePost; import ml.docilealligator.infinityforreddit.ParsePost;
import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.ReadMessage; import ml.docilealligator.infinityforreddit.ReadMessage;
import ml.docilealligator.infinityforreddit.RedditAPI; import ml.docilealligator.infinityforreddit.RedditAPI;

View File

@ -55,7 +55,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.ReadMessage; import ml.docilealligator.infinityforreddit.ReadMessage;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;

View File

@ -61,7 +61,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment
import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.ReadMessage; import ml.docilealligator.infinityforreddit.ReadMessage;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;

View File

@ -76,8 +76,8 @@ import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView;
import ml.docilealligator.infinityforreddit.CustomView.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.CustomView.MarkwonLinearLayoutManager;
import ml.docilealligator.infinityforreddit.FetchComment; import ml.docilealligator.infinityforreddit.FetchComment;
import ml.docilealligator.infinityforreddit.Fragment.ModifyCommentBottomSheetFragment; import ml.docilealligator.infinityforreddit.Fragment.ModifyCommentBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SaveThing;

View File

@ -55,8 +55,8 @@ import ml.docilealligator.infinityforreddit.AsyncTask.LoadUserDataAsyncTask;
import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView; import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView;
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity; import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity;
import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.SaveThing;

View File

@ -14,6 +14,7 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils; import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
import ml.docilealligator.infinityforreddit.Utils.RedditUtils; import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
import retrofit2.Call; import retrofit2.Call;

View File

@ -1,6 +1,6 @@
package ml.docilealligator.infinityforreddit.Event; package ml.docilealligator.infinityforreddit.Event;
import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.Post.Post;
public class PostUpdateEventToDetailActivity { public class PostUpdateEventToDetailActivity {
public final Post post; public final Post post;

View File

@ -1,6 +1,6 @@
package ml.docilealligator.infinityforreddit.Event; package ml.docilealligator.infinityforreddit.Event;
import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.Post.Post;
public class PostUpdateEventToPostList { public class PostUpdateEventToPostList {
public final Post post; public final Post post;

View File

@ -1,6 +1,6 @@
package ml.docilealligator.infinityforreddit.Event; package ml.docilealligator.infinityforreddit.Event;
import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.Post.Post;
public class SubmitTextOrLinkPostEvent { public class SubmitTextOrLinkPostEvent {
public boolean postSuccess; public boolean postSuccess;

View File

@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
import java.util.Locale; import java.util.Locale;
import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.Utils.RedditUtils; import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;

View File

@ -59,9 +59,9 @@ import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.PostDataSource; import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.PostViewModel; import ml.docilealligator.infinityforreddit.Post.PostViewModel;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortType;
@ -318,8 +318,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
boolean showElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); boolean showElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
PostViewModel.Factory factory;
if (postType == PostDataSource.TYPE_SEARCH) { if (postType == PostDataSource.TYPE_SEARCH) {
String subredditName = getArguments().getString(EXTRA_NAME); String subredditName = getArguments().getString(EXTRA_NAME);
String query = getArguments().getString(EXTRA_QUERY); String query = getArguments().getString(EXTRA_QUERY);
@ -349,13 +347,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}); });
if (accessToken == null) { if (accessToken == null) {
factory = new PostViewModel.Factory(mRetrofit, accessToken, mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mRetrofit, null,
getResources().getConfiguration().locale, subredditName, query, postType, getResources().getConfiguration().locale, subredditName, query, postType,
sortType, filter, nsfw); sortType, filter, nsfw)).get(PostViewModel.class);
} else { } else {
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mOauthRetrofit, accessToken,
getResources().getConfiguration().locale, subredditName, query, postType, getResources().getConfiguration().locale, subredditName, query, postType,
sortType, filter, nsfw); sortType, filter, nsfw)).get(PostViewModel.class);
} }
} else if (postType == PostDataSource.TYPE_SUBREDDIT) { } else if (postType == PostDataSource.TYPE_SUBREDDIT) {
String subredditName = getArguments().getString(EXTRA_NAME); String subredditName = getArguments().getString(EXTRA_NAME);
@ -411,13 +409,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}); });
if (accessToken == null) { if (accessToken == null) {
factory = new PostViewModel.Factory(mRetrofit, accessToken, mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mRetrofit, accessToken,
getResources().getConfiguration().locale, subredditName, postType, sortType, getResources().getConfiguration().locale, subredditName, postType, sortType,
filter, nsfw); filter, nsfw)).get(PostViewModel.class);
} else { } else {
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mOauthRetrofit, accessToken,
getResources().getConfiguration().locale, subredditName, postType, sortType, getResources().getConfiguration().locale, subredditName, postType, sortType,
filter, nsfw); filter, nsfw)).get(PostViewModel.class);
} }
} else if(postType == PostDataSource.TYPE_MULTI_REDDIT) { } else if(postType == PostDataSource.TYPE_MULTI_REDDIT) {
String multiRedditPath = getArguments().getString(EXTRA_NAME); String multiRedditPath = getArguments().getString(EXTRA_NAME);
@ -459,13 +457,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}); });
if (accessToken == null) { if (accessToken == null) {
factory = new PostViewModel.Factory(mRetrofit, accessToken, mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mRetrofit, null,
getResources().getConfiguration().locale, multiRedditPath, postType, sortType, getResources().getConfiguration().locale, multiRedditPath, postType, sortType,
filter, nsfw); filter, nsfw)).get(PostViewModel.class);
} else { } else {
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mOauthRetrofit, accessToken,
getResources().getConfiguration().locale, multiRedditPath, postType, sortType, getResources().getConfiguration().locale, multiRedditPath, postType, sortType,
filter, nsfw); filter, nsfw)).get(PostViewModel.class);
} }
} else if (postType == PostDataSource.TYPE_USER) { } else if (postType == PostDataSource.TYPE_USER) {
String username = getArguments().getString(EXTRA_USER_NAME); String username = getArguments().getString(EXTRA_USER_NAME);
@ -506,13 +504,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}); });
if (accessToken == null) { if (accessToken == null) {
factory = new PostViewModel.Factory(mRetrofit, accessToken, mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mRetrofit, accessToken,
getResources().getConfiguration().locale, username, postType, sortType, where, getResources().getConfiguration().locale, username, postType, sortType, where,
filter, nsfw); filter, nsfw)).get(PostViewModel.class);
} else { } else {
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mOauthRetrofit, accessToken,
getResources().getConfiguration().locale, username, postType, sortType, where, getResources().getConfiguration().locale, username, postType, sortType, where,
filter, nsfw); filter, nsfw)).get(PostViewModel.class);
} }
} else { } else {
String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name()); String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name());
@ -543,13 +541,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} }
}); });
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken, mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mOauthRetrofit, accessToken,
getResources().getConfiguration().locale, postType, sortType, filter, nsfw); getResources().getConfiguration().locale, postType, sortType, filter, nsfw)).get(PostViewModel.class);
} }
mPostRecyclerView.setAdapter(mAdapter); mPostRecyclerView.setAdapter(mAdapter);
mPostViewModel = new ViewModelProvider(this, factory).get(PostViewModel.class);
mPostViewModel.getPosts().observe(this, posts -> mAdapter.submitList(posts)); mPostViewModel.getPosts().observe(this, posts -> mAdapter.submitList(posts));
mPostViewModel.hasPost().observe(this, hasPost -> { mPostViewModel.hasPost().observe(this, hasPost -> {

View File

@ -1,8 +1,8 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
public class NetworkState { public class NetworkState {
static final NetworkState LOADED; public static final NetworkState LOADED;
static final NetworkState LOADING; public static final NetworkState LOADING;
static { static {
LOADED = new NetworkState(Status.SUCCESS, "Success"); LOADED = new NetworkState(Status.SUCCESS, "Success");
@ -12,7 +12,7 @@ public class NetworkState {
private final Status status; private final Status status;
private final String msg; private final String msg;
NetworkState(Status status, String msg) { public NetworkState(Status status, String msg) {
this.status = status; this.status = status;
this.msg = msg; this.msg = msg;
} }

View File

@ -13,6 +13,7 @@ import java.util.Calendar;
import java.util.Locale; import java.util.Locale;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils; import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils; import ml.docilealligator.infinityforreddit.Utils.Utils;
@ -21,7 +22,7 @@ import ml.docilealligator.infinityforreddit.Utils.Utils;
*/ */
public class ParsePost { public class ParsePost {
static void parsePosts(String response, Locale locale, int nPosts, int filter, boolean nsfw, public static void parsePosts(String response, Locale locale, int nPosts, int filter, boolean nsfw,
ParsePostsListingListener parsePostsListingListener) { ParsePostsListingListener parsePostsListingListener) {
new ParsePostDataAsyncTask(response, locale, nPosts, filter, nsfw, parsePostsListingListener).execute(); new ParsePostDataAsyncTask(response, locale, nPosts, filter, nsfw, parsePostsListingListener).execute();
} }
@ -284,7 +285,7 @@ public class ParsePost {
return post; return post;
} }
interface ParsePostsListingListener { public interface ParsePostsListingListener {
void onParsePostsListingSuccess(ArrayList<Post> newPostData, String lastItem); void onParsePostsListingSuccess(ArrayList<Post> newPostData, String lastItem);
void onParsePostsListingFail(); void onParsePostsListingFail();

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit.Post;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit.Post;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
@ -7,6 +7,10 @@ import androidx.paging.PageKeyedDataSource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.ParsePost;
import ml.docilealligator.infinityforreddit.RedditAPI;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.Utils.RedditUtils; import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit.Post;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
@ -6,6 +6,7 @@ import androidx.paging.DataSource;
import java.util.Locale; import java.util.Locale;
import ml.docilealligator.infinityforreddit.SortType;
import retrofit2.Retrofit; import retrofit2.Retrofit;
class PostDataSourceFactory extends DataSource.Factory { class PostDataSourceFactory extends DataSource.Factory {

View File

@ -1,4 +1,4 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit.Post;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.util.Pair; import androidx.core.util.Pair;
@ -13,6 +13,8 @@ import androidx.paging.PagedList;
import java.util.Locale; import java.util.Locale;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.SortType;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class PostViewModel extends ViewModel { public class PostViewModel extends ViewModel {

View File

@ -35,7 +35,7 @@ import ml.docilealligator.infinityforreddit.Event.SubmitTextOrLinkPostEvent;
import ml.docilealligator.infinityforreddit.Event.SubmitVideoPostEvent; import ml.docilealligator.infinityforreddit.Event.SubmitVideoPostEvent;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NotificationUtils; import ml.docilealligator.infinityforreddit.NotificationUtils;
import ml.docilealligator.infinityforreddit.Post; import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SubmitPost; import ml.docilealligator.infinityforreddit.SubmitPost;
import retrofit2.Retrofit; import retrofit2.Retrofit;

View File

@ -20,6 +20,7 @@ import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils; import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
import ml.docilealligator.infinityforreddit.Utils.RedditUtils; import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
import okhttp3.MediaType; import okhttp3.MediaType;