content: /*
   * Copyright (C) 2017 MINDORKS NEXTGEN PRIVATE LIMITED
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     https://mindorks.com/license/apache-v2
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License
   */
  
  package <%= appPackage %>.ui.main.rating;
  
  
  import <%= appPackage %>.R;
  import <%= appPackage %>.ui.base.BasePresenter;
  import <%= appPackage %>.utils.rx.SchedulerProvider;
  
  import javax.inject.Inject;
  
  import io.reactivex.disposables.CompositeDisposable;
  
  /**
   * Created by janisharali on 22/03/17.
   */
  
  public class RatingDialogPresenter<V extends RatingDialogMvpView,
          I extends RatingDialogMvpInteractor> extends BasePresenter<V, I>
          implements RatingDialogMvpPresenter<V, I> {
  
      public static final String TAG = "RatingDialogPresenter";
  
      private boolean isRatingSecondaryActionShown = false;
  
      @Inject
      public RatingDialogPresenter(I mvpInteractor,
                                   SchedulerProvider schedulerProvider,
                                   CompositeDisposable compositeDisposable) {
          super(mvpInteractor, schedulerProvider, compositeDisposable);
      }
  
      @Override
      public void onRatingSubmitted(final float rating, String message) {
  
          if (rating == 0) {
              getMvpView().showMessage(R.string.rating_not_provided_error);
              return;
          }
  
          if (!isRatingSecondaryActionShown) {
              if (rating == 5) {
                  getMvpView().showPlayStoreRatingView();
                  getMvpView().hideSubmitButton();
                  getMvpView().disableRatingStars();
              } else {
                  getMvpView().showRatingMessageView();
              }
              isRatingSecondaryActionShown = true;
              return;
          }
  
          getMvpView().showLoading();
  
          //for demo
          getMvpView().hideLoading();
          getMvpView().showMessage(R.string.rating_thanks);
          getMvpView().dismissDialog();
  
      }
  
      private void sendRatingDataToServerInBackground(float rating) {
  
      }
  
      @Override
      public void onCancelClicked() {
          getMvpView().dismissDialog();
      }
  
      @Override
      public void onLaterClicked() {
          getMvpView().dismissDialog();
      }
  
      @Override
      public void onPlayStoreRatingClicked() {
          getMvpView().openPlayStoreForRating();
          sendRatingDataToServerInBackground(5);
          getMvpView().dismissDialog();
      }
  }
  