Search in sources :

Example 1 with ComplaintsAdapter

use of app.insti.adapter.ComplaintsAdapter in project IITB-App by wncc.

the class ComplaintsHomeFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_complaints_home, container, false);
    RecyclerView recyclerViewHome = view.findViewById(R.id.recyclerViewHome);
    homeListAdapter = new ComplaintsAdapter(getActivity(), uID, uProfileUrl);
    swipeContainer = view.findViewById(R.id.swipeContainer);
    error_message_home = view.findViewById(R.id.error_message_home);
    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    recyclerViewHome.setLayoutManager(llm);
    recyclerViewHome.setHasFixedSize(true);
    recyclerViewHome.setAdapter(homeListAdapter);
    recyclerViewHome.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (networkBusy || currentIndex == -1)
                return;
            if (!recyclerView.canScrollVertically(1)) {
                networkBusy = true;
                swipeContainer.setRefreshing(true);
                RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
                retrofitInterface.getAllComplaints(Utils.getSessionIDHeader(), currentIndex, 5).enqueue(new Callback<List<Venter.Complaint>>() {

                    @Override
                    public void onResponse(Call<List<Venter.Complaint>> call, Response<List<Venter.Complaint>> response) {
                        if (response.isSuccessful()) {
                            if (response.body() != null && !response.body().isEmpty()) {
                                complaints.addAll(response.body());
                                initialiseRecyclerView(complaints);
                                currentIndex += 5;
                            } else {
                                currentIndex = -1;
                            }
                        }
                        networkBusy = false;
                        swipeContainer.setRefreshing(false);
                    }

                    @Override
                    public void onFailure(Call<List<Venter.Complaint>> call, Throwable t) {
                        networkBusy = false;
                        swipeContainer.setRefreshing(false);
                    }
                });
            }
        }
    });
    swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            callServerToGetNearbyComplaints();
        }
    });
    swipeContainer.setColorSchemeResources(R.color.colorPrimary);
    if (!isCalled) {
        swipeContainer.post(new Runnable() {

            @Override
            public void run() {
                swipeContainer.setRefreshing(true);
                callServerToGetNearbyComplaints();
            }
        });
        isCalled = true;
    }
    return view;
}
Also used : Call(retrofit2.Call) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ComplaintsAdapter(app.insti.adapter.ComplaintsAdapter) Response(retrofit2.Response) Callback(retrofit2.Callback) RecyclerView(androidx.recyclerview.widget.RecyclerView) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 2 with ComplaintsAdapter

use of app.insti.adapter.ComplaintsAdapter in project IITB-App by wncc.

the class ComplaintsMeFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_complaints_me, container, false);
    RecyclerView recyclerViewMe = view.findViewById(R.id.recyclerViewMe);
    meListAdapter = new ComplaintsAdapter(getActivity(), uID, uProfileUrl);
    swipeContainer = view.findViewById(R.id.swipeContainer);
    error_message_me = view.findViewById(R.id.error_message_me);
    LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    recyclerViewMe.setLayoutManager(llm);
    recyclerViewMe.setHasFixedSize(true);
    recyclerViewMe.setAdapter(meListAdapter);
    swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            getMeItems();
        }
    });
    swipeContainer.setColorSchemeColors(getResources().getColor(R.color.colorPrimary));
    if (!isCalled) {
        swipeContainer.post(new Runnable() {

            @Override
            public void run() {
                swipeContainer.setRefreshing(true);
                getMeItems();
            }
        });
        isCalled = true;
    }
    return view;
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ComplaintsAdapter(app.insti.adapter.ComplaintsAdapter)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)2 ComplaintsAdapter (app.insti.adapter.ComplaintsAdapter)2 RetrofitInterface (app.insti.api.RetrofitInterface)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1