fix issues with audio paths and download service
This commit is contained in:
parent
d2afefe595
commit
1b9c79ad5f
4 changed files with 23 additions and 9 deletions
|
|
@ -80,7 +80,7 @@ public abstract class AbsPlayerFragment extends AbsMusicServiceFragment implemen
|
|||
}
|
||||
|
||||
protected void toggleFavorite(Song song) {
|
||||
MusicUtil.toggleFavorite(requireActivity(), song);
|
||||
MusicUtil.toggleFavorite(song);
|
||||
}
|
||||
|
||||
protected boolean isToolbarShown() {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.net.URLConnection;
|
|||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public class DownloadService extends Service {
|
||||
public static final String PACKAGE_NAME = BuildConfig.APPLICATION_ID;
|
||||
public static final String EXTRA_SONG = PACKAGE_NAME + ".extra.song";
|
||||
|
|
@ -59,6 +60,8 @@ public class DownloadService extends Service {
|
|||
|
||||
download.getParentFile().mkdirs();
|
||||
download.createNewFile();
|
||||
audio.getParentFile().mkdirs();
|
||||
audio.createNewFile();
|
||||
|
||||
InputStream input = connection.getInputStream();
|
||||
OutputStream output = new FileOutputStream(download);
|
||||
|
|
@ -78,10 +81,14 @@ public class DownloadService extends Service {
|
|||
input = new FileInputStream(download);
|
||||
output = new FileOutputStream(audio);
|
||||
|
||||
output.write(input.read());
|
||||
while ((count = input.read(data)) != -1) {
|
||||
output.write(data, 0, count);
|
||||
}
|
||||
|
||||
input.close();
|
||||
output.close();
|
||||
|
||||
download.delete();
|
||||
App.getDatabase().cacheDao().insertCache(new Cache(song));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -86,12 +86,17 @@ public class MusicUtil {
|
|||
public static String getFileUri(Song song) {
|
||||
File root = new File(PreferenceUtil.getInstance(App.getInstance()).getLocationDownload(), "music");
|
||||
|
||||
String path = "/" + song.artistName + "/" + song.albumName + "/";
|
||||
String name = song.discNumber + "." + song.trackNumber + " - " + song.title + "." + song.container;
|
||||
String path = "/" + ascii(song.artistName) + "/" + ascii(song.albumName);
|
||||
String name = "/" + song.discNumber + "." + song.trackNumber + " - " + ascii(song.title) + "." + song.container;
|
||||
|
||||
return root + path + name;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String ascii(String string) {
|
||||
return string.replaceAll("[^\\x20-\\x2E\\x30-\\x7E]", "");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Intent createShareSongFileIntent(@NonNull final Song song, Context context) {
|
||||
try {
|
||||
|
|
@ -175,10 +180,10 @@ public class MusicUtil {
|
|||
|
||||
@NonNull
|
||||
public static String buildInfoString(@Nullable final String one, @Nullable final String two) {
|
||||
// skip empty strings
|
||||
if (TextUtils.isEmpty(one)) {
|
||||
return TextUtils.isEmpty(two) ? "" : two;
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(two)) {
|
||||
return TextUtils.isEmpty(one) ? "" : one;
|
||||
}
|
||||
|
|
@ -186,7 +191,7 @@ public class MusicUtil {
|
|||
return one + " • " + two;
|
||||
}
|
||||
|
||||
public static void toggleFavorite(@NonNull final Context context, @NonNull final Song song) {
|
||||
public static void toggleFavorite(Song song) {
|
||||
song.favorite = !song.favorite;
|
||||
|
||||
String user = App.getApiClient().getCurrentUserId();
|
||||
|
|
@ -205,7 +210,7 @@ public class MusicUtil {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public static String getSectionName(@Nullable String musicMediaTitle) {
|
||||
public static String getSectionName(String musicMediaTitle) {
|
||||
if (TextUtils.isEmpty(musicMediaTitle)) return "";
|
||||
|
||||
musicMediaTitle = musicMediaTitle.trim().toLowerCase();
|
||||
|
|
@ -215,7 +220,10 @@ public class MusicUtil {
|
|||
musicMediaTitle = musicMediaTitle.substring(2);
|
||||
}
|
||||
|
||||
if (musicMediaTitle.isEmpty()) return "";
|
||||
if (musicMediaTitle.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return String.valueOf(musicMediaTitle.charAt(0)).toUpperCase();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@
|
|||
<item name="dividerColor">#18FFFFFF</item>
|
||||
<item name="defaultFooterColor">#424242</item>
|
||||
<item name="cardBackgroundColor">#212121</item>
|
||||
<item name="md_background_color">#212121</item>
|
||||
</style>
|
||||
|
||||
<style name="FabParent">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue