2018-12-02 04:47:57 -05:00
|
|
|
package com.topjohnwu.magisk.components;
|
|
|
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.androidnetworking.interfaces.DownloadProgressListener;
|
|
|
|
import com.topjohnwu.magisk.Const;
|
|
|
|
import com.topjohnwu.magisk.Data;
|
2018-12-02 05:33:53 -05:00
|
|
|
import com.topjohnwu.magisk.MagiskManager;
|
|
|
|
import com.topjohnwu.magisk.R;
|
2018-12-02 04:47:57 -05:00
|
|
|
import com.topjohnwu.magisk.utils.Notifications;
|
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
|
|
|
|
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import androidx.core.app.NotificationManagerCompat;
|
|
|
|
|
|
|
|
public class NotificationProgress implements DownloadProgressListener {
|
|
|
|
|
|
|
|
private NotificationManagerCompat mgr;
|
|
|
|
private NotificationCompat.Builder builder;
|
|
|
|
private long prevTime;
|
|
|
|
|
|
|
|
public NotificationProgress(String title) {
|
2018-12-02 05:33:53 -05:00
|
|
|
MagiskManager mm = Data.MM();
|
|
|
|
mgr = NotificationManagerCompat.from(mm);
|
2018-12-02 04:47:57 -05:00
|
|
|
builder = Notifications.progress(title);
|
|
|
|
mgr.notify(Const.ID.DOWNLOAD_PROGRESS_ID, builder.build());
|
|
|
|
prevTime = System.currentTimeMillis();
|
2018-12-02 05:33:53 -05:00
|
|
|
Utils.toast(mm.getString(R.string.downloading_toast, title), Toast.LENGTH_SHORT);
|
2018-12-02 04:47:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onProgress(long bytesDownloaded, long totalBytes) {
|
|
|
|
long cur = System.currentTimeMillis();
|
|
|
|
if (cur - prevTime >= 1000) {
|
|
|
|
prevTime = cur;
|
2018-12-02 15:15:42 -05:00
|
|
|
int progress = (int) (bytesDownloaded * 100 / totalBytes);
|
|
|
|
builder.setProgress(100, progress, false);
|
|
|
|
builder.setContentText(progress + "%");
|
2018-12-02 04:47:57 -05:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-02 15:15:42 -05:00
|
|
|
public NotificationCompat.Builder getNotification() {
|
2018-12-02 04:47:57 -05:00
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void update() {
|
|
|
|
mgr.notify(Const.ID.DOWNLOAD_PROGRESS_ID, builder.build());
|
|
|
|
}
|
|
|
|
|
2018-12-02 05:33:53 -05:00
|
|
|
public void dlDone() {
|
2018-12-02 15:15:42 -05:00
|
|
|
builder.setProgress(0, 0, false)
|
|
|
|
.setContentText(Data.MM().getString(R.string.download_complete))
|
|
|
|
.setSmallIcon(R.drawable.ic_check_circle);
|
2018-12-02 04:47:57 -05:00
|
|
|
update();
|
|
|
|
}
|
2018-12-02 05:33:53 -05:00
|
|
|
|
|
|
|
public void dismiss() {
|
|
|
|
mgr.cancel(Const.ID.DOWNLOAD_PROGRESS_ID);
|
|
|
|
}
|
2018-12-02 04:47:57 -05:00
|
|
|
}
|