Search in sources :

Example 6 with ThreadListAdapter

use of ingage.ingage.adapters.ThreadListAdapter in project iNGAGE by davis123123.

the class SearchResultArchivedFragment 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);
    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
                }
            }
        }
    });
}
Also used : ThreadListAdapter(ingage.ingage.adapters.ThreadListAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 7 with ThreadListAdapter

use of ingage.ingage.adapters.ThreadListAdapter in project iNGAGE by davis123123.

the class CategoriesPageFragment 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);
    inflateThreads();
    threadListAdapter.setOnLoadMoreListener(new ThreadListAdapter.OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
            Log.d("haint", "Load More");
            rowCount += 10;
            Thread getJSON = new Thread(new Runnable() {

                @Override
                public void run() {
                    getThreadsJSON(rowCount);
                    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();
            }
        }
    });
    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();
                }
            }
        }
    });
}
Also used : ThreadListAdapter(ingage.ingage.adapters.ThreadListAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 8 with ThreadListAdapter

use of ingage.ingage.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);
    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
                }
            }
        }
    });
}
Also used : ThreadListAdapter(ingage.ingage.adapters.ThreadListAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

ThreadListAdapter (ingage.ingage.adapters.ThreadListAdapter)8 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 SessionManager (ingage.ingage.managers.SessionManager)2