/** * Displays some useful info about the account, to demonstrate that we've successfully logged in * * @param account */ public void action(DropboxAPI.Account account) { synchronized (this) { if (account != null) { Intent intent = getIntent(); int contact_id = intent.getIntExtra("action", -1); DBHelper mHelper = new DBHelper(this); mHelper.getReadableDatabase().close(); File data = Environment.getDataDirectory(); String currentDBPath = "/data/edu.stanford.mobisocial.dungbeetle/databases/" + DBHelper.DB_NAME; File currentDB = new File(data, currentDBPath); String newDBPath = "/data/edu.stanford.mobisocial.dungbeetle/databases/" + DBHelper.DB_NAME + ".new"; File newDB = new File(data, newDBPath); if (contact_id == 0) { api.delete("dropbox", "/" + DBHelper.DB_NAME); api.putFile("dropbox", "/", currentDB); showToast("backed up"); } else if (contact_id == 1) { try { downloadDropboxFile(DBHelper.DB_NAME, newDB); mHelper.importDatabase(newDBPath); showToast("restored"); } catch (Exception e) { showToast("could not restore"); } } finish(); } } }
@Override public void onAct(Context context, DbEntryHandler objType, DbObj obj) { DBHelper dbh = DBHelper.getGlobal(context); try { // TODO: do with content provider... this method ignore the // feed uri for now long hash = obj.getHash(); Uri feedUri = obj.getContainingFeed().getUri(); if (hash == 0) { Toast.makeText(context, "Message not yet sent.", Toast.LENGTH_SHORT).show(); return; } Helpers.sendToFeeds(context, DeleteObj.TYPE, DeleteObj.json(hash), new Uri[] {feedUri}); dbh.deleteObjByHash(feedUri, hash); } finally { dbh.close(); } }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (null != getActivity().findViewById(R.id.feed_view)) { getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); } mHelper = DBHelper.getGlobal(getActivity()); getLoaderManager().initLoader(0, null, this); }