-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up ru.vtosters.hooks.music unnecessary constructions suppyAsync…
…(() -> { }).get()
- Loading branch information
Showing
14 changed files
with
170 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 28 additions & 38 deletions
66
app/src/main/java/ru/vtosters/lite/music/downloader/CachedDownloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,55 @@ | ||
package ru.vtosters.lite.music.downloader; | ||
|
||
import com.vk.dto.music.MusicTrack; | ||
|
||
import com.vk.dto.music.Playlist; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import ru.vtosters.lite.music.cache.MusicCacheImpl; | ||
import ru.vtosters.lite.music.cache.delegate.PlaylistCacheDbDelegate; | ||
import ru.vtosters.lite.music.interfaces.Callback; | ||
import ru.vtosters.lite.music.interfaces.ITrackDownloader; | ||
import ru.vtosters.lite.music.interfaces.IDownloader; | ||
import ru.vtosters.lite.utils.AndroidUtils; | ||
|
||
public final class CachedDownloader implements ITrackDownloader { | ||
|
||
private final ITrackDownloader origin; | ||
|
||
public CachedDownloader(ITrackDownloader origin) { | ||
this.origin = origin; | ||
public final class CachedDownloader implements IDownloader<MusicTrack> { | ||
private final File to; | ||
private final Playlist playlist; | ||
private final Callback callback; | ||
|
||
public CachedDownloader(File to, | ||
Playlist playlist, | ||
Callback callback) { | ||
this.to = to; | ||
this.playlist = playlist; | ||
this.callback = callback; | ||
} | ||
|
||
@Override | ||
public void download(MusicTrack track, Callback callback, Playlist playlist) { | ||
origin.download(track, new Callback() { | ||
public void download(MusicTrack track) { | ||
new Mp3Downloader(to, new Callback() { | ||
@Override | ||
public void onProgress(int progress) { | ||
callback.onProgress(progress); | ||
} | ||
|
||
@Override | ||
public void onSuccess() { | ||
new ThumbnailTrackDownloader().download(track, new Callback() { | ||
@Override public void onProgress(int progress) { | ||
|
||
} | ||
|
||
@Override public void onSuccess() { | ||
|
||
} | ||
|
||
@Override | ||
public void onFailure(Throwable e) { | ||
callback.onFailure(e); | ||
} | ||
|
||
@Override public void onSizeReceived(long size, long header) { | ||
|
||
} | ||
}, null); | ||
|
||
PlaylistCacheDbDelegate.addTrackToPlaylist(AndroidUtils.getGlobalContext(), playlist.v1(), track.y1()); | ||
MusicCacheImpl.addTrack(track); | ||
callback.onSuccess(); | ||
try { | ||
new ThumbnailTrackDownloader().download(track); | ||
PlaylistCacheDbDelegate.addTrackToPlaylist(AndroidUtils.getGlobalContext(), playlist.v1(), track.y1()); | ||
MusicCacheImpl.addTrack(track); | ||
callback.onSuccess(); | ||
} catch (IOException e) { | ||
callback.onFailure(e); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Throwable e) { | ||
callback.onFailure(e); | ||
} | ||
|
||
@Override | ||
public void onSizeReceived(long size, long header) { | ||
callback.onSizeReceived(size, header); | ||
} | ||
}, playlist); | ||
}).download(track); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.