Android Open Source - RateMyApp Rate My App Builder






From Project

Back to project page RateMyApp.

License

The source code is released under:

MIT License

If you think the Android project RateMyApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mariosangiorgio.ratemyapp;
//  ww  w  .  j av  a2  s.co  m
import android.content.Context;
import android.text.TextUtils;

import com.mariosangiorgio.ratemyapp.actions.Action;
import com.mariosangiorgio.ratemyapp.actions.ShowDialogAction.ShowDialogActionFactory;

public class RateMyAppBuilder {
    private int launchesBeforeAlert = -1;
    private int daysBeforeAlert = -1;
    private Action notificationAction = null;
    private String emailAddress = null;
    private String emailMessage = null;

    public RateMyAppBuilder setNotificationAction(Action notificationAction){
        if(notificationAction == null){
            throw new IllegalArgumentException("Not-null notificationAction expected");
        }
        this.notificationAction = notificationAction;
        return this;
    }

    public RateMyAppBuilder setLaunchesBeforeAlert(int launchesBeforeAlert){
        if(launchesBeforeAlert < 0){
            throw new IllegalArgumentException("Expected a non-negative number");
        }
        this.launchesBeforeAlert = launchesBeforeAlert;
        return this;

    }

    public RateMyAppBuilder setDaysBeforeAlert(int daysBeforeAlert){
        if(daysBeforeAlert < 0){
            throw new IllegalArgumentException("Expected a non-negative number");
        }
        this.daysBeforeAlert = daysBeforeAlert;
        return this;
    }

    private boolean isValid(String emailAddress){
        return !TextUtils.isEmpty(emailAddress) &&
                android.util.Patterns.EMAIL_ADDRESS.matcher(emailAddress).matches();
    }

    public RateMyAppBuilder setEmailAddress(String emailAddress){
        if(!isValid(emailAddress)){
            throw new IllegalArgumentException("Invalid email address "+emailAddress);
        }
        this.emailAddress = emailAddress;
        return this;
    }

    public RateMyAppBuilder setEmailMessage(String emailMessage) {
        this.emailMessage = emailMessage;
        return this;
    }

    public RateMyApp build(Context context) {
        PreferencesManager preferencesManager = SharedPreferencesManager.buildFromContext(context);
        return build(preferencesManager);
    }
    
    public RateMyApp build(PreferencesManager preferencesManager){
        OptionalValue<Integer> daysBeforeAlert = this.daysBeforeAlert == -1 ?
                new OptionalValue<Integer>() : new OptionalValue<Integer>(this.daysBeforeAlert);
        OptionalValue<Integer> launchesBeforeAlert = this.launchesBeforeAlert == -1 ?
                new OptionalValue<Integer>() : new OptionalValue<Integer>(this.launchesBeforeAlert);

        if(notificationAction == null){

            if (TextUtils.isEmpty(emailAddress)) {
                notificationAction = ShowDialogActionFactory.getWantToRateAction(preferencesManager);
            } else {
                notificationAction = ShowDialogActionFactory.getWantToRateAction(preferencesManager, emailAddress, emailMessage);
            }
        }
        return new RateMyApp(preferencesManager, daysBeforeAlert, launchesBeforeAlert, notificationAction);
    }
}




Java Source Code List

com.mariosangiorgio.ratemyapp.ContextUtils.java
com.mariosangiorgio.ratemyapp.OptionalValue.java
com.mariosangiorgio.ratemyapp.PreferencesManager.java
com.mariosangiorgio.ratemyapp.RateMyAppBuilder.java
com.mariosangiorgio.ratemyapp.RateMyApp.java
com.mariosangiorgio.ratemyapp.SharedPreferencesManager.java
com.mariosangiorgio.ratemyapp.actions.Action.java
com.mariosangiorgio.ratemyapp.actions.OpenPlayStoreAction.java
com.mariosangiorgio.ratemyapp.actions.ShowDialogAction.java
com.mariosangiorgio.ratemyapp.dialogs.AbstractDialogFragment.java
com.mariosangiorgio.ratemyapp.dialogs.NumberOfStarsDialog.java
com.mariosangiorgio.ratemyapp.dialogs.SendEmailDialog.java
com.mariosangiorgio.ratemyapp.dialogs.WantToRateDialog.java
com.mariosangiorgio.ratemyapp.listeners.DialogClickListener.java
com.mariosangiorgio.ratemyapp.listeners.NumberOfStarsDialogListener.java
com.mariosangiorgio.ratemyapp.listeners.SentEmailDialogListener.java
com.mariosangiorgio.ratemyapp.listeners.WantToRateDialogListener.java
com.mariosangiorgio.ratemyapp.sample.MainActivity.java