Skip to content

Commit

Permalink
Check nullable values in MainApp due to increased Lint
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 authored and AndyScherzinger committed Nov 7, 2023
1 parent 0e0d98a commit fd5df6e
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions app/src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,12 @@ protected void attachBaseContext(Context base) {

if (!isCrashReportingProcess && !appInfo.isDebugBuild()) {
Thread.UncaughtExceptionHandler defaultPlatformHandler = Thread.getDefaultUncaughtExceptionHandler();
final ExceptionHandler crashReporter = new ExceptionHandler(this,
defaultPlatformHandler);
Thread.setDefaultUncaughtExceptionHandler(crashReporter);

if (defaultPlatformHandler != null) {
final ExceptionHandler crashReporter = new ExceptionHandler(this,
defaultPlatformHandler);
Thread.setDefaultUncaughtExceptionHandler(crashReporter);
}
}
}

Expand Down Expand Up @@ -791,25 +794,34 @@ private static void splitOutAutoUploadEntries(Clock clock,
+ syncedFolder.getId() + " - " + syncedFolder.getLocalPath());

for (MediaFolder imageMediaFolder : imageMediaFolders) {
if (imageMediaFolder.absolutePath.equals(syncedFolder.getLocalPath())) {
newSyncedFolder = (SyncedFolder) syncedFolder.clone();
newSyncedFolder.setType(MediaFolderType.IMAGE);
primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
Log_OC.i(TAG, "Migrated image synced_folders record: "
+ primaryKey + " - " + newSyncedFolder.getLocalPath());
break;
String absolutePathOfImageFolder = imageMediaFolder.absolutePath;

if (absolutePathOfImageFolder != null) {
if (absolutePathOfImageFolder.equals(syncedFolder.getLocalPath())) {
newSyncedFolder = (SyncedFolder) syncedFolder.clone();
newSyncedFolder.setType(MediaFolderType.IMAGE);
primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
Log_OC.i(TAG, "Migrated image synced_folders record: "
+ primaryKey + " - " + newSyncedFolder.getLocalPath());
break;
}
}
}

for (MediaFolder videoMediaFolder : videoMediaFolders) {
if (videoMediaFolder.absolutePath.equals(syncedFolder.getLocalPath())) {
newSyncedFolder = (SyncedFolder) syncedFolder.clone();
newSyncedFolder.setType(MediaFolderType.VIDEO);
primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
Log_OC.i(TAG, "Migrated video synced_folders record: "
+ primaryKey + " - " + newSyncedFolder.getLocalPath());
break;
String absolutePathOfVideoFolder = videoMediaFolder.absolutePath;

if (absolutePathOfVideoFolder != null) {
if (absolutePathOfVideoFolder.equals(syncedFolder.getLocalPath())) {
newSyncedFolder = (SyncedFolder) syncedFolder.clone();
newSyncedFolder.setType(MediaFolderType.VIDEO);
primaryKey = syncedFolderProvider.storeSyncedFolder(newSyncedFolder);
Log_OC.i(TAG, "Migrated video synced_folders record: "
+ primaryKey + " - " + newSyncedFolder.getLocalPath());
break;
}
}

}
}

Expand All @@ -835,19 +847,22 @@ private static void cleanOldEntries(Clock 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());
Long folderId = syncedFolders.get(checkPair);

if (folderId != null) {
if (syncedFolder.getId() > folderId) {
syncedFolders.put(checkPair, syncedFolder.getId());
}
}
} else {
syncedFolders.put(checkPair, syncedFolder.getId());
}
}

ids.addAll(syncedFolders.values());
ArrayList<Long> ids = new ArrayList<>(syncedFolders.values());

if (ids.size() > 0) {
int deletedCount = syncedFolderProvider.deleteSyncedFoldersNotInList(ids);
Expand All @@ -865,18 +880,11 @@ public AndroidInjector<Object> androidInjector() {
return dispatchingAndroidInjector;
}


public static void setAppTheme(DarkMode mode) {
switch (mode) {
case LIGHT:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
break;
case DARK:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
break;
case SYSTEM:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
break;
case LIGHT -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
case DARK -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
case SYSTEM -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
}
}

0 comments on commit fd5df6e

Please sign in to comment.