Skip to content
This repository was archived by the owner on Sep 30, 2021. It is now read-only.

Commit 2201125

Browse files
author
k0shk0sh
committed
log crash to fabric
1 parent 1bed328 commit 2201125

1 file changed

Lines changed: 32 additions & 24 deletions

File tree

app/src/main/java/com/fastaccess/provider/rest/RestProvider.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import android.content.Context;
55
import android.net.Uri;
66
import android.os.Environment;
7+
78
import androidx.annotation.NonNull;
89
import androidx.annotation.Nullable;
10+
911
import android.text.TextUtils;
1012
import android.widget.Toast;
1113

14+
import com.crashlytics.android.Crashlytics;
1215
import com.fastaccess.App;
1316
import com.fastaccess.BuildConfig;
1417
import com.fastaccess.R;
@@ -91,31 +94,36 @@ private static Retrofit provideRetrofit(boolean enterprise) {
9194
}
9295

9396
public static void downloadFile(@NonNull Context context, @NonNull String url) {
94-
if (InputHelper.isEmpty(url)) return;
95-
boolean isEnterprise = LinkParserHelper.isEnterprise(url);
96-
Uri uri = Uri.parse(url);
97-
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
98-
DownloadManager.Request request = new DownloadManager.Request(uri);
99-
String authToken = isEnterprise ? PrefGetter.getEnterpriseToken() : PrefGetter.getToken();
100-
if (!TextUtils.isEmpty(authToken)) {
101-
request.addRequestHeader("Authorization", authToken.startsWith("Basic") ? authToken : "token " + authToken);
102-
}
103-
File direct = new File(Environment.getExternalStorageDirectory() + File.separator + context.getString(R.string.app_name));
104-
if (!direct.isDirectory() || !direct.exists()) {
105-
boolean isCreated = direct.mkdirs();
106-
if (!isCreated) {
107-
Toast.makeText(App.getInstance(), "Unable to create directory to download file", Toast.LENGTH_SHORT).show();
108-
return;
97+
try {
98+
if (InputHelper.isEmpty(url)) return;
99+
boolean isEnterprise = LinkParserHelper.isEnterprise(url);
100+
Uri uri = Uri.parse(url);
101+
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
102+
DownloadManager.Request request = new DownloadManager.Request(uri);
103+
String authToken = isEnterprise ? PrefGetter.getEnterpriseToken() : PrefGetter.getToken();
104+
if (!TextUtils.isEmpty(authToken)) {
105+
request.addRequestHeader("Authorization", authToken.startsWith("Basic") ? authToken : "token " + authToken);
109106
}
110-
}
111-
String fileName = new File(url).getName();
112-
request.setDestinationInExternalPublicDir(context.getString(R.string.app_name), fileName);
113-
request.setTitle(fileName);
114-
request.setDescription(context.getString(R.string.downloading_file));
115-
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
116-
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
117-
if (downloadManager != null) {
118-
downloadManager.enqueue(request);
107+
File direct =
108+
new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) + File.separator + context.getString(R.string.app_name));
109+
if (!direct.isDirectory() || !direct.exists()) {
110+
boolean isCreated = direct.mkdirs();
111+
if (!isCreated) {
112+
Toast.makeText(App.getInstance(), "Unable to create directory to download file", Toast.LENGTH_SHORT).show();
113+
return;
114+
}
115+
}
116+
String fileName = new File(url).getName();
117+
request.setDestinationInExternalPublicDir(context.getString(R.string.app_name), fileName);
118+
request.setTitle(fileName);
119+
request.setDescription(context.getString(R.string.downloading_file));
120+
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
121+
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
122+
if (downloadManager != null) {
123+
downloadManager.enqueue(request);
124+
}
125+
} catch (Exception e) {
126+
Crashlytics.logException(e);
119127
}
120128
}
121129

0 commit comments

Comments
 (0)