Skip to content

Commit

Permalink
Merge pull request #56 from kaczmarkiewiczp/dev
Browse files Browse the repository at this point in the history
Group notifications
  • Loading branch information
patrykcoding authored Apr 24, 2018
2 parents cb9293c + e083143 commit f875a05
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 73 deletions.
5 changes: 3 additions & 2 deletions .idea/assetWizardSettings.xml

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

Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ Grab the [latest version](https://github.com/kaczmarkiewiczp/rcloneExplorer/rele
Credits/Libraries
-----------------
- [About Libraries](https://github.com/mikepenz/AboutLibraries) - AboutLibraries is a library to offer some information of libraries.
- [Android Iconics](https://github.com/mikepenz/Android-Iconics) - Use any icon font, or vector (.svg) as drawable in your application.
- [ExFile Picker](https://github.com/bartwell/ExFilePicker) - Open source Android library. Implement choosing files and directories in your application.
- [Floating Action Button SpeedDial](https://github.com/leinardi/FloatingActionButtonSpeedDial) - A Floating Action Button Speed Dial implementation for Android that follows the Material Design specification
- [Font Awesome Icons](https://fontawesome.com/) - The iconic SVG, font, and CSS toolkit
- [Markdown View](https://github.com/falnatsheh/MarkdownView) - MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.
- [Material Design Icons](https://github.com/Templarian/MaterialDesign) - 2200+ Material Design Icons from the Community
- [Material Dialogs](https://github.com/afollestad/material-dialogs) - A beautiful, fluid, and customizable dialogs API
- [rclone](https://github.com/ncw/rclone) - "rsync for cloud storage"
- [Toasty](https://github.com/GrenderG/Toasty) - The usual Toast, but with steroids
Expand Down
4 changes: 0 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ dependencies {
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
implementation "com.leinardi.android:speed-dial:1.0-alpha03"
implementation 'ru.bartwell:exfilepicker:2.4'
implementation "com.mikepenz:iconics-core:3.0.3@aar"
implementation 'com.mikepenz:community-material-typeface:2.0.46.1@aar'
implementation 'com.mikepenz:fontawesome-typeface:5.0.6.0@aar'
implementation 'com.mikepenz:octicons-typeface:3.2.0.4@aar'
implementation "com.mikepenz:aboutlibraries:6.0.8"
implementation 'us.feras.mdv:markdownview:1.1.0'
implementation 'jp.wasabeef:recyclerview-animators:2.3.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ca.pkay.rcloneexplorer.RecyclerViewAdapters;


import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
Expand All @@ -10,11 +9,6 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.mikepenz.community_material_typeface_library.CommunityMaterial;
import com.mikepenz.fontawesome_typeface_library.FontAwesome;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.octicons_typeface_library.Octicons;

import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -50,40 +44,40 @@ public void onBindViewHolder(@NonNull final ViewHolder holder, final int positio

switch (remoteType) {
case "crypt":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(CommunityMaterial.Icon.cmd_lock).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_lock_black));
break;
case "amazon cloud drive":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(CommunityMaterial.Icon.cmd_amazon).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_amazon));
break;
case "b2":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(FontAwesome.Icon.faw_gripfire).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_b2));
break;
case "drive":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(CommunityMaterial.Icon.cmd_google_drive).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_google_drive));
break;
case "dropbox":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(CommunityMaterial.Icon.cmd_dropbox).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_dropbox));
break;
case "google cloud storage":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(CommunityMaterial.Icon.cmd_google_drive).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_google));
break;
case "onedrive":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(CommunityMaterial.Icon.cmd_onedrive).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_onedrive));
break;
case "s3":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(CommunityMaterial.Icon.cmd_amazon).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_amazon));
break;
case "yandex":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(FontAwesome.Icon.faw_yandex).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_yandex));
break;
case "box":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(CommunityMaterial.Icon.cmd_box).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_box));
break;
case "sftp":
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(Octicons.Icon.oct_terminal).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_terminal));
break;
default:
holder.ivIcon.setImageDrawable(new IconicsDrawable(view.getContext()).icon(CommunityMaterial.Icon.cmd_cloud).color(Color.BLACK).sizeDp(24));
holder.ivIcon.setImageDrawable(view.getResources().getDrawable(R.drawable.ic_cloud));
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.SuppressLint;
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand All @@ -11,6 +12,7 @@
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;

import java.util.List;
import java.util.concurrent.ExecutionException;
Expand All @@ -26,7 +28,9 @@ public class DownloadService extends IntentService {
public static final String DOWNLOAD_LIST_ARG = "ca.pkay.rcexplorer.download_service.arg1";
public static final String DOWNLOAD_PATH_ARG = "ca.pkay.rcexplorer.download_service.arg2";
public static final String REMOTE_ARG = "ca.pkay.rcexplorer.download_service.arg3";
private final String CHANNEL_ID = "ca.pkay.rcexplorer.download_channel";
private final String CHANNEL_ID = "ca.pkay.rcexplorer.DOWNLOAD_CHANNEL";
private final String DOWNLOAD_FINISHED_GROUP = "ca.pkay.rcexplorer.DOWNLOAD_FINISHED_GROUP";
private final String DOWNLOAD_FAILED_GROUP = "ca.pkay.rcexplorer.DOWNLOAD_FAILED_GROUP";
private final String CHANNEL_NAME = "Downloads";
private final int PERSISTENT_NOTIFICATION_ID = 167;
private final int FAILED_DOWNLOAD_NOTIFICATION_ID = 138;
Expand Down Expand Up @@ -81,9 +85,8 @@ protected void onHandleIntent(@Nullable Intent intent) {
numOfFinishedDownloads = 0;
numOfFailedDownloads = 0;
AsyncTask[] asyncTasks = new AsyncTask[numOfRunningProcesses];
int i = 0;
for (Process process : runningProcesses) {
asyncTasks[i++] = new MonitorDownload().execute(process);
for (int i = 0; i < numOfRunningProcesses; i++) {
asyncTasks[i] = new MonitorDownload(downloadList.get(i), runningProcesses.get(i)).execute();
}

for (AsyncTask asyncTask : asyncTasks) {
Expand All @@ -97,32 +100,65 @@ protected void onHandleIntent(@Nullable Intent intent) {
stopForeground(true);
}

private void showDownloadFinishedNotification(int numOfFinishedDownloads, int numOfTotalDownloads) {
String notificationText = numOfFinishedDownloads + " " + getString(R.string.out_of) + " " + numOfTotalDownloads + " " + getString(R.string.downloads_finished);
private void showDownloadFinishedNotification(int notificationID, String contentText) {
createSummaryNotificationForFinished();

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(android.R.drawable.stat_sys_download_done)
.setContentTitle(getString(R.string.download_complete))
.setContentText(notificationText)
.setContentText(contentText)
.setGroup(DOWNLOAD_FINISHED_GROUP)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_LOW);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(DOWNLOAD_FINISHED_NOTIFICATION_ID, builder.build());
}
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(notificationID, builder.build());
}

private void showDownloadFailedNotification(int numOfFailedDownloads, int numOfTotalDownloads) {
String notificationText = numOfFailedDownloads + " " + getString(R.string.out_of) + " " + numOfTotalDownloads + " " + getString(R.string.downloads_failed);
private void createSummaryNotificationForFinished() {
Notification summaryNotification =
new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle(getString(R.string.download_complete))
//set content text to support devices running API level < 24
.setContentText(getString(R.string.download_complete))
.setSmallIcon(android.R.drawable.stat_sys_download_done)
.setGroup(DOWNLOAD_FINISHED_GROUP)
.setGroupSummary(true)
.setAutoCancel(true)
.build();

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(DOWNLOAD_FINISHED_NOTIFICATION_ID, summaryNotification);
}

private void showDownloadFailedNotification(int notificationId, String contentText) {
createSummaryNotificationForFailed();

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(android.R.drawable.stat_sys_warning)
.setContentTitle(getString(R.string.download_failed))
.setContentText(notificationText)
.setContentText(contentText)
.setGroup(DOWNLOAD_FAILED_GROUP)
.setPriority(NotificationCompat.PRIORITY_LOW);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(FAILED_DOWNLOAD_NOTIFICATION_ID, builder.build());
}
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(notificationId, builder.build());
}

private void createSummaryNotificationForFailed() {
Notification summaryNotification =
new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle(getString(R.string.download_failed))
//set content text to support devices running API level < 24
.setContentText(getString(R.string.download_failed))
.setSmallIcon(android.R.drawable.stat_sys_warning)
.setGroup(DOWNLOAD_FAILED_GROUP)
.setGroupSummary(true)
.setAutoCancel(true)
.build();

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(FAILED_DOWNLOAD_NOTIFICATION_ID, summaryNotification);
}

@Override
Expand All @@ -148,11 +184,18 @@ private void setNotificationChannel() {
}

@SuppressLint("StaticFieldLeak")
private class MonitorDownload extends AsyncTask<Process, Void, Boolean> {
private class MonitorDownload extends AsyncTask<Void, Void, Boolean> {

private FileItem file;
private Process process;

MonitorDownload(FileItem file, Process process) {
this.file = file;
this.process = process;
}

@Override
protected Boolean doInBackground(Process... processes) {
Process process = processes[0];
protected Boolean doInBackground(Void... voids) {
try {
process.waitFor();
} catch (InterruptedException e) {
Expand All @@ -164,10 +207,12 @@ protected Boolean doInBackground(Process... processes) {
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
int notificationId = (int)System.currentTimeMillis();

if (result) {
showDownloadFinishedNotification(++numOfFinishedDownloads, numOfRunningProcesses);
showDownloadFinishedNotification(notificationId, file.getName());
} else {
showDownloadFailedNotification(++numOfFailedDownloads, numOfRunningProcesses);
showDownloadFailedNotification(notificationId, file.getName());
}
}
}
Expand Down
Loading

0 comments on commit f875a05

Please sign in to comment.