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

Commit

Permalink
log crash to fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
k0shk0sh committed Dec 25, 2019
1 parent 1bed328 commit 2201125
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions app/src/main/java/com/fastaccess/provider/rest/RestProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import android.content.Context;
import android.net.Uri;
import android.os.Environment;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.text.TextUtils;
import android.widget.Toast;

import com.crashlytics.android.Crashlytics;
import com.fastaccess.App;
import com.fastaccess.BuildConfig;
import com.fastaccess.R;
Expand Down Expand Up @@ -91,31 +94,36 @@ private static Retrofit provideRetrofit(boolean enterprise) {
}

public static void downloadFile(@NonNull Context context, @NonNull String url) {
if (InputHelper.isEmpty(url)) return;
boolean isEnterprise = LinkParserHelper.isEnterprise(url);
Uri uri = Uri.parse(url);
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
String authToken = isEnterprise ? PrefGetter.getEnterpriseToken() : PrefGetter.getToken();
if (!TextUtils.isEmpty(authToken)) {
request.addRequestHeader("Authorization", authToken.startsWith("Basic") ? authToken : "token " + authToken);
}
File direct = new File(Environment.getExternalStorageDirectory() + File.separator + context.getString(R.string.app_name));
if (!direct.isDirectory() || !direct.exists()) {
boolean isCreated = direct.mkdirs();
if (!isCreated) {
Toast.makeText(App.getInstance(), "Unable to create directory to download file", Toast.LENGTH_SHORT).show();
return;
try {
if (InputHelper.isEmpty(url)) return;
boolean isEnterprise = LinkParserHelper.isEnterprise(url);
Uri uri = Uri.parse(url);
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(uri);
String authToken = isEnterprise ? PrefGetter.getEnterpriseToken() : PrefGetter.getToken();
if (!TextUtils.isEmpty(authToken)) {
request.addRequestHeader("Authorization", authToken.startsWith("Basic") ? authToken : "token " + authToken);
}
}
String fileName = new File(url).getName();
request.setDestinationInExternalPublicDir(context.getString(R.string.app_name), fileName);
request.setTitle(fileName);
request.setDescription(context.getString(R.string.downloading_file));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
if (downloadManager != null) {
downloadManager.enqueue(request);
File direct =
new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) + File.separator + context.getString(R.string.app_name));
if (!direct.isDirectory() || !direct.exists()) {
boolean isCreated = direct.mkdirs();
if (!isCreated) {
Toast.makeText(App.getInstance(), "Unable to create directory to download file", Toast.LENGTH_SHORT).show();
return;
}
}
String fileName = new File(url).getName();
request.setDestinationInExternalPublicDir(context.getString(R.string.app_name), fileName);
request.setTitle(fileName);
request.setDescription(context.getString(R.string.downloading_file));
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
if (downloadManager != null) {
downloadManager.enqueue(request);
}
} catch (Exception e) {
Crashlytics.logException(e);
}
}

Expand Down

0 comments on commit 2201125

Please sign in to comment.