Skip to content

Instantly share code, notes, and snippets.

@jjhesk
Created February 23, 2016 08:14
Show Gist options
  • Save jjhesk/7ed3ebd979b2c93f5fa5 to your computer and use it in GitHub Desktop.
Save jjhesk/7ed3ebd979b2c93f5fa5 to your computer and use it in GitHub Desktop.
package com.hypetrak.editorial.pages.list_2016;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.util.Log;
import android.view.View;
import com.hypebeast.sdk.api.exception.ApiException;
import com.hypebeast.sdk.api.model.hypetrak.htpost;
import com.hypebeast.sdk.api.resources.ht.hTrak;
import com.hypebeast.sdk.clients.HTEditorialClient;
import com.hypetrak.editorial.Dialog.ErrorMessage;
import com.hypetrak.editorial.R;
import com.hypetrak.editorial.life.HTUtil;
import com.hypetrak.editorial.life.LifeCycleApp;
import com.marshalchen.ultimaterecyclerview.UltimateRecyclerView;
import com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder;
import com.marshalchen.ultimaterecyclerview.quickAdapter.easyRegularAdapter;
import com.squareup.picasso.Picasso;
import java.util.List;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
/**
* Created by hesk on 15/2/16.
*/
public abstract class listLinear<ADAP extends easyRegularAdapter, bind extends UltimateRecyclerviewViewHolder> extends catelogLinear<ADAP, bind> implements UltimateRecyclerView.OnLoadMoreListener {
/*
public final static String URL = "data_url", FRAGMENTTITLE = "fragment_title", FRAGMENTTITLE_RESID = "title_idres", LIST_WITH_AD = "HasAdOnIt", SLUG = "slug", REQUEST_TYPE = "typerequest", TAGLABEL = "newfeed", SEARCH_WORD = "search_wd";
protected Picasso mpicasso;
protected HTEditorialClient client;
protected hTrak interfacerequest;
protected LifeCycleApp app;
protected ADAP listadapter;
private int requestType;
protected int getRequestType() {
return requestType;
}
public final static int
MAJOR = -1,
MAJOR_FILTERED = -2,
CATE = -5,
TAG = -6,
UNSET = -9,
LATEST = -10,
BROWSERABLE_FULL_URL = -7,
SEARCH = -8;
public static Bundle con_latest(final @IdRes int title) {
final Bundle n = new Bundle();
n.putInt(FRAGMENTTITLE_RESID, title);
n.putInt(REQUEST_TYPE, LATEST);
return n;
}
public static Bundle con_cate(final @IdRes int title, final String cate_item) {
final Bundle n = new Bundle();
n.putInt(FRAGMENTTITLE_RESID, title);
n.putInt(REQUEST_TYPE, CATE);
n.putString(SLUG, cate_item);
return n;
}
public static Bundle con_cate(final String cate_item) {
final Bundle n = new Bundle();
n.putInt(REQUEST_TYPE, CATE);
n.putString(SLUG, cate_item);
return n;
}
public static Bundle con_tag(final String cate_item) {
final Bundle n = new Bundle();
n.putInt(REQUEST_TYPE, TAG);
n.putString(SLUG, cate_item);
return n;
}
public static Bundle con_major(final String major_tab) {
final Bundle n = new Bundle();
n.putInt(REQUEST_TYPE, MAJOR);
n.putString(SLUG, major_tab);
return n;
}
public static Bundle conSearch(final String e) {
final Bundle n = new Bundle();
n.putInt(REQUEST_TYPE, SEARCH);
n.putString(SEARCH_WORD, e);
return n;
}
protected void successResponse(List<htpost> list, Response res) {
try {
setTotalPages(HTEditorialClient.totalPages(res));
madapter.insert(list);
afterNotifiedAdapter();
} catch (Exception e) {
if (getActivity() != null)
ErrorMessage.alert(e.getMessage(), getChildFragmentManager());
}
}
private void afterNotifiedAdapter() {
if (shouldEnableLoadMore() && !listview_layout.isLoadMoreEnabled()) {
listview_layout.reenableLoadmore();
Log.d("LoadMore", "should enable load more");
}
if (!shouldEnableLoadMore() && listview_layout.isLoadMoreEnabled()) {
listview_layout.disableLoadmore();
Log.d("LoadMore", "should disable load more");
}
hideLoadingCircle();
}
protected final Callback<List<htpost>> post_response = new Callback<List<htpost>>() {
@Override
public void success(List<htpost> list, Response response) {
successResponse(list, response);
}
@Override
public void failure(RetrofitError error) {
Log.d("tager", error.getMessage());
if (getActivity() != null)
ErrorMessage.alert(error.getMessage(), getChildFragmentManager());
}
};
protected final Callback<List<htpost>> search_response = new Callback<List<htpost>>() {
@Override
public void success(List<htpost> responsePostFromSearch, Response response) {
// setSearchKeyword(r);
successResponse(responsePostFromSearch, response);
}
@Override
public void failure(RetrofitError error) {
if (getActivity() != null)
ErrorMessage.alert(error.getMessage(), getChildFragmentManager(), new Runnable() {
@Override
public void run() {
getActivity().finish();
}
});
}
};
@Override
protected void onClickItem(final long post_id) {
HTUtil.routeSinglePage(post_id, getActivity());
}
@Override
protected void onClickItem(final String route) {
HTUtil.routeSinglePage(route, getActivity());
}
@Override
protected int getFragmentResId() {
return R.layout.n_content_fragment_image_list;
}
@Override
protected int getUltimate_recycler_viewResId() {
return R.id.ultimate_recycler_view;
}
@Override
protected int getColumn() {
return 0;
}
@Override
protected void setUltimateRecyclerViewExtra(UltimateRecyclerView listview, ADAP madapter) {
// listview.enableLoadmore();
listview.setOnLoadMoreListener(this);
listview.setLoadMoreView(R.layout.custom_bottom_progressbar);
listview.setEmptyView(R.layout.emptyview,
UltimateRecyclerView.EMPTY_CLEAR_ALL,
UltimateRecyclerView.STARTWITH_ONLINE_ITEMS);
}
*/
/**
* step 1:
* takes the arguement form the intent bundle and determine if there is a need to queue a loading process. If that is a yes then we need to load up the data before displaying the list out.
*
* @param r and the data bundle
* @return tells if there is a loading process to be done before hand
*//*
@Override
protected boolean onArguments(Bundle r) {
requestType = r.getInt(REQUEST_TYPE, UNSET);
setFullEndPoint(r.getString(URL, ""));
//setTag_keyword(r.getString(SLUG, ""));
return requestType == UNSET ? false : true;
}
protected int getItemsShownPerPage() {
return 20;
}
protected void makeInitalQuest() throws ApiException {
setCurrentPage(1);
try {
makeQuest();
} catch (ApiException e) {
e.printStackTrace();
}
}
protected void makeQuest() throws ApiException {
if (requestType == LATEST) {
interfacerequest.lateset(getPagePerItems(), "DESC", getCurrentPage(), post_response);
} else if (requestType == CATE) {
interfacerequest.category(getTagKeyword(), getCurrentPage(), getPagePerItems(), "DESC", post_response);
} else if (requestType == SEARCH) {
triggerSearch(getArguments().getString(SEARCH_WORD));
} else if (requestType == TAG) {
interfacerequest.tag(getTagKeyword(), getCurrentPage(), getPagePerItems(), "DESC", post_response);
}
}
private void triggerSearch(final String searchWord) {
try {
interfacerequest.search(getSearchKeyword(), 1, getPagePerItems(), "DESC", search_response);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void triggerNewSearchKeyWord(String word) {
super.triggerNewSearchKeyWord(word);
requestType = SEARCH;
setCurrentPage(1);
setTotalPages(1);
try {
makeQuest();
showLoadingCircle();
} catch (ApiException e) {
e.printStackTrace();
}
}
*/
/**
* more items to be loaded
*
* @param itemsCount current items
* @param maxLastVisiblePosition max last position
*//*
public void loadMore(int itemsCount, int maxLastVisiblePosition) {
nextPage();
try {
makeQuest();
} catch (ApiException e) {
e.printStackTrace();
}
}
@Override
protected void renderviewlayout(View view) throws Exception {
getProgressbar(view, R.id.bottom_progress_bar);
super.renderviewlayout(view);
}
protected void beforeMakingQuest() {
}
@Override
protected void loadDataInitial(ADAP list) {
try {
mpicasso = Picasso.with(getActivity());
client = HTEditorialClient.getInstance();
interfacerequest = client.createPostsFeed();
beforeMakingQuest();
makeInitalQuest();
} catch (ApiException e) {
if (getActivity() != null)
ErrorMessage.alert(e.getMessage(), getChildFragmentManager());
} catch (Exception e) {
if (getActivity() != null)
ErrorMessage.alert(e.getMessage(), getChildFragmentManager());
}
}
@LayoutRes
protected int getItemLayoutId() {
return R.layout.superlist_recycle_item_2;
}
protected abstract void binddata(bind holderm, final T data, int position);
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment