Created
April 19, 2016 09:21
-
-
Save anstaendig/2d7769172a7bbc4c80613cd682fcb23b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This Fragment is used to show a list of outfits in a recyclerview. For the blogger app integration | |
* a type needs to be provided for the different outfit categories (ready for review, draft, live, | |
* on hold). This might be reused for any kind of OutfitList. | |
*/ | |
public class OutfitListFragment extends Fragment { | |
// Constants | |
private static final String TAG = "OutfitListFragment"; | |
private static final String TYPE = "type"; | |
// Member variables | |
@InjectView(R.id.outflit_list) | |
RecyclerView mOutfitList; | |
private BloggerAppOutfitResponse.Type mType; | |
private boolean mIsLoading = false; | |
private BloggerAppOutfitAdapter mOutfitAdapter; | |
private LinearLayoutManager mLayoutManager; | |
private BloggerAppOutfitLoader mOutfitLoader = null; | |
private BloggerAppOutfitTypeFilterConfiguration mFilterConfiguration; | |
// Callbacks | |
final private LoaderCallback<BloggerAppOutfitResponse> mCallbackOutfits = new LoaderCallback<BloggerAppOutfitResponse>() { | |
@Override | |
public void onItemsLoaded(BloggerAppOutfitResponse response, LoaderDirection resultFor) { | |
mIsLoading = false; | |
if (response.list.size() == 0) { | |
Snackbar.make(getView(), R.string.general_message_request_failed_text, Snackbar.LENGTH_SHORT).show(); | |
} else { | |
mOutfitAdapter.addAll(response.list); | |
} | |
} | |
}; | |
// Constructors | |
public OutfitListFragment() { | |
// Required empty public constructor | |
} | |
// Factory methods | |
public static OutfitListFragment newInstance(BloggerAppOutfitResponse.Type type) { | |
OutfitListFragment fragment = new OutfitListFragment(); | |
Bundle args = new Bundle(); | |
args.putSerializable(TYPE, type); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
// Lifecycle methods | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if (getArguments() != null) { | |
mType = (BloggerAppOutfitResponse.Type) getArguments().getSerializable(TYPE); | |
} | |
mFilterConfiguration = new BloggerAppOutfitTypeFilterConfiguration(mType); | |
mOutfitLoader = new BloggerAppOutfitLoader(mCallbackOutfits); | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
return inflater.inflate(R.layout.fragment_blogger_app_list, container, false); | |
} | |
@Override | |
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | |
super.onViewCreated(view, savedInstanceState); | |
ButterKnife.inject(this, view); | |
} | |
@Override | |
public void onResume() { | |
super.onResume(); | |
Log.d(TAG, "onResume: Type: " + mType); | |
mLayoutManager = new LinearLayoutManager(getActivity()); | |
mOutfitList.setLayoutManager(mLayoutManager); | |
mOutfitAdapter = new BloggerAppOutfitAdapter(); | |
mOutfitList.setAdapter(mOutfitAdapter); | |
loadOutfits(); | |
} | |
// Helper methods | |
private void loadOutfits() { | |
mIsLoading = true; | |
mOutfitLoader.reloadItems(mFilterConfiguration); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment