check available beta version
authortobiasKaminsky <tobias@kaminsky.me>
Thu, 5 Nov 2015 20:37:08 +0000 (21:37 +0100)
committertobiasKaminsky <tobias@kaminsky.me>
Thu, 5 Nov 2015 20:37:08 +0000 (21:37 +0100)
AndroidManifest.xml
apks/latest [new file with mode: 0644]
apks/owncloud-beta-2015-11-02.apk [new file with mode: 0644]
apks/owncloud-beta-20151105.apk [new file with mode: 0644]
build.gradle
oc_jb_workaround/build.gradle
res/values/setup.xml
res/xml/preferences.xml
src/com/owncloud/android/ui/activity/Preferences.java

index 77f8a0d..240d73b 100644 (file)
@@ -17,8 +17,7 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->
 <manifest package="com.owncloud.android"
-    android:versionCode="10800000"
-    android:versionName="1.8.0" xmlns:android="http://schemas.android.com/apk/res/android">
+    android:versionName="ownCloud beta" xmlns:android="http://schemas.android.com/apk/res/android">
 
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
     <uses-permission android:name="android.permission.USE_CREDENTIALS" />
diff --git a/apks/latest b/apks/latest
new file mode 100644 (file)
index 0000000..57d5957
--- /dev/null
@@ -0,0 +1 @@
+20151105
diff --git a/apks/owncloud-beta-2015-11-02.apk b/apks/owncloud-beta-2015-11-02.apk
new file mode 100644 (file)
index 0000000..924f626
Binary files /dev/null and b/apks/owncloud-beta-2015-11-02.apk differ
diff --git a/apks/owncloud-beta-20151105.apk b/apks/owncloud-beta-20151105.apk
new file mode 100644 (file)
index 0000000..0206ed5
Binary files /dev/null and b/apks/owncloud-beta-20151105.apk differ
index be674c9..d707b02 100644 (file)
@@ -3,13 +3,12 @@ buildscript {
         mavenCentral()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:1.2.3'
+        classpath 'com.android.tools.build:gradle:1.3.0'
     }
 }
 
 apply plugin: 'com.android.application'
 
-
 repositories {
     mavenCentral()
 
@@ -33,6 +32,7 @@ android {
 
     defaultConfig {
         applicationId "com.owncloud.android.beta"
+        versionCode computeVersionCode()
     }
 
     sourceSets {
@@ -73,4 +73,8 @@ android {
     }
 }
 
-
+def computeVersionCode() {
+    def date = new Date()
+    def formattedDate = date.format('yyyyMMdd').toInteger()
+    return formattedDate
+}
\ No newline at end of file
index 2fcc9f6..4a48a29 100644 (file)
@@ -3,7 +3,7 @@ buildscript {
         mavenCentral()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:1.2.3'
+        classpath 'com.android.tools.build:gradle:1.3.0'
     }
 }
 apply plugin: 'com.android.library'
index c1c6e7a..0d156b2 100644 (file)
@@ -47,7 +47,7 @@
     <bool name="recommend_enabled">true</bool>
     <bool name="feedback_enabled">true</bool>
     <string name="url_help">http://owncloud.com/mobile/help</string>
-    <string name="beta_link">https://github.com/owncloud/android/raw/beta/apks/latest.apk</string>
+    <string name="beta_link">https://github.com/owncloud/android/raw/beta/apks/owncloud-beta-</string>
     <string name="url_imprint"></string>
     <string name="mail_recommend">"mailto:"</string>
     <string name="mail_feedback">"mailto:apps@owncloud.com"</string>
index 06e9142..29e8fe2 100644 (file)
                                        android:key="about_app" />
 
        <Preference android:id="@+id/beta_link"
-                               android:title="Download latest beta"
+                               android:title="Download latest beta version"
                                android:key="beta_link" />
        </PreferenceCategory>
 
index 8ba6428..6bdc1e1 100644 (file)
@@ -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.
@@ -478,12 +487,30 @@ public class Preferences extends PreferenceActivity
             pBetaLink.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                 @Override
                 public boolean onPreferenceClick(Preference preference) {
-                    String betaLinkWeb = (String) getText(R.string.beta_link);
-                    if (betaLinkWeb != null && betaLinkWeb.length() > 0) {
-                        Uri uriUrl = Uri.parse(betaLinkWeb);
-                        Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
-                        startActivity(intent);
+                    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;
                 }
             });
@@ -641,6 +668,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);
@@ -917,4 +945,29 @@ public class Preferences extends PreferenceActivity
             }
         }
     };
+
+    /**
+     *
+     * 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://www.tobiaskaminsky.de/ocVersion");
+                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;
+        }
+    }
 }