Skip to content

Commit 5fdaba1

Browse files
committed
update Theme
1 parent 16c8436 commit 5fdaba1

File tree

18 files changed

+203
-258
lines changed

18 files changed

+203
-258
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
android:networkSecurityConfig="@xml/network_security_config"
6767
android:requestLegacyExternalStorage="true"
6868
android:roundIcon="@mipmap/ic_launcher_round"
69-
android:theme="@style/AppTheme.Material3">
69+
android:theme="@style/V27.BaseTheme.App.Toolbar">
7070

7171
<!-- <provider-->
7272
<!-- android:name="androidx.startup.InitializationProvider"-->
@@ -190,7 +190,7 @@
190190
<provider
191191
android:name=".provider.SeafileProvider"
192192
android:authorities="${applicationId}.documents"
193-
android:enabled="@bool/atLeastKitKat"
193+
android:enabled="true"
194194
android:exported="true"
195195
android:grantUriPermissions="true"
196196
android:permission="android.permission.MANAGE_DOCUMENTS">

app/src/main/java/com/seafile/seadroid2/SeafException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class SeafException extends Exception {
1616

1717
public static final SeafException OUT_OF_QUOTA = new SeafException(HTTP_ABOVE_QUOTA, SeadroidApplication.getAppString(R.string.above_quota));
1818
public static final SeafException REQUEST_EXCEPTION = new SeafException(400, "request failed");
19-
public static final SeafException SERVER_INTERNAL_ERROR = new SeafException(500, "server internal error");
19+
public static final SeafException SERVER_INTERNAL_ERROR = new SeafException(500, SeadroidApplication.getAppString(R.string.internal_server_error));
2020

2121
public static final SeafException UNKNOWN_EXCEPTION = new SeafException(1, "unknown error");
2222
public static final SeafException NETWORK_EXCEPTION = new SeafException(2, SeadroidApplication.getAppString(R.string.network_error));

app/src/main/java/com/seafile/seadroid2/enums/FeatureDataSource.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@ public enum FeatureDataSource {
99
AUTO_UPDATE_LOCAL_FILE;
1010

1111
public static TransferDataSource toTransferDataSource(FeatureDataSource transferDataSource) {
12-
switch (transferDataSource) {
13-
case ALBUM_BACKUP:
14-
return TransferDataSource.ALBUM_BACKUP;
15-
case FOLDER_BACKUP:
16-
return TransferDataSource.FOLDER_BACKUP;
17-
case DOWNLOAD, AUTO_UPDATE_LOCAL_FILE:
18-
return TransferDataSource.DOWNLOAD;
19-
case MANUAL_FILE_UPLOAD, SHARE_FILE_TO_SEAFILE:
20-
return TransferDataSource.FILE_BACKUP;
21-
default:
22-
return null;
23-
}
12+
return switch (transferDataSource) {
13+
case ALBUM_BACKUP -> TransferDataSource.ALBUM_BACKUP;
14+
case FOLDER_BACKUP -> TransferDataSource.FOLDER_BACKUP;
15+
case DOWNLOAD, AUTO_UPDATE_LOCAL_FILE -> TransferDataSource.DOWNLOAD;
16+
case MANUAL_FILE_UPLOAD, SHARE_FILE_TO_SEAFILE -> TransferDataSource.FILE_BACKUP;
17+
};
2418
}
2519
}

app/src/main/java/com/seafile/seadroid2/enums/ServiceActionEnum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public enum ServiceActionEnum {
44
RESTART_PHOTO_BACKUP,
55
STOP_PHOTO_BACKUP,
6-
START_FOLDER_BACKUP,
6+
RESTART_FOLDER_BACKUP,
77
STOP_FOLDER_BACKUP,
88
START_MANUAL_UPLOAD,
99
START_SHARE_TO_SEAFILE_UPLOAD,

app/src/main/java/com/seafile/seadroid2/framework/file_monitor/FileSyncService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.seafile.seadroid2.framework.worker.GlobalTransferCacheList;
2929
import com.seafile.seadroid2.framework.worker.queue.TransferModel;
3030
import com.seafile.seadroid2.ui.camera_upload.CameraUploadManager;
31-
import com.seafile.seadroid2.ui.folder_backup.RepoConfig;
3231

3332
import org.apache.commons.io.monitor.FileAlterationListener;
3433
import org.apache.commons.io.monitor.FileAlterationObserver;
@@ -203,7 +202,7 @@ private void startWorkers() {
203202
}
204203

205204
if (FolderBackupSharePreferenceHelper.isFolderBackupEnable()) {
206-
TransferService.restartFolderBackupService(getApplicationContext());
205+
TransferService.restartFolderBackupService(getApplicationContext(), true);
207206
}
208207
}
209208

@@ -306,7 +305,7 @@ private void doBackup(String action, File file) {
306305
TransferService.startLocalFileUpdateService(getApplicationContext());
307306
}
308307
} else {
309-
TransferService.restartFolderBackupService(getApplicationContext());
308+
TransferService.restartFolderBackupService(getApplicationContext(), true);
310309
}
311310
}
312311

app/src/main/java/com/seafile/seadroid2/framework/service/TransferService.java

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.concurrent.ThreadFactory;
4141
import java.util.concurrent.ThreadPoolExecutor;
4242
import java.util.concurrent.TimeUnit;
43+
import java.util.concurrent.atomic.AtomicBoolean;
4344
import java.util.concurrent.atomic.AtomicInteger;
4445
import java.util.function.BiConsumer;
4546

@@ -48,8 +49,17 @@ public class TransferService extends EventService {
4849

4950
private TransferNotificationDispatcher transferNotificationDispatcher;
5051

52+
private static final ConcurrentHashMap<FeatureDataSource, CompletableFuture<Void>> _activeTasks = new ConcurrentHashMap<>();
53+
private static final AtomicBoolean _isRunning = new AtomicBoolean(false);
5154
private final AtomicInteger runningTaskCount = new AtomicInteger(0);
52-
private final ConcurrentHashMap<FeatureDataSource, CompletableFuture<Void>> _activeTasks = new ConcurrentHashMap<>();
55+
56+
public static boolean getServiceRunning() {
57+
return _isRunning.get();
58+
}
59+
60+
public static ConcurrentHashMap<FeatureDataSource, CompletableFuture<Void>> getActiveTasks() {
61+
return _activeTasks;
62+
}
5363

5464
private ThreadPoolExecutor _executor;
5565
// 使用线程池工厂创建可配置的线程池
@@ -61,38 +71,38 @@ public static void restartPhotoBackupService(Context context) {
6171
Bundle bundle = new Bundle();
6272
bundle.putBoolean("is_force", true);
6373
bundle.putBoolean("is_restart", true);
64-
startService(context, "RESTART_PHOTO_BACKUP", bundle);
74+
startService(context, ServiceActionEnum.RESTART_PHOTO_BACKUP.name(), bundle);
6575
}
6676

6777
public static void stopPhotoBackupService(Context context) {
68-
startService(context, "STOP_PHOTO_BACKUP");
78+
startService(context, ServiceActionEnum.STOP_PHOTO_BACKUP.name());
6979
}
7080

71-
public static void restartFolderBackupService(Context context) {
81+
public static void restartFolderBackupService(Context context, boolean isForce) {
7282
Bundle bundle = new Bundle();
73-
bundle.putBoolean("is_force", true);
83+
bundle.putBoolean("is_force", isForce);
7484
bundle.putBoolean("is_restart", true);
75-
startService(context, "START_FOLDER_BACKUP", bundle);
85+
startService(context, ServiceActionEnum.RESTART_FOLDER_BACKUP.name(), bundle);
7686
}
7787

7888
public static void stopFolderBackupService(Context context) {
79-
startService(context, "STOP_FOLDER_BACKUP");
89+
startService(context, ServiceActionEnum.STOP_FOLDER_BACKUP.name());
8090
}
8191

8292
public static void startManualUploadService(Context context) {
83-
startService(context, "START_MANUAL_UPLOAD");
93+
startService(context, ServiceActionEnum.START_MANUAL_UPLOAD.name());
8494
}
8595

8696
public static void startShareToSeafileUploadService(Context context) {
87-
startService(context, "START_SHARE_TO_SEAFILE_UPLOAD");
97+
startService(context, ServiceActionEnum.START_SHARE_TO_SEAFILE_UPLOAD.name());
8898
}
8999

90100
public static void startDownloadService(Context context) {
91-
startService(context, "START_FILE_DOWNLOAD");
101+
startService(context, ServiceActionEnum.START_FILE_DOWNLOAD.name());
92102
}
93103

94104
public static void startLocalFileUpdateService(Context context) {
95-
startService(context, "START_LOCAL_FILE_UPDATE");
105+
startService(context, ServiceActionEnum.START_LOCAL_FILE_UPDATE.name());
96106
}
97107

98108
public static void stopTransfer(Context context, TransferModel model) {
@@ -170,6 +180,9 @@ public IBinder onBind(Intent intent) {
170180

171181
@Override
172182
public int onStartCommand(Intent intent, int flags, int startId) {
183+
184+
_isRunning.set(true);
185+
173186
if (intent == null) return START_STICKY;
174187

175188
String action = intent.getAction();
@@ -189,7 +202,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
189202
stopPhotoBackup();
190203

191204
break;
192-
case START_FOLDER_BACKUP:
205+
case RESTART_FOLDER_BACKUP:
193206
startFolderBackup(intent);
194207

195208
break;
@@ -232,7 +245,7 @@ private void startPhotoBackup(Intent intent) {
232245

233246
if (isRestart) {
234247
// if running, then restart, if not run, start it.
235-
CompletableFuture<Void> future = _activeTasks.get(FeatureDataSource.ALBUM_BACKUP);
248+
CompletableFuture<Void> future = getActiveTasks().get(FeatureDataSource.ALBUM_BACKUP);
236249
if (future != null && !future.isDone() && mediaBackupUploader != null) {
237250
//cancel
238251
mediaBackupUploader.stop();
@@ -259,7 +272,7 @@ private void launchAlbumBackup(Bundle extras) {
259272
private void stopPhotoBackup() {
260273
startForegroundNotification(FeatureDataSource.ALBUM_BACKUP);
261274

262-
CompletableFuture<Void> future = _activeTasks.get(FeatureDataSource.ALBUM_BACKUP);
275+
CompletableFuture<Void> future = getActiveTasks().get(FeatureDataSource.ALBUM_BACKUP);
263276
if (future != null && !future.isDone() && mediaBackupUploader != null) {
264277
mediaBackupUploader.stop();
265278
future.cancel(true);
@@ -283,7 +296,7 @@ private void startFolderBackup(Intent intent) {
283296

284297
if (isRestart) {
285298
// if running, then restart, if not run, start it.
286-
CompletableFuture<Void> folderUploadFuture = _activeTasks.get(FeatureDataSource.FOLDER_BACKUP);
299+
CompletableFuture<Void> folderUploadFuture = getActiveTasks().get(FeatureDataSource.FOLDER_BACKUP);
287300
if (folderUploadFuture != null && !folderUploadFuture.isDone() && folderBackupUploader != null) {
288301
//cancel
289302
folderBackupUploader.stop();
@@ -311,7 +324,7 @@ private void launchFolderBackup(Bundle extras) {
311324
private void stopFolderBackup() {
312325
startForegroundNotification(FeatureDataSource.FOLDER_BACKUP);
313326

314-
CompletableFuture<Void> future = _activeTasks.get(FeatureDataSource.FOLDER_BACKUP);
327+
CompletableFuture<Void> future = getActiveTasks().get(FeatureDataSource.FOLDER_BACKUP);
315328
if (future != null && !future.isDone() && folderBackupUploader != null) {
316329
folderBackupUploader.stop();
317330

@@ -385,7 +398,7 @@ public void stopById(Bundle extras) {
385398
private void manageTask(FeatureDataSource source, Bundle extras) {
386399
startForegroundNotification(source);
387400

388-
CompletableFuture<Void> existingTask = _activeTasks.get(source);
401+
CompletableFuture<Void> existingTask = getActiveTasks().get(source);
389402
if (existingTask != null && !existingTask.isDone()) {
390403
SafeLogs.d(TAG, "manageTask()", source.name(), "task is already running");
391404
return;
@@ -434,21 +447,21 @@ public void run() {
434447
mediaBackupUploader = new MediaBackupUploader(getApplicationContext(), transferNotificationDispatcher);
435448
SeafException uploadSeafException = mediaBackupUploader.upload();
436449
if (uploadSeafException != SeafException.SUCCESS) {
437-
SafeLogs.d(TAG, "runAlbumBackupTask()", "scan error: " + uploadSeafException);
450+
SafeLogs.d(TAG, "runAlbumBackupTask()", "upload error: " + uploadSeafException);
438451
} else {
439-
SafeLogs.d(TAG, "runAlbumBackupTask()", "scan success");
452+
SafeLogs.d(TAG, "runAlbumBackupTask()", "upload success");
440453
}
441454
}
442455
}, new Runnable() {
443456
@Override
444457
public void run() {
445458
mediaBackupUploader = null;
446459
transferNotificationDispatcher.releaseAcquire(FeatureDataSource.ALBUM_BACKUP);
447-
_activeTasks.remove(FeatureDataSource.ALBUM_BACKUP);
460+
getActiveTasks().remove(FeatureDataSource.ALBUM_BACKUP);
448461
}
449462
});
450463

451-
_activeTasks.put(FeatureDataSource.ALBUM_BACKUP, completableFuture);
464+
getActiveTasks().put(FeatureDataSource.ALBUM_BACKUP, completableFuture);
452465

453466
}
454467

@@ -490,11 +503,11 @@ public void run() {
490503
public void run() {
491504
folderBackupUploader = null;
492505
transferNotificationDispatcher.releaseAcquire(FeatureDataSource.FOLDER_BACKUP);
493-
_activeTasks.remove(FeatureDataSource.FOLDER_BACKUP);
506+
getActiveTasks().remove(FeatureDataSource.FOLDER_BACKUP);
494507
}
495508
});
496509

497-
_activeTasks.put(FeatureDataSource.FOLDER_BACKUP, completableFuture);
510+
getActiveTasks().put(FeatureDataSource.FOLDER_BACKUP, completableFuture);
498511
}
499512

500513
private void runFileUploadTask() {
@@ -516,7 +529,7 @@ public void run() {
516529

517530
}
518531
});
519-
_activeTasks.put(FeatureDataSource.MANUAL_FILE_UPLOAD, completableFuture);
532+
getActiveTasks().put(FeatureDataSource.MANUAL_FILE_UPLOAD, completableFuture);
520533

521534
}
522535

@@ -538,10 +551,10 @@ public void run() {
538551
public void run() {
539552
downloader = null;
540553
transferNotificationDispatcher.releaseAcquire(FeatureDataSource.DOWNLOAD);
541-
_activeTasks.remove(FeatureDataSource.DOWNLOAD);
554+
getActiveTasks().remove(FeatureDataSource.DOWNLOAD);
542555
}
543556
});
544-
_activeTasks.put(FeatureDataSource.DOWNLOAD, completableFuture);
557+
getActiveTasks().put(FeatureDataSource.DOWNLOAD, completableFuture);
545558
}
546559

547560
private void runLocalFileUpdateTask() {
@@ -562,10 +575,10 @@ public void run() {
562575
public void run() {
563576
localFileUpdater = null;
564577
transferNotificationDispatcher.releaseAcquire(FeatureDataSource.AUTO_UPDATE_LOCAL_FILE);
565-
_activeTasks.remove(FeatureDataSource.AUTO_UPDATE_LOCAL_FILE);
578+
getActiveTasks().remove(FeatureDataSource.AUTO_UPDATE_LOCAL_FILE);
566579
}
567580
});
568-
_activeTasks.put(FeatureDataSource.AUTO_UPDATE_LOCAL_FILE, completableFuture);
581+
getActiveTasks().put(FeatureDataSource.AUTO_UPDATE_LOCAL_FILE, completableFuture);
569582
}
570583

571584
private void runShareToSeafileUploadTask() {
@@ -587,11 +600,11 @@ public void run() {
587600
public void run() {
588601
shareToSeafileUploader = null;
589602
transferNotificationDispatcher.releaseAcquire(FeatureDataSource.SHARE_FILE_TO_SEAFILE);
590-
_activeTasks.remove(FeatureDataSource.SHARE_FILE_TO_SEAFILE);
603+
getActiveTasks().remove(FeatureDataSource.SHARE_FILE_TO_SEAFILE);
591604
}
592605
});
593606

594-
_activeTasks.put(FeatureDataSource.SHARE_FILE_TO_SEAFILE, completableFuture);
607+
getActiveTasks().put(FeatureDataSource.SHARE_FILE_TO_SEAFILE, completableFuture);
595608
}
596609

597610
private CompletableFuture<Void> runTask(Runnable runnable, Runnable onComplete) {
@@ -602,7 +615,8 @@ private CompletableFuture<Void> runTask(Runnable runnable, Runnable onComplete)
602615
@Override
603616
public void accept(Void unused, Throwable throwable) {
604617
if (onComplete != null) onComplete.run();
605-
if (runningTaskCount.decrementAndGet() == 0) {
618+
int currentCount = runningTaskCount.decrementAndGet();
619+
if (currentCount == 0) {
606620
stopThisService();
607621
SafeLogs.e(TAG + " - all task complete");
608622
}
@@ -621,7 +635,7 @@ private void stopThisService() {
621635
public void onDestroy() {
622636
SafeLogs.e(TAG, "onDestroy()");
623637

624-
_activeTasks.forEach((key, value) -> {
638+
getActiveTasks().forEach((key, value) -> {
625639
cancel(value);
626640
});
627641

@@ -640,6 +654,8 @@ public void onDestroy() {
640654
}
641655
}
642656

657+
_isRunning.set(false);
658+
643659
super.onDestroy();
644660
}
645661

app/src/main/java/com/seafile/seadroid2/framework/util/ExceptionUtils.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ public static SeafException parseByThrowable(Throwable throwable) {
7979
}
8080

8181
public static SeafException parse(int errorCode, String bodyString) {
82-
//401
83-
if (HttpURLConnection.HTTP_UNAUTHORIZED == errorCode) {
84-
return SeafException.NOT_FOUND_LOGGED_USER_EXCEPTION;
85-
}
8682

8783
//400
8884
if (HttpURLConnection.HTTP_BAD_REQUEST == errorCode) {
@@ -98,21 +94,17 @@ public static SeafException parse(int errorCode, String bodyString) {
9894
if (bodyString.toLowerCase().contains("operation not supported")) {
9995
return SeafException.OPERATION_NOT_SUPPORTED_EXCEPTION;
10096
}
101-
//{
102-
// "non_field_errors" : [ "Not allowed to connect to android client." ]
103-
//}
97+
98+
//{
99+
// "non_field_errors" : [ "Not allowed to connect to android client." ]
100+
//}
104101
return SeafException.REQUEST_EXCEPTION;
105102
}
106103

107-
//504
108-
if (HttpURLConnection.HTTP_GATEWAY_TIMEOUT == errorCode) {
109-
if (NetworkUtils.isConnected()) {
110-
Toasts.show(R.string.transfer_list_network_error);
111-
} else {
112-
Toasts.show(R.string.network_unavailable);
113-
}
114104

115-
return SeafException.NETWORK_EXCEPTION;
105+
//401
106+
if (HttpURLConnection.HTTP_UNAUTHORIZED == errorCode) {
107+
return SeafException.NOT_FOUND_LOGGED_USER_EXCEPTION;
116108
}
117109

118110
//403, need to re-logg-in
@@ -136,7 +128,7 @@ public static SeafException parse(int errorCode, String bodyString) {
136128
}
137129

138130
//500: HTTP_INTERNAL_ERROR
139-
if (HttpURLConnection.HTTP_INTERNAL_ERROR == errorCode) {
131+
if (errorCode >= HttpURLConnection.HTTP_INTERNAL_ERROR) {
140132
return SeafException.SERVER_INTERNAL_ERROR;
141133
}
142134

app/src/main/java/com/seafile/seadroid2/ui/account/AccountViewModel.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public void subscribe(SingleEmitter<Account> emitter) throws Exception {
9393
}
9494

9595
//the SYNC way
96-
9796
Call<TokenModel> call = getLoginCall(tempAccount, pwd, authToken, isRememberDevice);
9897
Response<TokenModel> response = call.execute();
9998
if (!response.isSuccessful()) {

0 commit comments

Comments
 (0)