Issue #20 - network failure during repo update shouldn't empty the app list

This commit is contained in:
Ciaran Gultnieks 2011-01-26 23:02:27 +00:00
parent 6fddf13fb3
commit 4be4b8ddaa
3 changed files with 16 additions and 8 deletions

View File

@ -363,8 +363,8 @@ public class FDroid extends TabActivity implements OnItemClickListener {
|| netstate.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED) { || netstate.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED) {
new Thread() { new Thread() {
public void run() { public void run() {
RepoXMLHandler.doUpdates(FDroid.this, db); boolean success = RepoXMLHandler.doUpdates(FDroid.this, db);
update_handler.sendEmptyMessage(0); update_handler.sendEmptyMessage(success ? 0 : 1);
} }
}.start(); }.start();
return true; return true;
@ -382,7 +382,13 @@ public class FDroid extends TabActivity implements OnItemClickListener {
private Handler update_handler = new Handler() { private Handler update_handler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
if (msg.what == 1) {
Toast.makeText(FDroid.this,
getString(R.string.connection_error_msg),
Toast.LENGTH_LONG).show();
} else {
populateLists(true); populateLists(true);
}
if (pd.isShowing()) if (pd.isShowing())
pd.dismiss(); pd.dismiss();
} }

View File

@ -188,7 +188,7 @@ public class RepoXMLHandler extends DefaultHandler {
} }
} }
public static void doUpdates(Context ctx, DB db) { public static boolean doUpdates(Context ctx, DB db) {
db.beginUpdate(); db.beginUpdate();
Vector<DB.Repo> repos = db.getRepos(); Vector<DB.Repo> repos = db.getRepos();
for (DB.Repo repo : repos) { for (DB.Repo repo : repos) {
@ -233,6 +233,7 @@ public class RepoXMLHandler extends DefaultHandler {
} catch (Exception e) { } catch (Exception e) {
Log.d("FDroid", "Exception updating from " + repo.address Log.d("FDroid", "Exception updating from " + repo.address
+ " - " + e.getMessage()); + " - " + e.getMessage());
return false;
} finally { } finally {
ctx.deleteFile("tempindex.xml"); ctx.deleteFile("tempindex.xml");
} }
@ -240,7 +241,7 @@ public class RepoXMLHandler extends DefaultHandler {
} }
} }
db.endUpdate(); db.endUpdate();
return true;
} }
} }

View File

@ -116,9 +116,10 @@ public class UpdateService extends Service {
if (notify) if (notify)
prevUpdates = db.getNumUpdates(); prevUpdates = db.getNumUpdates();
RepoXMLHandler.doUpdates(getBaseContext(), db); boolean success = RepoXMLHandler.doUpdates(
getBaseContext(), db);
if (notify) { if (success && notify) {
if (db.getNumUpdates() > prevUpdates) { if (db.getNumUpdates() > prevUpdates) {
// And the user wants to know. // And the user wants to know.
NotificationManager n = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager n = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);