Move Utils#getApkUrl(String repoAddress, Apk apk)
to Apk#getUrl()
Added assertions that both apkName and repoAddress need to be populated in order to call `getUrl()`. Also verified that this is the case for all usages of this method, which it should be. All `Apk` objects which currently have `getUrl()` called on them are loaded using the `ApkProvider.Helper.findById()` method without specifying which columns to load (which defaults to all).
This commit is contained in:
parent
e72ba25fe5
commit
3a1fcfd226
@ -815,9 +815,6 @@ public class AppDetails extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String repoaddress = getRepoAddress(apk);
|
|
||||||
if (repoaddress == null) return;
|
|
||||||
|
|
||||||
if (!apk.compatible) {
|
if (!apk.compatible) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setMessage(R.string.installIncompatible);
|
builder.setMessage(R.string.installIncompatible);
|
||||||
@ -826,7 +823,7 @@ public class AppDetails extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog,
|
public void onClick(DialogInterface dialog,
|
||||||
int whichButton) {
|
int whichButton) {
|
||||||
startDownload(apk, repoaddress);
|
startDownload(apk);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(R.string.no,
|
builder.setNegativeButton(R.string.no,
|
||||||
@ -855,21 +852,11 @@ public class AppDetails extends AppCompatActivity {
|
|||||||
alert.show();
|
alert.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
startDownload(apk, repoaddress);
|
startDownload(apk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private void startDownload(Apk apk) {
|
||||||
private String getRepoAddress(Apk apk) {
|
activeDownloadUrlString = apk.getUrl();
|
||||||
final String[] projection = {RepoProvider.DataColumns.ADDRESS};
|
|
||||||
Repo repo = RepoProvider.Helper.findById(this, apk.repo, projection);
|
|
||||||
if (repo == null || repo.address == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return repo.address;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startDownload(Apk apk, String repoAddress) {
|
|
||||||
activeDownloadUrlString = Utils.getApkUrl(repoAddress, apk);
|
|
||||||
registerDownloaderReceivers();
|
registerDownloaderReceivers();
|
||||||
headerFragment.startProgress();
|
headerFragment.startProgress();
|
||||||
DownloaderService.queue(this, apk.packageName, activeDownloadUrlString);
|
DownloaderService.queue(this, apk.packageName, activeDownloadUrlString);
|
||||||
|
@ -393,7 +393,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
|
|
||||||
// now that downloading the index is done, start downloading updates
|
// now that downloading the index is done, start downloading updates
|
||||||
if (changes && fdroidPrefs.isAutoDownloadEnabled()) {
|
if (changes && fdroidPrefs.isAutoDownloadEnabled()) {
|
||||||
autoDownloadUpdates(repo.address);
|
autoDownloadUpdates();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,7 +485,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
return inboxStyle;
|
return inboxStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void autoDownloadUpdates(String repoAddress) {
|
private void autoDownloadUpdates() {
|
||||||
Cursor cursor = getContentResolver().query(
|
Cursor cursor = getContentResolver().query(
|
||||||
AppProvider.getCanUpdateUri(),
|
AppProvider.getCanUpdateUri(),
|
||||||
new String[]{
|
new String[]{
|
||||||
@ -496,10 +496,8 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
for (int i = 0; i < cursor.getCount(); i++) {
|
for (int i = 0; i < cursor.getCount(); i++) {
|
||||||
App app = new App(cursor);
|
App app = new App(cursor);
|
||||||
Apk apk = ApkProvider.Helper.find(this, app.packageName, app.suggestedVersionCode, new String[]{
|
Apk apk = ApkProvider.Helper.find(this, app.packageName, app.suggestedVersionCode);
|
||||||
ApkProvider.DataColumns.NAME,
|
String urlString = apk.getUrl();
|
||||||
});
|
|
||||||
String urlString = Utils.getApkUrl(repoAddress, apk);
|
|
||||||
DownloaderService.queue(this, app.packageName, urlString);
|
DownloaderService.queue(this, app.packageName, urlString);
|
||||||
cursor.moveToNext();
|
cursor.moveToNext();
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ import com.nostra13.universalimageloader.utils.StorageUtils;
|
|||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.fdroid.fdroid.compat.FileCompat;
|
import org.fdroid.fdroid.compat.FileCompat;
|
||||||
import org.fdroid.fdroid.data.Apk;
|
|
||||||
import org.fdroid.fdroid.data.Repo;
|
import org.fdroid.fdroid.data.Repo;
|
||||||
import org.fdroid.fdroid.data.SanitizedFile;
|
import org.fdroid.fdroid.data.SanitizedFile;
|
||||||
import org.xml.sax.XMLReader;
|
import org.xml.sax.XMLReader;
|
||||||
@ -434,10 +433,6 @@ public final class Utils {
|
|||||||
return new Locale(languageTag);
|
return new Locale(languageTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getApkUrl(String repoAddress, Apk apk) {
|
|
||||||
return repoAddress + "/" + apk.apkName.replace(" ", "%20");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class CommaSeparatedList implements Iterable<String> {
|
public static final class CommaSeparatedList implements Iterable<String> {
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
@ -121,6 +121,13 @@ public class Apk extends ValueObject implements Comparable<Apk> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
if (repoAddress == null || apkName == null) {
|
||||||
|
throw new IllegalStateException("Apk needs to have both ApkProvider.DataColumns.REPO_ADDRESS and ApkProvider.DataColumns.NAME set in order to calculate URL.");
|
||||||
|
}
|
||||||
|
return repoAddress + "/" + apkName.replace(" ", "%20");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return packageName + " (version " + versionCode + ")";
|
return packageName + " (version " + versionCode + ")";
|
||||||
|
@ -297,7 +297,7 @@ public class SwapAppsView extends ListView implements
|
|||||||
// TODO: Unregister receivers correctly...
|
// TODO: Unregister receivers correctly...
|
||||||
|
|
||||||
Apk apk = getApkToInstall();
|
Apk apk = getApkToInstall();
|
||||||
String url = Utils.getApkUrl(apk.repoAddress, apk);
|
String url = apk.getUrl();
|
||||||
|
|
||||||
localBroadcastManager = LocalBroadcastManager.getInstance(getActivity());
|
localBroadcastManager = LocalBroadcastManager.getInstance(getActivity());
|
||||||
localBroadcastManager.registerReceiver(appListViewResetReceiver,
|
localBroadcastManager.registerReceiver(appListViewResetReceiver,
|
||||||
|
@ -778,7 +778,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
public void install(@NonNull final App app) {
|
public void install(@NonNull final App app) {
|
||||||
final Apk apk = ApkProvider.Helper.find(this, app.packageName, app.suggestedVersionCode);
|
final Apk apk = ApkProvider.Helper.find(this, app.packageName, app.suggestedVersionCode);
|
||||||
String urlString = Utils.getApkUrl(apk.repoAddress, apk);
|
String urlString = apk.getUrl();
|
||||||
downloadCompleteReceiver = new BroadcastReceiver() {
|
downloadCompleteReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user