Search in sources :

Example 6 with Review

use of com.cmput301w18t05.taskzilla.Review in project Taskzilla by CMPUT301W18T05.

the class ProfileFragment method providerRatingOnClick.

/**
 * providerRatingOnClick
 * upon clicking the provider rating field
 * shows dialog with a list of the user's reviews as the provider
 * @author myapplestory
 */
public void providerRatingOnClick() {
    final AlertDialog mBuilder = new AlertDialog.Builder(this.getContext()).create();
    final View mView = getLayoutInflater().inflate(R.layout.dialog_review_list, null);
    final ListView ReviewsListView = mView.findViewById(R.id.ReviewsListView);
    final TextView ReviewBannerTextView = mView.findViewById(R.id.ReviewsBannerTextView);
    GetReviewsByUserIdRequest request = new GetReviewsByUserIdRequest(user.getId());
    RequestManager.getInstance().invokeRequest(request);
    ArrayList<Review> ReviewsList = new ArrayList<>();
    // taken from https://stackoverflow.com/questions/18448671/how-to-avoid-concurrentmodificationexception-while-removing-elements-from-arr
    // 2018-04-08
    ArrayList<Review> ReviewListTemp = request.getResult();
    while (ReviewListTemp.size() > 0) {
        Iterator<Review> iter = ReviewListTemp.iterator();
        while (iter.hasNext()) {
            Review review = iter.next();
            System.out.println(review.getTitle());
            if (review.getReviewType().equals("r")) {
                iter.remove();
            }
        }
        ReviewsList.addAll(ReviewListTemp);
        RequestManager.getInstance().invokeRequest(request);
        ReviewListTemp = request.getResult();
    }
    if (ReviewsList.isEmpty()) {
        ArrayList<String> tempList = new ArrayList<>();
        tempList.add("No reviews yet :/");
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this.getContext(), android.R.layout.simple_list_item_1, tempList);
        ReviewsListView.setAdapter(adapter);
    } else {
        ArrayAdapter<Review> adapter = new ReviewCustomAdapter(this.getContext(), R.layout.list_view_review, ReviewsList);
        ReviewsListView.setAdapter(adapter);
    }
    String text = "Reviews for " + currentUser.getInstance().getName() + " as a provider";
    ReviewBannerTextView.setText(text);
    mBuilder.setView(mView);
    mBuilder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ArrayList(java.util.ArrayList) Review(com.cmput301w18t05.taskzilla.Review) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) GetReviewsByUserIdRequest(com.cmput301w18t05.taskzilla.request.command.GetReviewsByUserIdRequest) TextView(android.widget.TextView) ReviewCustomAdapter(com.cmput301w18t05.taskzilla.ReviewCustomAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

Review (com.cmput301w18t05.taskzilla.Review)5 AlertDialog (android.support.v7.app.AlertDialog)4 View (android.view.View)4 ArrayAdapter (android.widget.ArrayAdapter)4 ImageView (android.widget.ImageView)4 ListView (android.widget.ListView)4 TextView (android.widget.TextView)4 ReviewCustomAdapter (com.cmput301w18t05.taskzilla.ReviewCustomAdapter)4 GetReviewsByUserIdRequest (com.cmput301w18t05.taskzilla.request.command.GetReviewsByUserIdRequest)4 ArrayList (java.util.ArrayList)4 AddUserRequest (com.cmput301w18t05.taskzilla.request.command.AddUserRequest)1 GetUserRequest (com.cmput301w18t05.taskzilla.request.command.GetUserRequest)1