// /////////////////////////////////////////////////////////////////////////// // LIST ACTIONS // /////////////////////////////////////////////////////////////////////////// public void onListItemClick(GridView l, View v, int position, long id) { Cursor cursor = (Cursor) l.getItemAtPosition(position); String nodeId = cursor.getString(SyncContentSchema.COLUMN_NODE_ID_ID); String documentName = cursor.getString(SyncContentSchema.COLUMN_TITLE_ID); if (DisplayUtils.hasCentralPane(getActivity())) { FragmentDisplayer.with(getActivity()) .remove(DisplayUtils.getCentralFragmentId(getActivity())); } Boolean hideDetails = false; if (!selectedItems.isEmpty()) { hideDetails = selectedItems.get(0).equals(nodeId); } l.setItemChecked(position, true); if (nActions != null) { nActions.selectNode(nodeId); if (selectedItems.size() == 0) { hideDetails = true; } } else { selectedItems.clear(); if (!hideDetails && DisplayUtils.hasCentralPane(getActivity())) { selectedItems.add(nodeId); } } if (hideDetails) { selectedItems.clear(); displayTitle(); } else if (nActions == null) { if (SyncContentManager.isFolder(cursor)) { selectedItems.clear(); if (SyncContentManager.getInstance(getActivity()).hasActivateSync(acc)) { // GO TO Local subfolder SyncFragment.with(getActivity()) .mode(getMode()) .folderIdentifier(nodeId) .folderName(documentName) .display(); } else { DocumentFolderBrowserFragment.with(getActivity()) .folderIdentifier(nodeId) .shortcut(true) .display(); } } else { if (!ConnectivityUtils.hasInternetAvailable(getActivity())) { NodeDetailsFragment.with(getActivity()) .node(getOfflineNode(nodeId)) .isFavorite(true) .display(); } else { NodeDetailsFragment.with(getActivity()).nodeId(nodeId).isFavorite(true).display(); } } } adapter.notifyDataSetChanged(); }
// /////////////////////////////////////////////////////////////////////////// // LIFECYCLE // /////////////////////////////////////////////////////////////////////////// @Override protected LoaderResult<Void> doInBackground() { LoaderResult<Void> result = new LoaderResult<Void>(); try { // Delete All local files in sync folder File synchroFolder = SyncContentManager.getInstance(context).getSynchroFolder(accountUsername, accountUrl); if (synchroFolder != null && synchroFolder.exists()) { IOUtils.deleteContents(synchroFolder); } // For each sync row, reset status Cursor allFavoritesCursor = context .getContentResolver() .query( SyncContentProvider.CONTENT_URI, SyncContentSchema.COLUMN_ALL, SyncContentProvider.getAccountFilter(accountId), null, null); while (allFavoritesCursor.moveToNext()) { if (isDeletion) { // Update Sync Info context .getContentResolver() .delete( SyncContentManager.getUri( allFavoritesCursor.getLong(SyncContentSchema.COLUMN_ID_ID)), null, null); } else { // Update Sync Info ContentValues cValues = new ContentValues(); cValues.put(OperationSchema.COLUMN_STATUS, SyncContentStatus.STATUS_PENDING); context .getContentResolver() .update( SyncContentManager.getUri( allFavoritesCursor.getLong(SyncContentSchema.COLUMN_ID_ID)), cValues, null, null); } } } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); result.setException(e); } return result; }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode != RequestCode.SAVE_BACK && requestCode != RequestCode.DECRYPTED) { return; } final File dlFile = null; if (dlFile == null) { return; } long datetime = dlFile.lastModified(); Date d = new Date(datetime); boolean modified; final Uri lUri = null; switch (requestCode) { case RequestCode.SAVE_BACK: modified = (d != null && downloadDateTime != null) ? d.after(downloadDateTime) : false; if (modified) { // Update to Pending ContentValues cValues = new ContentValues(); cValues.put(SyncContentSchema.COLUMN_STATUS, Operation.STATUS_PENDING); getActivity().getContentResolver().update(lUri, cValues, null, null); // Start sync if possible if (SyncContentManager.getInstance(getActivity()).canSync(acc)) { SyncContentManager.getInstance(getActivity()).sync(acc); } } break; case RequestCode.DECRYPTED: modified = (d != null && decryptDateTime != null) ? d.after(decryptDateTime) : false; if (modified) { // If modified by user, we flag the uri // The next sync will update the content. ContentValues cValues = new ContentValues(); cValues.put(SyncContentSchema.COLUMN_STATUS, SyncContentStatus.STATUS_MODIFIED); getActivity().getContentResolver().update(lUri, cValues, null, null); } DataProtectionManager.getInstance(getActivity()).checkEncrypt(acc, dlFile); break; default: break; } }
@Override public void refresh() { if (!ConnectivityUtils.hasNetwork(getActivity())) { if (mi != null) { mi.setActionView(null); } if (!ConnectivityUtils.hasNetwork(getActivity())) { Crouton.cancelAllCroutons(); Crouton.showText( getActivity(), Html.fromHtml( getString(org.alfresco.mobile.android.foundation.R.string.error_session_nodata)), Style.INFO, (ViewGroup) (getRootView().getParent())); } refreshHelper.setRefreshComplete(); return; } SyncContentManager.getInstance(getActivity()).sync(acc); if (mi != null) { // Display spinning wheel instead of refresh mi.setActionView(R.layout.app_spinning); } if (adapter != null) { ((SyncCursorAdapter) adapter).refresh(); gv.setAdapter(adapter); } }
private Node getOfflineNode(String nodeIdentifier) { Node syncedNode = null; try { SyncContentManager syncManager = SyncContentManager.getInstance(getActivity()); // Retrieve Sync Cursor for the specified node Uri localUri = syncManager.getUri(acc, nodeIdentifier); Cursor syncCursor = getActivity() .getContentResolver() .query(localUri, SyncContentSchema.COLUMN_ALL, null, null, null); if (syncCursor.getCount() == 1 && syncCursor.moveToFirst()) { Map<String, Serializable> properties = retrievePropertiesMap(syncCursor); syncedNode = new NodeSyncPlaceHolder(properties); } CursorUtils.closeCursor(syncCursor); } catch (Exception e) { // Do Nothing } return syncedNode; }
@Subscribe public void onDocumentUpdated(UpdateNodeEvent event) { if (event.hasException) { return; } Node updatedNode = event.data; if (updatedNode == null) { return; } Cursor syncCursor = null; try { syncCursor = getActivity() .getContentResolver() .query( SyncContentProvider.CONTENT_URI, SyncContentSchema.COLUMN_ALL, SyncContentProvider.getAccountFilter(acc) + " AND " + SyncContentSchema.COLUMN_NODE_ID + " LIKE '" + NodeRefUtils.getCleanIdentifier(updatedNode.getIdentifier()) + "%'", null, null); boolean hasSynced = (syncCursor.getCount() == 1); if (hasSynced && !hasSynchroActive) { syncCursor.moveToFirst(); ContentValues cValues = new ContentValues(); cValues.put(SyncContentSchema.COLUMN_NODE_ID, updatedNode.getIdentifier()); cValues.put( SyncContentSchema.COLUMN_SERVER_MODIFICATION_TIMESTAMP, updatedNode.getModifiedAt().getTimeInMillis()); getActivity() .getContentResolver() .update( SyncContentManager.getUri(syncCursor.getLong(SyncContentSchema.COLUMN_ID_ID)), cValues, null, null); } } catch (Exception e) { // Do nothing } finally { CursorUtils.closeCursor(syncCursor); } }
@Override public void onResume() { getLoaderManager().restartLoader(0, null, this); hasSynchroActive = getMode() == MODE_PROGRESS || SyncContentManager.getInstance(getActivity()).hasActivateSync(acc); mContentProviderHandle = ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE, this); if (isSyncActive()) { startRefresh(); } super.onResume(); }
public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, int newVersion) { // Update database to add the Paid Account flag. This was introduced in // DB version 3. if (oldVersion <= DatabaseVersionNumber.VERSION_1_0_0) { db.execSQL(QUERY_ADD_PAID_ACCOUNT_COLUM); } // Update database to create account content provider if (oldVersion <= DatabaseVersionNumber.VERSION_1_1_0) { // Rename old table db.execSQL(QUERY_RENAME_TABLE_OLD); db.execSQL(QUERY_TABLE_CREATE); db.execSQL(REPLICATE_ACCOUNT); db.execSQL(QUERY_DROP_TABLE_OLD); } // Migrate all accounts to Account Manager if (oldVersion < DatabaseVersionNumber.VERSION_1_5_0) { // List<Account> accounts = AccountProvider.retrieveAccounts(db); android.accounts.Account newAccount; String accountName; AccountManager mAccountManager = AccountManager.get(context); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); SyncContentManager syncManager = SyncContentManager.getInstance(context); for (Account account : accounts) { // Check Account Name accountName = AlfrescoAccountManager.getInstance(context) .createUniqueAccountName(account.getUsername()); newAccount = new android.accounts.Account(accountName, AlfrescoAccount.ACCOUNT_TYPE); Bundle b = new Bundle(); // Very important ! // We keep the same Account Id from previous version. // Used by the SyncService b.putString(AlfrescoAccount.ACCOUNT_ID, Long.toString(account.getId())); BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_NAME, account.getDescription()); BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_URL, account.getUrl()); BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_USERNAME, account.getUsername()); BundleUtils.addIfNotEmpty( b, AlfrescoAccount.ACCOUNT_REPOSITORY_ID, account.getRepositoryId()); BundleUtils.addIfNotEmpty( b, AlfrescoAccount.ACCOUNT_REPOSITORY_TYPE_ID, String.valueOf(account.getTypeId())); BundleUtils.addIfNotEmpty( b, AlfrescoAccount.ACCOUNT_IS_PAID_ACCOUNT, Boolean.toString(account.getIsPaidAccount())); BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_ACTIVATION, account.getActivation()); BundleUtils.addIfNotEmpty( b, AlfrescoAccount.ACCOUNT_ACCESS_TOKEN, account.getAccessToken()); BundleUtils.addIfNotEmpty( b, AlfrescoAccount.ACCOUNT_REFRESH_TOKEN, account.getRefreshToken()); // Time to create. if (mAccountManager.addAccountExplicitly(newAccount, account.getPassword(), b)) { // Let's define if sync automatically regarding previous // settings syncManager.setActivateSync( account.getId(), sharedPref.getBoolean(SYNCHRO_PREFIX + account.getId(), false)); sharedPref.edit().remove(SYNCHRO_PREFIX + account.getId()).apply(); } Log.i( "Migration", "Account " + account.getDescription() + "[" + account.getId() + "] has been migrated"); } // Delete old table db.execSQL(QUERY_DROP_TABLE); } }