androidx.appcompat.widget.AppCompatRatingBar Java Examples

The following examples show how to use androidx.appcompat.widget.AppCompatRatingBar. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DialogUtils.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
public void showRateDialog(@NonNull Activity activity, @NonNull String appName,
    @NonNull String packageName, @Nullable String storeName,
    @Nullable Action0 onPositiveCallback) {

  if (!accountManager.isLoggedIn()) {
    ShowMessage.asSnack(activity, R.string.you_need_to_be_logged_in, R.string.login,
        snackView -> {
          accountNavigator.navigateToAccountView(AccountAnalytics.AccountOrigins.RATE_DIALOG);
        }, Snackbar.LENGTH_SHORT);

    return;
  }

  final View view = LayoutInflater.from(activity)
      .inflate(R.layout.dialog_rate_app, null);

  final TextView titleTextView = (TextView) view.findViewById(R.id.title);
  final AppCompatRatingBar reviewRatingBar =
      (AppCompatRatingBar) view.findViewById(R.id.rating_bar);
  final TextInputLayout reviewTextInputLayout =
      (TextInputLayout) view.findViewById(R.id.input_layout_review);
  final Button cancelBtn = (Button) view.findViewById(R.id.cancel_button);
  final Button rateBtn = (Button) view.findViewById(R.id.rate_button);

  titleTextView.setText(String.format(LOCALE, activity.getString(R.string.rate_app), appName));

  AlertDialog.Builder builder = new AlertDialog.Builder(activity).setView(view);
  AlertDialog dialog = builder.create();

  cancelBtn.setOnClickListener(v -> dialog.dismiss());
  rateBtn.setOnClickListener(v -> {

    AptoideUtils.SystemU.hideKeyboard(activity);

    final String reviewText = reviewTextInputLayout.getEditText()
        .getText()
        .toString();
    final int reviewRating = Math.round(reviewRatingBar.getRating());

    dialog.dismiss();

    final SuccessRequestListener<BaseV7Response> successRequestListener = response -> {
      if (response.isOk()) {
        Logger.getInstance()
            .d(TAG, "review added");
        ShowMessage.asSnack(activity, R.string.review_success);
        ManagerPreferences.setForceServerRefreshFlag(true, sharedPreferences);
        if (onPositiveCallback != null) {
          onPositiveCallback.call();
        }
      } else {
        ShowMessage.asSnack(activity, R.string.error_occured);
      }
    };

    final ErrorRequestListener errorRequestListener = e -> {
      CrashReport.getInstance()
          .log(e);
      ShowMessage.asSnack(activity, R.string.error_occured);
    };

    if (storeName != null) {
      PostReviewRequest.of(storeName, packageName, reviewText, reviewRating, bodyInterceptor,
          httpClient, converterFactory, isAppInstalled(packageName), tokenInvalidator,
          sharedPreferences)
          .execute(successRequestListener, errorRequestListener);
    } else {
      PostReviewRequest.of(packageName, reviewText, reviewRating, bodyInterceptor, httpClient,
          converterFactory, isAppInstalled(packageName), tokenInvalidator, sharedPreferences)
          .execute(successRequestListener, errorRequestListener);
    }
  });

  // create and show rating dialog
  dialog.show();
}
 
Example #2
Source File: RatingTotalsLayout.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
public RatingTotalsLayout(View view) {
  usersVoted = (TextView) view.findViewById(R.id.users_voted);
  ratingValue = (TextView) view.findViewById(R.id.rating_value);
  ratingBar = (AppCompatRatingBar) view.findViewById(R.id.rating_bar);
}