Reorganize item fragments lifecycle
This commit is contained in:
parent
e22adbe451
commit
90d5208402
|
@ -36,6 +36,9 @@ import com.joanzapata.iconify.Iconify;
|
|||
import com.joanzapata.iconify.widget.IconButton;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -71,9 +74,6 @@ import io.reactivex.Observable;
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
/**
|
||||
* Displays information about a FeedItem and actions.
|
||||
|
@ -266,7 +266,6 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
|
|||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -274,6 +273,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
|
|||
super.onStart();
|
||||
EventDistributor.getInstance().register(contentUpdate);
|
||||
EventBus.getDefault().register(this);
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -306,19 +306,20 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
|
|||
|
||||
@Override
|
||||
public boolean onSwipeLeftToRight() {
|
||||
Log.d(TAG, "onSwipeLeftToRight()");
|
||||
feedItemPos = feedItemPos - 1;
|
||||
if(feedItemPos < 0) {
|
||||
feedItemPos = feedItems.length - 1;
|
||||
}
|
||||
load();
|
||||
return true;
|
||||
return swipeFeedItem(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSwipeRightToLeft() {
|
||||
Log.d(TAG, "onSwipeRightToLeft()");
|
||||
feedItemPos = (feedItemPos + 1) % feedItems.length;
|
||||
return swipeFeedItem(+1);
|
||||
}
|
||||
|
||||
private boolean swipeFeedItem(int position) {
|
||||
Log.d(TAG, String.format("onSwipe() shift: %s", position));
|
||||
feedItemPos = (feedItemPos + position) % feedItems.length;
|
||||
if (feedItemPos < 0) {
|
||||
feedItemPos = feedItems.length - 1;
|
||||
}
|
||||
load();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@ import com.joanzapata.iconify.Iconify;
|
|||
import com.joanzapata.iconify.widget.IconTextView;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -71,9 +74,6 @@ import io.reactivex.Observable;
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
/**
|
||||
* Displays a list of FeedItems.
|
||||
|
@ -96,8 +96,6 @@ public class ItemlistFragment extends ListFragment {
|
|||
private long feedID;
|
||||
private Feed feed;
|
||||
|
||||
private boolean itemsLoaded = false;
|
||||
private boolean viewsCreated = false;
|
||||
private boolean headerCreated = false;
|
||||
|
||||
private List<Downloader> downloaderList;
|
||||
|
@ -146,9 +144,7 @@ public class ItemlistFragment extends ListFragment {
|
|||
super.onStart();
|
||||
EventDistributor.getInstance().register(contentUpdate);
|
||||
EventBus.getDefault().register(this);
|
||||
if (viewsCreated && itemsLoaded) {
|
||||
onFragmentLoaded();
|
||||
}
|
||||
loadItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -156,7 +152,6 @@ public class ItemlistFragment extends ListFragment {
|
|||
super.onResume();
|
||||
((MainActivity)getActivity()).getSupportActionBar().setTitle("");
|
||||
updateProgressBarVisibility();
|
||||
loadItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -177,7 +172,6 @@ public class ItemlistFragment extends ListFragment {
|
|||
|
||||
private void resetViewState() {
|
||||
adapter = null;
|
||||
viewsCreated = false;
|
||||
listFooter = null;
|
||||
}
|
||||
|
||||
|
@ -195,7 +189,6 @@ public class ItemlistFragment extends ListFragment {
|
|||
}
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
||||
if (itemsLoaded) {
|
||||
FeedMenuHandler.onCreateOptionsMenu(inflater, menu);
|
||||
|
||||
MenuItem searchItem = menu.findItem(R.id.action_search);
|
||||
|
@ -206,7 +199,7 @@ public class ItemlistFragment extends ListFragment {
|
|||
@Override
|
||||
public boolean onQueryTextSubmit(String s) {
|
||||
sv.clearFocus();
|
||||
if (itemsLoaded) {
|
||||
if (feed != null) {
|
||||
((MainActivity) getActivity()).loadChildFragment(SearchFragment.newInstance(s, feed.getId()));
|
||||
}
|
||||
return true;
|
||||
|
@ -224,11 +217,10 @@ public class ItemlistFragment extends ListFragment {
|
|||
|
||||
isUpdatingFeed = MenuItemUtils.updateRefreshMenuItem(menu, R.id.refresh_item, updateRefreshMenuItemChecker);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
if (itemsLoaded) {
|
||||
if (feed != null) {
|
||||
FeedMenuHandler.onPrepareOptionsMenu(menu, feed);
|
||||
}
|
||||
}
|
||||
|
@ -341,11 +333,6 @@ public class ItemlistFragment extends ListFragment {
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
registerForContextMenu(getListView());
|
||||
|
||||
viewsCreated = true;
|
||||
if (itemsLoaded) {
|
||||
onFragmentLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -503,7 +490,7 @@ public class ItemlistFragment extends ListFragment {
|
|||
butShowInfo.setOnClickListener(v -> showFeedInfo());
|
||||
imgvCover.setOnClickListener(v -> showFeedInfo());
|
||||
butShowSettings.setOnClickListener(v -> {
|
||||
if (viewsCreated && itemsLoaded) {
|
||||
if (feed != null) {
|
||||
Intent startIntent = new Intent(getActivity(), FeedSettingsActivity.class);
|
||||
startIntent.putExtra(FeedSettingsActivity.EXTRA_FEED_ID,
|
||||
feed.getId());
|
||||
|
@ -514,7 +501,7 @@ public class ItemlistFragment extends ListFragment {
|
|||
}
|
||||
|
||||
private void showFeedInfo() {
|
||||
if (viewsCreated && itemsLoaded) {
|
||||
if (feed != null) {
|
||||
Intent startIntent = new Intent(getActivity(), FeedInfoActivity.class);
|
||||
startIntent.putExtra(FeedInfoActivity.EXTRA_FEED_ID,
|
||||
feed.getId());
|
||||
|
@ -624,10 +611,7 @@ public class ItemlistFragment extends ListFragment {
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(result -> {
|
||||
feed = result.orElse(null);
|
||||
itemsLoaded = true;
|
||||
if (viewsCreated) {
|
||||
onFragmentLoaded();
|
||||
}
|
||||
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue