Merge pull request #586 from afischerdev/app-download

Fixed some smaller app problems
This commit is contained in:
afischerdev 2023-07-10 11:07:37 +02:00 committed by GitHub
commit 086503e529
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 16 deletions

View file

@ -6,6 +6,7 @@ import static btools.routingapp.BInstallerView.MASK_INSTALLED_RD5;
import static btools.routingapp.BInstallerView.MASK_SELECTED_RD5; import static btools.routingapp.BInstallerView.MASK_SELECTED_RD5;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -14,7 +15,6 @@ import android.content.pm.PackageManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.StatFs;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
@ -65,16 +65,11 @@ public class BInstallerActivity extends AppCompatActivity {
BInstallerView.OnSelectListener onSelectListener; BInstallerView.OnSelectListener onSelectListener;
@SuppressWarnings("deprecation") @SuppressLint("UsableSpace")
public static long getAvailableSpace(String baseDir) { public static long getAvailableSpace(String baseDir) {
StatFs stat = new StatFs(baseDir); File f = new File(baseDir);
if (!f.exists()) return 0L;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { return f.getUsableSpace();
return stat.getAvailableBlocksLong() * stat.getBlockSizeLong();
} else {
//noinspection deprecation
return (long) stat.getAvailableBlocks() * stat.getBlockSize();
}
} }
@Override @Override
@ -158,6 +153,7 @@ public class BInstallerActivity extends AppCompatActivity {
} }
private void updateDownloadButton() { private void updateDownloadButton() {
if (mBaseDir == null) return;
final ArrayList<Integer> selectedTilesDownload = mBInstallerView.getSelectedTiles(MASK_SELECTED_RD5); final ArrayList<Integer> selectedTilesDownload = mBInstallerView.getSelectedTiles(MASK_SELECTED_RD5);
final ArrayList<Integer> selectedTilesLastUpdate = mBInstallerView.getSelectedTiles(MASK_CURRENT_RD5); final ArrayList<Integer> selectedTilesLastUpdate = mBInstallerView.getSelectedTiles(MASK_CURRENT_RD5);
final ArrayList<Integer> selectedTilesUpdate = mBInstallerView.getSelectedTiles(MASK_INSTALLED_RD5); final ArrayList<Integer> selectedTilesUpdate = mBInstallerView.getSelectedTiles(MASK_INSTALLED_RD5);
@ -199,18 +195,30 @@ public class BInstallerActivity extends AppCompatActivity {
public void downloadAll(ArrayList<Integer> downloadList, int all) { public void downloadAll(ArrayList<Integer> downloadList, int all) {
ArrayList<String> urlparts = new ArrayList<>(); ArrayList<String> urlparts = new ArrayList<>();
int len = 0;
for (Integer i : downloadList) { for (Integer i : downloadList) {
urlparts.add(baseNameForTile(i)); urlparts.add(baseNameForTile(i));
len++;
if (len > 500) break; // don't do too much work, data size 10240 Bytes only
} }
downloadCanceled = false; downloadCanceled = false;
mProgressIndicator.show(); mProgressIndicator.show();
mButtonDownload.setEnabled(false); mButtonDownload.setEnabled(false);
Data inputData = new Data.Builder() Data inputData = null;
.putStringArray(DownloadWorker.KEY_INPUT_SEGMENT_NAMES, urlparts.toArray(new String[0])) try {
.putInt(DownloadWorker.KEY_INPUT_SEGMENT_ALL, all) inputData = new Data.Builder()
.build(); .putStringArray(DownloadWorker.KEY_INPUT_SEGMENT_NAMES, urlparts.toArray(new String[0]))
.putInt(DownloadWorker.KEY_INPUT_SEGMENT_ALL, all)
.build();
} catch (IllegalStateException e) {
Toast.makeText(this, "Too much data for download. Please reduce.", Toast.LENGTH_LONG).show();
e.printStackTrace();
return;
}
Constraints constraints = new Constraints.Builder() Constraints constraints = new Constraints.Builder()
.setRequiresBatteryNotLow(true) .setRequiresBatteryNotLow(true)

View file

@ -174,8 +174,18 @@ public class BRouterView extends View {
// new init is done move old files // new init is done move old files
if (waitingForMigration) { if (waitingForMigration) {
Log.d("BR", "path " + oldMigrationPath + " " + basedir); Log.d("BR", "path " + oldMigrationPath + " " + basedir);
if (!oldMigrationPath.equals(basedir + "/brouter")) Thread t = new Thread(new Runnable() {
moveFolders(oldMigrationPath, basedir + "/brouter"); @Override
public void run() {
if (!oldMigrationPath.equals(basedir + "/brouter"))
moveFolders(oldMigrationPath, basedir + "/brouter");
}});
t.start();
try {
t.join(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
waitingForMigration = false; waitingForMigration = false;
} }