enable slow update
This commit is contained in:
parent
0478c9fc30
commit
6d937d00ac
4 changed files with 65 additions and 59 deletions
|
|
@ -189,7 +189,6 @@ public class MainActivity extends AppCompatThemeActivity {
|
|||
long total;
|
||||
Storage storage;
|
||||
EncodingStorage encodings;
|
||||
long last = 0;
|
||||
|
||||
public EncodingDialog() {
|
||||
}
|
||||
|
|
@ -228,42 +227,38 @@ public class MainActivity extends AppCompatThemeActivity {
|
|||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what == EncodingStorage.UPDATE) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (last + 1000 < now) {
|
||||
last = now;
|
||||
Intent intent = (Intent) msg.obj;
|
||||
cur = intent.getLongExtra("cur", -1);
|
||||
total = intent.getLongExtra("total", -1);
|
||||
final Uri targetUri = intent.getParcelableExtra("targetUri");
|
||||
final RawSamples.Info info;
|
||||
try {
|
||||
info = new RawSamples.Info(intent.getStringExtra("info"));
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Intent intent = (Intent) msg.obj;
|
||||
cur = intent.getLongExtra("cur", -1);
|
||||
total = intent.getLongExtra("total", -1);
|
||||
final Uri targetUri = intent.getParcelableExtra("targetUri");
|
||||
final RawSamples.Info info;
|
||||
try {
|
||||
info = new RawSamples.Info(intent.getStringExtra("info"));
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (progress != null)
|
||||
progress.setProgress(cur, total);
|
||||
if (progress != null)
|
||||
progress.setProgress(cur, total);
|
||||
|
||||
if (snackbar == null || !snackbar.isShownOrQueued()) {
|
||||
snackbar = Snackbar.make(fab, printEncodings(targetUri), Snackbar.LENGTH_LONG);
|
||||
snackbar.setDuration(Snackbar.LENGTH_INDEFINITE);
|
||||
snackbar.getView().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
progress = new ProgressEncoding(context, info);
|
||||
progress.setTitle(R.string.encoding_title);
|
||||
progress.setMessage(".../" + Storage.getName(context, targetUri));
|
||||
progress.show();
|
||||
progress.setProgress(cur, total);
|
||||
EncodingService.startIfPending(context);
|
||||
}
|
||||
});
|
||||
snackbar.show();
|
||||
} else {
|
||||
snackbar.setText(printEncodings(targetUri));
|
||||
snackbar.show();
|
||||
}
|
||||
if (snackbar == null || !snackbar.isShownOrQueued()) {
|
||||
snackbar = Snackbar.make(fab, printEncodings(targetUri), Snackbar.LENGTH_LONG);
|
||||
snackbar.setDuration(Snackbar.LENGTH_INDEFINITE);
|
||||
snackbar.getView().setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
progress = new ProgressEncoding(context, info);
|
||||
progress.setTitle(R.string.encoding_title);
|
||||
progress.setMessage(".../" + Storage.getName(context, targetUri));
|
||||
progress.show();
|
||||
progress.setProgress(cur, total);
|
||||
EncodingService.startIfPending(context);
|
||||
}
|
||||
});
|
||||
snackbar.show();
|
||||
} else {
|
||||
snackbar.setText(printEncodings(targetUri));
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
if (msg.what == EncodingStorage.DONE) {
|
||||
|
|
@ -313,9 +308,6 @@ public class MainActivity extends AppCompatThemeActivity {
|
|||
public void onResume() {
|
||||
if (progress != null)
|
||||
progress.onResume(cur);
|
||||
encodings.load();
|
||||
if (encodings.isEmpty())
|
||||
hide();
|
||||
}
|
||||
|
||||
public void Error(final File in, final RawSamples.Info info, Throwable e) {
|
||||
|
|
|
|||
|
|
@ -155,18 +155,24 @@ public class EncodingStorage extends HashMap<File, EncodingStorage.Info> {
|
|||
|
||||
public void encoding(final FileEncoder encoder, final OnFlyEncoding fly, final RawSamples.Info info, final Runnable done) {
|
||||
encoder.run(new Runnable() {
|
||||
long last = 0;
|
||||
|
||||
@Override
|
||||
public void run() { // progress
|
||||
try {
|
||||
long cur = encoder.getCurrent();
|
||||
long total = encoder.getTotal();
|
||||
Intent intent = new Intent()
|
||||
.putExtra("cur", cur)
|
||||
.putExtra("total", total)
|
||||
.putExtra("info", info.save().toString())
|
||||
.putExtra("targetUri", fly.targetUri)
|
||||
.putExtra("targetFile", Storage.getName(storage.getContext(), fly.targetUri));
|
||||
Post(UPDATE, intent);
|
||||
long now = System.currentTimeMillis();
|
||||
if (last + 1000 < now) {
|
||||
last = now;
|
||||
long cur = encoder.getCurrent();
|
||||
long total = encoder.getTotal();
|
||||
Intent intent = new Intent()
|
||||
.putExtra("cur", cur)
|
||||
.putExtra("total", total)
|
||||
.putExtra("info", info.save().toString())
|
||||
.putExtra("targetUri", fly.targetUri)
|
||||
.putExtra("targetFile", Storage.getName(storage.getContext(), fly.targetUri));
|
||||
Post(UPDATE, intent);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
@ -203,13 +209,27 @@ public class EncodingStorage extends HashMap<File, EncodingStorage.Info> {
|
|||
OnFlyEncoding fly = new OnFlyEncoding(storage, targetUri, info);
|
||||
encoder = new FileEncoder(storage.getContext(), in, fly);
|
||||
filters(encoder, info);
|
||||
encoding(encoder, fly, info, null);
|
||||
encoding(encoder, fly, info, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
encoder.close();
|
||||
encoder = null;
|
||||
Post(EXIT, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void saveAsWAV(File in, File out, RawSamples.Info info) {
|
||||
OnFlyEncoding fly = new OnFlyEncoding(storage, out, info);
|
||||
encoder = new FileEncoder(storage.getContext(), in, fly);
|
||||
encoding(encoder, fly, info, null);
|
||||
encoding(encoder, fly, info, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
encoder.close();
|
||||
encoder = null;
|
||||
Post(EXIT, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void restart() {
|
||||
|
|
|
|||
|
|
@ -61,10 +61,10 @@ public class Recordings extends com.github.axet.audiolibrary.app.Recordings {
|
|||
|
||||
@Override
|
||||
public void scan(List<Storage.Node> nn, boolean clean, Runnable done) {
|
||||
EncodingStorage storage = new EncodingStorage(context);
|
||||
EncodingStorage encodings = ((AudioApplication)context.getApplicationContext()).encodings;
|
||||
for (Storage.Node n : new ArrayList<>(nn)) {
|
||||
for (File key : storage.keySet()) {
|
||||
EncodingStorage.Info info = storage.get(key);
|
||||
for (File key : encodings.keySet()) {
|
||||
EncodingStorage.Info info = encodings.get(key);
|
||||
if (n.uri.equals(info.targetUri))
|
||||
nn.remove(n);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,16 +42,10 @@ public class EncodingService extends PersistentService {
|
|||
|
||||
Storage storage; // for storage path
|
||||
Handler handler = new Handler() {
|
||||
long last = 0;
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (msg.what == EncodingStorage.UPDATE) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (last + 1000 < now) {
|
||||
last = now;
|
||||
optimization.icon.updateIcon((Intent) msg.obj);
|
||||
}
|
||||
optimization.icon.updateIcon((Intent) msg.obj);
|
||||
}
|
||||
if (msg.what == EncodingStorage.DONE) {
|
||||
EncodingStorage encodings = ((AudioApplication) getApplication()).encodings;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue