Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8113ef3f8a | ||
|
|
a74ed0e93b | ||
|
|
11f42bf71e | ||
|
|
1ece7ff433 | ||
|
|
bb64e91648 | ||
|
|
69398f6a2c | ||
|
|
bef7aa0ae9 | ||
|
|
2776696501 | ||
|
|
fa075df278 | ||
|
|
05311fd3a1 | ||
|
|
79001239d9 | ||
|
|
e344733bf0 | ||
|
|
282fdbb903 | ||
|
|
ee7c571101 | ||
|
|
87e42d6b7e | ||
|
|
8fcf135280 | ||
|
|
ae9364ad7e | ||
|
|
6aa44d8a9e | ||
|
|
3f013d1272 | ||
|
|
94d1f5a4eb | ||
|
|
1d8a7d838b | ||
|
|
c5d441fa1f | ||
|
|
4276a78a81 | ||
|
|
36c24a448f | ||
|
|
4bf1051549 | ||
|
|
fc4ab3128c | ||
|
|
65d32ea13e | ||
|
|
4cd8c80226 | ||
|
|
7adcdc43cf | ||
|
|
77852dc135 | ||
|
|
746ca62ca7 | ||
|
|
5e993f0fcc | ||
|
|
168dbba62c | ||
|
|
4db7bf814c | ||
|
|
21a3ff318b |
No files matched your search
+1
-1
Submodule app updated: bc62580aae...601c589f69.
@@ -36,7 +36,7 @@ version.filename = %(source.dir)s/main.py
|
||||
|
||||
# (list) Application requirements
|
||||
# comma seperated e.g. requirements = sqlite3,kivy
|
||||
requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro==1.4.0, pyjnius, certifi==2018.11.29, appdirs==1.4.3, docopt==0.6.2, base58==1.0.0, colorama==0.3.7, ecdsa==0.13.3, jsonschema==2.6.0, pbkdf2==1.3, pyyaml, protobuf==3.6.1, keyring==10.4.0, defusedxml, git+https://github.com/lbryio/aioupnp.git@ab7ef0048bbce6404e463d20e8a15046ea6941f0#egg=aioupnp, asn1crypto, mock, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, yarl==1.3.0, chardet==3.0.4, async_timeout==3.0.1, coincurve, msgpack==0.6.1, six, attrs==18.2.0, pylru, hachoir, "git+https://github.com/lbryio/lbry-sdk@v0.51.2#egg=lbry&subdirectory=lbry", "git+https://github.com/lbryio/lbry-sdk@v0.51.2#egg=torba&subdirectory=torba"
|
||||
requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro==1.4.0, pyjnius, certifi==2018.11.29, appdirs==1.4.3, docopt==0.6.2, base58==1.0.0, colorama==0.3.7, ecdsa==0.13.3, jsonschema==2.6.0, pbkdf2==1.3, pyyaml, protobuf==3.6.1, keyring==10.4.0, defusedxml, git+https://github.com/lbryio/aioupnp.git@ab7ef0048bbce6404e463d20e8a15046ea6941f0#egg=aioupnp, asn1crypto, mock, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, yarl==1.3.0, chardet==3.0.4, async_timeout==3.0.1, coincurve, msgpack==0.6.1, six, attrs==18.2.0, pylru, hachoir, prometheus_client==0.7.1, "git+https://github.com/lbryio/lbry-sdk@v0.56.0#egg=lbry"
|
||||
|
||||
# (str) Custom source folders for requirements
|
||||
# Sets custom source for any requirements with recipes
|
||||
|
||||
@@ -36,7 +36,7 @@ version.filename = %(source.dir)s/main.py
|
||||
|
||||
# (list) Application requirements
|
||||
# comma seperated e.g. requirements = sqlite3,kivy
|
||||
requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro==1.4.0, pyjnius, certifi==2018.11.29, appdirs==1.4.3, docopt==0.6.2, base58==1.0.0, colorama==0.3.7, ecdsa==0.13.3, jsonschema==2.6.0, pbkdf2==1.3, pyyaml, protobuf==3.6.1, keyring==10.4.0, defusedxml, git+https://github.com/lbryio/aioupnp.git@ab7ef0048bbce6404e463d20e8a15046ea6941f0#egg=aioupnp, asn1crypto, mock, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, yarl==1.3.0, chardet==3.0.4, async_timeout==3.0.1, coincurve, msgpack==0.6.1, six, attrs==18.2.0, pylru, hachoir, "git+https://github.com/lbryio/lbry-sdk@v0.51.2#egg=lbry&subdirectory=lbry", "git+https://github.com/lbryio/lbry-sdk@v0.51.2#egg=torba&subdirectory=torba"
|
||||
requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro==1.4.0, pyjnius, certifi==2018.11.29, appdirs==1.4.3, docopt==0.6.2, base58==1.0.0, colorama==0.3.7, ecdsa==0.13.3, jsonschema==2.6.0, pbkdf2==1.3, pyyaml, protobuf==3.6.1, keyring==10.4.0, defusedxml, git+https://github.com/lbryio/aioupnp.git@ab7ef0048bbce6404e463d20e8a15046ea6941f0#egg=aioupnp, asn1crypto, mock, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, yarl==1.3.0, chardet==3.0.4, async_timeout==3.0.1, coincurve, msgpack==0.6.1, six, attrs==18.2.0, pylru, hachoir, prometheus_client==0.7.1, "git+https://github.com/lbryio/lbry-sdk@v0.56.0#egg=lbry"
|
||||
|
||||
# (str) Custom source folders for requirements
|
||||
# Sets custom source for any requirements with recipes
|
||||
|
||||
@@ -36,7 +36,7 @@ version.filename = %(source.dir)s/main.py
|
||||
|
||||
# (list) Application requirements
|
||||
# comma seperated e.g. requirements = sqlite3,kivy
|
||||
requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro==1.4.0, pyjnius, certifi==2018.11.29, appdirs==1.4.3, docopt==0.6.2, base58==1.0.0, colorama==0.3.7, ecdsa==0.13.3, jsonschema==2.6.0, pbkdf2==1.3, pyyaml, protobuf==3.6.1, keyring==10.4.0, defusedxml, git+https://github.com/lbryio/aioupnp.git@ab7ef0048bbce6404e463d20e8a15046ea6941f0#egg=aioupnp, asn1crypto, mock, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, yarl==1.3.0, chardet==3.0.4, async_timeout==3.0.1, coincurve, msgpack==0.6.1, six, attrs==18.2.0, pylru, hachoir, "git+https://github.com/lbryio/lbry-sdk@v0.51.2#egg=lbry&subdirectory=lbry", "git+https://github.com/lbryio/lbry-sdk@v0.51.2#egg=torba&subdirectory=torba"
|
||||
requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro==1.4.0, pyjnius, certifi==2018.11.29, appdirs==1.4.3, docopt==0.6.2, base58==1.0.0, colorama==0.3.7, ecdsa==0.13.3, jsonschema==2.6.0, pbkdf2==1.3, pyyaml, protobuf==3.6.1, keyring==10.4.0, defusedxml, git+https://github.com/lbryio/aioupnp.git@ab7ef0048bbce6404e463d20e8a15046ea6941f0#egg=aioupnp, asn1crypto, mock, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, yarl==1.3.0, chardet==3.0.4, async_timeout==3.0.1, coincurve, msgpack==0.6.1, six, attrs==18.2.0, pylru, hachoir, prometheus_client==0.7.1, "git+https://github.com/lbryio/lbry-sdk@v0.56.0#egg=lbry"
|
||||
|
||||
# (str) Custom source folders for requirements
|
||||
# Sets custom source for any requirements with recipes
|
||||
|
||||
@@ -36,7 +36,7 @@ version.filename = %(source.dir)s/main.py
|
||||
|
||||
# (list) Application requirements
|
||||
# comma seperated e.g. requirements = sqlite3,kivy
|
||||
requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro==1.4.0, pyjnius, certifi==2018.11.29, appdirs==1.4.3, docopt==0.6.2, base58==1.0.0, colorama==0.3.7, ecdsa==0.13.3, jsonschema==2.6.0, pbkdf2==1.3, pyyaml, protobuf==3.6.1, keyring==10.4.0, defusedxml, git+https://github.com/lbryio/aioupnp.git@ab7ef0048bbce6404e463d20e8a15046ea6941f0#egg=aioupnp, asn1crypto, mock, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, yarl==1.3.0, chardet==3.0.4, async_timeout==3.0.1, coincurve, msgpack==0.6.1, six, attrs==18.2.0, pylru, hachoir, "git+https://github.com/lbryio/lbry-sdk@v0.51.2#egg=lbry&subdirectory=lbry", "git+https://github.com/lbryio/lbry-sdk@v0.51.2#egg=torba&subdirectory=torba"
|
||||
requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro==1.4.0, pyjnius, certifi==2018.11.29, appdirs==1.4.3, docopt==0.6.2, base58==1.0.0, colorama==0.3.7, ecdsa==0.13.3, jsonschema==2.6.0, pbkdf2==1.3, pyyaml, protobuf==3.6.1, keyring==10.4.0, defusedxml, git+https://github.com/lbryio/aioupnp.git@ab7ef0048bbce6404e463d20e8a15046ea6941f0#egg=aioupnp, asn1crypto, mock, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, yarl==1.3.0, chardet==3.0.4, async_timeout==3.0.1, coincurve, msgpack==0.6.1, six, attrs==18.2.0, pylru, hachoir, prometheus_client==0.7.1, "git+https://github.com/lbryio/lbry-sdk@v0.56.0#egg=lbry"
|
||||
|
||||
# (str) Custom source folders for requirements
|
||||
# Sets custom source for any requirements with recipes
|
||||
|
||||
@@ -2,5 +2,20 @@
|
||||
<style name="LbryAppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="android:windowBackground">@color/lbryGreen</item>
|
||||
<item name="colorControlActivated">@color/nextLbryGreen</item>
|
||||
<item name="android:spinnerItemStyle">@style/LbrySpinnerItem</item>
|
||||
<item name="android:spinnerDropDownItemStyle">@style/LbrySpinnerDropDownItem</item>
|
||||
</style>
|
||||
|
||||
<style name="LbrySpinnerItem" parent="@style/Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="android:fontFamily">Inter-Regular</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
</style>
|
||||
|
||||
<style name="LbrySpinnerDropDownItem" parent="@style/Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="android:fontFamily">Inter-Regular</item>
|
||||
<item name="android:paddingLeft">16dp</item>
|
||||
<item name="android:paddingRight">16dp</item>
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
</style>
|
||||
</resources>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -10,6 +10,7 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
@@ -18,10 +19,11 @@ import com.facebook.react.bridge.ReactMethod;
|
||||
import io.lbry.browser.receivers.NotificationDeletedReceiver;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class DownloadManager {
|
||||
private Context context;
|
||||
@@ -30,6 +32,11 @@ public class DownloadManager {
|
||||
|
||||
private List<String> completedDownloads = new ArrayList<String>();
|
||||
|
||||
private Map<String, String> downloadIdOutpointsMap = new HashMap<String, String>();
|
||||
|
||||
// maintain a map of uris to writtenBytes, so that we check if it's changed and don't flood RN with update events every 500ms
|
||||
private Map<String, Double> writtenDownloadBytes = new HashMap<String, Double>();
|
||||
|
||||
private HashMap<Integer, NotificationCompat.Builder> builders = new HashMap<Integer, NotificationCompat.Builder>();
|
||||
|
||||
private HashMap<String, Integer> downloadIdNotificationIdMap = new HashMap<String, Integer>();
|
||||
@@ -120,7 +127,35 @@ public class DownloadManager {
|
||||
return intent;
|
||||
}
|
||||
|
||||
public void startDownload(String id, String filename) {
|
||||
public void updateWrittenBytesForDownload(String id, double writtenBytes) {
|
||||
if (!writtenDownloadBytes.containsKey(id)) {
|
||||
writtenDownloadBytes.put(id, writtenBytes);
|
||||
}
|
||||
}
|
||||
|
||||
public double getWrittenBytesForDownload(String id) {
|
||||
if (writtenDownloadBytes.containsKey(id)) {
|
||||
return writtenDownloadBytes.get(id);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void clearWrittenBytesForDownload(String id) {
|
||||
if (writtenDownloadBytes.containsKey(id)) {
|
||||
writtenDownloadBytes.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
private Intent getDeleteDownloadIntent(String uri) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(LbrynetService.ACTION_DELETE_DOWNLOAD);
|
||||
intent.putExtra("uri", uri);
|
||||
intent.putExtra("nativeDelete", true);
|
||||
return intent;
|
||||
}
|
||||
|
||||
public void startDownload(String id, String filename, String outpoint) {
|
||||
if (filename == null || filename.trim().length() == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -128,20 +163,26 @@ public class DownloadManager {
|
||||
synchronized (this) {
|
||||
if (!isDownloadActive(id)) {
|
||||
activeDownloads.add(id);
|
||||
downloadIdOutpointsMap.put(id, outpoint);
|
||||
}
|
||||
|
||||
createNotificationChannel();
|
||||
createNotificationGroup();
|
||||
|
||||
PendingIntent stopDownloadIntent = PendingIntent.getBroadcast(context, 0, getDeleteDownloadIntent(id), PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
|
||||
// The file URI is used as the unique ID
|
||||
builder.setContentIntent(getLaunchPendingIntent(id, context))
|
||||
builder.setColor(ContextCompat.getColor(context, R.color.lbryGreen))
|
||||
.setContentIntent(getLaunchPendingIntent(id, context))
|
||||
.setContentTitle(String.format("Downloading %s", truncateFilename(filename)))
|
||||
.setGroup(GROUP_DOWNLOADS)
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||
.setProgress(MAX_PROGRESS, 0, false)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download);
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
.setOngoing(true)
|
||||
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Stop", stopDownloadIntent);
|
||||
|
||||
int notificationId = getNotificationId(id);
|
||||
downloadIdNotificationIdMap.put(id, notificationId);
|
||||
@@ -170,9 +211,13 @@ public class DownloadManager {
|
||||
if (builders.containsKey(notificationId)) {
|
||||
builder = builders.get(notificationId);
|
||||
} else {
|
||||
PendingIntent stopDownloadIntent = PendingIntent.getBroadcast(context, 0, getDeleteDownloadIntent(id), PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
builder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID);
|
||||
builder.setContentTitle(String.format("Downloading %s", truncateFilename(filename)))
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW);
|
||||
builder.setColor(ContextCompat.getColor(context, R.color.lbryGreen))
|
||||
.setContentTitle(String.format("Downloading %s", truncateFilename(filename)))
|
||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
||||
.setOngoing(true)
|
||||
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Stop", stopDownloadIntent);
|
||||
builders.put(notificationId, builder);
|
||||
}
|
||||
|
||||
@@ -189,7 +234,9 @@ public class DownloadManager {
|
||||
.setContentText(String.format("%s", formatBytes(totalBytes)))
|
||||
.setGroup(GROUP_DOWNLOADS)
|
||||
.setProgress(0, 0, false)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download_done);
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||
.setOngoing(false);
|
||||
builder.mActions.clear();
|
||||
notificationManager.notify(notificationId, builder.build());
|
||||
|
||||
if (downloadIdNotificationIdMap.containsKey(id)) {
|
||||
@@ -234,11 +281,13 @@ public class DownloadManager {
|
||||
.setContentText(String.format("%s", formatBytes(totalBytes)))
|
||||
.setGroup(GROUP_DOWNLOADS)
|
||||
.setProgress(0, 0, false)
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download_done);
|
||||
notificationManager.notify(notificationId, builder.build());
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||
.setOngoing(false);
|
||||
builder.mActions.clear();
|
||||
notificationManager.notify(notificationId, builder.build());
|
||||
|
||||
// If there are no more downloads and the group exists, set the icon to stop animating
|
||||
checkGroupDownloadIcon(notificationManager);
|
||||
// If there are no more downloads and the group exists, set the icon to stop animating
|
||||
checkGroupDownloadIcon(notificationManager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,11 +320,22 @@ public class DownloadManager {
|
||||
return completedDownloads;
|
||||
}
|
||||
|
||||
public String getOutpointForDownload(String uri) {
|
||||
if (downloadIdOutpointsMap.containsKey(uri)) {
|
||||
return downloadIdOutpointsMap.get(uri);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void deleteDownloadUri(String uri) {
|
||||
synchronized (this) {
|
||||
activeDownloads.remove(uri);
|
||||
completedDownloads.remove(uri);
|
||||
|
||||
if (downloadIdOutpointsMap.containsKey(uri)) {
|
||||
downloadIdOutpointsMap.remove(uri);
|
||||
}
|
||||
if (downloadIdNotificationIdMap.containsKey(uri)) {
|
||||
removeDownloadNotification(uri);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class LbrynetService extends PythonService {
|
||||
|
||||
public static LbrynetService serviceInstance;
|
||||
|
||||
private static final int SDK_POLL_INTERVAL = 500; // 500 milliseconds
|
||||
private static final int SDK_POLL_INTERVAL = 1000; // 1 second
|
||||
|
||||
private BroadcastReceiver stopServiceReceiver;
|
||||
|
||||
@@ -123,7 +123,8 @@ public class LbrynetService extends PythonService {
|
||||
}
|
||||
} else if (ACTION_DELETE_DOWNLOAD.equals(action)) {
|
||||
String uri = intent.getStringExtra("uri");
|
||||
LbrynetService.this.deleteDownload(uri);
|
||||
boolean nativeDelete = intent.getBooleanExtra("nativeDelete", false);
|
||||
LbrynetService.this.deleteDownload(uri, nativeDelete);
|
||||
} else if (ACTION_CHECK_DOWNLOADS.equals(action)) {
|
||||
LbrynetService.this.checkDownloads();
|
||||
}
|
||||
@@ -210,7 +211,14 @@ public class LbrynetService extends PythonService {
|
||||
}
|
||||
|
||||
if (streamManagerReady) {
|
||||
String fileList = Utils.sdkCall("file_list");
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("page_size", 100);
|
||||
params.put("reverse", true);
|
||||
params.put("sort", "added_on");
|
||||
/*params.put("status", "stopped");
|
||||
params.put("comparison", "ne");*/
|
||||
|
||||
String fileList = Utils.sdkCall("file_list", params);
|
||||
if (fileList != null) {
|
||||
JSONObject response = new JSONObject(fileList);
|
||||
if (!response.has("error")) {
|
||||
@@ -229,7 +237,7 @@ public class LbrynetService extends PythonService {
|
||||
(new AsyncTask<Void, Void, String>() {
|
||||
protected String doInBackground(Void... param) {
|
||||
try {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("outpoint", outpoint);
|
||||
return Utils.sdkCall("file_list", params);
|
||||
} catch (ConnectException ex) {
|
||||
@@ -244,7 +252,7 @@ public class LbrynetService extends PythonService {
|
||||
if (!response.has("error")) {
|
||||
JSONObject result = response.getJSONObject("result");
|
||||
if (result != null) {
|
||||
JSONArray fileItems = response.optJSONArray("items");
|
||||
JSONArray fileItems = result.optJSONArray("items");
|
||||
if (fileItems != null && fileItems.length() > 0) {
|
||||
// TODO: Create Java FileItem class
|
||||
JSONObject item = fileItems.getJSONObject(0);
|
||||
@@ -257,10 +265,11 @@ public class LbrynetService extends PythonService {
|
||||
String uri = String.format("lbry://%s#%s", claimName, claimId);
|
||||
|
||||
if (!downloadManager.isDownloadActive(uri) && !downloadManager.isDownloadCompleted(uri)) {
|
||||
downloadManager.clearWrittenBytesForDownload(uri);
|
||||
File file = new File(downloadPath);
|
||||
Intent intent = createDownloadEventIntent(uri, outpoint, item.toString());
|
||||
intent.putExtra("action", "start");
|
||||
downloadManager.startDownload(uri, file.getName());
|
||||
downloadManager.startDownload(uri, file.getName(), outpoint);
|
||||
|
||||
Context context = getApplicationContext();
|
||||
if (context != null) {
|
||||
@@ -280,10 +289,46 @@ public class LbrynetService extends PythonService {
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void deleteDownload(String uri) {
|
||||
private void deleteDownload(String uri, boolean nativeDelete) {
|
||||
final String outpoint = downloadManager.getOutpointForDownload(uri);
|
||||
if (nativeDelete && outpoint != null) {
|
||||
// send call sdk to delete the file on the corresponding outpoint
|
||||
removeDownloadFromManager(uri);
|
||||
|
||||
(new AsyncTask<Void, Void, String>() {
|
||||
protected String doInBackground(Void... param) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("outpoint", outpoint);
|
||||
params.put("delete_from_download_dir", true);
|
||||
return Utils.sdkCall("file_delete", params);
|
||||
} catch (ConnectException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onPostExecute(String response) {
|
||||
// after deletion, remove the download from the download manager
|
||||
Intent intent = createDownloadEventIntent(uri, outpoint, null);
|
||||
intent.putExtra("action", "abort");
|
||||
|
||||
Context context = getApplicationContext();
|
||||
if (context != null) {
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
removeDownloadFromManager(uri);
|
||||
}
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
removeDownloadFromManager(uri);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeDownloadFromManager(String uri) {
|
||||
if (downloadManager.isDownloadActive(uri)) {
|
||||
downloadManager.abortDownload(uri);
|
||||
}
|
||||
|
||||
downloadManager.deleteDownloadUri(uri);
|
||||
}
|
||||
|
||||
@@ -295,7 +340,6 @@ public class LbrynetService extends PythonService {
|
||||
JSONArray fileItems = result.optJSONArray("items");
|
||||
if (fileItems != null) {
|
||||
try {
|
||||
//List<String> itemUris = new ArrayList<String>();
|
||||
for (int i = 0; i < fileItems.length(); i++) {
|
||||
JSONObject item = fileItems.getJSONObject(i);
|
||||
String downloadPath = item.isNull("download_path") ? null : item.getString("download_path");
|
||||
@@ -320,18 +364,29 @@ public class LbrynetService extends PythonService {
|
||||
|
||||
File file = new File(downloadPath);
|
||||
Intent intent = createDownloadEventIntent(uri, outpoint, item.toString());
|
||||
boolean shouldSendBroadcast = true;
|
||||
if (downloadManager.isDownloadActive(uri)) {
|
||||
if (writtenBytes >= totalBytes || completed) {
|
||||
// completed download
|
||||
downloadManager.clearWrittenBytesForDownload(uri);
|
||||
intent.putExtra("action", "complete");
|
||||
downloadManager.completeDownload(uri, file.getName(), totalBytes);
|
||||
} else {
|
||||
intent.putExtra("action", "update");
|
||||
intent.putExtra("progress", (writtenBytes / totalBytes) * 100);
|
||||
downloadManager.updateDownload(uri, file.getName(), writtenBytes, totalBytes);
|
||||
double prevWrittenBytes = downloadManager.getWrittenBytesForDownload(uri);
|
||||
if (prevWrittenBytes == writtenBytes) {
|
||||
// no change, don't send an update event
|
||||
shouldSendBroadcast = false;
|
||||
}
|
||||
downloadManager.updateWrittenBytesForDownload(uri, writtenBytes);
|
||||
|
||||
if (shouldSendBroadcast) {
|
||||
intent.putExtra("action", "update");
|
||||
intent.putExtra("progress", (writtenBytes / totalBytes) * 100);
|
||||
downloadManager.updateDownload(uri, file.getName(), writtenBytes, totalBytes);
|
||||
}
|
||||
}
|
||||
|
||||
if (context != null) {
|
||||
if (context != null && shouldSendBroadcast) {
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
} else {
|
||||
@@ -339,25 +394,17 @@ public class LbrynetService extends PythonService {
|
||||
// do not start a download that is considered completed
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!completed && downloadPath != null) {
|
||||
downloadManager.clearWrittenBytesForDownload(uri);
|
||||
intent.putExtra("action", "start");
|
||||
downloadManager.startDownload(uri, file.getName());
|
||||
downloadManager.startDownload(uri, file.getName(), outpoint);
|
||||
if (context != null) {
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check download manager uris and clear downloads that may have been cancelled / deleted
|
||||
/*List<String> activeUris = downloadManager.getActiveDownloads();
|
||||
for (int i = 0; i < activeUris.size(); i++) {
|
||||
String activeUri = activeUris.get(i);
|
||||
if (!itemUris.contains(activeUri)) {
|
||||
downloadManager.abortDownload(activeUri);
|
||||
fileListUris.remove(activeUri); // remove URIs from the session that may have been deleted
|
||||
}
|
||||
}*/
|
||||
} catch (JSONException ex) {
|
||||
// pass
|
||||
Log.e(TAG, ex.getMessage(), ex);
|
||||
|
||||
@@ -212,17 +212,28 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
|
||||
String outpoint = intent.getStringExtra("outpoint");
|
||||
String fileInfoJson = intent.getStringExtra("file_info");
|
||||
|
||||
if (uri == null || outpoint == null || fileInfoJson == null) {
|
||||
|
||||
if (uri == null || outpoint == null || (fileInfoJson == null && !"abort".equals(downloadAction))) {
|
||||
return;
|
||||
}
|
||||
|
||||
String eventName = null;
|
||||
WritableMap params = Arguments.createMap();
|
||||
params.putString("uri", uri);
|
||||
params.putString("outpoint", outpoint);
|
||||
|
||||
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
||||
if ("abort".equals(downloadAction)) {
|
||||
eventName = "onDownloadAborted";
|
||||
if (reactContext != null) {
|
||||
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String eventName = null;
|
||||
JSONObject json = new JSONObject(fileInfoJson);
|
||||
WritableMap fileInfo = JSONObjectToMap(json);
|
||||
WritableMap params = Arguments.createMap();
|
||||
params.putString("uri", uri);
|
||||
params.putString("outpoint", outpoint);
|
||||
params.putMap("fileInfo", fileInfo);
|
||||
|
||||
if (DownloadManager.ACTION_UPDATE.equals(downloadAction)) {
|
||||
@@ -233,7 +244,6 @@ public class MainActivity extends FragmentActivity implements DefaultHardwareBac
|
||||
eventName = (DownloadManager.ACTION_START.equals(downloadAction)) ? "onDownloadStarted" : "onDownloadCompleted";
|
||||
}
|
||||
|
||||
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
||||
if (reactContext != null) {
|
||||
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
|
||||
}
|
||||
|
||||
@@ -346,13 +346,13 @@ public final class Utils {
|
||||
return sdkCall(method, null);
|
||||
}
|
||||
|
||||
public static String sdkCall(String method, Map<String, String> params) throws ConnectException {
|
||||
public static String sdkCall(String method, Map<String, Object> params) throws ConnectException {
|
||||
try {
|
||||
JSONObject request = new JSONObject();
|
||||
request.put("method", method);
|
||||
if (params != null) {
|
||||
JSONObject requestParams = new JSONObject();
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
requestParams.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
request.put("params", requestParams);
|
||||
|
||||
@@ -4,13 +4,15 @@ import logging
|
||||
import pathlib
|
||||
import platform
|
||||
import sys
|
||||
import lbry.wallet
|
||||
|
||||
from jnius import autoclass
|
||||
from keyring.backend import KeyringBackend
|
||||
from lbry import __version__ as lbrynet_version, build_type
|
||||
from lbry import __version__ as lbrynet_version, build_info
|
||||
from lbry.conf import Config
|
||||
from lbry.extras.daemon.loggly_handler import get_loggly_handler
|
||||
from lbry.extras.daemon.Components import DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT
|
||||
from lbry.extras.daemon.Daemon import Daemon
|
||||
from lbry.extras.daemon.components import DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT
|
||||
from lbry.extras.daemon.daemon import Daemon
|
||||
from lbry.extras.daemon.loggly_handler import get_loggly_handler
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -19,7 +21,7 @@ log.setLevel(logging.DEBUG)
|
||||
lbrynet_android_utils = autoclass('io.lbry.browser.Utils')
|
||||
service = autoclass('io.lbry.browser.LbrynetService').serviceInstance
|
||||
platform.platform = lambda: 'Android %s (API %s)' % (lbrynet_android_utils.getAndroidRelease(), lbrynet_android_utils.getAndroidSdk())
|
||||
build_type.BUILD = 'dev' if lbrynet_android_utils.isDebug() else 'release'
|
||||
build_info.BUILD = 'dev' if lbrynet_android_utils.isDebug() else 'release'
|
||||
|
||||
# Keyring backend
|
||||
class LbryAndroidKeyring(KeyringBackend):
|
||||
@@ -74,7 +76,7 @@ def start():
|
||||
keyring.set_keyring(LbryAndroidKeyring())
|
||||
private_storage_dir = lbrynet_android_utils.getAppInternalStorageDir(service.getApplicationContext())
|
||||
configured_download_dir = lbrynet_android_utils.getConfiguredDownloadDirectory(service.getApplicationContext())
|
||||
print('configured_download_dir={}'.format(configured_download_dir))
|
||||
|
||||
conf = Config(
|
||||
data_dir=f'{private_storage_dir}/lbrynet',
|
||||
wallet_dir=f'{private_storage_dir}/lbryum',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
__version__ = "0.12.2"
|
||||
__version__ = "0.13.0"
|
||||
|
||||
class ServiceApp(App):
|
||||
def build(self):
|
||||
|
||||
Reference in new issue
Block a user