Source:
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Intent intent = getActivity().getIntent(); State state; if (intent != null && intent.getExtras() != null && intent.getExtras().getSerializable("state") != null) { state = (State) intent.getExtras().getSerializable("state"); } else { state = ProductFragment.mState; } product = state.getProduct(); imageNames = new ArrayList<>(); imagesRecycler = view.findViewById(R.id.images_recycler); openFoodAPIClient.getImages(product.getCode(), (value, response) -> { if (value && response != null) { JSONObject jsonObject = Utils.createJsonObject(response); JSONObject images = null; try { images = jsonObject.getJSONObject("product").getJSONObject("images"); } catch (JSONException e) { Log.w(ProductPhotosFragment.class.getSimpleName(), "can get product / images in jon", e); } if (images != null) { final JSONArray names = images.names(); if (names != null) { for (int i = 0; i < names.length(); i++) { try { final String namesString = names.getString(i); if (namesString.contains("n") || namesString.contains("f") || namesString.contains("i") || namesString.contains("o")) { continue; } imageNames.add(namesString); } catch (JSONException e) { Log.w(ProductPhotosFragment.class.getSimpleName(), "can get product / images in jon", e); } } } } SharedPreferences preferences = getActivity().getSharedPreferences("login", 0); String login = preferences.getString("user", null); adapter = new ImagesAdapter(getContext(), imageNames, product.getCode(), ProductPhotosFragment.this::onImageClick, product, login != null); imagesRecycler.setAdapter(adapter); imagesRecycler.setLayoutManager(new GridLayoutManager(getContext(), 3)); } }); }

Target:
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); Intent intent = getActivity().getIntent(); State state; if (intent != null && intent.getExtras() != null && intent.getExtras().getSerializable("state") != null) { state = (State) intent.getExtras().getSerializable("state"); } else { state = ProductFragment.mState; } product = state.getProduct(); imageNames = new ArrayList<>(); imagesRecycler = view.findViewById(R.id.images_recycler); openFoodAPIClient.getImages(product.getCode(), (value, response) -> { if (value && response != null) { JSONObject jsonObject = Utils.createJsonObject(response); JSONObject images = null; try { images = jsonObject.getJSONObject("product").getJSONObject("images"); } catch (JSONException e) { Log.w(ProductPhotosFragment.class.getSimpleName(), "can't get product / images in json", e); } if (images != null) { final JSONArray names = images.names(); if (names != null) { for (int i = 0; i < names.length(); i++) { try { final String namesString = names.getString(i); if (namesString.contains("n") || namesString.contains("f") || namesString.contains("i") || namesString.contains("o")) { continue; } imageNames.add(namesString); } catch (JSONException e) { Log.w(ProductPhotosFragment.class.getSimpleName(), "can't get product / images in json", e); } } } } SharedPreferences preferences = getActivity().getSharedPreferences("login", 0); String login = preferences.getString("user", null); adapter = new ImagesAdapter(getContext(), imageNames, product.getCode(), ProductPhotosFragment.this::onImageClick, product, login != null); imagesRecycler.setAdapter(adapter); imagesRecycler.setLayoutManager(new GridLayoutManager(getContext(), 3)); } }); }