X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/981ecb91c9550958161bda9fa1b44c207f99567d..989c3379798a744100fadb82d9fbfa3ecf8ff6e4:/src/com/owncloud/android/ui/activity/Preferences.java diff --git a/src/com/owncloud/android/ui/activity/Preferences.java b/src/com/owncloud/android/ui/activity/Preferences.java index f74da5aa..0a224141 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@ -34,6 +34,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; import android.net.Uri; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -62,6 +63,7 @@ import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; +import android.widget.Toast; import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; @@ -80,6 +82,13 @@ import com.owncloud.android.services.OperationsService; import com.owncloud.android.ui.RadioButtonPreference; import com.owncloud.android.utils.DisplayUtils; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.concurrent.ExecutionException; + /** * An Activity that allows the user to change the application's settings. @@ -247,11 +256,10 @@ public class Preferences extends PreferenceActivity pCacheSize.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - String temp = (String) newValue; - Long size = Long.decode(temp); + Long size = Long.decode((String) newValue); if (ThumbnailsCacheManager.setMaxSize(size)){ appPrefs.edit().putString("pref_cache_size", size.toString()); - pCacheSize.setSummary(size + " Mb"); + pCacheSize.setSummary(size + " MB"); return true; } else { return false; @@ -473,6 +481,58 @@ public class Preferences extends PreferenceActivity Context.BIND_AUTO_CREATE); } + /* Link to Beta apks */ + Preference pBetaLink = findPreference("beta_link"); + if (pBetaLink != null ){ + pBetaLink.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Integer currentVersion = BuildConfig.VERSION_CODE; + LoadingVersionNumberTask loadTask = new LoadingVersionNumberTask(); + loadTask.execute(); + Integer latestVersion = -1; + try { + latestVersion = loadTask.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } + if (latestVersion == -1) { + Toast.makeText(getApplicationContext(), "No information available!", Toast.LENGTH_SHORT).show(); + } + if (latestVersion > currentVersion) { + String betaLinkWeb = (String) getText(R.string.beta_link) + latestVersion + ".apk"; + if (betaLinkWeb != null && betaLinkWeb.length() > 0) { + Uri uriUrl = Uri.parse(betaLinkWeb); + 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; + } + return true; + } + }); + } + + /* Link to Beta apks */ + Preference pChangelogLink = findPreference("changelog_link"); + if (pChangelogLink != null){ + pChangelogLink.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + String betaLinkWeb = getString(R.string.changelog); + if (betaLinkWeb != null && betaLinkWeb.length() > 0) { + Uri uriUrl = Uri.parse(betaLinkWeb); + Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl); + startActivity(intent); + return true; + } + return true; + } + }); + } } private void toggleInstantPictureOptions(Boolean value){ @@ -480,8 +540,8 @@ public class Preferences extends PreferenceActivity mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPathWiFi); mPrefInstantUploadCategory.addPreference(mPrefInstantUploadPath); } else { - mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPathWiFi); - mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPath); +// mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPathWiFi); +// mPrefInstantUploadCategory.removePreference(mPrefInstantUploadPath); } } @@ -490,8 +550,8 @@ public class Preferences extends PreferenceActivity mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPathWiFi); mPrefInstantUploadCategory.addPreference(mPrefInstantVideoUploadPath); } else { - mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi); - mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath); +// mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPathWiFi); +// mPrefInstantUploadCategory.removePreference(mPrefInstantVideoUploadPath); } } @@ -626,6 +686,7 @@ public class Preferences extends PreferenceActivity public void setContentView(View view) { getDelegate().setContentView(view); } + @Override public void setContentView(View view, ViewGroup.LayoutParams params) { getDelegate().setContentView(view, params); @@ -828,7 +889,7 @@ public class Preferences extends PreferenceActivity SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mUploadVideoPath = appPrefs.getString("instant_video_upload_path", getString(R.string.instant_upload_path)); - mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath); +// mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath); } /** @@ -902,4 +963,29 @@ public class Preferences extends PreferenceActivity } } }; + + /** + * + * Class for loading the version number + * + */ + private class LoadingVersionNumberTask extends AsyncTask { + protected Integer doInBackground(Void... args) { + try { + URL url = new URL("https://github.com/owncloud/android/raw/beta/apks/latest"); + BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); + + Integer latestVersion = Integer.parseInt(in.readLine()); + in.close(); + + return latestVersion; + + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return -1; + } + } }