Android Open Source - RateMyApp Rate My App






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;
/* w  ww  .j  a v  a  2  s  . c  o  m*/
import android.app.Activity;
import android.app.FragmentManager;
import android.util.Log;

import com.mariosangiorgio.ratemyapp.actions.Action;

public class RateMyApp {
    private final PreferencesManager preferencesManager;
    private final OptionalValue<Integer> daysUntilPrompt;
    private final OptionalValue<Integer> launchesUntilPrompt;
    private final Action action;

    RateMyApp(
            PreferencesManager preferencesManager,
            OptionalValue<Integer> daysUntilPrompt,
            OptionalValue<Integer> launchesUntilPrompt,
            Action action
    ){
        if(( daysUntilPrompt.hasValue() && daysUntilPrompt.value() < 0 )  || (launchesUntilPrompt.hasValue() && launchesUntilPrompt.value() < 0))
        {
            throw new IllegalArgumentException("Expected non-negative values");
        }
        this.daysUntilPrompt = daysUntilPrompt;
        this.launchesUntilPrompt = launchesUntilPrompt;
        if(preferencesManager == null){
            throw new IllegalArgumentException("preferences manager should not be null");
        }
        this.preferencesManager = preferencesManager;
        if(action == null){
            throw new IllegalArgumentException("action should not be null");
        }
        this.action = action;
    }

    public void appLaunched(Activity activity){
        Log.i("RateMyApp", "Application launch registered");
        FragmentManager fragmentManager = activity.getFragmentManager();
        if(preferencesManager.alertEnabled() && canShowDialog() && fragmentManager != null){
            action.execute(activity, fragmentManager);
        }
        preferencesManager.incrementLaunchCounter();
    }

    private boolean launchCounterConditionsMet(){
        if(launchesUntilPrompt.hasValue()){
            return preferencesManager.launchCounter() >= launchesUntilPrompt.value();
        }
        else{
            return true;
        }
    }

    private boolean daysElapsedConditionsMet(){
        if(daysUntilPrompt.hasValue()){
            return preferencesManager.daysFromFirstLaunch() >= daysUntilPrompt.value();
        }
        else{
            return true;
        }
    }

    private boolean canShowDialog() {
        return launchCounterConditionsMet() && daysElapsedConditionsMet();
    }
}




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