mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Fix null favourites menu item, and add pull to refresh in feed
This commit is contained in:
parent
cc9348d8c5
commit
437162639f
@ -94,8 +94,6 @@ public final class CommentsViewerFragment extends Fragment implements SwipeRefre
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.follow, menu);
|
||||
final MenuItem favItem = menu.findItem(R.id.favourites);
|
||||
if (favItem != null) favItem.setVisible(false);
|
||||
menu.findItem(R.id.action_compare).setVisible(false);
|
||||
final MenuItem menuSearch = menu.findItem(R.id.action_search);
|
||||
final SearchView searchView = (SearchView) menuSearch.getActionView();
|
||||
|
@ -236,10 +236,6 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull final Menu menu, final MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.follow, menu);
|
||||
final MenuItem favItem = menu.findItem(R.id.favourites);
|
||||
if (favItem != null) {
|
||||
favItem.setVisible(false);
|
||||
}
|
||||
final MenuItem menuSearch = menu.findItem(R.id.action_search);
|
||||
final SearchView searchView = (SearchView) menuSearch.getActionView();
|
||||
searchView.setQueryHint(getResources().getString(R.string.action_search));
|
||||
|
@ -165,10 +165,6 @@ public class StoryViewerFragment extends Fragment {
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(@NonNull final Menu menu) {
|
||||
// hide menu items from activity
|
||||
final MenuItem item = menu.findItem(R.id.favourites);
|
||||
if (item != null) {
|
||||
item.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -364,8 +364,6 @@ public class DirectMessageThreadFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(@NonNull final Menu menu) {
|
||||
final MenuItem item = menu.findItem(R.id.favourites);
|
||||
item.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,6 +19,7 @@ import androidx.navigation.NavDirections;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.facebook.common.executors.UiThreadImmediateExecutorService;
|
||||
import com.facebook.datasource.BaseDataSubscriber;
|
||||
@ -62,7 +63,7 @@ import awais.instagrabber.utils.Utils;
|
||||
|
||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||
|
||||
public class FeedFragment extends Fragment {
|
||||
public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
private static final String TAG = "FeedFragment";
|
||||
private static final double MAX_VIDEO_HEIGHT = 0.9 * Utils.displayMetrics.heightPixels;
|
||||
private static final int RESIZED_VIDEO_HEIGHT = (int) (0.8 * Utils.displayMetrics.heightPixels);
|
||||
@ -77,6 +78,7 @@ public class FeedFragment extends Fragment {
|
||||
private FeedViewModel feedViewModel;
|
||||
private VideoAwareRecyclerScroller videoAwareRecyclerScroller;
|
||||
private boolean shouldRefresh = true;
|
||||
private boolean isPullToRefresh;
|
||||
|
||||
private final FetchListener<FeedModel[]> feedFetchListener = new FetchListener<FeedModel[]>() {
|
||||
@Override
|
||||
@ -86,7 +88,10 @@ public class FeedFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onResult(final FeedModel[] result) {
|
||||
if (result == null) return;
|
||||
if (result == null || result.length <= 0) {
|
||||
binding.feedSwipeRefreshLayout.setRefreshing(false);
|
||||
return;
|
||||
}
|
||||
final List<FeedModel> currentFeedModelList = feedViewModel.getList().getValue();
|
||||
final Map<String, FeedModel> thumbToFeedMap = new HashMap<>();
|
||||
for (final FeedModel feedModel : result) {
|
||||
@ -133,10 +138,15 @@ public class FeedFragment extends Fragment {
|
||||
|
||||
public void updateAdapter() {
|
||||
if (failed + success != result.length) return;
|
||||
final List<FeedModel> finalList = currentFeedModelList == null || currentFeedModelList.isEmpty()
|
||||
List<FeedModel> finalList = currentFeedModelList == null || currentFeedModelList.isEmpty()
|
||||
? new ArrayList<>()
|
||||
: new ArrayList<>(currentFeedModelList);
|
||||
finalList.addAll(Arrays.asList(result));
|
||||
final List<FeedModel> resultList = Arrays.asList(result);
|
||||
if (isPullToRefresh) {
|
||||
finalList = resultList;
|
||||
} else {
|
||||
finalList.addAll(resultList);
|
||||
}
|
||||
feedViewModel.getList().postValue(finalList);
|
||||
final PostModel feedPostModel = result[result.length - 1];
|
||||
if (feedPostModel != null) {
|
||||
@ -266,6 +276,7 @@ public class FeedFragment extends Fragment {
|
||||
break;
|
||||
}
|
||||
};
|
||||
private FeedStoriesViewModel feedStoriesViewModel;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
@ -291,6 +302,7 @@ public class FeedFragment extends Fragment {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
|
||||
if (!shouldRefresh) return;
|
||||
binding.feedSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
setupFeedStories();
|
||||
setupFeed();
|
||||
shouldRefresh = false;
|
||||
@ -312,6 +324,14 @@ public class FeedFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
isPullToRefresh = true;
|
||||
feedEndCursor = null;
|
||||
fetchFeed();
|
||||
fetchStories();
|
||||
}
|
||||
|
||||
private void setupFeed() {
|
||||
feedViewModel = new ViewModelProvider(fragmentActivity).get(FeedViewModel.class);
|
||||
final LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
|
||||
@ -336,13 +356,11 @@ public class FeedFragment extends Fragment {
|
||||
|
||||
private void fetchFeed() {
|
||||
binding.feedSwipeRefreshLayout.setRefreshing(true);
|
||||
new FeedFetcher(feedEndCursor, feedFetchListener)
|
||||
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
feedEndCursor = null;
|
||||
new FeedFetcher(feedEndCursor, feedFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void setupFeedStories() {
|
||||
final FeedStoriesViewModel feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
|
||||
feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
|
||||
final FeedStoriesAdapter feedStoriesAdapter = new FeedStoriesAdapter((model, position) -> {
|
||||
final NavDirections action = FeedFragmentDirections.actionFeedFragmentToStoryViewerFragment(position, null, false);
|
||||
NavHostFragment.findNavController(this).navigate(action);
|
||||
@ -350,6 +368,10 @@ public class FeedFragment extends Fragment {
|
||||
binding.feedStoriesRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false));
|
||||
binding.feedStoriesRecyclerView.setAdapter(feedStoriesAdapter);
|
||||
feedStoriesViewModel.getList().observe(fragmentActivity, feedStoriesAdapter::submitList);
|
||||
fetchStories();
|
||||
}
|
||||
|
||||
private void fetchStories() {
|
||||
storiesService.getFeedStories(new ServiceCallback<List<FeedStoryModel>>() {
|
||||
@Override
|
||||
public void onSuccess(final List<FeedStoryModel> result) {
|
||||
|
@ -42,13 +42,6 @@ public class SettingsPreferencesFragment extends BasePreferencesFragment {
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(@NonNull final Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
final MenuItem item = menu.findItem(R.id.favourites);
|
||||
item.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
void setupPreferenceScreen(final PreferenceScreen screen) {
|
||||
screen.addPreference(getLanguagePreference());
|
||||
|
Loading…
Reference in New Issue
Block a user