Merge branch 'audiorecorder-3.2.58'

This commit is contained in:
Alexey Kuznetsov 2019-03-12 12:25:40 +03:00
commit 48322e1add
6 changed files with 54 additions and 15 deletions

View file

@ -8,8 +8,8 @@ android {
applicationId "com.github.axet.audiorecorder"
minSdkVersion 9
targetSdkVersion 26
versionCode 315
versionName "3.2.57"
versionCode 316
versionName "3.2.58"
}
signingConfigs {
release {

View file

@ -8,14 +8,22 @@ import android.os.Build;
import android.preference.PreferenceManager;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
public class Storage extends com.github.axet.audiolibrary.app.Storage {
public static final SimpleDateFormat ISO8601Z = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.US) {{
setTimeZone(TimeZone.getTimeZone("UTC"));
}};
public static String getFormatted(String format, Date date) {
format = format.replaceAll("%s", SIMPLE.format(date));
format = format.replaceAll("%I", ISO8601.format(date));
format = format.replaceAll("%T", "" + System.currentTimeMillis() / 1000);
format = format.replaceAll("%U", ISO8601Z.format(date));
return format;
}
@ -41,7 +49,7 @@ public class Storage extends com.github.axet.audiolibrary.app.Storage {
return getNextFile(context, path, format, ext);
} else if (s.equals(ContentResolver.SCHEME_FILE)) {
File f = getFile(path);
if (!f.exists() && !f.mkdirs())
if (!f.exists() && !f.mkdirs() && !f.exists())
throw new RuntimeException("Unable to create: " + path);
return Uri.fromFile(getNextFile(f, format, ext));
} else {
@ -58,7 +66,7 @@ public class Storage extends com.github.axet.audiolibrary.app.Storage {
format = getFormatted(format, new Date());
if (!f.exists() && !f.mkdirs())
if (!f.exists() && !f.mkdirs() && !f.exists())
throw new RuntimeException("Unable to create: " + f);
return getNextFile(f, format, ext);
}

View file

@ -1,13 +1,20 @@
package com.github.axet.audiorecorder.widgets;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.preference.PreferenceManager;
import android.support.v7.preference.ListPreference;
import android.util.AttributeSet;
import com.github.axet.audiorecorder.app.AudioApplication;
import com.github.axet.audiorecorder.app.Storage;
import java.util.Date;
public class NameFormatPreferenceCompat extends com.github.axet.androidlibrary.widgets.NameFormatPreferenceCompat {
public class NameFormatPreferenceCompat extends ListPreference {
public long now = System.currentTimeMillis();
public NameFormatPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@ -25,15 +32,37 @@ public class NameFormatPreferenceCompat extends com.github.axet.androidlibrary.w
}
@Override
public String getFormatted(String str) {
public boolean callChangeListener(Object newValue) {
update(newValue);
return super.callChangeListener(newValue);
}
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
Object def = super.onGetDefaultValue(a, index);
update(def);
return def;
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
super.onSetInitialValue(restoreValue, defaultValue);
CharSequence[] text = getEntries();
CharSequence[] values = getEntryValues();
for (int i = 0; i < text.length; i++) {
String t = text[i].toString();
String v = values[i].toString();
if (v.equals(str))
return t;
}
return Storage.getFormatted(str, new Date(1487926249000l));
for (int i = 0; i < values.length; i++)
text[i] = getFormatted((String) values[i]);
setEntries(text);
update(getValue()); // defaultValue null after defaults set
}
public void update(Object value) {
String v = (String) value;
setSummary(getFormatted(v));
}
public String getFormatted(String str) {
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(getContext());
String ext = shared.getString(AudioApplication.PREFERENCE_ENCODING, "");
return Storage.getFormatted(str, new Date(now)) + "." + ext;
}
}

View file

@ -38,11 +38,13 @@
<item>2017-02-01 09.08.01.wav</item>
<item>1487926249.wav</item>
<item>20170528T043902.wav</item>
<item>20170528T043902Z.wav</item>
</string-array>
<string-array name="format_values" formatted="false" translatable="false">
<item>%s</item>
<item>%T</item>
<item>%I</item>
<item>%U</item>
</string-array>
</resources>

View file

@ -47,7 +47,7 @@
android:summary="@string/pref_mode_summary"
android:title="@string/pref_mode_title" />
<ListPreference
<com.github.axet.audiorecorder.widgets.NameFormatPreferenceCompat
android:defaultValue="%s"
android:entries="@array/format_text"
android:entryValues="@array/format_values"

View file

@ -5,7 +5,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.3.2'
}
}