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;
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;
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.
/* 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();
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 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;
+ }
+ });
+ }
}
private void toggleInstantPictureOptions(Boolean value){
public void setContentView(View view) {
getDelegate().setContentView(view);
}
+
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().setContentView(view, params);
SharedPreferences appPrefs =
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
mUploadVideoPath = appPrefs.getString("instant_video_upload_path", getString(R.string.instant_upload_path));
-// mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
+ mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
}
/**
}
}
};
+
+ /**
+ *
+ * Class for loading the version number
+ *
+ */
+ private class LoadingVersionNumberTask extends AsyncTask<Void, Void, Integer> {
+ 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;
+ }
+ }
}