mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Add a feature which is refreshing the posts by clicking the refresh button. Minor bugs fixed. Rewrite some code.
This commit is contained in:
parent
a7d4485fc1
commit
bfb311d75f
47
.idea/assetWizardSettings.xml
Normal file
47
.idea/assetWizardSettings.xml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="WizardSettings">
|
||||||
|
<option name="children">
|
||||||
|
<map>
|
||||||
|
<entry key="vectorWizard">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="children">
|
||||||
|
<map>
|
||||||
|
<entry key="vectorAssetStep">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="children">
|
||||||
|
<map>
|
||||||
|
<entry key="clipartAsset">
|
||||||
|
<value>
|
||||||
|
<PersistentState>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="url" value="jar:file:/home/alex/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/navigation/ic_refresh_black_24dp.xml" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
<option name="values">
|
||||||
|
<map>
|
||||||
|
<entry key="color" value="ffffff" />
|
||||||
|
<entry key="outputName" value="ic_refresh_white_24dp" />
|
||||||
|
<entry key="sourceFile" value="$USER_HOME$" />
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</PersistentState>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,5 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
interface FragmentCommunicator {
|
||||||
|
void refresh();
|
||||||
|
}
|
@ -16,6 +16,8 @@ import android.support.v7.app.AppCompatActivity;
|
|||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -55,6 +57,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private boolean mFetchUserInfoSuccess;
|
private boolean mFetchUserInfoSuccess;
|
||||||
private boolean mInsertSuccess;
|
private boolean mInsertSuccess;
|
||||||
|
|
||||||
|
private FragmentCommunicator mFragmentCommunicator;
|
||||||
|
|
||||||
private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
|
private SubscribedSubredditViewModel mSubscribedSubredditViewModel;
|
||||||
private SubscribedUserViewModel mSubscribedUserViewModel;
|
private SubscribedUserViewModel mSubscribedUserViewModel;
|
||||||
|
|
||||||
@ -254,6 +258,24 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
getMenuInflater().inflate(R.menu.main_activity, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.action_refresh_main_activity:
|
||||||
|
if(mFragment instanceof FragmentCommunicator) {
|
||||||
|
((FragmentCommunicator) mFragment).refresh();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||||
|
@ -10,9 +10,10 @@ class PaginationSynchronizer implements Parcelable {
|
|||||||
private PaginationRetryNotifier paginationRetryNotifier;
|
private PaginationRetryNotifier paginationRetryNotifier;
|
||||||
private LastItemSynchronizer lastItemSynchronizer;
|
private LastItemSynchronizer lastItemSynchronizer;
|
||||||
|
|
||||||
PaginationSynchronizer() {
|
PaginationSynchronizer(LastItemSynchronizer lastItemSynchronizer) {
|
||||||
loadingState = false;
|
loadingState = false;
|
||||||
loadSuccess = true;
|
loadSuccess = true;
|
||||||
|
this. lastItemSynchronizer = lastItemSynchronizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PaginationSynchronizer(Parcel in) {
|
protected PaginationSynchronizer(Parcel in) {
|
||||||
|
@ -6,7 +6,6 @@ import android.content.ClipboardManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.design.widget.CoordinatorLayout;
|
import android.support.design.widget.CoordinatorLayout;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
@ -33,61 +32,36 @@ import retrofit2.converter.scalars.ScalarsConverterFactory;
|
|||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
*/
|
*/
|
||||||
public class PostFragment extends Fragment {
|
public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||||
|
|
||||||
static final String SUBREDDIT_NAME_KEY = "SNK";
|
static final String SUBREDDIT_NAME_KEY = "SNK";
|
||||||
static final String IS_BEST_POST_KEY = "IBPK";
|
static final String IS_BEST_POST_KEY = "IBPK";
|
||||||
|
|
||||||
|
private static final String PostDataParcelableState = "BPDPS";
|
||||||
|
private static final String lastItemState = "LIS";
|
||||||
|
private static final String paginationSynchronizerState = "PSS";
|
||||||
|
|
||||||
private CoordinatorLayout mCoordinatorLayout;
|
private CoordinatorLayout mCoordinatorLayout;
|
||||||
private RecyclerView mPostRecyclerView;
|
private RecyclerView mPostRecyclerView;
|
||||||
private LinearLayoutManager mLinearLayoutManager;
|
private LinearLayoutManager mLinearLayoutManager;
|
||||||
private ProgressBar mProgressBar;
|
private ProgressBar mProgressBar;
|
||||||
private ArrayList<PostData> mPostData;
|
|
||||||
private String mLastItem;
|
|
||||||
private PaginationSynchronizer mPaginationSynchronizer;
|
|
||||||
private PostRecyclerViewAdapter mAdapter;
|
|
||||||
private LinearLayout mFetchPostErrorLinearLayout;
|
private LinearLayout mFetchPostErrorLinearLayout;
|
||||||
private ImageView mFetchPostErrorImageView;
|
private ImageView mFetchPostErrorImageView;
|
||||||
|
|
||||||
|
private ArrayList<PostData> mPostData;
|
||||||
|
private String mLastItem;
|
||||||
|
private PaginationSynchronizer mPaginationSynchronizer;
|
||||||
|
|
||||||
private boolean mIsBestPost;
|
private boolean mIsBestPost;
|
||||||
private String mSubredditName;
|
private String mSubredditName;
|
||||||
private String PostDataParcelableState = "BPDPS";
|
|
||||||
private String lastItemState = "LIS";
|
|
||||||
private String paginationSynchronizerState = "PSS";
|
|
||||||
|
|
||||||
public PostFragment() {
|
public PostFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
if(savedInstanceState != null) {
|
|
||||||
if(savedInstanceState.containsKey(PostDataParcelableState)) {
|
|
||||||
mPostData = savedInstanceState.getParcelableArrayList(PostDataParcelableState);
|
|
||||||
mLastItem = savedInstanceState.getString(lastItemState);
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(getActivity(), mPostData, mPaginationSynchronizer);
|
|
||||||
mPostRecyclerView.setAdapter(mAdapter);
|
|
||||||
mPostRecyclerView.addOnScrollListener(new PostPaginationScrollListener(
|
|
||||||
getActivity(), mLinearLayoutManager, mAdapter, mLastItem, mPostData,
|
|
||||||
mPaginationSynchronizer, mSubredditName, mIsBestPost,
|
|
||||||
mPaginationSynchronizer.isLoading(), mPaginationSynchronizer.isLoadSuccess(),
|
|
||||||
getResources().getConfiguration().locale));
|
|
||||||
mProgressBar.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
if(mIsBestPost) {
|
|
||||||
fetchBestPost(1);
|
|
||||||
} else {
|
|
||||||
fetchPost();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|
||||||
if(mPostData != null) {
|
if(mPostData != null) {
|
||||||
outState.putParcelableArrayList(PostDataParcelableState, mPostData);
|
outState.putParcelableArrayList(PostDataParcelableState, mPostData);
|
||||||
outState.putString(lastItemState, mLastItem);
|
outState.putString(lastItemState, mLastItem);
|
||||||
@ -98,13 +72,13 @@ public class PostFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if(mAdapter != null) {
|
if(mPostRecyclerView.getAdapter() != null) {
|
||||||
mAdapter.setCanStartActivity(true);
|
((PostRecyclerViewAdapter) mPostRecyclerView.getAdapter()).setCanStartActivity(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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_post, container, false);
|
View rootView = inflater.inflate(R.layout.fragment_post, container, false);
|
||||||
@ -140,10 +114,25 @@ public class PostFragment extends Fragment {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(savedInstanceState != null && savedInstanceState.getParcelable(paginationSynchronizerState) != null) {
|
if(savedInstanceState != null && savedInstanceState.containsKey(PostDataParcelableState)) {
|
||||||
|
mPostData = savedInstanceState.getParcelableArrayList(PostDataParcelableState);
|
||||||
|
mLastItem = savedInstanceState.getString(lastItemState);
|
||||||
mPaginationSynchronizer = savedInstanceState.getParcelable(paginationSynchronizerState);
|
mPaginationSynchronizer = savedInstanceState.getParcelable(paginationSynchronizerState);
|
||||||
|
PostRecyclerViewAdapter adapter = new PostRecyclerViewAdapter(getActivity(), mPostData, mPaginationSynchronizer);
|
||||||
|
mPostRecyclerView.setAdapter(adapter);
|
||||||
|
mPostRecyclerView.addOnScrollListener(new PostPaginationScrollListener(
|
||||||
|
getActivity(), mLinearLayoutManager, adapter, mLastItem, mPostData,
|
||||||
|
mPaginationSynchronizer, mSubredditName, mIsBestPost,
|
||||||
|
mPaginationSynchronizer.isLoading(), mPaginationSynchronizer.isLoadSuccess(),
|
||||||
|
getResources().getConfiguration().locale));
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
mPaginationSynchronizer = new PaginationSynchronizer();
|
mPaginationSynchronizer = new PaginationSynchronizer(new LastItemSynchronizer() {
|
||||||
|
@Override
|
||||||
|
public void lastItemChanged(String lastItem) {
|
||||||
|
mLastItem = lastItem;
|
||||||
|
}
|
||||||
|
});
|
||||||
if(mIsBestPost) {
|
if(mIsBestPost) {
|
||||||
fetchBestPost(1);
|
fetchBestPost(1);
|
||||||
} else {
|
} else {
|
||||||
@ -151,14 +140,6 @@ public class PostFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LastItemSynchronizer lastItemSynchronizer = new LastItemSynchronizer() {
|
|
||||||
@Override
|
|
||||||
public void lastItemChanged(String lastItem) {
|
|
||||||
mLastItem = lastItem;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mPaginationSynchronizer.setLastItemSynchronizer(lastItemSynchronizer);
|
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,11 +178,11 @@ public class PostFragment extends Fragment {
|
|||||||
if(isAdded() && getActivity() != null) {
|
if(isAdded() && getActivity() != null) {
|
||||||
mPostData = postData;
|
mPostData = postData;
|
||||||
mLastItem = lastItem;
|
mLastItem = lastItem;
|
||||||
mAdapter = new PostRecyclerViewAdapter(getActivity(), postData, mPaginationSynchronizer);
|
PostRecyclerViewAdapter adapter = new PostRecyclerViewAdapter(getActivity(), postData, mPaginationSynchronizer);
|
||||||
|
|
||||||
mPostRecyclerView.setAdapter(mAdapter);
|
mPostRecyclerView.setAdapter(adapter);
|
||||||
mPostRecyclerView.addOnScrollListener(new PostPaginationScrollListener(
|
mPostRecyclerView.addOnScrollListener(new PostPaginationScrollListener(
|
||||||
getActivity(), mLinearLayoutManager, mAdapter, lastItem, postData,
|
getActivity(), mLinearLayoutManager, adapter, lastItem, postData,
|
||||||
mPaginationSynchronizer, mSubredditName, mIsBestPost,
|
mPaginationSynchronizer, mSubredditName, mIsBestPost,
|
||||||
mPaginationSynchronizer.isLoading(), mPaginationSynchronizer.isLoadSuccess(),
|
mPaginationSynchronizer.isLoading(), mPaginationSynchronizer.isLoadSuccess(),
|
||||||
getResources().getConfiguration().locale));
|
getResources().getConfiguration().locale));
|
||||||
@ -269,11 +250,11 @@ public class PostFragment extends Fragment {
|
|||||||
if(isAdded() && getActivity() != null) {
|
if(isAdded() && getActivity() != null) {
|
||||||
mPostData = postData;
|
mPostData = postData;
|
||||||
mLastItem = lastItem;
|
mLastItem = lastItem;
|
||||||
mAdapter = new PostRecyclerViewAdapter(getActivity(), postData, mPaginationSynchronizer);
|
PostRecyclerViewAdapter adapter = new PostRecyclerViewAdapter(getActivity(), postData, mPaginationSynchronizer);
|
||||||
|
|
||||||
mPostRecyclerView.setAdapter(mAdapter);
|
mPostRecyclerView.setAdapter(adapter);
|
||||||
mPostRecyclerView.addOnScrollListener(new PostPaginationScrollListener(
|
mPostRecyclerView.addOnScrollListener(new PostPaginationScrollListener(
|
||||||
getActivity(), mLinearLayoutManager, mAdapter, lastItem, postData,
|
getActivity(), mLinearLayoutManager, adapter, lastItem, postData,
|
||||||
mPaginationSynchronizer, mSubredditName, mIsBestPost,
|
mPaginationSynchronizer, mSubredditName, mIsBestPost,
|
||||||
mPaginationSynchronizer.isLoading(), mPaginationSynchronizer.isLoadSuccess(),
|
mPaginationSynchronizer.isLoading(), mPaginationSynchronizer.isLoadSuccess(),
|
||||||
getResources().getConfiguration().locale));
|
getResources().getConfiguration().locale));
|
||||||
@ -304,8 +285,10 @@ public class PostFragment extends Fragment {
|
|||||||
private void showErrorView() {
|
private void showErrorView() {
|
||||||
mProgressBar.setVisibility(View.GONE);
|
mProgressBar.setVisibility(View.GONE);
|
||||||
if(mIsBestPost) {
|
if(mIsBestPost) {
|
||||||
mFetchPostErrorLinearLayout.setVisibility(View.VISIBLE);
|
if(getActivity() != null && isAdded()) {
|
||||||
Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchPostErrorImageView);
|
mFetchPostErrorLinearLayout.setVisibility(View.VISIBLE);
|
||||||
|
Glide.with(this).load(R.drawable.load_post_error_indicator).into(mFetchPostErrorImageView);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Snackbar snackbar = Snackbar.make(mCoordinatorLayout, "Error getting post", Snackbar.LENGTH_INDEFINITE);
|
Snackbar snackbar = Snackbar.make(mCoordinatorLayout, "Error getting post", Snackbar.LENGTH_INDEFINITE);
|
||||||
snackbar.setAction(R.string.retry, new View.OnClickListener() {
|
snackbar.setAction(R.string.retry, new View.OnClickListener() {
|
||||||
@ -321,4 +304,29 @@ public class PostFragment extends Fragment {
|
|||||||
snackbar.show();
|
snackbar.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refresh() {
|
||||||
|
mLastItem = null;
|
||||||
|
mPaginationSynchronizer = new PaginationSynchronizer(new LastItemSynchronizer() {
|
||||||
|
@Override
|
||||||
|
public void lastItemChanged(String lastItem) {
|
||||||
|
mLastItem = lastItem;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mPostRecyclerView.clearOnScrollListeners();
|
||||||
|
mPostRecyclerView.getRecycledViewPool().clear();
|
||||||
|
if(mPostData != null) {
|
||||||
|
mPostData.clear();
|
||||||
|
}
|
||||||
|
mPostData = null;
|
||||||
|
if(mPostRecyclerView.getAdapter() != null) {
|
||||||
|
(mPostRecyclerView.getAdapter()).notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
if(mIsBestPost) {
|
||||||
|
fetchBestPost(1);
|
||||||
|
} else {
|
||||||
|
fetchPost();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -117,14 +117,16 @@ class PostPaginationScrollListener extends RecyclerView.OnScrollListener {
|
|||||||
ParsePost.parsePost(response.body(), mPostData, locale, new ParsePost.ParsePostListener() {
|
ParsePost.parsePost(response.body(), mPostData, locale, new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(ArrayList<PostData> postData, String lastItem) {
|
public void onParsePostSuccess(ArrayList<PostData> postData, String lastItem) {
|
||||||
mAdapter.notifyItemRangeInserted(mPostData.size(), postData.size());
|
if(mAdapter != null) {
|
||||||
mLastItem = lastItem;
|
mAdapter.notifyItemRangeInserted(mPostData.size(), postData.size());
|
||||||
mLastItemSynchronizer.lastItemChanged(mLastItem);
|
mLastItem = lastItem;
|
||||||
|
mLastItemSynchronizer.lastItemChanged(lastItem);
|
||||||
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
loadSuccess = true;
|
loadSuccess = true;
|
||||||
mPaginationSynchronizer.setLoading(false);
|
mPaginationSynchronizer.setLoading(false);
|
||||||
mPaginationSynchronizer.setLoadingState(true);
|
mPaginationSynchronizer.setLoadingState(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -188,14 +190,16 @@ class PostPaginationScrollListener extends RecyclerView.OnScrollListener {
|
|||||||
ParsePost.parsePost(response.body(), mPostData, locale, new ParsePost.ParsePostListener() {
|
ParsePost.parsePost(response.body(), mPostData, locale, new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(ArrayList<PostData> postData, String lastItem) {
|
public void onParsePostSuccess(ArrayList<PostData> postData, String lastItem) {
|
||||||
mAdapter.notifyItemRangeInserted(mPostData.size(), postData.size());
|
if(mAdapter != null) {
|
||||||
mLastItem = lastItem;
|
mAdapter.notifyItemRangeInserted(mPostData.size(), postData.size());
|
||||||
mLastItemSynchronizer.lastItemChanged(mLastItem);
|
mLastItem = lastItem;
|
||||||
|
mLastItemSynchronizer.lastItemChanged(lastItem);
|
||||||
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
loadSuccess = true;
|
loadSuccess = true;
|
||||||
mPaginationSynchronizer.setLoading(false);
|
mPaginationSynchronizer.setLoading(false);
|
||||||
mPaginationSynchronizer.setLoadingState(true);
|
mPaginationSynchronizer.setLoadingState(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,10 +83,10 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
|
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
|
||||||
if(holder instanceof DataViewHolder) {
|
if(holder instanceof DataViewHolder) {
|
||||||
if(mPostData.get(position) == null) {
|
if(mPostData.get(holder.getAdapterPosition()) == null) {
|
||||||
Log.i("is null", Integer.toString(position));
|
Log.i("is null", Integer.toString(holder.getAdapterPosition()));
|
||||||
} else {
|
} else {
|
||||||
final int adapterPosition = holder.getAdapterPosition();
|
final int adapterPosition = holder.getAdapterPosition();
|
||||||
final String id = mPostData.get(adapterPosition).getFullName();
|
final String id = mPostData.get(adapterPosition).getFullName();
|
||||||
@ -103,15 +103,17 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||||||
new LoadSubredditIconAsyncTask.LoadSubredditIconAsyncTaskListener() {
|
new LoadSubredditIconAsyncTask.LoadSubredditIconAsyncTaskListener() {
|
||||||
@Override
|
@Override
|
||||||
public void loadIconSuccess(String iconImageUrl) {
|
public void loadIconSuccess(String iconImageUrl) {
|
||||||
if(!iconImageUrl.equals("")) {
|
if(mContext != null && !mPostData.isEmpty()) {
|
||||||
Glide.with(mContext).load(iconImageUrl)
|
if(!iconImageUrl.equals("")) {
|
||||||
.into(((DataViewHolder) holder).subredditIconCircleImageView);
|
Glide.with(mContext).load(iconImageUrl)
|
||||||
} else {
|
.into(((DataViewHolder) holder).subredditIconCircleImageView);
|
||||||
Glide.with(mContext).load(R.drawable.subreddit_default_icon)
|
} else {
|
||||||
.into(((DataViewHolder) holder).subredditIconCircleImageView);
|
Glide.with(mContext).load(R.drawable.subreddit_default_icon)
|
||||||
}
|
.into(((DataViewHolder) holder).subredditIconCircleImageView);
|
||||||
|
}
|
||||||
|
|
||||||
mPostData.get(adapterPosition).setSubredditIconUrl(iconImageUrl);
|
mPostData.get(adapterPosition).setSubredditIconUrl(iconImageUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).execute();
|
}).execute();
|
||||||
} else if(!mPostData.get(position).getSubredditIconUrl().equals("")) {
|
} else if(!mPostData.get(position).getSubredditIconUrl().equals("")) {
|
||||||
@ -253,7 +255,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||||||
builder.addDefaultShareMenuItem();
|
builder.addDefaultShareMenuItem();
|
||||||
builder.setToolbarColor(mContext.getResources().getColor(R.color.colorPrimary));
|
builder.setToolbarColor(mContext.getResources().getColor(R.color.colorPrimary));
|
||||||
CustomTabsIntent customTabsIntent = builder.build();
|
CustomTabsIntent customTabsIntent = builder.build();
|
||||||
customTabsIntent.launchUrl(mContext, Uri.parse(mPostData.get(position).getUrl()));
|
customTabsIntent.launchUrl(mContext, Uri.parse(mPostData.get(holder.getAdapterPosition()).getUrl()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -482,6 +484,9 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
|
if(mPostData == null || mPostData.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return mPostData.size() + 1;
|
return mPostData.size() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,11 +37,13 @@ class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<Recycl
|
|||||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
|
if(viewHolder.getAdapterPosition() >= 0) {
|
||||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getName());
|
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
|
||||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_VALUE_KEY, mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getId());
|
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getName());
|
||||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_QUERY_BY_ID_KEY, true);
|
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_VALUE_KEY, mSubscribedSubredditData.get(viewHolder.getAdapterPosition()).getId());
|
||||||
mContext.startActivity(intent);
|
intent.putExtra(ViewSubredditDetailActivity.EXTRA_QUERY_BY_ID_KEY, true);
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!mSubscribedSubredditData.get(i).getIconUrl().equals("")) {
|
if(!mSubscribedSubredditData.get(i).getIconUrl().equals("")) {
|
||||||
|
@ -11,6 +11,7 @@ import android.support.design.widget.CollapsingToolbarLayout;
|
|||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -195,12 +196,22 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
getMenuInflater().inflate(R.menu.view_subreddit_detail_activity, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.action_refresh_view_subreddit_detail_activity:
|
||||||
|
if(mFragment instanceof FragmentCommunicator) {
|
||||||
|
((FragmentCommunicator) mFragment).refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
5
app/src/main/res/drawable/ic_refresh_white_24dp.xml
Normal file
5
app/src/main/res/drawable/ic_refresh_white_24dp.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||||
|
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="#FF000000" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
|
||||||
|
</vector>
|
12
app/src/main/res/menu/main_activity.xml
Normal file
12
app/src/main/res/menu/main_activity.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:context="ml.docilealligator.infinityforreddit.MainActivity">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_refresh_main_activity"
|
||||||
|
android:orderInCategory="1"
|
||||||
|
android:title="@string/action_refresh"
|
||||||
|
android:icon="@drawable/ic_refresh_white_24dp"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
</menu>
|
12
app/src/main/res/menu/view_subreddit_detail_activity.xml
Normal file
12
app/src/main/res/menu/view_subreddit_detail_activity.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:context="ml.docilealligator.infinityforreddit.ViewSubredditDetailActivity">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_refresh_view_subreddit_detail_activity"
|
||||||
|
android:orderInCategory="1"
|
||||||
|
android:title="@string/action_refresh"
|
||||||
|
android:icon="@drawable/ic_refresh_white_24dp"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
</menu>
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="action_download">Download</string>
|
<string name="action_download">Download</string>
|
||||||
|
<string name="action_refresh">Refresh</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>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user