This commit is contained in:
Alexey Kuznetsov 2018-12-08 23:22:31 +03:00
commit b91d66e3b5
4 changed files with 14 additions and 49 deletions

View file

@ -28,6 +28,7 @@ import com.github.axet.androidlibrary.app.SuperUser;
import com.github.axet.androidlibrary.services.StorageProvider;
import com.github.axet.androidlibrary.widgets.AboutPreferenceCompat;
import com.github.axet.androidlibrary.widgets.AppCompatThemeActivity;
import com.github.axet.androidlibrary.widgets.ErrorDialog;
import com.github.axet.androidlibrary.widgets.SearchView;
import com.github.axet.audiolibrary.app.Recordings;
import com.github.axet.audiolibrary.app.Storage;
@ -206,7 +207,7 @@ public class MainActivity extends AppCompatThemeActivity {
try {
storage.migrateLocalStorage();
} catch (RuntimeException e) {
Error(e);
ErrorDialog.Error(this, e);
}
final String last = shared.getString(AudioApplication.PREFERENCE_LAST, "");
@ -261,7 +262,7 @@ public class MainActivity extends AppCompatThemeActivity {
try {
storage.migrateLocalStorage();
} catch (RuntimeException e) {
Error(e);
ErrorDialog.Error(MainActivity.this, e);
}
recordings.load(false, null);
checkPending();
@ -292,30 +293,9 @@ public class MainActivity extends AppCompatThemeActivity {
void updateHeader() {
Uri uri = storage.getStoragePath();
long free = storage.getFree(uri);
long free = Storage.getFree(this, uri);
long sec = Storage.average(this, free);
TextView text = (TextView) findViewById(R.id.space_left);
text.setText(AudioApplication.formatFree(this, free, sec));
}
public void Error(Throwable e) {
Error(SuperUser.toMessage(e));
}
public void Error(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Error");
builder.setMessage(msg);
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
}
});
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}
}

View file

@ -32,6 +32,7 @@ import com.github.axet.androidlibrary.animations.MarginBottomAnimation;
import com.github.axet.androidlibrary.app.SuperUser;
import com.github.axet.androidlibrary.sound.AudioTrack;
import com.github.axet.androidlibrary.widgets.AppCompatThemeActivity;
import com.github.axet.androidlibrary.widgets.ErrorDialog;
import com.github.axet.androidlibrary.widgets.OpenFileDialog;
import com.github.axet.audiolibrary.app.RawSamples;
import com.github.axet.audiolibrary.app.Sound;
@ -192,16 +193,6 @@ public class RecordingActivity extends AppCompatThemeActivity {
}
}
public void Post(final Throwable e) {
Log.e(TAG, "error", e);
handler.post(new Runnable() {
@Override
public void run() {
Error(toMessage(e));
}
});
}
public String toMessage(Throwable e) {
Throwable t;
if (encoder == null) {
@ -220,9 +211,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
}
public void Error(String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Error");
builder.setMessage(msg);
ErrorDialog builder = new ErrorDialog(this, msg);
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
@ -337,7 +326,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
} catch (RuntimeException e) {
Error(e);
}
recording.storage.delete(recording.targetUri);
Storage.delete(RecordingActivity.this, recording.targetUri);
}
Storage.delete(recording.storage.getTempRecording());
finish();
@ -862,7 +851,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
}, new Runnable() {
@Override
public void run() { // or error
recording.storage.delete(fly.targetUri); // fly has fd, delete target manually
Storage.delete(RecordingActivity.this, fly.targetUri); // fly has fd, delete target manually
d.cancel();
Error(encoder.getException());
}

View file

@ -37,20 +37,18 @@ public class Storage extends com.github.axet.audiolibrary.app.Storage {
String s = path.getScheme();
if (Build.VERSION.SDK_INT >= 21 && s.startsWith(ContentResolver.SCHEME_CONTENT)) {
Uri n = getNextFile(path, format, ext);
return n;
return getNextFile(context, path, format, ext);
} else if (s.startsWith(ContentResolver.SCHEME_FILE)) {
File f = getFile(path);
if (!f.exists() && !f.mkdirs()) {
if (!f.exists() && !f.mkdirs())
throw new RuntimeException("Unable to create: " + path);
}
return Uri.fromFile(getNextFile(f, format, ext));
} else {
throw new UnknownUri();
}
}
public File getNewFile(File path, String ext) {
public File getNewFile(File f, String ext) {
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
String format = "%s";
@ -59,10 +57,8 @@ public class Storage extends com.github.axet.audiolibrary.app.Storage {
format = getFormatted(format, new Date());
File f = path;
if (!f.exists() && !f.mkdirs()) {
throw new RuntimeException("Unable to create: " + path);
}
if (!f.exists() && !f.mkdirs())
throw new RuntimeException("Unable to create: " + f);
return getNextFile(f, format, ext);
}

View file

@ -168,7 +168,7 @@ public class RecordingService extends Service {
if (targetFile == null) {
title = getString(R.string.app_name);
Uri f = storage.getStoragePath();
long free = storage.getFree(f);
long free = Storage.getFree(this, f);
long sec = Storage.average(this, free);
text = AudioApplication.formatFree(this, free, sec);
builder = new RemoteNotificationCompat.Low(this, R.layout.notifictaion);