Skip to content

Commit 109c3ec

Browse files
authored
Merge pull request #198 from kaczmarkiewiczp/dev
Show more info in notification during transfers
2 parents 22156fb + 658c0a0 commit 109c3ec

File tree

7 files changed

+100
-17
lines changed

7 files changed

+100
-17
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/ca/pkay/rcloneexplorer/MainActivity.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ private void startRemotesFragment() {
306306
fragmentManager.popBackStack();
307307
}
308308

309-
fragmentManager.beginTransaction().replace(R.id.flFragment, fragment).commit();
309+
if (!isFinishing()) {
310+
fragmentManager.beginTransaction().replace(R.id.flFragment, fragment).commitAllowingStateLoss();
311+
}
310312
}
311313

312314
private RemoteItem getRemoteItemFromName(String remoteName) {

app/src/main/java/ca/pkay/rcloneexplorer/Rclone.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ public Process sync(RemoteItem remoteItem, String remote, String localPath, int
385385
String remotePath = (remote.compareTo("//" + remoteName) == 0) ? remoteName + ":" + localRemotePath : remoteName + ":" + localRemotePath + remote;
386386

387387
if (syncDirection == 1) {
388-
command = createCommandWithOptions("sync", localPath, remotePath, "--stats=1s", "--stats-log-level", "NOTICE");
388+
command = createCommandWithOptions("sync", localPath, remotePath, "--transfers", "1", "--stats=1s", "--stats-log-level", "NOTICE");
389389
} else if (syncDirection == 2) {
390-
command = createCommandWithOptions("sync", remotePath, localPath, "--stats=1s", "--stats-log-level", "NOTICE");
390+
command = createCommandWithOptions("sync", remotePath, localPath, "--transfers", "1", "--stats=1s", "--stats-log-level", "NOTICE");
391391
} else {
392392
return null;
393393
}
@@ -416,7 +416,7 @@ public Process downloadFile(RemoteItem remote, FileItem downloadItem, String dow
416416
} else {
417417
localFilePath = downloadPath;
418418
}
419-
command = createCommandWithOptions("copy", remoteFilePath, localFilePath, "--stats=1s", "--stats-log-level", "NOTICE");
419+
command = createCommandWithOptions("copy", remoteFilePath, localFilePath, "--transfers", "1", "--stats=1s", "--stats-log-level", "NOTICE");
420420

421421
try {
422422
return Runtime.getRuntime().exec(command);
@@ -447,7 +447,7 @@ public Process uploadFile(RemoteItem remote, String uploadPath, String uploadFil
447447
path = (uploadPath.compareTo("//" + remoteName) == 0) ? remoteName + ":" + localRemotePath : remoteName + ":" + localRemotePath + uploadPath;
448448
}
449449

450-
command = createCommandWithOptions("copy", uploadFile, path, "--stats=1s", "--stats-log-level", "NOTICE");
450+
command = createCommandWithOptions("copy", uploadFile, path, "--transfers", "1", "--stats=1s", "--stats-log-level", "NOTICE");
451451

452452
try {
453453
return Runtime.getRuntime().exec(command);

app/src/main/java/ca/pkay/rcloneexplorer/Services/DownloadService.java

+32-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.io.BufferedReader;
1616
import java.io.IOException;
1717
import java.io.InputStreamReader;
18+
import java.util.regex.Matcher;
19+
import java.util.regex.Pattern;
1820

1921
import ca.pkay.rcloneexplorer.BroadcastReceivers.DownloadCancelAction;
2022
import ca.pkay.rcloneexplorer.Items.FileItem;
@@ -83,10 +85,28 @@ protected void onHandleIntent(@Nullable Intent intent) {
8385
try {
8486
BufferedReader reader = new BufferedReader(new InputStreamReader(currentProcess.getErrorStream()));
8587
String line;
88+
String notificationContent = "";
89+
String[] notificationBigText = new String[5];
8690
while ((line = reader.readLine()) != null) {
8791
if (line.startsWith("Transferred:") && !line.matches("Transferred:\\s+\\d+$")) {
88-
updateNotification(downloadItem, line);
92+
notificationBigText[0] = line;
93+
notificationContent = line;
8994
}
95+
if (line.startsWith(" *")) {
96+
String s = line.substring(2).trim();
97+
notificationBigText[1] = s;
98+
}
99+
if (line.startsWith("Errors:")) {
100+
notificationBigText[2] = line;
101+
}
102+
if (line.startsWith("Checks:")) {
103+
notificationBigText[3] = line;
104+
}
105+
if (line.matches("Transferred:\\s+\\d+$")) {
106+
notificationBigText[4] = line;
107+
}
108+
109+
updateNotification(downloadItem, notificationContent, notificationBigText);
90110
}
91111
} catch (IOException e) {
92112
e.printStackTrace();
@@ -111,7 +131,15 @@ protected void onHandleIntent(@Nullable Intent intent) {
111131
stopForeground(true);
112132
}
113133

114-
private void updateNotification(FileItem downloadItem, String transferred) {
134+
private void updateNotification(FileItem downloadItem, String content, String[] bigTextArray) {
135+
StringBuilder bigText = new StringBuilder();
136+
for (int i = 0; i < bigTextArray.length; i++) {
137+
bigText.append(bigTextArray[i]);
138+
if (i < 4) {
139+
bigText.append("\n");
140+
}
141+
}
142+
115143
Intent foregroundIntent = new Intent(this, DownloadService.class);
116144
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);
117145

@@ -120,12 +148,11 @@ private void updateNotification(FileItem downloadItem, String transferred) {
120148

121149
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
122150
.setSmallIcon(android.R.drawable.stat_sys_download)
123-
//.setContentTitle(getString(R.string.download_service_notification_title))
124151
.setContentTitle(downloadItem.getName())
125-
//.setContentText(downloadItem.getName())
126-
.setContentText(transferred)
152+
.setContentText(content)
127153
.setPriority(NotificationCompat.PRIORITY_LOW)
128154
.setContentIntent(pendingIntent)
155+
.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString()))
129156
.addAction(R.drawable.ic_cancel_download, getString(R.string.cancel), cancelPendingIntent);
130157

131158
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);

app/src/main/java/ca/pkay/rcloneexplorer/Services/SyncService.java

+30-3
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,28 @@ protected void onHandleIntent(@Nullable Intent intent) {
8686
try {
8787
BufferedReader reader = new BufferedReader(new InputStreamReader(currentProcess.getErrorStream()));
8888
String line;
89+
String notificationContent = "";
90+
String[] notificationBigText = new String[5];
8991
while ((line = reader.readLine()) != null) {
9092
if (line.startsWith("Transferred:") && !line.matches("Transferred:\\s+\\d+$")) {
91-
updateNotification(title, line);
93+
notificationBigText[0] = line;
94+
notificationContent = line;
9295
}
96+
if (line.startsWith(" *")) {
97+
String s = line.substring(2).trim();
98+
notificationBigText[1] = s;
99+
}
100+
if (line.startsWith("Errors:")) {
101+
notificationBigText[2] = line;
102+
}
103+
if (line.startsWith("Checks:")) {
104+
notificationBigText[3] = line;
105+
}
106+
if (line.matches("Transferred:\\s+\\d+$")) {
107+
notificationBigText[4] = line;
108+
}
109+
110+
updateNotification(title, notificationContent, notificationBigText);
93111
}
94112
} catch (IOException e) {
95113
e.printStackTrace();
@@ -114,7 +132,15 @@ protected void onHandleIntent(@Nullable Intent intent) {
114132
stopForeground(true);
115133
}
116134

117-
private void updateNotification(String title, String transferred) {
135+
private void updateNotification(String title, String content, String[] bigTextArray) {
136+
StringBuilder bigText = new StringBuilder();
137+
for (int i = 0; i < bigTextArray.length; i++) {
138+
bigText.append(bigTextArray[i]);
139+
if (i < 4) {
140+
bigText.append("\n");
141+
}
142+
}
143+
118144
Intent foregroundIntent = new Intent(this, SyncService.class);
119145
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);
120146

@@ -124,8 +150,9 @@ private void updateNotification(String title, String transferred) {
124150
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
125151
.setSmallIcon(R.drawable.ic_notification)
126152
.setContentTitle(getString(R.string.syncing_service, title))
127-
.setContentText(transferred)
153+
.setContentText(content)
128154
.setContentIntent(pendingIntent)
155+
.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString()))
129156
.addAction(R.drawable.ic_cancel_download, getString(R.string.cancel), cancelPendingIntent)
130157
.setPriority(NotificationCompat.PRIORITY_LOW);
131158

app/src/main/java/ca/pkay/rcloneexplorer/Services/UploadService.java

+30-3
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,28 @@ protected void onHandleIntent(@Nullable Intent intent) {
9090
try {
9191
BufferedReader reader = new BufferedReader(new InputStreamReader(currentProcess.getErrorStream()));
9292
String line;
93+
String notificationContent = "";
94+
String[] notificationBigText = new String[5];
9395
while ((line = reader.readLine()) != null) {
9496
if (line.startsWith("Transferred:") && !line.matches("Transferred:\\s+\\d+$")) {
95-
updateNotification(uploadFileName, line);
97+
notificationBigText[0] = line;
98+
notificationContent = line;
9699
}
100+
if (line.startsWith(" *")) {
101+
String s = line.substring(2).trim();
102+
notificationBigText[1] = s;
103+
}
104+
if (line.startsWith("Errors:")) {
105+
notificationBigText[2] = line;
106+
}
107+
if (line.startsWith("Checks:")) {
108+
notificationBigText[3] = line;
109+
}
110+
if (line.matches("Transferred:\\s+\\d+$")) {
111+
notificationBigText[4] = line;
112+
}
113+
114+
updateNotification(uploadFileName, notificationContent, notificationBigText);
97115
}
98116
} catch (IOException e) {
99117
e.printStackTrace();
@@ -116,7 +134,15 @@ protected void onHandleIntent(@Nullable Intent intent) {
116134
stopForeground(true);
117135
}
118136

119-
private void updateNotification(String uploadFileName, String transferred) {
137+
private void updateNotification(String uploadFileName, String content, String[] bigTextArray) {
138+
StringBuilder bigText = new StringBuilder();
139+
for (int i = 0; i < bigTextArray.length; i++) {
140+
bigText.append(bigTextArray[i]);
141+
if (i < 4) {
142+
bigText.append("\n");
143+
}
144+
}
145+
120146
Intent foregroundIntent = new Intent(this, UploadService.class);
121147
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);
122148

@@ -126,9 +152,10 @@ private void updateNotification(String uploadFileName, String transferred) {
126152
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
127153
.setSmallIcon(android.R.drawable.stat_sys_upload)
128154
.setContentTitle(uploadFileName)
129-
.setContentText(transferred)
155+
.setContentText(content)
130156
.setPriority(NotificationCompat.PRIORITY_LOW)
131157
.setContentIntent(pendingIntent)
158+
.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString()))
132159
.addAction(R.drawable.ic_cancel_download, getString(R.string.cancel), cancelPendingIntent);
133160

134161
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);

0 commit comments

Comments
 (0)