use of ingage.ingage20.adapters.ThreadListAdapter in project iNGAGE by davis123123.
the class SearchResultFragment method onViewCreated.
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// TODO fix threadlistadapter for dynamic threads
threadListRecyclerView = (RecyclerView) rootView.findViewById(R.id.rv_posts);
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
threadListRecyclerView.setLayoutManager(layoutManager);
threadListRecyclerView.setAdapter(threadListAdapter);
Log.d("STATE", "serverstring" + json_string);
postThreadButton = (FloatingActionButton) rootView.findViewById(R.id.fab);
postThreadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v == postThreadButton) {
// goInsertThread();
session.updatePage("date");
/* initilize FrontPage Fragment*/
final FragmentManager fragmentManager = getFragmentManager();
final Class fragmentClass = FrontPageFragment.class;
final Fragment fragment = Fragment.instantiate(getContext(), fragmentClass.getName());
fragmentManager.beginTransaction().replace(R.id.main_fragment_container, fragment, fragmentClass.getSimpleName()).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
Toast.makeText(getActivity(), "Returned to main lobby!", Toast.LENGTH_LONG).show();
}
}
});
threadListAdapter.setOnLoadMoreListener(new ThreadListAdapter.OnLoadMoreListener() {
@Override
public void onLoadMore() {
Log.d("haint", "Load More");
// threadListAdapter.list.add(null);
// threadListAdapter.notifyItemInserted(threadListAdapter.list.size() - 1);
rowCount += 10;
Thread getJSON = new Thread(new Runnable() {
@Override
public void run() {
getThreadsJSON(rowCount, searchString);
while (true) {
if (!threadListAdapter.getLoadStat()) {
Log.d("haint", "Load More222");
break;
}
// no longer loading
}
}
});
getJSON.start();
try {
getJSON.join();
threadListAdapter.list.remove(threadListAdapter.list.size() - 1);
threadListAdapter.notifyItemRemoved(threadListAdapter.list.size());
inflateThreads();
} catch (InterruptedException e) {
e.printStackTrace();
}
// getThreadsJSON(rowCount);
// inflateThreads();
/*new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Log.e("haint", "Load More 2");
threadListAdapter.list.remove(threadListAdapter.list.size() - 1);
threadListAdapter.notifyItemRemoved(threadListAdapter.list.size());
rowCount += 10;
getThreadsJSON(rowCount);
inflateThreads();
threadListAdapter.setLoaded();
}
}, 10000);*/
}
});
threadListRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
Log.d("...", "Lastnot Item Wow !");
if (// check for scroll down
dy > 0) {
visibleItemCount = layoutManager.getChildCount();
totalItemCount = layoutManager.getItemCount();
pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
if (!threadListAdapter.isLoading && (visibleItemCount + pastVisiblesItems) >= totalItemCount) {
// if(mOnLoadMoreListener != null){
Log.d("...", "Last Item Wow !");
threadListAdapter.isLoading = true;
threadListAdapter.list.add(null);
threadListAdapter.mOnLoadMoreListener.onLoadMore();
// }
// loading = false;
// rowCount += 10;
// getThreadsJSON(rowCount);
// inflateThreads();
// Do pagination.. i.e. fetch new data
}
}
}
});
}
Aggregations