|
@@ -56,6 +56,7 @@ import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.webkit.URLUtil;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import com.owncloud.android.BuildConfig;
|
|
|
import com.owncloud.android.MainApp;
|
|
@@ -70,12 +71,14 @@ import com.owncloud.android.lib.common.ExternalLinkType;
|
|
|
import com.owncloud.android.lib.common.OwnCloudAccount;
|
|
|
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
|
|
import com.owncloud.android.lib.common.utils.Log_OC;
|
|
|
+import com.owncloud.android.ui.asynctasks.LoadingVersionNumberTask;
|
|
|
import com.owncloud.android.utils.AnalyticsUtils;
|
|
|
import com.owncloud.android.utils.DisplayUtils;
|
|
|
import com.owncloud.android.utils.MimeTypeUtil;
|
|
|
import com.owncloud.android.utils.ThemeUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
/**
|
|
|
* An Activity that allows the user to change the application's settings.
|
|
@@ -161,6 +164,64 @@ public class Preferences extends PreferenceActivity
|
|
|
|
|
|
// About
|
|
|
setupAboutCategory(accentColor, appVersion);
|
|
|
+
|
|
|
+ // Dev
|
|
|
+ setupDevCategory(accentColor, preferenceScreen);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setupDevCategory(int accentColor, PreferenceScreen preferenceScreen) {
|
|
|
+ // Dev category
|
|
|
+ PreferenceCategory preferenceCategoryDev = (PreferenceCategory) findPreference("dev_category");
|
|
|
+
|
|
|
+ if (getResources().getBoolean(R.bool.is_beta)) {
|
|
|
+ preferenceCategoryDev.setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_dev),
|
|
|
+ accentColor));
|
|
|
+
|
|
|
+ /* Link to dev apks */
|
|
|
+ Preference pDevLink = findPreference("dev_link");
|
|
|
+ if (pDevLink != null) {
|
|
|
+ pDevLink.setOnPreferenceClickListener(preference -> {
|
|
|
+ Integer latestVersion = -1;
|
|
|
+ Integer currentVersion = -1;
|
|
|
+ try {
|
|
|
+ currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
|
|
+ String url = getString(R.string.dev_latest);
|
|
|
+ LoadingVersionNumberTask loadTask = new LoadingVersionNumberTask();
|
|
|
+ loadTask.execute(url);
|
|
|
+ latestVersion = loadTask.get();
|
|
|
+ } catch (InterruptedException | ExecutionException | NameNotFoundException e) {
|
|
|
+ Log_OC.e(TAG, "Error detecting app version", e);
|
|
|
+ }
|
|
|
+ if (latestVersion == -1 || currentVersion == -1) {
|
|
|
+ Toast.makeText(getApplicationContext(), "No information available!", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ if (latestVersion > currentVersion) {
|
|
|
+ String devApkLink = (String) getText(R.string.dev_link) + latestVersion + ".apk";
|
|
|
+ Uri uriUrl = Uri.parse(devApkLink);
|
|
|
+ Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
|
|
|
+ startActivity(intent);
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ Toast.makeText(getApplicationContext(), "No new version available!", Toast.LENGTH_SHORT).show();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Link to dev changelog */
|
|
|
+ Preference pChangelogLink = findPreference("changelog_link");
|
|
|
+ if (pChangelogLink != null) {
|
|
|
+ pChangelogLink.setOnPreferenceClickListener(preference -> {
|
|
|
+ String devChangelogLink = getString(R.string.dev_changelog);
|
|
|
+ Uri uriUrl = Uri.parse(devChangelogLink);
|
|
|
+ Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
|
|
|
+ startActivity(intent);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ preferenceScreen.removePreference(preferenceCategoryDev);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void setupAboutCategory(int accentColor, String appVersion) {
|