use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.
the class PushUtils method migratePushKeys.
private static void migratePushKeys() {
Context context = MainApp.getAppContext();
AppPreferences preferences = AppPreferencesImpl.fromContext(context);
if (!preferences.isKeysMigrationEnabled()) {
String oldKeyPath = MainApp.getStoragePath() + File.separator + MainApp.getDataFolder() + File.separator + "nc-keypair";
File oldPrivateKeyFile = new File(oldKeyPath, "push_key.priv");
File oldPublicKeyFile = new File(oldKeyPath, "push_key.pub");
String keyPath = context.getDir("nc-keypair", Context.MODE_PRIVATE).getAbsolutePath();
File privateKeyFile = new File(keyPath, "push_key.priv");
File publicKeyFile = new File(keyPath, "push_key.pub");
if ((privateKeyFile.exists() && publicKeyFile.exists()) || (!oldPrivateKeyFile.exists() && !oldPublicKeyFile.exists())) {
preferences.setKeysMigrationEnabled(true);
} else {
if (oldPrivateKeyFile.exists()) {
FileStorageUtils.moveFile(oldPrivateKeyFile, privateKeyFile);
}
if (oldPublicKeyFile.exists()) {
FileStorageUtils.moveFile(oldPublicKeyFile, publicKeyFile);
}
if (privateKeyFile.exists() && publicKeyFile.exists()) {
preferences.setKeysMigrationEnabled(true);
}
}
}
}
use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.
the class MainApp method updateToAutoUpload.
private static void updateToAutoUpload() {
Context context = getAppContext();
AppPreferences preferences = AppPreferencesImpl.fromContext(context);
if (preferences.instantPictureUploadEnabled() || preferences.instantVideoUploadEnabled()) {
preferences.removeLegacyPreferences();
// show info pop-up
try {
new AlertDialog.Builder(context, R.style.Theme_ownCloud_Dialog).setTitle(R.string.drawer_synced_folders).setMessage(R.string.synced_folders_new_info).setPositiveButton(R.string.drawer_open, (dialog, which) -> {
// show Auto Upload
Intent folderSyncIntent = new Intent(context, SyncedFoldersActivity.class);
dialog.dismiss();
context.startActivity(folderSyncIntent);
}).setNegativeButton(R.string.drawer_close, (dialog, which) -> dialog.dismiss()).setIcon(R.drawable.nav_synced_folders).show();
} catch (WindowManager.BadTokenException e) {
Log_OC.i(TAG, "Error showing Auto Upload Update dialog, so skipping it: " + e.getMessage());
}
}
}
use of com.nextcloud.client.preferences.AppPreferences in project android by nextcloud.
the class MainApp method cleanOldEntries.
private static void cleanOldEntries(Clock clock) {
// previous versions of application created broken entries in the SyncedFolderProvider
// database, and this cleans all that and leaves 1 (newest) entry per synced folder
Context context = getAppContext();
AppPreferences preferences = AppPreferencesImpl.fromContext(context);
if (!preferences.isLegacyClean()) {
SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(context.getContentResolver(), preferences, clock);
List<SyncedFolder> syncedFolderList = syncedFolderProvider.getSyncedFolders();
Map<Pair<String, String>, Long> syncedFolders = new HashMap<>();
ArrayList<Long> ids = new ArrayList<>();
for (SyncedFolder syncedFolder : syncedFolderList) {
Pair<String, String> checkPair = new Pair<>(syncedFolder.getAccount(), syncedFolder.getLocalPath());
if (syncedFolders.containsKey(checkPair)) {
if (syncedFolder.getId() > syncedFolders.get(checkPair)) {
syncedFolders.put(checkPair, syncedFolder.getId());
}
} else {
syncedFolders.put(checkPair, syncedFolder.getId());
}
}
ids.addAll(syncedFolders.values());
if (ids.size() > 0) {
int deletedCount = syncedFolderProvider.deleteSyncedFoldersNotInList(ids);
if (deletedCount > 0) {
preferences.setLegacyClean(true);
}
} else {
preferences.setLegacyClean(true);
}
}
}
Aggregations