From 38796aeb892379b8c2b7e4e1d7af00c4c050e8dc Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Thu, 23 Nov 2017 11:34:52 +0100 Subject: Add Splash StartActivity * added Splash StartActivity to handle updates and initialization * created global Constants * renamed EIP Constants --- .../java/se/leap/bitmaskclient/StartActivity.java | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 app/src/main/java/se/leap/bitmaskclient/StartActivity.java (limited to 'app/src/main/java/se/leap/bitmaskclient/StartActivity.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java new file mode 100644 index 00000000..410daf7d --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -0,0 +1,115 @@ +package se.leap.bitmaskclient; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.support.annotation.IntDef; +import android.support.annotation.Nullable; +import android.util.Log; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import de.blinkt.openvpn.core.VpnStatus; +import se.leap.bitmaskclient.userstatus.User; + +/** + * Activity shown at startup. Evaluates if App is started for the first time or has been upgraded + * and acts and calls another activity accordingly. + * + */ +public class StartActivity extends Activity { + public static final String TAG = Dashboard.class.getSimpleName(); + + @Retention(RetentionPolicy.SOURCE) + @IntDef({FIRST, NORMAL, UPGRADE, DOWNGRADE}) + private @interface StartupMode {} + private static final int FIRST = 0; + private static final int NORMAL = 1; + private static final int UPGRADE = 2; + private static final int DOWNGRADE = 3; + + /** + * check if normal start, first run, up or downgrade + * @return @StartupMode + */ + @StartupMode + private int checkAppStart() { + SharedPreferences preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); + try { + int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; + int lastDetectedVersion = preferences.getInt(Constants.PREFERENCES_APP_VERSION, -1); + + // versions do match -> normal start + if (versionCode == lastDetectedVersion) { + Log.d(TAG, "App start was: NORMAL START"); + return NORMAL; + } + + // something changed -> save current version + preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply(); + + // no previous app version -> first start + if (lastDetectedVersion == -1 ) { + Log.d(TAG, "App start was: FIRST START"); + return FIRST; + } + + // version has increased -> upgrade + if (versionCode > lastDetectedVersion) { + Log.d(TAG, "App start was: UPGRADE"); + return UPGRADE; + } + // version has decreased -> downgrade + if (versionCode < lastDetectedVersion) { + Log.d(TAG, "App start was: DOWNGRADE"); + return DOWNGRADE; + } + + } catch (PackageManager.NameNotFoundException e) { + Log.d(TAG, "Splash screen didn't find any " + getPackageName() + " package"); + } + + return NORMAL; + } + + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Intent intent; + + Log.d(TAG, "Started"); + + switch (checkAppStart()) { + case NORMAL: + break; + + case FIRST: + // TODO start ProfileCreation & replace below code + intent = new Intent(this, Dashboard.class); + startActivity(intent); + break; + + case UPGRADE: + // TODO appropriate data copying + // TODO show donation dialog + break; + + case DOWNGRADE: + // TODO think how and why this should happen and what todo + break; + } + + // initialize app necessities + ProviderAPICommand.initialize(this); + VpnStatus.initLogCache(getApplicationContext().getCacheDir()); + User.init(getString(R.string.default_username)); + + // go to Dashboard + intent = new Intent(this, Dashboard.class); + startActivity(intent); + } +} -- cgit v1.2.3 From da7293252f197e9b54c1abd8127b4abe45b95110 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Wed, 6 Dec 2017 01:58:21 +0100 Subject: move constants * move EIPConstants to Constants * unify EIPConstants where possible * create Updater --- .../java/se/leap/bitmaskclient/StartActivity.java | 116 +++++++++++++-------- 1 file changed, 70 insertions(+), 46 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/StartActivity.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index 410daf7d..ade43701 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -13,6 +13,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import de.blinkt.openvpn.core.VpnStatus; +import se.leap.bitmaskclient.updates.ConstantUnification; import se.leap.bitmaskclient.userstatus.User; /** @@ -31,40 +32,76 @@ public class StartActivity extends Activity { private static final int UPGRADE = 2; private static final int DOWNGRADE = 3; + private int versionCode; + private int previousVersionCode; + + private SharedPreferences preferences; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); + + Log.d(TAG, "Started"); + + switch (checkAppStart()) { + case NORMAL: + break; + + case FIRST: + // TODO start ProfileCreation & replace below code + break; + + case UPGRADE: + executeUpgrade(); + // TODO show donation dialog + break; + + case DOWNGRADE: + // TODO think how and why this should happen and what todo + break; + } + + // initialize app necessities + ProviderAPICommand.initialize(this); + VpnStatus.initLogCache(getApplicationContext().getCacheDir()); + User.init(getString(R.string.default_username)); + + // go to Dashboard + Intent intent = new Intent(this, Dashboard.class); + startActivity(intent); + } + /** * check if normal start, first run, up or downgrade * @return @StartupMode */ @StartupMode private int checkAppStart() { - SharedPreferences preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); try { - int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; - int lastDetectedVersion = preferences.getInt(Constants.PREFERENCES_APP_VERSION, -1); + versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; + previousVersionCode = preferences.getInt(Constants.PREFERENCES_APP_VERSION, -1); // versions do match -> normal start - if (versionCode == lastDetectedVersion) { + if (versionCode == previousVersionCode) { Log.d(TAG, "App start was: NORMAL START"); return NORMAL; } - // something changed -> save current version - preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply(); - // no previous app version -> first start - if (lastDetectedVersion == -1 ) { - Log.d(TAG, "App start was: FIRST START"); + if (previousVersionCode == -1 ) { + Log.d(TAG, "FIRST START"); return FIRST; } // version has increased -> upgrade - if (versionCode > lastDetectedVersion) { - Log.d(TAG, "App start was: UPGRADE"); + if (versionCode > previousVersionCode) { + Log.d(TAG, "UPGRADE"); return UPGRADE; } // version has decreased -> downgrade - if (versionCode < lastDetectedVersion) { - Log.d(TAG, "App start was: DOWNGRADE"); + if (versionCode < previousVersionCode) { + Log.d(TAG, "DOWNGRADE"); return DOWNGRADE; } @@ -75,41 +112,28 @@ public class StartActivity extends Activity { return NORMAL; } - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Intent intent; - - Log.d(TAG, "Started"); - - switch (checkAppStart()) { - case NORMAL: - break; - - case FIRST: - // TODO start ProfileCreation & replace below code - intent = new Intent(this, Dashboard.class); - startActivity(intent); - break; - - case UPGRADE: - // TODO appropriate data copying - // TODO show donation dialog - break; - - case DOWNGRADE: - // TODO think how and why this should happen and what todo - break; + /** + * execute necessary updates for version change + */ + private void executeUpgrade() { + if (passedMilestone(VersionMilestone.MULTIPLE_PROFILES)) { + // TODO prepare usage of multiple profiles + } + if (passedMilestone(VersionMilestone.CONSTANT_UNIFICATION)) { + ConstantUnification.upgrade(preferences); } - // initialize app necessities - ProviderAPICommand.initialize(this); - VpnStatus.initLogCache(getApplicationContext().getCacheDir()); - User.init(getString(R.string.default_username)); + // ensure all upgrades have passed before storing new information + preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply(); + } - // go to Dashboard - intent = new Intent(this, Dashboard.class); - startActivity(intent); + /** + * check if an upgrade passed or moved to given milestone + * @param milestone Version code of the Milestone VersionMilestone.MILE_STONE + * @return true if milestone is reached - false otherwise + */ + private boolean passedMilestone(int milestone) { + return previousVersionCode < milestone && versionCode >= milestone; } + } -- cgit v1.2.3 From f8c2f76971f5a7f26d18e5e669d5e0ce9c560f3f Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Thu, 7 Dec 2017 12:52:29 +0100 Subject: Rename constants * renamed last constants * remove unnecessary updates/ConstantUnification --- app/src/main/java/se/leap/bitmaskclient/StartActivity.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/StartActivity.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index ade43701..dd2be212 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -13,7 +13,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import de.blinkt.openvpn.core.VpnStatus; -import se.leap.bitmaskclient.updates.ConstantUnification; import se.leap.bitmaskclient.userstatus.User; /** @@ -113,15 +112,12 @@ public class StartActivity extends Activity { } /** - * execute necessary updates for version change + * execute necessary upgrades for version change */ private void executeUpgrade() { - if (passedMilestone(VersionMilestone.MULTIPLE_PROFILES)) { + if (hasNewFeature(FeatureVersionCode.MULTIPLE_PROFILES)) { // TODO prepare usage of multiple profiles } - if (passedMilestone(VersionMilestone.CONSTANT_UNIFICATION)) { - ConstantUnification.upgrade(preferences); - } // ensure all upgrades have passed before storing new information preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply(); @@ -129,11 +125,11 @@ public class StartActivity extends Activity { /** * check if an upgrade passed or moved to given milestone - * @param milestone Version code of the Milestone VersionMilestone.MILE_STONE + * @param featureVersionCode Version code of the Milestone FeatureVersionCode.MILE_STONE * @return true if milestone is reached - false otherwise */ - private boolean passedMilestone(int milestone) { - return previousVersionCode < milestone && versionCode >= milestone; + private boolean hasNewFeature(int featureVersionCode) { + return previousVersionCode < featureVersionCode && versionCode >= featureVersionCode; } } -- cgit v1.2.3 From d835a9b8f38acf1970acc18ce2030f7d5f7377dd Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 28 Nov 2017 01:51:19 +0100 Subject: base for sidebar --- app/src/main/java/se/leap/bitmaskclient/StartActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/StartActivity.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index dd2be212..1bf81aea 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -67,7 +67,7 @@ public class StartActivity extends Activity { User.init(getString(R.string.default_username)); // go to Dashboard - Intent intent = new Intent(this, Dashboard.class); + Intent intent = new Intent(this, MainActivity.class); startActivity(intent); } -- cgit v1.2.3 From bd99fc61a2e8217c41b70c6f2ff0df87e7008ea0 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Mon, 8 Jan 2018 15:49:34 +0100 Subject: seperate accountList and settingsList in drawer --- app/src/main/java/se/leap/bitmaskclient/StartActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/StartActivity.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index 1bf81aea..55760cb3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -48,7 +48,7 @@ public class StartActivity extends Activity { break; case FIRST: - // TODO start ProfileCreation & replace below code + // (new Intent(getActivity(), ConfigurationWizard.class), Constants.REQUEST_CODE_SWITCH_PROVIDER); break; case UPGRADE: -- cgit v1.2.3 From 1690dec51d78a27a6a1f7c83d30b28d1ab432f93 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Sat, 13 Jan 2018 16:53:54 +0100 Subject: static constant imports --- app/src/main/java/se/leap/bitmaskclient/StartActivity.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/se/leap/bitmaskclient/StartActivity.java') diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index 614c6b8d..43d7f152 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -15,6 +15,9 @@ import java.lang.annotation.RetentionPolicy; import de.blinkt.openvpn.core.VpnStatus; import se.leap.bitmaskclient.userstatus.User; +import static se.leap.bitmaskclient.Constants.PREFERENCES_APP_VERSION; +import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; + /** * Activity shown at startup. Evaluates if App is started for the first time or has been upgraded * and acts and calls another activity accordingly. @@ -39,7 +42,7 @@ public class StartActivity extends Activity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); + preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); Log.d(TAG, "Started"); @@ -81,7 +84,7 @@ public class StartActivity extends Activity { private int checkAppStart() { try { versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; - previousVersionCode = preferences.getInt(Constants.PREFERENCES_APP_VERSION, -1); + previousVersionCode = preferences.getInt(PREFERENCES_APP_VERSION, -1); // versions do match -> normal start if (versionCode == previousVersionCode) { @@ -135,7 +138,7 @@ public class StartActivity extends Activity { } private void storeAppVersion() { - preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply(); + preferences.edit().putInt(PREFERENCES_APP_VERSION, versionCode).apply(); } } -- cgit v1.2.3