Added remote param

This commit is contained in:
Alexey Kulish 2016-11-13 11:51:02 +03:00 committed by Victor Shcherb
parent e71266bbf6
commit 1e57d9ec8d
3 changed files with 76 additions and 16 deletions

View file

@ -23,6 +23,7 @@ import android.view.accessibility.AccessibilityManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin;
@ -60,7 +61,9 @@ import java.io.PrintStream;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import btools.routingapp.BRouterServiceConnection;
import btools.routingapp.IBRouterService;
@ -69,6 +72,8 @@ public class OsmandApplication extends MultiDexApplication {
public static final String EXCEPTION_PATH = "exception.log"; //$NON-NLS-1$
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandApplication.class);
public static final String SHOW_PLUS_VERSION_PARAM = "show_plus_version";
final AppInitializer appInitializer = new AppInitializer(this);
OsmandSettings osmandSettings = null;
OsmAndAppCustomization appCustomization;
@ -149,6 +154,7 @@ public class OsmandApplication extends MultiDexApplication {
// targetPointsHelper.clearPointToNavigate(false);
// }
initRemoteConfig();
startApplication();
System.out.println("Time to start application " + (System.currentTimeMillis() - timeToStart) + " ms. Should be less < 800 ms");
timeToStart = System.currentTimeMillis();
@ -792,4 +798,64 @@ public class OsmandApplication extends MultiDexApplication {
e.printStackTrace();
}
}
public void initRemoteConfig() {
try {
if(Version.isGooglePlayEnabled(this) && Version.isFreeVersion(this)) {
Class<?> cl = Class.forName("com.google.firebase.remoteconfig.FirebaseRemoteConfig");
Method mm = cl.getMethod("getInstance");
Object inst = mm.invoke(null);
Method log = cl.getMethod("setDefaults", Map.class);
Map<String, Object> defaults = new HashMap<>();
defaults.put(SHOW_PLUS_VERSION_PARAM, Boolean.FALSE);
log.invoke(inst, defaults);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void fetchRemoteParams() {
try {
if(Version.isGooglePlayEnabled(this) && Version.isFreeVersion(this)) {
Class<?> cl = Class.forName("com.google.firebase.remoteconfig.FirebaseRemoteConfig");
Method mm = cl.getMethod("getInstance");
Object inst = mm.invoke(null);
Method log = cl.getMethod("fetch");
log.invoke(inst);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void activateFetchedRemoteParams() {
try {
if(Version.isGooglePlayEnabled(this) && Version.isFreeVersion(this)) {
Class<?> cl = Class.forName("com.google.firebase.remoteconfig.FirebaseRemoteConfig");
Method mm = cl.getMethod("getInstance");
Object inst = mm.invoke(null);
Method log = cl.getMethod("activateFetched");
log.invoke(inst);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean getRemoteBoolean(String key, boolean defaultValue) {
try {
if(Version.isGooglePlayEnabled(this) && Version.isFreeVersion(this)) {
Class<?> cl = Class.forName("com.google.firebase.remoteconfig.FirebaseRemoteConfig");
Method mm = cl.getMethod("getInstance");
Object inst = mm.invoke(null);
Method log = cl.getMethod("getBoolean", String.class);
Boolean res = (Boolean)log.invoke(inst, key);
return res == null ? defaultValue : res;
}
} catch (Exception e) {
e.printStackTrace();
}
return defaultValue;
}
}

View file

@ -121,6 +121,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
protected void onCreate(Bundle savedInstanceState) {
getMyApplication().applyTheme(this);
super.onCreate(savedInstanceState);
getMyApplication().fetchRemoteParams();
downloadThread = getMyApplication().getDownloadThread();
DownloadResources indexes = getDownloadThread().getIndexes();
if (!indexes.isDownloadedFromInternet) {

View file

@ -1,51 +1,44 @@
package net.osmand.plus.download.ui;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper;
import android.view.View;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivity.FreeVersionDialog;
import net.osmand.util.Algorithms;
import static net.osmand.plus.OsmandApplication.SHOW_PLUS_VERSION_PARAM;
public class FreeVersionDialogFragment extends DialogFragment {
private FreeVersionDialog dialog;
@SuppressLint("HardwareIds")
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
OsmandApplication app = (OsmandApplication) getActivity().getApplication();
app.activateFetchedRemoteParams();
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.OsmandDarkTheme));
builder.setNegativeButton(R.string.later, null);
View view = getActivity().getLayoutInflater().inflate(R.layout.free_version_banner, null);
boolean hidePlus = false;
try {
String devId = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
if (!Algorithms.isEmpty(devId)) {
hidePlus = devId.hashCode() % 20 == 8;
}
} catch (Exception e) {
// ignored
}
boolean hidePlus = !app.getRemoteBoolean(SHOW_PLUS_VERSION_PARAM, false);
view.findViewById(R.id.osmLiveLayoutTopDivider).setVisibility(hidePlus ? View.GONE : View.VISIBLE);
view.findViewById(R.id.fullVersionLayout).setVisibility(hidePlus ? View.GONE : View.VISIBLE);
builder.setView(view);
dialog = new DownloadActivity.FreeVersionDialog(view, getDownloadActivity(), true);
dialog.initFreeVersionBanner();
dialog.expandBanner();
return builder.create();
}
DownloadActivity getDownloadActivity() {
return (DownloadActivity) getActivity();
}