Downloading songs needs some work
This commit is contained in:
+4
-4
File diff suppressed because one or more lines are too long
+1
-1
@@ -48,7 +48,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50"
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61'
|
||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||
implementation 'com.android.support:support-v4:28.0.0'
|
||||
implementation 'com.android.support:design:28.0.0'
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<activity android:name=".activities.IcarusSongActivity"></activity>
|
||||
<activity
|
||||
android:name=".activities.LoginActivity"
|
||||
android:label="@string/title_activity_demo_stream"
|
||||
android:label="@string/title_activity_main"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@@ -23,15 +23,6 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activities.SongViewActivity"
|
||||
android:label="@string/title_activity_song_view"
|
||||
android:parentActivityName=".activities.MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.example.mear.activities.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:label="@string/title_activity_settings"
|
||||
@@ -45,13 +36,18 @@
|
||||
<activity
|
||||
android:name=".activities.MainActivity"
|
||||
android:label="@string/title_activity_main"
|
||||
android:parentActivityName=".activities.LoginActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.example.mear.activities.LoginActivity" />
|
||||
<!--
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
-->
|
||||
</activity>
|
||||
|
||||
<service android:name=".playback.service.MusicService" />
|
||||
|
||||
@@ -271,24 +271,21 @@ void downloadSong(Song& song, const Token& token, const Str& path) {
|
||||
repository::local::APIRepository apiRepo;
|
||||
auto apiInfo = apiRepo.retrieveAPIInfo(path);
|
||||
repository::SongRepository songRepo;
|
||||
auto downloadedSong = songRepo.downloadSong(token, song, apiInfo);
|
||||
manager::DirectoryManager dirMgr;
|
||||
if (dirMgr.doesSongExist(song, path)) {
|
||||
std::cout << "song already exists\n";
|
||||
return;
|
||||
}
|
||||
|
||||
auto downloadedSong = songRepo.downloadSong(token, song, apiInfo);
|
||||
|
||||
dirMgr.createSongDirectory(song, path);
|
||||
downloadedSong.path = dirMgr.fullSongPath(song, path);
|
||||
std::fstream saveSong(downloadedSong.path, std::ios::out | std::ios::binary);
|
||||
saveSong.write((char*)&downloadedSong.data[0], downloadedSong.data.size());
|
||||
saveSong.close();
|
||||
|
||||
repository::local::SongRepository localSongRepo;
|
||||
if (!localSongRepo.databaseExist(path)) {
|
||||
localSongRepo.initializedDatabase(path);
|
||||
}
|
||||
|
||||
repository::local::SongRepository localSongRepo(path);
|
||||
if (!localSongRepo.doesTableExist(path)) {
|
||||
localSongRepo.createSongTable(path);
|
||||
}
|
||||
@@ -405,7 +402,7 @@ Java_com_example_mear_repositories_TrackRepository_retrieveSongsIncludingDownloa
|
||||
auto i = 0;
|
||||
|
||||
repository::local::SongRepository localSongRepo(appPath);
|
||||
auto localSongs = (localSongRepo.isTableEmpty(appPath)) ?
|
||||
auto localSongs = (!localSongRepo.isTableEmpty(appPath)) ?
|
||||
localSongRepo.retrieveAllSongs(appPath) : std::vector<model::Song>();
|
||||
|
||||
for (auto& sng: allSongs) {
|
||||
|
||||
@@ -52,11 +52,12 @@ namespace repository { namespace local {
|
||||
queryStr.append(m_tableName);
|
||||
|
||||
SQLite::Statement query(db, queryStr);
|
||||
auto r = query.exec();
|
||||
|
||||
auto r = query.executeStep();
|
||||
|
||||
const auto result = query.hasRow();
|
||||
|
||||
return result;
|
||||
return !result;
|
||||
} catch (std::exception& ex) {
|
||||
auto msg = ex.what();
|
||||
}
|
||||
|
||||
@@ -298,7 +298,6 @@ namespace repository {
|
||||
std::string queryString("DELETE FROM ");
|
||||
queryString.append(m_tableName);
|
||||
queryString.append(" WHERE Id = ?");
|
||||
// queryString.append("Duration, Track, Disc, Filename, Path, CoverArtId)");
|
||||
SQLite::Statement query(db, queryString);
|
||||
query.bind(1, song.id);
|
||||
|
||||
@@ -334,7 +333,7 @@ namespace repository {
|
||||
query.bind(12, song.path);
|
||||
query.bind(13, song.coverArtId);
|
||||
|
||||
query.exec();
|
||||
auto result = query.exec();
|
||||
} catch (std::exception& ex) {
|
||||
auto msg = ex.what();
|
||||
}
|
||||
|
||||
@@ -34,11 +34,8 @@ namespace repository { namespace local {
|
||||
|
||||
auto result = query.executeStep();
|
||||
|
||||
auto valZero = query.getColumn(1);
|
||||
auto valOne = query.getColumn(2);
|
||||
|
||||
user.username = valZero.getString();
|
||||
user.password = valOne.getString();
|
||||
user.username = std::move(query.getColumn(1).getString());
|
||||
user.password = std::move(query.getColumn(2).getString());
|
||||
|
||||
return user;
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import android.widget.Toast
|
||||
import org.jetbrains.anko.imageBitmap
|
||||
|
||||
import com.example.mear.listeners.TrackElaspingChange
|
||||
import com.example.mear.models.Song
|
||||
import com.example.mear.R
|
||||
import com.example.mear.repositories.*
|
||||
import com.example.mear.repositories.RepeatRepository.RepeatTypes
|
||||
@@ -55,8 +54,6 @@ class MainActivity : BaseServiceActivity() {
|
||||
setContentView(R.layout.activity_main)
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
//permissionPrompt()
|
||||
|
||||
initialize()
|
||||
}
|
||||
catch (ex: Exception) {
|
||||
@@ -358,7 +355,12 @@ class MainActivity : BaseServiceActivity() {
|
||||
private fun showPopup(view: View) {
|
||||
try {
|
||||
var popup = PopupMenu(this, view)
|
||||
popup.inflate(R.menu.popup_menu)
|
||||
if (musicService!!.getCurrentSong().downloaded) {
|
||||
popup.inflate(R.menu.popup_menu_song_downloaded)
|
||||
}
|
||||
else {
|
||||
popup.inflate(R.menu.popup_menu)
|
||||
}
|
||||
|
||||
popup.setOnMenuItemClickListener{ item: MenuItem? ->
|
||||
when (item!!.itemId) {
|
||||
@@ -368,8 +370,11 @@ class MainActivity : BaseServiceActivity() {
|
||||
R.id.action_song_view -> {
|
||||
startActivity(Intent(this, IcarusSongActivity::class.java))
|
||||
}
|
||||
R.id.action_song_delete -> {
|
||||
// TODO: handle song deletion
|
||||
val ss = true
|
||||
}
|
||||
R.id.action_song_download -> {
|
||||
// TODO: implement download functionality
|
||||
val appPath = appDirectory()
|
||||
val apiRepo = APIRepository()
|
||||
val tokenRepo = TokenRepository()
|
||||
@@ -379,6 +384,10 @@ class MainActivity : BaseServiceActivity() {
|
||||
val token = tokenRepo.retrieveToken(appPath)
|
||||
val apiInfo = apiRepo.retrieveRecord(appPath)
|
||||
trackRepo.download(token, song, appPath)
|
||||
musicService!!.changeSongDownloadStatus()
|
||||
// TODO: implement something to include the downloaded song into the songQueue
|
||||
// essentially replacing the song that already exists, that way one can
|
||||
// actually access the file without having to restart the app
|
||||
}
|
||||
R.id.action_song_play_count-> {
|
||||
val trk = musicService!!.getCurrentSong()
|
||||
|
||||
@@ -86,7 +86,6 @@ class SongAdapter(val mOnClickListener: (Song) -> Unit,
|
||||
|
||||
v.setOnClickListener { clickList(songItem!!)}
|
||||
if (songItems.downloaded) {
|
||||
var rs = v.resources
|
||||
v.setBackgroundColor(v.resources.getColor(R.color.track_seek))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,17 @@ class MusicService(var appPath: String = ""): Service() {
|
||||
}
|
||||
}
|
||||
|
||||
fun changeSongDownloadStatus() {
|
||||
currentSong.downloaded = true
|
||||
songQueue.forEach {
|
||||
s ->
|
||||
if (s.id == currentSong.id) {
|
||||
s.downloaded = true
|
||||
}
|
||||
}
|
||||
// songQueue[currentSongIndex!!].downloaded = true
|
||||
}
|
||||
|
||||
fun goToPosition(progress: Int) { trackPlayer!!.seekTo(progress) }
|
||||
|
||||
fun playSongTrack() {
|
||||
@@ -225,7 +236,8 @@ class MusicService(var appPath: String = ""): Service() {
|
||||
|
||||
val token = tokenRepo.retrieveToken(appPath)
|
||||
val apiInfo = apiRepo.retrieveRecord(appPath)
|
||||
val songs = trackRepo.fetchSongs(token, apiInfo.uri)
|
||||
// val songs = trackRepo.fetchSongs(token, apiInfo.uri)
|
||||
val songs = trackRepo.fetchSongsIncludingDownloaded(token, apiInfo.uri, appPath)
|
||||
songQueue = songs.toMutableList()
|
||||
|
||||
if (retrieveShuffleMode()!!) {
|
||||
@@ -280,6 +292,14 @@ class MusicService(var appPath: String = ""): Service() {
|
||||
|
||||
private fun offlinePlaySong(song: Song) {
|
||||
try {
|
||||
currentSong = song
|
||||
songQueue.forEach{ s ->
|
||||
if (s.id == currentSong.id) {
|
||||
s.downloaded = currentSong.downloaded
|
||||
s.filename = currentSong.filename
|
||||
s.path = currentSong.path
|
||||
}
|
||||
}
|
||||
trackPlayer!!.reset()
|
||||
trackPlayer!!.setDataSource(song.path)
|
||||
trackPlayer!!.prepare()
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item android:id="@+id/action_settings"
|
||||
android:title="@string/settings"
|
||||
app:showAsAction="never"/>
|
||||
<item android:id="@+id/action_song_view"
|
||||
android:title="@string/song_view"
|
||||
app:showAsAction="never" />
|
||||
<item android:id="@+id/action_song_delete"
|
||||
android:title="@string/song_delete"
|
||||
app:showAsAction="never" />
|
||||
<item android:id="@+id/action_song_play_count"
|
||||
android:title="@string/song_play_count"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
@@ -38,6 +38,7 @@
|
||||
<string name="song_view">Songs</string>
|
||||
<string name="song_play_count">Play Count</string>
|
||||
<string name="song_download">Download</string>
|
||||
<string name="song_delete">Delete</string>
|
||||
|
||||
<!-- Popups -->
|
||||
<string name="popup_about_header">About</string>
|
||||
|
||||
Reference in New Issue
Block a user