diff --git a/res/layout/apklistitem.xml b/res/layout/apklistitem.xml index 1ad4055bf..509bfcb12 100644 --- a/res/layout/apklistitem.xml +++ b/res/layout/apklistitem.xml @@ -15,6 +15,10 @@ android:layout_below="@id/version" android:layout_alignParentRight="false" android:layout_height="wrap_content" android:layout_width="wrap_content" /> + + diff --git a/src/org/fdroid/fdroid/AppDetails.java b/src/org/fdroid/fdroid/AppDetails.java index 5335b22c9..6b015fe79 100644 --- a/src/org/fdroid/fdroid/AppDetails.java +++ b/src/org/fdroid/fdroid/AppDetails.java @@ -102,10 +102,30 @@ public class AppDetails extends ListActivity { status.setText("Installed"); else status.setText("Not installed"); + TextView size = (TextView) v.findViewById(R.id.size); + if(apk.size==0) { + size.setText(""); + } else { + size.setText(getFriendlySize(apk.size)); + } return v; } } + private static String getFriendlySize(int size) + { + double s=size; + String[] format=new String[] {"%fb","%.0fK","%.1fM","%.2fG"}; + int i=0; + while(i=1024) + { + s=(100*s/1024)/100.0; + i++; + } + return String.format(format[i],s); + } + + private static final int INSTALL = Menu.FIRST; private static final int UNINSTALL = Menu.FIRST + 1; private static final int WEBSITE = Menu.FIRST + 2; diff --git a/src/org/fdroid/fdroid/DB.java b/src/org/fdroid/fdroid/DB.java index 0907d9f2a..993105ea9 100644 --- a/src/org/fdroid/fdroid/DB.java +++ b/src/org/fdroid/fdroid/DB.java @@ -38,6 +38,12 @@ public class DB { private SQLiteDatabase db; + // The TABLE_VERSION table tracks the database version. + private static final String TABLE_VERSION = "fdroid_version"; + private static final String CREATE_TABLE_VERSION = "create table " + + TABLE_VERSION + "( version int not null); insert into " + + TABLE_VERSION + "(version) values (1);"; + // The TABLE_APP table stores details of all the applications we know about. // This information is retrieved from the repositories. private static final String TABLE_APP = "fdroid_app"; @@ -78,7 +84,7 @@ public class DB { // True if there are new versions (apks) that the user hasn't // explicitly ignored. (We're currently not using the database - // field for this - we make the decision on the fly in getApps(). + // field for this - we make the decision on the fly in getApps(). public boolean hasUpdates; // Used internally for tracking during repo updates. @@ -116,17 +122,19 @@ public class DB { + "( " + "id text not null, " + "version text not null, " + "server text not null, " + "hash text not null, " + "vercode int not null," + "apkName text not null, " - + "primary key(id,version));"; + + "size int not null," + "primary key(id,version));"; public static class Apk { public Apk() { updated = false; + size = 0; } public String id; public String version; public int vercode; + public int size; // Size in bytes - 0 means we don't know! public String server; public String hash; public String apkName; @@ -159,7 +167,7 @@ public class DB { Cursor c = db.rawQuery( "SELECT name FROM sqlite_master WHERE type='table' AND name= '" - + TABLE_REPO + "'", null); + + TABLE_VERSION + "'", null); boolean newinst = (c.getCount() == 0); c.close(); if (newinst) @@ -171,9 +179,11 @@ public class DB { // Reset the database, i.e. (re-)create all the tables from scratch and // populate any initial data. public void reset() { + db.execSQL("drop table if exists " + TABLE_VERSION); db.execSQL("drop table if exists " + TABLE_REPO); db.execSQL("drop table if exists " + TABLE_APP); db.execSQL("drop table if exists " + TABLE_APK); + db.execSQL(CREATE_TABLE_VERSION); db.execSQL(CREATE_TABLE_REPO); db.execSQL(CREATE_TABLE_APP); db.execSQL(CREATE_TABLE_APK); @@ -233,6 +243,7 @@ public class DB { apk.vercode = c2.getInt(c2.getColumnIndex("vercode")); apk.server = c2.getString(c2.getColumnIndex("server")); apk.hash = c2.getString(c2.getColumnIndex("hash")); + apk.size = c2.getInt(c2.getColumnIndex("size")); apk.apkName = c2.getString(c2.getColumnIndex("apkName")); app.apks.add(apk); c2.moveToNext(); @@ -261,12 +272,14 @@ public class DB { // We'll say an application has updates if it's installed and the // installed version is not the 'current' one. - for(App app : result) { - if(app.installedVersion != null && !app.installedVersion.equals(app.getCurrentVersion().version)) { - app.hasUpdates=true; + for (App app : result) { + if (app.installedVersion != null + && !app.installedVersion + .equals(app.getCurrentVersion().version)) { + app.hasUpdates = true; } } - + return result; } @@ -433,6 +446,7 @@ public class DB { values.put("vercode", upapk.vercode); values.put("server", upapk.server); values.put("hash", upapk.hash); + values.put("size", upapk.size); values.put("apkName", upapk.apkName); if (oldapk != null) { db.update(TABLE_APK, values, "id = '" + oldapk.id diff --git a/src/org/fdroid/fdroid/RepoXMLHandler.java b/src/org/fdroid/fdroid/RepoXMLHandler.java index 417c8fb73..d7b84e879 100644 --- a/src/org/fdroid/fdroid/RepoXMLHandler.java +++ b/src/org/fdroid/fdroid/RepoXMLHandler.java @@ -67,6 +67,12 @@ public class RepoXMLHandler extends DefaultHandler { } catch (NumberFormatException ex) { curapk.vercode = 0; } + } else if (curel == "size") { + try { + curapk.size = Integer.parseInt(str); + } catch (NumberFormatException ex) { + curapk.size = 0; + } } else if (curel == "hash") { curapk.hash = str; } else if (curel == "apkname") {