commit f153600dd1d3ef1c483ad6c06c6bfa90873729a5 Author: arrase arrase@gmail.com Date: Sun Nov 27 19:12:16 2016 +0100
insert or update --- .../ui/hiddenservices/backup/BackupUtils.java | 28 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java b/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java index d446190..a11cb71 100644 --- a/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java +++ b/app/src/main/java/org/torproject/android/ui/hiddenservices/backup/BackupUtils.java @@ -149,16 +149,14 @@ public class BackupUtils { try { JSONObject savedValues = new JSONObject(jString); ContentValues fields = new ContentValues(); + int port = savedValues.getInt(HSContentProvider.HiddenService.PORT);
fields.put( HSContentProvider.HiddenService.NAME, savedValues.getString(HSContentProvider.HiddenService.NAME) );
- fields.put( - HSContentProvider.HiddenService.PORT, - savedValues.getInt(HSContentProvider.HiddenService.PORT) - ); + fields.put(HSContentProvider.HiddenService.PORT, port);
fields.put( HSContentProvider.HiddenService.ONION_PORT, @@ -175,7 +173,27 @@ public class BackupUtils { savedValues.getInt(HSContentProvider.HiddenService.CREATED_BY_USER) );
- mResolver.insert(HSContentProvider.CONTENT_URI, fields); + Cursor service = mResolver.query( + HSContentProvider.CONTENT_URI, + HSContentProvider.PROJECTION, + HSContentProvider.HiddenService.PORT + "=" + port, + null, + null + ); + + if (service.getCount() == 0) { + mResolver.insert(HSContentProvider.CONTENT_URI, fields); + } else { + mResolver.update( + HSContentProvider.CONTENT_URI, + fields, + HSContentProvider.HiddenService.PORT + "=" + port, + null + ); + } + + service.close(); + } catch (JSONException e) { e.printStackTrace(); Toast.makeText(mContext, R.string.error, Toast.LENGTH_LONG).show();
tor-commits@lists.torproject.org