X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b4496cc5863e25be44bb06822f7d7eeb1be15d74..cdeb9e0fcea3dfe8b952ee3e7f48dddbecd6403a:/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 8ba64280..3f242c2d 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. @@ -453,8 +462,15 @@ public class Preferences extends PreferenceActivity /* About App */ pAboutApp = (Preference) findPreference("about_app"); if (pAboutApp != null) { - pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name))); - pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion)); + pAboutApp.setTitle(String.format(getString(R.string.about_android), + getString(R.string.app_name))); + try { + Integer currentVersion = getPackageManager().getPackageInfo + (getPackageName(), 0).versionCode; + pAboutApp.setSummary(String.format(getString(R.string.about_version), + currentVersion)); + } catch (NameNotFoundException e) { + } } loadInstantUploadPath(); @@ -478,11 +494,54 @@ public class Preferences extends PreferenceActivity pBetaLink.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - String betaLinkWeb = (String) getText(R.string.beta_link); + Integer latestVersion = -1; + Integer currentVersion = -1; + try { + currentVersion = getPackageManager().getPackageInfo + (getPackageName(), 0).versionCode; + LoadingVersionNumberTask loadTask = new LoadingVersionNumberTask(); + loadTask.execute(); + latestVersion = loadTask.get(); + } catch (InterruptedException | ExecutionException e) { + e.printStackTrace(); + } catch (NameNotFoundException e) { + e.printStackTrace(); + } + if (latestVersion == -1 || currentVersion == -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; } @@ -641,6 +700,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); @@ -843,7 +903,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); } /** @@ -917,4 +977,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; + } + } }