Merge pull request #3713 from ByteHamster/initialize-variable-before-use

Initialize variable directly before using
This commit is contained in:
H. Lehmann 2020-01-01 21:32:41 +01:00 committed by GitHub
commit c668464968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 7 deletions

View File

@ -50,9 +50,6 @@ public class ItemPagerFragment extends Fragment {
* @return The ItemFragment instance * @return The ItemFragment instance
*/ */
public static ItemPagerFragment newInstance(long[] feeditems, int feedItemPos) { public static ItemPagerFragment newInstance(long[] feeditems, int feedItemPos) {
if (feeditems.length <= feedItemPos) {
throw new IllegalArgumentException("Trying to show a feed item that is out of the list");
}
ItemPagerFragment fragment = new ItemPagerFragment(); ItemPagerFragment fragment = new ItemPagerFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLongArray(ARG_FEEDITEMS, feeditems); args.putLongArray(ARG_FEEDITEMS, feeditems);
@ -62,7 +59,6 @@ public class ItemPagerFragment extends Fragment {
} }
private long[] feedItems; private long[] feedItems;
private int feedItemPos;
private FeedItem item; private FeedItem item;
private Disposable disposable; private Disposable disposable;
@ -70,9 +66,6 @@ public class ItemPagerFragment extends Fragment {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setHasOptionsMenu(true); setHasOptionsMenu(true);
feedItems = getArguments().getLongArray(ARG_FEEDITEMS);
feedItemPos = getArguments().getInt(ARG_FEEDITEM_POS);
} }
@Override @Override
@ -81,6 +74,9 @@ public class ItemPagerFragment extends Fragment {
super.onCreateView(inflater, container, savedInstanceState); super.onCreateView(inflater, container, savedInstanceState);
View layout = inflater.inflate(R.layout.feeditem_pager_fragment, container, false); View layout = inflater.inflate(R.layout.feeditem_pager_fragment, container, false);
feedItems = getArguments().getLongArray(ARG_FEEDITEMS);
int feedItemPos = getArguments().getInt(ARG_FEEDITEM_POS);
ViewPager pager = layout.findViewById(R.id.pager); ViewPager pager = layout.findViewById(R.id.pager);
// FragmentStatePagerAdapter documentation: // FragmentStatePagerAdapter documentation:
// > When using FragmentStatePagerAdapter the host ViewPager must have a valid ID set. // > When using FragmentStatePagerAdapter the host ViewPager must have a valid ID set.