mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Fixed the user's posts cannot be loaded. Refreshing in MainActivity also refreshes user info, subscribed users and subreddits. Enlarge the area which contains subreddit or user name and icon for easier touching.
This commit is contained in:
parent
f7a192dcbe
commit
d733be6e55
Binary file not shown.
BIN
.idea/caches/gradle_models.ser
Normal file
BIN
.idea/caches/gradle_models.ser
Normal file
Binary file not shown.
@ -3,6 +3,9 @@
|
|||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
<compositeConfiguration>
|
||||||
|
<compositeBuild compositeDefinitionSource="SCRIPT" />
|
||||||
|
</compositeConfiguration>
|
||||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
|
@ -56,11 +56,16 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private static final String FETCH_USER_INFO_STATE = "FUIS";
|
private static final String FETCH_USER_INFO_STATE = "FUIS";
|
||||||
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
|
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
|
||||||
|
|
||||||
@BindView(R.id.subscribed_subreddit_recycler_view_main_activity) RecyclerView subscribedSubredditRecyclerView;
|
@BindView(R.id.subscribed_subreddit_recycler_view_main_activity)
|
||||||
@BindView(R.id.subscriptions_label_main_activity) TextView subscriptionsLabelTextView;
|
RecyclerView subscribedSubredditRecyclerView;
|
||||||
@BindView(R.id.subscribed_user_recycler_view_main_activity) RecyclerView subscribedUserRecyclerView;
|
@BindView(R.id.subscriptions_label_main_activity)
|
||||||
@BindView(R.id.following_label_main_activity) TextView followingLabelTextView;
|
TextView subscriptionsLabelTextView;
|
||||||
@BindView(R.id.profile_linear_layout_main_activity) LinearLayout profileLinearLayout;
|
@BindView(R.id.subscribed_user_recycler_view_main_activity)
|
||||||
|
RecyclerView subscribedUserRecyclerView;
|
||||||
|
@BindView(R.id.following_label_main_activity)
|
||||||
|
TextView followingLabelTextView;
|
||||||
|
@BindView(R.id.profile_linear_layout_main_activity)
|
||||||
|
LinearLayout profileLinearLayout;
|
||||||
|
|
||||||
private TextView mNameTextView;
|
private TextView mNameTextView;
|
||||||
private TextView mKarmaTextView;
|
private TextView mKarmaTextView;
|
||||||
@ -82,13 +87,16 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
|
private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
|
||||||
private SubscribedUserViewModel mSubscribedUserViewModel;
|
private SubscribedUserViewModel mSubscribedUserViewModel;
|
||||||
|
|
||||||
@Inject @Named("user_info")
|
@Inject
|
||||||
|
@Named("user_info")
|
||||||
SharedPreferences mUserInfoSharedPreferences;
|
SharedPreferences mUserInfoSharedPreferences;
|
||||||
|
|
||||||
@Inject @Named("auth_info")
|
@Inject
|
||||||
|
@Named("auth_info")
|
||||||
SharedPreferences mAuthInfoSharedPreferences;
|
SharedPreferences mAuthInfoSharedPreferences;
|
||||||
|
|
||||||
@Inject @Named("oauth")
|
@Inject
|
||||||
|
@Named("oauth")
|
||||||
Retrofit mOauthRetrofit;
|
Retrofit mOauthRetrofit;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -109,11 +117,11 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
toggle.syncState();
|
toggle.syncState();
|
||||||
|
|
||||||
String accessToken = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE).getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
String accessToken = getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE).getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
|
||||||
if(accessToken.equals("")) {
|
if (accessToken.equals("")) {
|
||||||
Intent loginIntent = new Intent(this, LoginActivity.class);
|
Intent loginIntent = new Intent(this, LoginActivity.class);
|
||||||
startActivity(loginIntent);
|
startActivity(loginIntent);
|
||||||
} else {
|
} else {
|
||||||
if(savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mFragment = new PostFragment();
|
mFragment = new PostFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_FRONT_PAGE);
|
bundle.putInt(PostFragment.POST_TYPE_KEY, PostDataSource.TYPE_FRONT_PAGE);
|
||||||
@ -124,7 +132,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadUserData(savedInstanceState);
|
loadUserData();
|
||||||
|
|
||||||
View header = findViewById(R.id.nav_header_main_activity);
|
View header = findViewById(R.id.nav_header_main_activity);
|
||||||
mNameTextView = header.findViewById(R.id.name_text_view_nav_header_main);
|
mNameTextView = header.findViewById(R.id.name_text_view_nav_header_main);
|
||||||
@ -146,10 +154,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
mNameTextView.setText(mName);
|
mNameTextView.setText(mName);
|
||||||
mKarmaTextView.setText(mKarma);
|
mKarmaTextView.setText(mKarma);
|
||||||
glide = Glide.with(this);
|
glide = Glide.with(this);
|
||||||
if(!mProfileImageUrl.equals("")) {
|
if (!mProfileImageUrl.equals("")) {
|
||||||
glide.load(mProfileImageUrl).into(mProfileImageView);
|
glide.load(mProfileImageUrl).into(mProfileImageView);
|
||||||
}
|
}
|
||||||
if(!mBannerImageUrl.equals("")) {
|
if (!mBannerImageUrl.equals("")) {
|
||||||
glide.load(mBannerImageUrl).into(mBannerImageView);
|
glide.load(mBannerImageUrl).into(mBannerImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,83 +197,76 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadUserData(Bundle savedInstanceState) {
|
private void loadUserData() {
|
||||||
if (savedInstanceState == null) {
|
if (!mFetchUserInfoSuccess) {
|
||||||
if (!mFetchUserInfoSuccess) {
|
FetchMyInfo.fetchMyInfo(mOauthRetrofit, mAuthInfoSharedPreferences, new FetchMyInfo.FetchUserMyListener() {
|
||||||
FetchMyInfo.fetchMyInfo(mOauthRetrofit, mAuthInfoSharedPreferences, 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() {
|
@Override
|
||||||
@Override
|
public void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
|
||||||
public void onParseMyInfoSuccess(String name, String profileImageUrl, String bannerImageUrl, int karma) {
|
mNameTextView.setText(name);
|
||||||
mNameTextView.setText(name);
|
if (!mProfileImageUrl.equals("")) {
|
||||||
if (!mProfileImageUrl.equals("")) {
|
glide.load(profileImageUrl).into(mProfileImageView);
|
||||||
glide.load(profileImageUrl).into(mProfileImageView);
|
}
|
||||||
}
|
if (!mBannerImageUrl.equals("")) {
|
||||||
if (!mBannerImageUrl.equals("")) {
|
glide.load(bannerImageUrl).into(mBannerImageView);
|
||||||
glide.load(bannerImageUrl).into(mBannerImageView);
|
|
||||||
}
|
|
||||||
|
|
||||||
mName = name;
|
|
||||||
mProfileImageUrl = profileImageUrl;
|
|
||||||
mBannerImageUrl = bannerImageUrl;
|
|
||||||
mKarma = getString(R.string.karma_info, karma);
|
|
||||||
|
|
||||||
mKarmaTextView.setText(mKarma);
|
|
||||||
|
|
||||||
SharedPreferences.Editor editor = mUserInfoSharedPreferences.edit();
|
|
||||||
editor.putString(SharedPreferencesUtils.USER_KEY, name);
|
|
||||||
editor.putString(SharedPreferencesUtils.PROFILE_IMAGE_URL_KEY, profileImageUrl);
|
|
||||||
editor.putString(SharedPreferencesUtils.BANNER_IMAGE_URL_KEY, bannerImageUrl);
|
|
||||||
editor.putString(SharedPreferencesUtils.KARMA_KEY, mKarma);
|
|
||||||
editor.apply();
|
|
||||||
mFetchUserInfoSuccess = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
mName = name;
|
||||||
public void onParseMyInfoFail() {
|
mProfileImageUrl = profileImageUrl;
|
||||||
mFetchUserInfoSuccess = false;
|
mBannerImageUrl = bannerImageUrl;
|
||||||
}
|
mKarma = getString(R.string.karma_info, karma);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
mKarmaTextView.setText(mKarma);
|
||||||
public void onFetchMyInfoFail() {
|
|
||||||
mFetchUserInfoSuccess = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mInsertSuccess) {
|
SharedPreferences.Editor editor = mUserInfoSharedPreferences.edit();
|
||||||
FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAuthInfoSharedPreferences, null,
|
editor.putString(SharedPreferencesUtils.USER_KEY, name);
|
||||||
new ArrayList<SubscribedSubredditData>(), new ArrayList<SubscribedUserData>(),
|
editor.putString(SharedPreferencesUtils.PROFILE_IMAGE_URL_KEY, profileImageUrl);
|
||||||
new ArrayList<SubredditData>(),
|
editor.putString(SharedPreferencesUtils.BANNER_IMAGE_URL_KEY, bannerImageUrl);
|
||||||
new FetchSubscribedThing.FetchSubscribedThingListener() {
|
editor.putString(SharedPreferencesUtils.KARMA_KEY, mKarma);
|
||||||
@Override
|
editor.apply();
|
||||||
public void onFetchSubscribedThingSuccess(ArrayList<SubscribedSubredditData> subscribedSubredditData,
|
mFetchUserInfoSuccess = true;
|
||||||
ArrayList<SubscribedUserData> subscribedUserData,
|
}
|
||||||
ArrayList<SubredditData> subredditData) {
|
|
||||||
new InsertSubscribedThingsAsyncTask(
|
|
||||||
SubscribedSubredditRoomDatabase.getDatabase(MainActivity.this),
|
|
||||||
SubscribedUserRoomDatabase.getDatabase(MainActivity.this),
|
|
||||||
SubredditRoomDatabase.getDatabase(MainActivity.this),
|
|
||||||
subscribedSubredditData,
|
|
||||||
subscribedUserData,
|
|
||||||
subredditData,
|
|
||||||
new InsertSubscribedThingsAsyncTask.InsertSubscribedThingListener() {
|
|
||||||
@Override
|
|
||||||
public void insertSuccess() {
|
|
||||||
mInsertSuccess = true;
|
|
||||||
}
|
|
||||||
}).execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchSubscribedThingFail() {
|
public void onParseMyInfoFail() {
|
||||||
mInsertSuccess = false;
|
mFetchUserInfoSuccess = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFetchMyInfoFail() {
|
||||||
|
mFetchUserInfoSuccess = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mInsertSuccess) {
|
||||||
|
FetchSubscribedThing.fetchSubscribedThing(mOauthRetrofit, mAuthInfoSharedPreferences, null,
|
||||||
|
new ArrayList<>(), new ArrayList<>(),
|
||||||
|
new ArrayList<>(),
|
||||||
|
new FetchSubscribedThing.FetchSubscribedThingListener() {
|
||||||
|
@Override
|
||||||
|
public void onFetchSubscribedThingSuccess(ArrayList<SubscribedSubredditData> subscribedSubredditData,
|
||||||
|
ArrayList<SubscribedUserData> subscribedUserData,
|
||||||
|
ArrayList<SubredditData> subredditData) {
|
||||||
|
new InsertSubscribedThingsAsyncTask(
|
||||||
|
SubscribedSubredditRoomDatabase.getDatabase(MainActivity.this),
|
||||||
|
SubscribedUserRoomDatabase.getDatabase(MainActivity.this),
|
||||||
|
SubredditRoomDatabase.getDatabase(MainActivity.this),
|
||||||
|
subscribedSubredditData,
|
||||||
|
subscribedUserData,
|
||||||
|
subredditData,
|
||||||
|
() -> mInsertSuccess = true).execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFetchSubscribedThingFail() {
|
||||||
|
mInsertSuccess = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,8 +280,11 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_refresh_main_activity:
|
case R.id.action_refresh_main_activity:
|
||||||
if(mFragment instanceof FragmentCommunicator) {
|
if (mFragment instanceof FragmentCommunicator) {
|
||||||
((FragmentCommunicator) mFragment).refresh();
|
((FragmentCommunicator) mFragment).refresh();
|
||||||
|
mFetchUserInfoSuccess = false;
|
||||||
|
mInsertSuccess = false;
|
||||||
|
loadUserData();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -300,7 +304,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
if(mFragment != null) {
|
if (mFragment != null) {
|
||||||
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
|
||||||
}
|
}
|
||||||
outState.putString(NAME_STATE, mName);
|
outState.putString(NAME_STATE, mName);
|
||||||
@ -322,10 +326,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
|
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
|
||||||
mNameTextView.setText(mName);
|
mNameTextView.setText(mName);
|
||||||
mKarmaTextView.setText(mKarma);
|
mKarmaTextView.setText(mKarma);
|
||||||
if(!mProfileImageUrl.equals("")) {
|
if (!mProfileImageUrl.equals("")) {
|
||||||
glide.load(mProfileImageUrl).into(mProfileImageView);
|
glide.load(mProfileImageUrl).into(mProfileImageView);
|
||||||
}
|
}
|
||||||
if(!mBannerImageUrl.equals("")) {
|
if (!mBannerImageUrl.equals("")) {
|
||||||
glide.load(mBannerImageUrl).into(mBannerImageView);
|
glide.load(mBannerImageUrl).into(mBannerImageView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,13 +366,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(final Void... params) {
|
protected Void doInBackground(final Void... params) {
|
||||||
for(SubscribedSubredditData s : subscribedSubredditData) {
|
for (SubscribedSubredditData s : subscribedSubredditData) {
|
||||||
mSubscribedSubredditDao.insert(s);
|
mSubscribedSubredditDao.insert(s);
|
||||||
}
|
}
|
||||||
for(SubscribedUserData s : subscribedUserData) {
|
for (SubscribedUserData s : subscribedUserData) {
|
||||||
mUserDao.insert(s);
|
mUserDao.insert(s);
|
||||||
}
|
}
|
||||||
for(SubredditData s : subredditData) {
|
for (SubredditData s : subredditData) {
|
||||||
mSubredditDao.insert(s);
|
mSubredditDao.insert(s);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -13,6 +13,11 @@ import retrofit2.Callback;
|
|||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
class PostDataSource extends PageKeyedDataSource<String, Post> {
|
class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||||
|
interface OnPostFetchedCallback {
|
||||||
|
void hasPost();
|
||||||
|
void noPost();
|
||||||
|
}
|
||||||
|
|
||||||
static final int TYPE_FRONT_PAGE = 0;
|
static final int TYPE_FRONT_PAGE = 0;
|
||||||
static final int TYPE_SUBREDDIT = 1;
|
static final int TYPE_SUBREDDIT = 1;
|
||||||
static final int TYPE_USER = 2;
|
static final int TYPE_USER = 2;
|
||||||
@ -22,6 +27,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
private Locale locale;
|
private Locale locale;
|
||||||
private String name;
|
private String name;
|
||||||
private int postType;
|
private int postType;
|
||||||
|
private OnPostFetchedCallback onPostFetchedCallback;
|
||||||
|
|
||||||
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
|
||||||
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
||||||
@ -31,22 +37,24 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
private LoadParams<String> params;
|
private LoadParams<String> params;
|
||||||
private LoadCallback<String, Post> callback;
|
private LoadCallback<String, Post> callback;
|
||||||
|
|
||||||
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, int postType) {
|
PostDataSource(Retrofit retrofit, String accessToken, Locale locale, int postType, OnPostFetchedCallback onPostFetchedCallback) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
paginationNetworkStateLiveData = new MutableLiveData();
|
paginationNetworkStateLiveData = new MutableLiveData();
|
||||||
initialLoadStateLiveData = new MutableLiveData();
|
initialLoadStateLiveData = new MutableLiveData();
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
|
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostDataSource(Retrofit retrofit, Locale locale, String name, int postType) {
|
PostDataSource(Retrofit retrofit, Locale locale, String name, int postType, OnPostFetchedCallback onPostFetchedCallback) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
paginationNetworkStateLiveData = new MutableLiveData();
|
paginationNetworkStateLiveData = new MutableLiveData();
|
||||||
initialLoadStateLiveData = new MutableLiveData();
|
initialLoadStateLiveData = new MutableLiveData();
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
|
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
MutableLiveData getPaginationNetworkStateLiveData() {
|
MutableLiveData getPaginationNetworkStateLiveData() {
|
||||||
@ -72,7 +80,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
loadSubredditPostsInitial(callback);
|
loadSubredditPostsInitial(callback);
|
||||||
break;
|
break;
|
||||||
case TYPE_USER:
|
case TYPE_USER:
|
||||||
loadUserPostsInitial(callback);
|
loadUserPostsInitial(callback, null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,6 +125,12 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
new ParsePost.ParsePostListener() {
|
new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
|
if(newPosts.size() == 0) {
|
||||||
|
onPostFetchedCallback.noPost();
|
||||||
|
} else {
|
||||||
|
onPostFetchedCallback.hasPost();
|
||||||
|
}
|
||||||
|
|
||||||
callback.onResult(newPosts, null, lastItem);
|
callback.onResult(newPosts, null, lastItem);
|
||||||
initialLoadStateLiveData.postValue(NetworkState.LOADED);
|
initialLoadStateLiveData.postValue(NetworkState.LOADED);
|
||||||
}
|
}
|
||||||
@ -187,6 +201,12 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
new ParsePost.ParsePostListener() {
|
new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
|
if(newPosts.size() == 0) {
|
||||||
|
onPostFetchedCallback.noPost();
|
||||||
|
} else {
|
||||||
|
onPostFetchedCallback.hasPost();
|
||||||
|
}
|
||||||
|
|
||||||
callback.onResult(newPosts, null, lastItem);
|
callback.onResult(newPosts, null, lastItem);
|
||||||
initialLoadStateLiveData.postValue(NetworkState.LOADED);
|
initialLoadStateLiveData.postValue(NetworkState.LOADED);
|
||||||
}
|
}
|
||||||
@ -245,9 +265,9 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadUserPostsInitial(@NonNull final LoadInitialCallback<String, Post> callback) {
|
private void loadUserPostsInitial(@NonNull final LoadInitialCallback<String, Post> callback, String lastItem) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
Call<String> getPost = api.getUserBestPosts(name, null);
|
Call<String> getPost = api.getUserBestPosts(name, lastItem);
|
||||||
getPost.enqueue(new Callback<String>() {
|
getPost.enqueue(new Callback<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<String> call, retrofit2.Response<String> response) {
|
public void onResponse(Call<String> call, retrofit2.Response<String> response) {
|
||||||
@ -256,8 +276,17 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
|
|||||||
new ParsePost.ParsePostListener() {
|
new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(ArrayList<Post> newPosts, String lastItem) {
|
public void onParsePostSuccess(ArrayList<Post> newPosts, String lastItem) {
|
||||||
callback.onResult(newPosts, null, lastItem);
|
if(newPosts.size() == 0 && lastItem.equals("null")) {
|
||||||
initialLoadStateLiveData.postValue(NetworkState.LOADED);
|
callback.onResult(newPosts, null, lastItem);
|
||||||
|
initialLoadStateLiveData.postValue(NetworkState.LOADED);
|
||||||
|
onPostFetchedCallback.noPost();
|
||||||
|
} else if(newPosts.size() == 0) {
|
||||||
|
loadUserPostsInitial(callback, lastItem);
|
||||||
|
} else {
|
||||||
|
callback.onResult(newPosts, null, lastItem);
|
||||||
|
initialLoadStateLiveData.postValue(NetworkState.LOADED);
|
||||||
|
onPostFetchedCallback.hasPost();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,32 +13,37 @@ class PostDataSourceFactory extends DataSource.Factory {
|
|||||||
private Locale locale;
|
private Locale locale;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
private int postType;
|
private int postType;
|
||||||
|
private PostDataSource.OnPostFetchedCallback onPostFetchedCallback;
|
||||||
|
|
||||||
private PostDataSource postDataSource;
|
private PostDataSource postDataSource;
|
||||||
private MutableLiveData<PostDataSource> postDataSourceLiveData;
|
private MutableLiveData<PostDataSource> postDataSourceLiveData;
|
||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, int postType) {
|
PostDataSourceFactory(Retrofit retrofit, String accessToken, Locale locale, int postType,
|
||||||
|
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
postDataSourceLiveData = new MutableLiveData<>();
|
postDataSourceLiveData = new MutableLiveData<>();
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
|
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostDataSourceFactory(Retrofit retrofit, Locale locale, String subredditName, int postType) {
|
PostDataSourceFactory(Retrofit retrofit, Locale locale, String subredditName, int postType,
|
||||||
|
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.subredditName = subredditName;
|
this.subredditName = subredditName;
|
||||||
postDataSourceLiveData = new MutableLiveData<>();
|
postDataSourceLiveData = new MutableLiveData<>();
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
|
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataSource create() {
|
public DataSource create() {
|
||||||
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
|
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||||
postDataSource = new PostDataSource(retrofit, accessToken, locale, postType);
|
postDataSource = new PostDataSource(retrofit, accessToken, locale, postType, onPostFetchedCallback);
|
||||||
} else {
|
} else {
|
||||||
postDataSource = new PostDataSource(retrofit, locale, subredditName, postType);
|
postDataSource = new PostDataSource(retrofit, locale, subredditName, postType, onPostFetchedCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
postDataSourceLiveData.postValue(postDataSource);
|
postDataSourceLiveData.postValue(postDataSource);
|
||||||
|
@ -7,7 +7,6 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.CoordinatorLayout;
|
import android.support.design.widget.CoordinatorLayout;
|
||||||
import android.support.design.widget.Snackbar;
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@ -16,6 +15,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
||||||
@ -38,8 +38,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
private RecyclerView mPostRecyclerView;
|
private RecyclerView mPostRecyclerView;
|
||||||
private LinearLayoutManager mLinearLayoutManager;
|
private LinearLayoutManager mLinearLayoutManager;
|
||||||
private CircleProgressBar mProgressBar;
|
private CircleProgressBar mProgressBar;
|
||||||
private LinearLayout mFetchPostErrorLinearLayout;
|
private LinearLayout mFetchPostInfoLinearLayout;
|
||||||
private ImageView mFetchPostErrorImageView;
|
private ImageView mFetchPostInfoImageView;
|
||||||
|
private TextView mFetchPostInfoTextView;
|
||||||
|
|
||||||
private String mName;
|
private String mName;
|
||||||
private int mPostType;
|
private int mPostType;
|
||||||
@ -82,8 +83,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
mLinearLayoutManager = new LinearLayoutManager(getActivity());
|
mLinearLayoutManager = new LinearLayoutManager(getActivity());
|
||||||
mPostRecyclerView.setLayoutManager(mLinearLayoutManager);
|
mPostRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||||
mProgressBar = rootView.findViewById(R.id.progress_bar_post_fragment);
|
mProgressBar = rootView.findViewById(R.id.progress_bar_post_fragment);
|
||||||
mFetchPostErrorLinearLayout = rootView.findViewById(R.id.fetch_post_error_linear_layout_post_fragment);
|
mFetchPostInfoLinearLayout = rootView.findViewById(R.id.fetch_post_info_linear_layout_post_fragment);
|
||||||
mFetchPostErrorImageView = rootView.findViewById(R.id.fetch_post_error_image_view_post_fragment);
|
mFetchPostInfoImageView = rootView.findViewById(R.id.fetch_post_info_image_view_post_fragment);
|
||||||
|
mFetchPostInfoTextView = rootView.findViewById(R.id.fetch_post_info_text_view_post_fragment);
|
||||||
/*FloatingActionButton fab = rootView.findViewById(R.id.fab_post_fragment);
|
/*FloatingActionButton fab = rootView.findViewById(R.id.fab_post_fragment);
|
||||||
fab.setOnClickListener(new View.OnClickListener() {
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -97,8 +99,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
if(mPostType != PostDataSource.TYPE_FRONT_PAGE) {
|
if(mPostType != PostDataSource.TYPE_FRONT_PAGE) {
|
||||||
mName = getArguments().getString(NAME_KEY);
|
mName = getArguments().getString(NAME_KEY);
|
||||||
} else {
|
|
||||||
mFetchPostErrorLinearLayout.setOnClickListener(view -> mPostViewModel.retry());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mPostType == PostDataSource.TYPE_FRONT_PAGE) {
|
if(mPostType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||||
@ -116,11 +116,38 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
PostViewModel.Factory factory;
|
PostViewModel.Factory factory;
|
||||||
if(mPostType == PostDataSource.TYPE_FRONT_PAGE) {
|
if(mPostType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||||
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
factory = new PostViewModel.Factory(mOauthRetrofit, accessToken,
|
||||||
getResources().getConfiguration().locale, mPostType);
|
getResources().getConfiguration().locale, mPostType, new PostDataSource.OnPostFetchedCallback() {
|
||||||
|
@Override
|
||||||
|
public void hasPost() {
|
||||||
|
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void noPost() {
|
||||||
|
mFetchPostInfoLinearLayout.setOnClickListener(view -> {
|
||||||
|
//Do nothing
|
||||||
|
});
|
||||||
|
showErrorView(R.string.no_posts);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
factory = new PostViewModel.Factory(mRetrofit,
|
factory = new PostViewModel.Factory(mRetrofit,
|
||||||
getResources().getConfiguration().locale, mName, mPostType);
|
getResources().getConfiguration().locale, mName, mPostType, new PostDataSource.OnPostFetchedCallback() {
|
||||||
|
@Override
|
||||||
|
public void hasPost() {
|
||||||
|
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void noPost() {
|
||||||
|
mFetchPostInfoLinearLayout.setOnClickListener(view -> {
|
||||||
|
//Do nothing
|
||||||
|
});
|
||||||
|
showErrorView(R.string.no_posts);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
mPostViewModel = ViewModelProviders.of(this, factory).get(PostViewModel.class);
|
mPostViewModel = ViewModelProviders.of(this, factory).get(PostViewModel.class);
|
||||||
mPostViewModel.getPosts().observe(this, posts -> mAdapter.submitList(posts));
|
mPostViewModel.getPosts().observe(this, posts -> mAdapter.submitList(posts));
|
||||||
|
|
||||||
@ -128,9 +155,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
|
if(networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
|
||||||
mProgressBar.setVisibility(View.GONE);
|
mProgressBar.setVisibility(View.GONE);
|
||||||
} else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
|
} else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) {
|
||||||
showErrorView();
|
mFetchPostInfoLinearLayout.setOnClickListener(view -> mPostViewModel.retry());
|
||||||
|
showErrorView(R.string.load_posts_error);
|
||||||
} else {
|
} else {
|
||||||
mFetchPostErrorLinearLayout.setVisibility(View.GONE);
|
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||||
mProgressBar.setVisibility(View.VISIBLE);
|
mProgressBar.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -147,17 +175,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
mPostViewModel.refresh();
|
mPostViewModel.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showErrorView() {
|
private void showErrorView(int stringResId) {
|
||||||
mProgressBar.setVisibility(View.GONE);
|
mProgressBar.setVisibility(View.GONE);
|
||||||
if(mPostType == PostDataSource.TYPE_FRONT_PAGE) {
|
if(getActivity() != null && isAdded()) {
|
||||||
if(getActivity() != null && isAdded()) {
|
mFetchPostInfoLinearLayout.setVisibility(View.VISIBLE);
|
||||||
mFetchPostErrorLinearLayout.setVisibility(View.VISIBLE);
|
mFetchPostInfoTextView.setText(stringResId);
|
||||||
Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchPostErrorImageView);
|
Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchPostInfoImageView);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Snackbar snackbar = Snackbar.make(mCoordinatorLayout, "Error getting post", Snackbar.LENGTH_INDEFINITE);
|
|
||||||
snackbar.setAction(R.string.retry, view -> mPostViewModel.retry());
|
|
||||||
snackbar.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,6 +23,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -212,20 +213,10 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
.into(((DataViewHolder) holder).subredditIconGifImageView);
|
.into(((DataViewHolder) holder).subredditIconGifImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
((DataViewHolder) holder).subredditIconGifImageView.setOnClickListener(view -> {
|
|
||||||
if(canStartActivity) {
|
|
||||||
canStartActivity = false;
|
|
||||||
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
|
|
||||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY,
|
|
||||||
post.getSubredditNamePrefixed().substring(2));
|
|
||||||
mContext.startActivity(intent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
((DataViewHolder) holder).subredditNameTextView.setTextColor(mContext.getResources().getColor(R.color.colorAccent));
|
((DataViewHolder) holder).subredditNameTextView.setTextColor(mContext.getResources().getColor(R.color.colorAccent));
|
||||||
((DataViewHolder) holder).subredditNameTextView.setText(subredditNamePrefixed);
|
((DataViewHolder) holder).subredditNameTextView.setText(subredditNamePrefixed);
|
||||||
|
|
||||||
((DataViewHolder) holder).subredditNameTextView.setOnClickListener(view -> {
|
((DataViewHolder) holder).subredditIconNameLinearLayout.setOnClickListener(view -> {
|
||||||
if(canStartActivity) {
|
if(canStartActivity) {
|
||||||
canStartActivity = false;
|
canStartActivity = false;
|
||||||
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
|
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
|
||||||
@ -297,19 +288,10 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
.into(((DataViewHolder) holder).subredditIconGifImageView);
|
.into(((DataViewHolder) holder).subredditIconGifImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
((DataViewHolder) holder).subredditIconGifImageView.setOnClickListener(view -> {
|
|
||||||
if(canStartActivity) {
|
|
||||||
canStartActivity = false;
|
|
||||||
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
|
||||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor());
|
|
||||||
mContext.startActivity(intent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
((DataViewHolder) holder).subredditNameTextView.setTextColor(mContext.getResources().getColor(R.color.colorPrimaryDark));
|
((DataViewHolder) holder).subredditNameTextView.setTextColor(mContext.getResources().getColor(R.color.colorPrimaryDark));
|
||||||
((DataViewHolder) holder).subredditNameTextView.setText(author);
|
((DataViewHolder) holder).subredditNameTextView.setText(author);
|
||||||
|
|
||||||
((DataViewHolder) holder).subredditNameTextView.setOnClickListener(view -> {
|
((DataViewHolder) holder).subredditIconNameLinearLayout.setOnClickListener(view -> {
|
||||||
if(canStartActivity) {
|
if(canStartActivity) {
|
||||||
canStartActivity = false;
|
canStartActivity = false;
|
||||||
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
||||||
@ -645,6 +627,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
|
|||||||
|
|
||||||
class DataViewHolder extends RecyclerView.ViewHolder {
|
class DataViewHolder extends RecyclerView.ViewHolder {
|
||||||
@BindView(R.id.card_view_view_post_detail) MaterialCardView cardView;
|
@BindView(R.id.card_view_view_post_detail) MaterialCardView cardView;
|
||||||
|
@BindView(R.id.subreddit_icon_name_linear_layout_view_item_best_post) LinearLayout subredditIconNameLinearLayout;
|
||||||
@BindView(R.id.subreddit_icon_gif_image_view_best_post_item) AspectRatioGifImageView subredditIconGifImageView;
|
@BindView(R.id.subreddit_icon_gif_image_view_best_post_item) AspectRatioGifImageView subredditIconGifImageView;
|
||||||
@BindView(R.id.subreddit_text_view_best_post_item) TextView subredditNameTextView;
|
@BindView(R.id.subreddit_text_view_best_post_item) TextView subredditNameTextView;
|
||||||
@BindView(R.id.stickied_post_image_view_best_post_item) ImageView stickiedPostImageView;
|
@BindView(R.id.stickied_post_image_view_best_post_item) ImageView stickiedPostImageView;
|
||||||
|
@ -18,8 +18,9 @@ public class PostViewModel extends ViewModel {
|
|||||||
private LiveData<NetworkState> initialLoadingState;
|
private LiveData<NetworkState> initialLoadingState;
|
||||||
private LiveData<PagedList<Post>> posts;
|
private LiveData<PagedList<Post>> posts;
|
||||||
|
|
||||||
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType) {
|
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType,
|
||||||
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, postType);
|
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||||
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, postType, onPostFetchedCallback);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
dataSource -> dataSource.getInitialLoadStateLiveData());
|
dataSource -> dataSource.getInitialLoadStateLiveData());
|
||||||
@ -34,8 +35,9 @@ public class PostViewModel extends ViewModel {
|
|||||||
posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostViewModel(Retrofit retrofit, Locale locale, String subredditName, int postType) {
|
public PostViewModel(Retrofit retrofit, Locale locale, String subredditName, int postType,
|
||||||
postDataSourceFactory = new PostDataSourceFactory(retrofit, locale, subredditName, postType);
|
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||||
|
postDataSourceFactory = new PostDataSourceFactory(retrofit, locale, subredditName, postType, onPostFetchedCallback);
|
||||||
|
|
||||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||||
dataSource -> dataSource.getInitialLoadStateLiveData());
|
dataSource -> dataSource.getInitialLoadStateLiveData());
|
||||||
@ -81,28 +83,33 @@ public class PostViewModel extends ViewModel {
|
|||||||
private Locale locale;
|
private Locale locale;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
private int postType;
|
private int postType;
|
||||||
|
private PostDataSource.OnPostFetchedCallback onPostFetchedCallback;
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, String accessToken, Locale locale, int postType) {
|
public Factory(Retrofit retrofit, String accessToken, Locale locale, int postType,
|
||||||
|
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
|
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Factory(Retrofit retrofit, Locale locale, String subredditName, int postType) {
|
public Factory(Retrofit retrofit, Locale locale, String subredditName, int postType,
|
||||||
|
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
this.subredditName = subredditName;
|
this.subredditName = subredditName;
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
|
this.onPostFetchedCallback = onPostFetchedCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
|
if(postType == PostDataSource.TYPE_FRONT_PAGE) {
|
||||||
return (T) new PostViewModel(retrofit, accessToken, locale, postType);
|
return (T) new PostViewModel(retrofit, accessToken, locale, postType, onPostFetchedCallback);
|
||||||
} else {
|
} else {
|
||||||
return (T) new PostViewModel(retrofit, locale, subredditName, postType);
|
return (T) new PostViewModel(retrofit, locale, subredditName, postType, onPostFetchedCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingTop="36dp"
|
android:paddingTop="36dp"
|
||||||
android:paddingBottom="16dp"
|
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingEnd="16dp"
|
android:paddingEnd="16dp"
|
||||||
android:layout_below="@id/banner_image_view_view_subreddit_detail_activity"
|
android:layout_below="@id/banner_image_view_view_subreddit_detail_activity"
|
||||||
@ -75,7 +74,8 @@
|
|||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp">
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginBottom="16dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/subscriber_count_text_view_view_subreddit_detail_activity"
|
android:id="@+id/subscriber_count_text_view_view_subreddit_detail_activity"
|
||||||
@ -83,8 +83,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_toStartOf="@id/online_subscriber_count_text_view_view_subreddit_detail_activity"
|
android:layout_toStartOf="@id/online_subscriber_count_text_view_view_subreddit_detail_activity" />
|
||||||
android:layout_marginBottom="16dp"/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/online_subscriber_count_text_view_view_subreddit_detail_activity"
|
android:id="@+id/online_subscriber_count_text_view_view_subreddit_detail_activity"
|
||||||
@ -99,6 +98,7 @@
|
|||||||
android:id="@+id/description_text_view_view_subreddit_detail_activity"
|
android:id="@+id/description_text_view_view_subreddit_detail_activity"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
android:textColor="@android:color/black"
|
android:textColor="@android:color/black"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/fetch_post_error_linear_layout_post_fragment"
|
android:id="@+id/fetch_post_info_linear_layout_post_fragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
@ -30,16 +30,16 @@
|
|||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/fetch_post_error_image_view_post_fragment"
|
android:id="@+id/fetch_post_info_image_view_post_fragment"
|
||||||
android:layout_width="150dp"
|
android:layout_width="150dp"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/fetch_post_info_text_view_post_fragment"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:gravity="center"
|
android:gravity="center" />
|
||||||
android:text="@string/load_posts_error"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -13,49 +13,60 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<RelativeLayout
|
<android.support.constraint.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:layout_margin="16dp">
|
|
||||||
|
|
||||||
<CustomView.AspectRatioGifImageView
|
<LinearLayout
|
||||||
android:id="@+id/subreddit_icon_gif_image_view_best_post_item"
|
android:id="@+id/subreddit_icon_name_linear_layout_view_item_best_post"
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="24dp"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:layout_centerVertical="true"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/subreddit_text_view_best_post_item"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:padding="16dp"
|
||||||
android:layout_marginEnd="8dp"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
android:layout_toStartOf="@id/stickied_post_image_view_best_post_item"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
android:layout_toEndOf="@id/subreddit_icon_gif_image_view_best_post_item"
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:textColor="#E91E63"/>
|
<CustomView.AspectRatioGifImageView
|
||||||
|
android:id="@+id/subreddit_icon_gif_image_view_best_post_item"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/subreddit_text_view_best_post_item"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textColor="#E91E63" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/stickied_post_image_view_best_post_item"
|
android:id="@+id/stickied_post_image_view_best_post_item"
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_toStartOf="@id/post_time_text_view_best_post_item"
|
android:layout_gravity="center"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:tint="@color/colorPrimary"
|
android:tint="@color/colorPrimary"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/post_time_text_view_best_post_item"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/post_time_text_view_best_post_item"
|
android:id="@+id/post_time_text_view_best_post_item"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_gravity="center"
|
||||||
android:layout_centerVertical="true"
|
android:layout_marginEnd="16dp"
|
||||||
android:gravity="center_vertical"/>
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</android.support.constraint.ConstraintLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title_text_view_best_post_item"
|
android:id="@+id/title_text_view_best_post_item"
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
<string name="tap_to_retry">Error loading image. Tap to retry.</string>
|
<string name="tap_to_retry">Error loading image. Tap to retry.</string>
|
||||||
<string name="load_posts_error">Error loading posts.\nTap to retry.</string>
|
<string name="load_posts_error">Error loading posts.\nTap to retry.</string>
|
||||||
|
<string name="no_posts">No posts here.</string>
|
||||||
|
|
||||||
<string name="load_data_failed">Cannot load posts</string>
|
<string name="load_data_failed">Cannot load posts</string>
|
||||||
<string name="load_comment_failed">Error loading comments</string>
|
<string name="load_comment_failed">Error loading comments</string>
|
||||||
@ -47,4 +48,6 @@
|
|||||||
<string name="unfollow_failed">Unfollowing Failed</string>
|
<string name="unfollow_failed">Unfollowing Failed</string>
|
||||||
|
|
||||||
<string name="content_description_banner_imageview">Subreddit Banner Image</string>
|
<string name="content_description_banner_imageview">Subreddit Banner Image</string>
|
||||||
|
|
||||||
|
<string name="error_loading_posts">Error loading post</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -7,7 +7,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
classpath 'com.android.tools.build:gradle:3.3.0'
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
#Fri Oct 19 21:24:28 HKT 2018
|
#Tue Jan 22 01:13:16 HKT 2019
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
|
||||||
|
Loading…
Reference in New Issue
Block a user