Show apk sizes next to each version (incorporates supporting database changes)
This commit is contained in:
parent
1eb07ede53
commit
9b2284d08f
@ -15,6 +15,10 @@
|
|||||||
android:layout_below="@id/version" android:layout_alignParentRight="false"
|
android:layout_below="@id/version" android:layout_alignParentRight="false"
|
||||||
android:layout_height="wrap_content" android:layout_width="wrap_content" />
|
android:layout_height="wrap_content" android:layout_width="wrap_content" />
|
||||||
|
|
||||||
|
<TextView android:id="@+id/size" android:textSize="12sp"
|
||||||
|
android:layout_below="@id/version" android:layout_alignParentRight="true"
|
||||||
|
android:layout_height="wrap_content" android:layout_width="wrap_content" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -102,10 +102,30 @@ public class AppDetails extends ListActivity {
|
|||||||
status.setText("Installed");
|
status.setText("Installed");
|
||||||
else
|
else
|
||||||
status.setText("Not installed");
|
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;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getFriendlySize(int size)
|
||||||
|
{
|
||||||
|
double s=size;
|
||||||
|
String[] format=new String[] {"%fb","%.0fK","%.1fM","%.2fG"};
|
||||||
|
int i=0;
|
||||||
|
while(i<format.length-1 && s>=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 INSTALL = Menu.FIRST;
|
||||||
private static final int UNINSTALL = Menu.FIRST + 1;
|
private static final int UNINSTALL = Menu.FIRST + 1;
|
||||||
private static final int WEBSITE = Menu.FIRST + 2;
|
private static final int WEBSITE = Menu.FIRST + 2;
|
||||||
|
@ -38,6 +38,12 @@ public class DB {
|
|||||||
|
|
||||||
private SQLiteDatabase 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.
|
// The TABLE_APP table stores details of all the applications we know about.
|
||||||
// This information is retrieved from the repositories.
|
// This information is retrieved from the repositories.
|
||||||
private static final String TABLE_APP = "fdroid_app";
|
private static final String TABLE_APP = "fdroid_app";
|
||||||
@ -116,17 +122,19 @@ public class DB {
|
|||||||
+ "( " + "id text not null, " + "version text not null, "
|
+ "( " + "id text not null, " + "version text not null, "
|
||||||
+ "server text not null, " + "hash text not null, "
|
+ "server text not null, " + "hash text not null, "
|
||||||
+ "vercode int not null," + "apkName 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 static class Apk {
|
||||||
|
|
||||||
public Apk() {
|
public Apk() {
|
||||||
updated = false;
|
updated = false;
|
||||||
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String id;
|
public String id;
|
||||||
public String version;
|
public String version;
|
||||||
public int vercode;
|
public int vercode;
|
||||||
|
public int size; // Size in bytes - 0 means we don't know!
|
||||||
public String server;
|
public String server;
|
||||||
public String hash;
|
public String hash;
|
||||||
public String apkName;
|
public String apkName;
|
||||||
@ -159,7 +167,7 @@ public class DB {
|
|||||||
|
|
||||||
Cursor c = db.rawQuery(
|
Cursor c = db.rawQuery(
|
||||||
"SELECT name FROM sqlite_master WHERE type='table' AND name= '"
|
"SELECT name FROM sqlite_master WHERE type='table' AND name= '"
|
||||||
+ TABLE_REPO + "'", null);
|
+ TABLE_VERSION + "'", null);
|
||||||
boolean newinst = (c.getCount() == 0);
|
boolean newinst = (c.getCount() == 0);
|
||||||
c.close();
|
c.close();
|
||||||
if (newinst)
|
if (newinst)
|
||||||
@ -171,9 +179,11 @@ public class DB {
|
|||||||
// Reset the database, i.e. (re-)create all the tables from scratch and
|
// Reset the database, i.e. (re-)create all the tables from scratch and
|
||||||
// populate any initial data.
|
// populate any initial data.
|
||||||
public void reset() {
|
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_REPO);
|
||||||
db.execSQL("drop table if exists " + TABLE_APP);
|
db.execSQL("drop table if exists " + TABLE_APP);
|
||||||
db.execSQL("drop table if exists " + TABLE_APK);
|
db.execSQL("drop table if exists " + TABLE_APK);
|
||||||
|
db.execSQL(CREATE_TABLE_VERSION);
|
||||||
db.execSQL(CREATE_TABLE_REPO);
|
db.execSQL(CREATE_TABLE_REPO);
|
||||||
db.execSQL(CREATE_TABLE_APP);
|
db.execSQL(CREATE_TABLE_APP);
|
||||||
db.execSQL(CREATE_TABLE_APK);
|
db.execSQL(CREATE_TABLE_APK);
|
||||||
@ -233,6 +243,7 @@ public class DB {
|
|||||||
apk.vercode = c2.getInt(c2.getColumnIndex("vercode"));
|
apk.vercode = c2.getInt(c2.getColumnIndex("vercode"));
|
||||||
apk.server = c2.getString(c2.getColumnIndex("server"));
|
apk.server = c2.getString(c2.getColumnIndex("server"));
|
||||||
apk.hash = c2.getString(c2.getColumnIndex("hash"));
|
apk.hash = c2.getString(c2.getColumnIndex("hash"));
|
||||||
|
apk.size = c2.getInt(c2.getColumnIndex("size"));
|
||||||
apk.apkName = c2.getString(c2.getColumnIndex("apkName"));
|
apk.apkName = c2.getString(c2.getColumnIndex("apkName"));
|
||||||
app.apks.add(apk);
|
app.apks.add(apk);
|
||||||
c2.moveToNext();
|
c2.moveToNext();
|
||||||
@ -261,9 +272,11 @@ public class DB {
|
|||||||
|
|
||||||
// We'll say an application has updates if it's installed and the
|
// We'll say an application has updates if it's installed and the
|
||||||
// installed version is not the 'current' one.
|
// installed version is not the 'current' one.
|
||||||
for(App app : result) {
|
for (App app : result) {
|
||||||
if(app.installedVersion != null && !app.installedVersion.equals(app.getCurrentVersion().version)) {
|
if (app.installedVersion != null
|
||||||
app.hasUpdates=true;
|
&& !app.installedVersion
|
||||||
|
.equals(app.getCurrentVersion().version)) {
|
||||||
|
app.hasUpdates = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,6 +446,7 @@ public class DB {
|
|||||||
values.put("vercode", upapk.vercode);
|
values.put("vercode", upapk.vercode);
|
||||||
values.put("server", upapk.server);
|
values.put("server", upapk.server);
|
||||||
values.put("hash", upapk.hash);
|
values.put("hash", upapk.hash);
|
||||||
|
values.put("size", upapk.size);
|
||||||
values.put("apkName", upapk.apkName);
|
values.put("apkName", upapk.apkName);
|
||||||
if (oldapk != null) {
|
if (oldapk != null) {
|
||||||
db.update(TABLE_APK, values, "id = '" + oldapk.id
|
db.update(TABLE_APK, values, "id = '" + oldapk.id
|
||||||
|
@ -67,6 +67,12 @@ public class RepoXMLHandler extends DefaultHandler {
|
|||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
curapk.vercode = 0;
|
curapk.vercode = 0;
|
||||||
}
|
}
|
||||||
|
} else if (curel == "size") {
|
||||||
|
try {
|
||||||
|
curapk.size = Integer.parseInt(str);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
curapk.size = 0;
|
||||||
|
}
|
||||||
} else if (curel == "hash") {
|
} else if (curel == "hash") {
|
||||||
curapk.hash = str;
|
curapk.hash = str;
|
||||||
} else if (curel == "apkname") {
|
} else if (curel == "apkname") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user