package de.jeisfeld.augendiagnoselib;
import android.app.Activity;
import java.util.concurrent.TimeUnit;
import de.jeisfeld.augendiagnoselib.Application.AuthorizationLevel;
import de.jeisfeld.augendiagnoselib.util.EncryptionUtil;
import de.jeisfeld.augendiagnoselib.util.PreferenceUtil;
/**
* Utility interface for Settings which are application specific.
*/
public abstract class ApplicationSettings {
/**
* Find out if the user is authorized to use all functionality of the app.
*
* @return The authorization level of the user.
*/
// OVERRIDABLE
protected AuthorizationLevel getAuthorizationLevel() {
String userKey = PreferenceUtil.getSharedPreferenceString(R.string.key_user_key);
boolean hasPremiumPack = PreferenceUtil.getSharedPreferenceBoolean(R.string.key_internal_has_premium_pack);
boolean hasUnlockerApp = PreferenceUtil.getSharedPreferenceBoolean(R.string.key_internal_has_unlocker_app);
boolean isAuthorizedUser = hasPremiumPack || hasUnlockerApp || EncryptionUtil.validateUserKey(userKey);
if (isAuthorizedUser) {
return AuthorizationLevel.FULL_ACCESS;
}
long firstStartTime = PreferenceUtil.getSharedPreferenceLong(R.string.key_statistics_firststarttime, -1);
return System.currentTimeMillis() < firstStartTime + TimeUnit.DAYS.toMillis(14) // MAGIC_NUMBER
? AuthorizationLevel.TRIAL_ACCESS : AuthorizationLevel.NO_ACCESS;
}
/**
* Start the application.
*
* @param triggeringActivity the triggering activity.
*/
public abstract void startApplication(Activity triggeringActivity);
}