diff --git a/app/build.gradle b/app/build.gradle index 3d74a7459..eb6acea10 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,8 +29,8 @@ android { applicationId "com.fastaccess.github" minSdkVersion 21 targetSdkVersion 29 - versionCode 471 - versionName "4.7.0" + versionCode 472 + versionName "4.7.2" buildConfigString "GITHUB_CLIENT_ID", (buildProperties.secrets['github_client_id'] | buildProperties.notThere['github_client_id']).string buildConfigString "GITHUB_SECRET", (buildProperties.secrets['github_secret'] | buildProperties.notThere['github_secret']).string buildConfigString "IMGUR_CLIENT_ID", (buildProperties.secrets['imgur_client_id'] | buildProperties.notThere['imgur_client_id']).string diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0ecf87ab9..d24510222 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -316,6 +316,10 @@ + + diff --git a/app/src/main/java/com/fastaccess/data/dao/SimpleUrlsModel.java b/app/src/main/java/com/fastaccess/data/dao/SimpleUrlsModel.java index ddff012b5..7a7293fe8 100644 --- a/app/src/main/java/com/fastaccess/data/dao/SimpleUrlsModel.java +++ b/app/src/main/java/com/fastaccess/data/dao/SimpleUrlsModel.java @@ -16,12 +16,19 @@ public class SimpleUrlsModel implements Parcelable { public String item; public String url; + public String extension; public SimpleUrlsModel(String item, String url) { this.item = item; this.url = url; } + public SimpleUrlsModel(String item, String url, String extension) { + this.item = item; + this.url = url; + this.extension = extension; + } + @Override public String toString() { return item; } diff --git a/app/src/main/java/com/fastaccess/provider/rest/RestProvider.java b/app/src/main/java/com/fastaccess/provider/rest/RestProvider.java index 94ae9800b..b2e0cb4eb 100644 --- a/app/src/main/java/com/fastaccess/provider/rest/RestProvider.java +++ b/app/src/main/java/com/fastaccess/provider/rest/RestProvider.java @@ -92,6 +92,10 @@ private static Retrofit provideRetrofit(boolean enterprise) { } public static void downloadFile(@NonNull Context context, @NonNull String url) { + downloadFile(context, url, null); + } + + public static void downloadFile(@NonNull Context context, @NonNull String url, @Nullable String extension) { try { if (InputHelper.isEmpty(url)) return; boolean isEnterprise = LinkParserHelper.isEnterprise(url); @@ -103,6 +107,9 @@ public static void downloadFile(@NonNull Context context, @NonNull String url) { request.addRequestHeader("Authorization", authToken.startsWith("Basic") ? authToken : "token " + authToken); } String fileName = new File(url).getName(); + if (!InputHelper.isEmpty(extension)) { + fileName += extension; + } request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); request.setTitle(fileName); request.setDescription(context.getString(R.string.downloading_file)); diff --git a/app/src/main/java/com/fastaccess/ui/modules/repos/code/releases/RepoReleasesFragment.java b/app/src/main/java/com/fastaccess/ui/modules/repos/code/releases/RepoReleasesFragment.java index 9a3996499..04a003c3c 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/repos/code/releases/RepoReleasesFragment.java +++ b/app/src/main/java/com/fastaccess/ui/modules/repos/code/releases/RepoReleasesFragment.java @@ -1,10 +1,13 @@ package com.fastaccess.ui.modules.repos.code.releases; +import android.app.Activity; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + import android.view.View; import com.annimon.stream.Collectors; @@ -139,13 +142,11 @@ public static RepoReleasesFragment newInstance(@NonNull String repoId, @NonNull ArrayList models = new ArrayList<>(); if (!InputHelper.isEmpty(item.getZipBallUrl())) { String url = item.getZipBallUrl(); - if (!url.endsWith(".tar.gz")) { - url = url + ".tar.gz"; - } - models.add(new SimpleUrlsModel(getString(R.string.download_as_zip), url)); + models.add(new SimpleUrlsModel(getString(R.string.download_as_zip), url, ".zip")); } if (!InputHelper.isEmpty(item.getTarballUrl())) { - models.add(new SimpleUrlsModel(getString(R.string.download_as_tar), item.getTarballUrl())); + String url = item.getTarballUrl(); + models.add(new SimpleUrlsModel(getString(R.string.download_as_tar), url, ".tar.gz")); } if (item.getAssets() != null && !item.getAssets().isEmpty()) { ArrayList mapped = Stream.of(item.getAssets()) @@ -180,8 +181,10 @@ public static RepoReleasesFragment newInstance(@NonNull String repoId, @NonNull } @Override public void onItemSelected(SimpleUrlsModel item) { - if (ActivityHelper.checkAndRequestReadWritePermission(getActivity())) { - RestProvider.downloadFile(getContext(), item.getUrl()); + Activity activity = getActivity(); + if (activity == null) return; + if (ActivityHelper.checkAndRequestReadWritePermission(activity)) { + RestProvider.downloadFile(activity, item.getUrl(), item.extension); } }