Skip to content

Commit

Permalink
Merge pull request #198 from kaczmarkiewiczp/dev
Browse files Browse the repository at this point in the history
Show more info in notification during transfers
  • Loading branch information
patrykcoding authored Aug 5, 2018
2 parents 22156fb + 658c0a0 commit 109c3ec
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 17 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion app/src/main/java/ca/pkay/rcloneexplorer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ private void startRemotesFragment() {
fragmentManager.popBackStack();
}

fragmentManager.beginTransaction().replace(R.id.flFragment, fragment).commit();
if (!isFinishing()) {
fragmentManager.beginTransaction().replace(R.id.flFragment, fragment).commitAllowingStateLoss();
}
}

private RemoteItem getRemoteItemFromName(String remoteName) {
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/ca/pkay/rcloneexplorer/Rclone.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ public Process sync(RemoteItem remoteItem, String remote, String localPath, int
String remotePath = (remote.compareTo("//" + remoteName) == 0) ? remoteName + ":" + localRemotePath : remoteName + ":" + localRemotePath + remote;

if (syncDirection == 1) {
command = createCommandWithOptions("sync", localPath, remotePath, "--stats=1s", "--stats-log-level", "NOTICE");
command = createCommandWithOptions("sync", localPath, remotePath, "--transfers", "1", "--stats=1s", "--stats-log-level", "NOTICE");
} else if (syncDirection == 2) {
command = createCommandWithOptions("sync", remotePath, localPath, "--stats=1s", "--stats-log-level", "NOTICE");
command = createCommandWithOptions("sync", remotePath, localPath, "--transfers", "1", "--stats=1s", "--stats-log-level", "NOTICE");
} else {
return null;
}
Expand Down Expand Up @@ -416,7 +416,7 @@ public Process downloadFile(RemoteItem remote, FileItem downloadItem, String dow
} else {
localFilePath = downloadPath;
}
command = createCommandWithOptions("copy", remoteFilePath, localFilePath, "--stats=1s", "--stats-log-level", "NOTICE");
command = createCommandWithOptions("copy", remoteFilePath, localFilePath, "--transfers", "1", "--stats=1s", "--stats-log-level", "NOTICE");

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

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

try {
return Runtime.getRuntime().exec(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import ca.pkay.rcloneexplorer.BroadcastReceivers.DownloadCancelAction;
import ca.pkay.rcloneexplorer.Items.FileItem;
Expand Down Expand Up @@ -83,10 +85,28 @@ protected void onHandleIntent(@Nullable Intent intent) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(currentProcess.getErrorStream()));
String line;
String notificationContent = "";
String[] notificationBigText = new String[5];
while ((line = reader.readLine()) != null) {
if (line.startsWith("Transferred:") && !line.matches("Transferred:\\s+\\d+$")) {
updateNotification(downloadItem, line);
notificationBigText[0] = line;
notificationContent = line;
}
if (line.startsWith(" *")) {
String s = line.substring(2).trim();
notificationBigText[1] = s;
}
if (line.startsWith("Errors:")) {
notificationBigText[2] = line;
}
if (line.startsWith("Checks:")) {
notificationBigText[3] = line;
}
if (line.matches("Transferred:\\s+\\d+$")) {
notificationBigText[4] = line;
}

updateNotification(downloadItem, notificationContent, notificationBigText);
}
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -111,7 +131,15 @@ protected void onHandleIntent(@Nullable Intent intent) {
stopForeground(true);
}

private void updateNotification(FileItem downloadItem, String transferred) {
private void updateNotification(FileItem downloadItem, String content, String[] bigTextArray) {
StringBuilder bigText = new StringBuilder();
for (int i = 0; i < bigTextArray.length; i++) {
bigText.append(bigTextArray[i]);
if (i < 4) {
bigText.append("\n");
}
}

Intent foregroundIntent = new Intent(this, DownloadService.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);

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

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(android.R.drawable.stat_sys_download)
//.setContentTitle(getString(R.string.download_service_notification_title))
.setContentTitle(downloadItem.getName())
//.setContentText(downloadItem.getName())
.setContentText(transferred)
.setContentText(content)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString()))
.addAction(R.drawable.ic_cancel_download, getString(R.string.cancel), cancelPendingIntent);

NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
Expand Down
33 changes: 30 additions & 3 deletions app/src/main/java/ca/pkay/rcloneexplorer/Services/SyncService.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,28 @@ protected void onHandleIntent(@Nullable Intent intent) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(currentProcess.getErrorStream()));
String line;
String notificationContent = "";
String[] notificationBigText = new String[5];
while ((line = reader.readLine()) != null) {
if (line.startsWith("Transferred:") && !line.matches("Transferred:\\s+\\d+$")) {
updateNotification(title, line);
notificationBigText[0] = line;
notificationContent = line;
}
if (line.startsWith(" *")) {
String s = line.substring(2).trim();
notificationBigText[1] = s;
}
if (line.startsWith("Errors:")) {
notificationBigText[2] = line;
}
if (line.startsWith("Checks:")) {
notificationBigText[3] = line;
}
if (line.matches("Transferred:\\s+\\d+$")) {
notificationBigText[4] = line;
}

updateNotification(title, notificationContent, notificationBigText);
}
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -114,7 +132,15 @@ protected void onHandleIntent(@Nullable Intent intent) {
stopForeground(true);
}

private void updateNotification(String title, String transferred) {
private void updateNotification(String title, String content, String[] bigTextArray) {
StringBuilder bigText = new StringBuilder();
for (int i = 0; i < bigTextArray.length; i++) {
bigText.append(bigTextArray[i]);
if (i < 4) {
bigText.append("\n");
}
}

Intent foregroundIntent = new Intent(this, SyncService.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,28 @@ protected void onHandleIntent(@Nullable Intent intent) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(currentProcess.getErrorStream()));
String line;
String notificationContent = "";
String[] notificationBigText = new String[5];
while ((line = reader.readLine()) != null) {
if (line.startsWith("Transferred:") && !line.matches("Transferred:\\s+\\d+$")) {
updateNotification(uploadFileName, line);
notificationBigText[0] = line;
notificationContent = line;
}
if (line.startsWith(" *")) {
String s = line.substring(2).trim();
notificationBigText[1] = s;
}
if (line.startsWith("Errors:")) {
notificationBigText[2] = line;
}
if (line.startsWith("Checks:")) {
notificationBigText[3] = line;
}
if (line.matches("Transferred:\\s+\\d+$")) {
notificationBigText[4] = line;
}

updateNotification(uploadFileName, notificationContent, notificationBigText);
}
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -116,7 +134,15 @@ protected void onHandleIntent(@Nullable Intent intent) {
stopForeground(true);
}

private void updateNotification(String uploadFileName, String transferred) {
private void updateNotification(String uploadFileName, String content, String[] bigTextArray) {
StringBuilder bigText = new StringBuilder();
for (int i = 0; i < bigTextArray.length; i++) {
bigText.append(bigTextArray[i]);
if (i < 4) {
bigText.append("\n");
}
}

Intent foregroundIntent = new Intent(this, UploadService.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);

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

NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
Expand Down

0 comments on commit 109c3ec

Please sign in to comment.