Add in app update

This commit is contained in:
NekoInverter committed 2020-07-20 19:53:37 +08:00
1 parent ad6770907d
commit 73440b3abb
22 files changed
+126 -54

No files matched your search

@@ -0,0 +1,48 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer;
import android.app.Application;
import com.hippo.scene.SceneFragment;
import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.crashes.Crashes;
import com.microsoft.appcenter.distribute.Distribute;
import java.util.HashMap;
import java.util.Map;
public final class Analytics {
public static void start(Application application) {
AppCenter.start(application, "1aa06805-037c-4f3c-8aaa-e23d1433986d", com.microsoft.appcenter.analytics.Analytics.class, Crashes.class, Distribute.class);
AppCenter.setUserId(Settings.getUserID());
}
public static boolean isEnabled() {
return AppCenter.isConfigured() && Settings.getEnableAnalytics();
}
public static void onSceneView(SceneFragment scene) {
if (isEnabled()) {
Map<String, String> properties = new HashMap<>();
properties.put("scene_simple_class", scene.getClass().getSimpleName());
properties.put("scene_class", scene.getClass().getName());
com.microsoft.appcenter.analytics.Analytics.trackEvent("scene_view", properties);
}
}
}
@@ -281,6 +281,10 @@ public class EhApplication extends RecordingApplication {
EhDB.mergeOldDB(this);
}
if (Settings.getEnableAnalytics()) {
Analytics.start(this);
}
AppCompatDelegate.setDefaultNightMode(Settings.getTheme());
// Do io tasks in new thread
@@ -58,6 +58,7 @@ import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.ListUrlBuilder;
import com.hippo.ehviewer.client.parser.GalleryDetailUrlParser;
import com.hippo.ehviewer.client.parser.GalleryPageUrlParser;
import com.hippo.ehviewer.ui.scene.AnalyticsScene;
import com.hippo.ehviewer.ui.scene.BaseScene;
import com.hippo.ehviewer.ui.scene.CookieSignInScene;
import com.hippo.ehviewer.ui.scene.DownloadLabelsScene;
@@ -108,7 +109,7 @@ public final class MainActivity extends StageActivity
static {
registerLaunchMode(SecurityScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(WarningScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
//registerLaunchMode(AnalyticsScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(AnalyticsScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(SignInScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(WebViewSignInScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(CookieSignInScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
@@ -153,9 +154,9 @@ public final class MainActivity extends StageActivity
return new Announcer(SecurityScene.class);
} else if (Settings.getShowWarning()) {
return new Announcer(WarningScene.class);
}/* else if (Settings.getAskAnalytics()) {
} else if (Settings.getAskAnalytics()) {
return new Announcer(AnalyticsScene.class);
}*/ else if (EhUtils.needSignedIn(this)) {
} else if (EhUtils.needSignedIn(this)) {
return new Announcer(SignInScene.class);
} else if (Settings.getSelectSite()) {
return new Announcer(SelectSiteScene.class);
@@ -179,12 +180,12 @@ public final class MainActivity extends StageActivity
newArgs.putString(WarningScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(WarningScene.KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(WarningScene.class).setArgs(newArgs);
}/* else if (Settings.getAskAnalytics()) {
} else if (Settings.getAskAnalytics()) {
Bundle newArgs = new Bundle();
newArgs.putString(AnalyticsScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(AnalyticsScene.KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(AnalyticsScene.class).setArgs(newArgs);
}*/ else if (EhUtils.needSignedIn(this)) {
} else if (EhUtils.needSignedIn(this)) {
Bundle newArgs = new Bundle();
newArgs.putString(SignInScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(SignInScene.KEY_TARGET_ARGS, announcer.getArgs());
@@ -22,10 +22,11 @@ import androidx.annotation.Nullable;
import androidx.preference.Preference;
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity;
import com.hippo.ehviewer.Analytics;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.ui.CommonOperations;
import com.hippo.util.AppHelper;
import com.microsoft.appcenter.distribute.Distribute;
import com.takisoft.preferencex.PreferenceFragmentCompat;
public class AboutFragment extends PreferenceFragmentCompat
@@ -41,13 +42,14 @@ public class AboutFragment extends PreferenceFragmentCompat
Preference author = findPreference(KEY_AUTHOR);
//Preference donate = findPreference(KEY_DONATE);
//Preference checkForUpdate = findPreference(KEY_CHECK_FOR_UPDATES);
Preference checkForUpdate = findPreference(KEY_CHECK_FOR_UPDATES);
author.setSummary(getString(R.string.settings_about_author_summary).replace('$', '@'));
author.setOnPreferenceClickListener(this);
//donate.setOnPreferenceClickListener(this);
//checkForUpdate.setOnPreferenceClickListener(this);
checkForUpdate.setOnPreferenceClickListener(this);
checkForUpdate.setVisible(Analytics.isEnabled());
OssLicensesMenuActivity.setActivityTitle(getString(R.string.license));
}
@@ -58,7 +60,7 @@ public class AboutFragment extends PreferenceFragmentCompat
AppHelper.sendEmail(requireActivity(), EhApplication.getDeveloperEmail(),
"About EhViewer", null);
} else if (KEY_CHECK_FOR_UPDATES.equals(key)) {
CommonOperations.checkUpdate(getActivity(), true);
Distribute.checkForUpdate();
}
return true;
}
@@ -6,6 +6,7 @@ import android.text.TextUtils;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import com.hippo.ehviewer.Analytics;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.takisoft.preferencex.PreferenceFragmentCompat;
@@ -14,12 +15,15 @@ import com.takisoft.preferencex.PreferenceFragmentCompat;
* Created by Mo10 on 2018/2/10.
*/
public class PrivacyFragment extends PreferenceFragmentCompat {
public class PrivacyFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceChangeListener {
private static final String KEY_PATTERN_PROTECTION = "pattern_protection";
@Override
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.privacy_settings);
Preference enableAnalytics = findPreference(Settings.KEY_ENABLE_ANALYTICS);
enableAnalytics.setOnPreferenceChangeListener(this);
}
@Override
@@ -31,4 +35,14 @@ public class PrivacyFragment extends PreferenceFragmentCompat {
R.string.settings_privacy_pattern_protection_set);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (Settings.KEY_ENABLE_ANALYTICS.equals(key)) {
if (newValue instanceof Boolean && (Boolean) newValue) {
Analytics.start(getActivity().getApplication());
}
}
return true;
}
}
@@ -25,6 +25,7 @@ import android.widget.TextView;
import androidx.annotation.Nullable;
import com.hippo.ehviewer.Analytics;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.ui.MainActivity;
@@ -74,6 +75,7 @@ public class AnalyticsScene extends SolidScene implements View.OnClickListener {
@Override
public void onClick(View v) {
Context context = getContext2();
MainActivity activity = getActivity2();
if (null == context) {
return;
}
@@ -83,11 +85,11 @@ public class AnalyticsScene extends SolidScene implements View.OnClickListener {
} else if (mAccept == v) {
Settings.putEnableAnalytics(true);
// Start Analytics
Analytics.start(activity.getApplication());
}
Settings.putAskAnalytics(false);
// Start new scene and finish it self
MainActivity activity = getActivity2();
if (null != activity) {
startSceneForCheckStep(CHECK_STEP_ANALYTICS, getArguments());
}
@@ -39,6 +39,7 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentActivity;
import com.hippo.android.resource.AttrResources;
import com.hippo.ehviewer.Analytics;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.scene.SceneFragment;
@@ -294,6 +295,12 @@ public abstract class BaseScene extends SceneFragment {
}
}
@Override
public void onResume() {
super.onResume();
Analytics.onSceneView(this);
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
@@ -45,10 +45,10 @@ public class SolidScene extends BaseScene {
break;
}
case CHECK_STEP_WARNING:
/*if (Settings.getAskAnalytics()) {
if (Settings.getAskAnalytics()) {
startScene(new Announcer(AnalyticsScene.class).setArgs(args));
break;
}*/
}
case CHECK_STEP_ANALYTICS:
if (EhUtils.needSignedIn(getContext2())) {
startScene(new Announcer(SignInScene.class).setArgs(args));