diff --git a/.gradle/5.4.1/executionHistory/executionHistory.bin b/.gradle/5.4.1/executionHistory/executionHistory.bin
index 5533df8..d1b1b32 100644
Binary files a/.gradle/5.4.1/executionHistory/executionHistory.bin and b/.gradle/5.4.1/executionHistory/executionHistory.bin differ
diff --git a/.gradle/5.4.1/executionHistory/executionHistory.lock b/.gradle/5.4.1/executionHistory/executionHistory.lock
index f2eca88..0ed7e58 100644
Binary files a/.gradle/5.4.1/executionHistory/executionHistory.lock and b/.gradle/5.4.1/executionHistory/executionHistory.lock differ
diff --git a/.gradle/5.4.1/fileHashes/fileHashes.bin b/.gradle/5.4.1/fileHashes/fileHashes.bin
index 787d0f3..1f9c85d 100644
Binary files a/.gradle/5.4.1/fileHashes/fileHashes.bin and b/.gradle/5.4.1/fileHashes/fileHashes.bin differ
diff --git a/.gradle/5.4.1/fileHashes/fileHashes.lock b/.gradle/5.4.1/fileHashes/fileHashes.lock
index 48bfc03..a36cd54 100644
Binary files a/.gradle/5.4.1/fileHashes/fileHashes.lock and b/.gradle/5.4.1/fileHashes/fileHashes.lock differ
diff --git a/.gradle/5.4.1/fileHashes/resourceHashesCache.bin b/.gradle/5.4.1/fileHashes/resourceHashesCache.bin
index 1c60897..dbcf76f 100644
Binary files a/.gradle/5.4.1/fileHashes/resourceHashesCache.bin and b/.gradle/5.4.1/fileHashes/resourceHashesCache.bin differ
diff --git a/.gradle/5.4.1/javaCompile/classAnalysis.bin b/.gradle/5.4.1/javaCompile/classAnalysis.bin
index 87d2437..a1e16d8 100644
Binary files a/.gradle/5.4.1/javaCompile/classAnalysis.bin and b/.gradle/5.4.1/javaCompile/classAnalysis.bin differ
diff --git a/.gradle/5.4.1/javaCompile/jarAnalysis.bin b/.gradle/5.4.1/javaCompile/jarAnalysis.bin
index 7ad9d85..5a8f202 100644
Binary files a/.gradle/5.4.1/javaCompile/jarAnalysis.bin and b/.gradle/5.4.1/javaCompile/jarAnalysis.bin differ
diff --git a/.gradle/5.4.1/javaCompile/javaCompile.lock b/.gradle/5.4.1/javaCompile/javaCompile.lock
index e6d630d..4b0c170 100644
Binary files a/.gradle/5.4.1/javaCompile/javaCompile.lock and b/.gradle/5.4.1/javaCompile/javaCompile.lock differ
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index bd2b064..30c6d29 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -7,9 +7,6 @@
-
-
-
@@ -22,7 +19,6 @@
-
@@ -85,32 +81,13 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
+
@@ -135,16 +112,17 @@
-
+
-
-
+
+
-
-
+
+
-
+
+
@@ -153,7 +131,7 @@
-
+
@@ -177,17 +155,30 @@
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -195,15 +186,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
@@ -211,15 +224,19 @@
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -228,7 +245,7 @@
-
+
@@ -241,8 +258,8 @@
-
-
+
+
@@ -251,6 +268,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -278,9 +307,7 @@
-
-
@@ -296,7 +323,6 @@
-
@@ -309,7 +335,6 @@
-
@@ -319,19 +344,24 @@
-
-
+
+
+
+
+
+
+
-
+
@@ -341,6 +371,7 @@
+
@@ -391,7 +422,7 @@
-
+
@@ -400,7 +431,7 @@
-
+
@@ -427,49 +458,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
@@ -623,11 +617,19 @@
1574733783595
-
+
+ 1575075251084
+
+
+
+ 1575075251084
+
+
+
@@ -638,17 +640,17 @@
-
-
+
-
-
+
+
+
@@ -667,7 +669,9 @@
-
+
+
+
@@ -752,7 +756,7 @@
file://$PROJECT_DIR$/app/src/main/java/com/example/mear/repositories/TrackRepository.kt
- 36
+ 37
@@ -838,15 +842,58 @@
file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 302
+ 314
+
+ file://$PROJECT_DIR$/app/src/main/cpp/manager/DirectoryManager.h
+ 111
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/manager/DirectoryManager.h
+ 93
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/manager/DirectoryManager.h
+ 46
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/manager/DirectoryManager.h
+ 36
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/manager/DirectoryManager.h
+ 55
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/manager/DirectoryManager.h
+ 78
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/manager/DirectoryManager.h
+ 65
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/manager/DirectoryManager.h
+ 24
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
+ 675
+
+
-
-
@@ -943,20 +990,20 @@
-
+
-
+
-
+
-
+
@@ -973,40 +1020,16 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -1014,16 +1037,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1045,16 +1058,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1062,13 +1065,7 @@
-
-
-
-
-
-
-
+
@@ -1093,34 +1090,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
@@ -1133,9 +1106,113 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -1144,17 +1221,10 @@
-
-
-
-
-
-
-
-
-
+
+
@@ -1162,65 +1232,16 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/cpp/Demo.cpp b/app/src/main/cpp/Demo.cpp
index 6452d03..cbba3de 100644
--- a/app/src/main/cpp/Demo.cpp
+++ b/app/src/main/cpp/Demo.cpp
@@ -58,6 +58,9 @@ jobject songToObj(JNIEnv *env, const model::Song& song)
jmethodID songDuration = env->GetMethodID( songClass, "setDuration", "(I)V" );
jmethodID songYear = env->GetMethodID( songClass, "setYear", "(I)V" );
jmethodID songCoverArtId = env->GetMethodID(songClass, "setCoverArtId", "(I)V");
+ jmethodID songPathId = env->GetMethodID(songClass, "setPath", "(Ljava/lang/String;)V");
+ jmethodID songFilenameId = env->GetMethodID(songClass, "setFilename", "(Ljava/lang/String;)V");
+ jmethodID songDownloadedId = env->GetMethodID(songClass, "setDownloaded", "(B)V");
jint id = song.id;
jstring title = env->NewStringUTF(song.title.c_str());
@@ -68,6 +71,10 @@ jobject songToObj(JNIEnv *env, const model::Song& song)
jint duration = song.duration;
jint year = song.year;
jint coverArtId = song.coverArtId;
+ jstring songPath = env->NewStringUTF(song.path.c_str());
+ jstring songFilename = env->NewStringUTF(song.filename.c_str());
+ jboolean songDownloaded = song.downloaded;
+
env->CallVoidMethod( songObj, songId, id );
env->CallVoidMethod(songObj, songTitle, title);
@@ -78,12 +85,17 @@ jobject songToObj(JNIEnv *env, const model::Song& song)
env->CallVoidMethod(songObj, songDuration, duration);
env->CallVoidMethod(songObj, songYear, year);
env->CallVoidMethod(songObj, songCoverArtId, coverArtId);
+ env->CallVoidMethod(songObj, songPathId, songPath);
+ env->CallVoidMethod(songObj, songFilenameId, songFilename);
+ env->CallVoidMethod(songObj, songDownloadedId, songDownloaded);
env->DeleteLocalRef(title);
env->DeleteLocalRef(album);
env->DeleteLocalRef(albumArtist);
env->DeleteLocalRef(artist);
env->DeleteLocalRef(genre);
+ env->DeleteLocalRef(songPath);
+ env->DeleteLocalRef(songFilename);
return songObj;
}
@@ -404,24 +416,6 @@ Java_com_example_mear_repositories_TrackRepository_retrieveSong(
return fetchedSongObj;
}
-extern "C"
-JNIEXPORT jobject
-JNICALL
-Java_com_example_mear_repositories_TrackRepositories_downloadSong(
- JNIEnv *env,
- jobject thisObj,
- jobject tokenObj,
- jobject songObj,
- jstring uriStr
- ) {
- // TODO: left off here
- model::Song downloadedSong;
- auto downloadedSongObj = songToObj(env, downloadedSong);
-
- return downloadedSongObj;
-
-}
-
extern "C"
JNIEXPORT jobject
JNICALL
@@ -648,7 +642,6 @@ Java_com_example_mear_repositories_APIRepository_saveAPIInfoRecord(
saveAPIInfo(apiInfo, path);
}
-
extern "C"
JNIEXPORT void
JNICALL
@@ -669,6 +662,21 @@ Java_com_example_mear_repositories_TokenRepository_saveTokenRecord(
saveToken(token, path);
}
+extern "C"
+JNIEXPORT void
+JNICALL
+Java_com_example_mear_repositories_TrackRepositories_downloadSong(
+ JNIEnv *env,
+ jobject thisObj,
+ jobject tokenObj,
+ jobject songObj,
+ jstring uriStr
+) {
+ // TODO: left off here
+ auto song = ObjToSong(env, songObj);
+
+}
+
extern "C"
JNIEXPORT void
JNICALL
diff --git a/app/src/main/cpp/Demo.h b/app/src/main/cpp/Demo.h
index 82a1512..ee52dfa 100644
--- a/app/src/main/cpp/Demo.h
+++ b/app/src/main/cpp/Demo.h
@@ -24,6 +24,32 @@ std::string jstringToString(JNIEnv*, jstring&);
model::APIInfo retrieveAPIInfo(const std::string&);
+template
+Song ObjToSong(JE *env, SongObj obj) {
+ jclass songClass = env->GetObjectClass(obj);
+ //jmethodID jconstructor = env->GetMethodID( songClass, "", "()V" );
+ //jobject songObj = env->NewObject( songClass, jconstructor );
+
+ auto songId = env->GetFieldID( songClass, "id", "I" );
+ auto songTitle = env->GetFieldID( songClass, "title", "Ljava/lang/String;" );
+ auto songAlbum = env->GetFieldID( songClass, "album", "Ljava/lang/String;" );
+ auto songAlbumArtist = env->GetFieldID(songClass, "albumArtist", "Ljava/lang/String;");
+ auto songArtist = env->GetFieldID( songClass, "artist", "Ljava/lang/String;" );
+ auto songGenre = env->GetFieldID( songClass, "genre", "Ljava/lang/String;" );
+ auto songDuration = env->GetFieldID( songClass, "duration", "I" );
+ auto songYear = env->GetFieldID( songClass, "year", "I" );
+ auto songCoverArtId = env->GetFieldID(songClass, "coverArtId", "I");
+ auto songPathId = env->GetFieldID(songClass, "path", "Ljava/lang/String;");
+ auto songFilenameId = env->GetFieldID(songClass, "filename", "Ljava/lang/String;");
+ auto songDownloadedId = env->GetFieldID(songClass, "downloaded", "B");
+
+ auto titleVal = (jstring)env->GetObjectField(obj, songTitle);
+
+ Song song;
+
+ return song;
+}
+
model::Song retrieveSong(const model::Token&, const model::Song&, const std::string&);
model::Token fetchToken(const model::User&, const std::string&);
@@ -44,6 +70,10 @@ void saveCredentials(const model::User&, const std::string&);
void saveToken(const model::Token&, const std::string&);
void updateRepeatMode(const std::string&);
void updateShuffleMode(const std::string&);
+template
+void downloadSong(Song& song) {
+
+}
diff --git a/app/src/main/cpp/manager/DirectoryManager.h b/app/src/main/cpp/manager/DirectoryManager.h
index 319d383..d372610 100644
--- a/app/src/main/cpp/manager/DirectoryManager.h
+++ b/app/src/main/cpp/manager/DirectoryManager.h
@@ -6,48 +6,122 @@
#define MEAR_DIRECTORYMANAGER_H
#include
+#include
+#include
+#include
+#include
+#include
+#include
#include "../model/Song.h"
+#include "../utility/GeneralUtility.h"
namespace manager {
+ template
class DirectoryManager {
public:
- template
+ template
Str fullSongPath(const Song& song, const Str& path) {
- auto s = "";
+ auto s = utility::GeneralUtility::appendForwardSlashToUri(path);
+ s.append(song.albumArtist);
+ s.append("/");
+ s.append(song.album);
+ s.append("/");
+ s.append(song.filename);
return s;
}
- template
+ template
Str albumPath(const Song& song, const Str& path) {
- auto ss = "";
+ auto s = utility::GeneralUtility::appendForwardSlashToUri(path);
+ s.append(song.albumArtist);
+ s.append("/");
+ s.append(song.album);
- return ss;
+ return s;
}
- template
+ template
Str artistPath(const Song& song, const Str& path) {
- return "art";
+ auto s = utility::GeneralUtility::appendForwardSlashToUri(path);
+ s.append(song.albumArtist);
+
+ return s;
}
- template
- bool doesSongExist(const Song& song, const Str& path) {
- return false;
+ template
+ B doesSongExist(const Song& song, const Str& path) {
+ auto s = albumPath(song, path);
+ s.append("/");
+ s.append(song.filename);
+
+ stat buffer;
+ return (stat (s.c_str(), &buffer) == 0);
+ }
+
+ template
+ B deleteSong(const Song& song, const Str& path) {
+ auto s = fullSongPath(song, path);
+ auto result = std::remove(s.c_str());
+
+ if (result == 0) {
+ return true;
+ } else {
+ return false;
+ }
}
- template
+ template
void createSongDirectory(const Song& song, const Str& path) {
-
+ if (!artistDirectoryExists(song, path)) {
+ auto status = mkdir(artistPath(song, path).c_str(), 0777);
+ }
+ if (!albumDirectoryExists(song, path)) {
+ auto status = mkdir(albumPath(song, path), 0777);
+ }
}
- template
+ template
void deleteSongDirectory(const Song& song, const Str& path) {
}
private:
+ template
+ B albumDirectoryExists(const Song song, const Str& path) {
+ auto albumPath = utility::GeneralUtility::appendForwardSlashToUri(path);
+ albumPath.append(song.albumArtist);
+ albumPath.append("/");
+ albumPath.append(song.album);
+ DIR* dir = opendir(albumPath.c_str());
+
+ if (dir) {
+ closedir(dir);
+ return true;
+ } else if (ENOENT == errno) {
+ return false;
+ }
+
+ return true;
+ }
+
+ template
+ B artistDirectoryExists(const Song song, const Str& path) {
+ auto artistPath = utility::GeneralUtility::appendForwardSlashToUri(path);
+ artistPath.append(song.albumArtist);
+ DIR* dir = opendir(artistPath.c_str());
+
+ if (dir) {
+ closedir(dir);
+ return true;
+ } else if (ENOENT == errno) {
+ return false;
+ }
+
+ return true;
+ }
};
}
diff --git a/app/src/main/cpp/model/Song.h b/app/src/main/cpp/model/Song.h
index 3b6cad7..84825ef 100644
--- a/app/src/main/cpp/model/Song.h
+++ b/app/src/main/cpp/model/Song.h
@@ -10,36 +10,35 @@
namespace model {
+ class Song {
+ public:
+ Song() = default;
+ Song(const int id) : id(id) { }
+ Song(const int id, const std::string& title, const std::string& artist,
+ const std::string& album, const std::string& genre,
+ const int duration, const int year) :
+ id(id), title(title), artist(artist), album(album),
+ genre(genre), duration(duration), year(year) { }
+ Song(const int id, const std::string& title, const std::string& artist,
+ const std::string& album, const std::string& albumArtist, const std::string& genre,
+ const int duration, const int year, const int coverArtId) :
+ id(id), title(title), artist(artist), album(album), albumArtist(albumArtist),
+ genre(genre), duration(duration), year(year), coverArtId(coverArtId) { }
-class Song
-{
-public:
- Song() = default;
- Song(const int id) : id(id) { }
- Song(const int id, const std::string& title, const std::string& artist,
- const std::string& album, const std::string& genre,
- const int duration, const int year) :
- id(id), title(title), artist(artist), album(album),
- genre(genre), duration(duration), year(year) { }
- Song(const int id, const std::string& title, const std::string& artist,
- const std::string& album, const std::string& albumArtist, const std::string& genre,
- const int duration, const int year, const int coverArtId) :
- id(id), title(title), artist(artist), album(album), albumArtist(albumArtist),
- genre(genre), duration(duration), year(year), coverArtId(coverArtId) { }
-
- int id;
- std::string title;
- std::string artist;
- std::string album;
- std::string albumArtist;
- std::string genre;
- int duration;
- int year;
- int coverArtId;
- std::vector data;
- bool downloaded;
- std::string path;
-};
+ int id;
+ std::string title;
+ std::string artist;
+ std::string album;
+ std::string albumArtist;
+ std::string genre;
+ int duration;
+ int year;
+ int coverArtId;
+ std::vector data;
+ bool downloaded;
+ std::string path;
+ std::string filename;
+ };
}
#endif //MEAR_SONG_H
diff --git a/app/src/main/cpp/repository/SongRepository.h b/app/src/main/cpp/repository/SongRepository.h
index 50b6e3c..52ada8a 100644
--- a/app/src/main/cpp/repository/SongRepository.h
+++ b/app/src/main/cpp/repository/SongRepository.h
@@ -140,6 +140,8 @@ namespace repository {
auto res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
downloadedSong.data = std::move(std::vector(data.begin(), data.end()));
+ downloadedSong.filename = downloadedSong.title;
+ downloadedSong.filename.append(".mp3");
return downloadedSong;
}
diff --git a/app/src/main/java/com/example/mear/models/Song.kt b/app/src/main/java/com/example/mear/models/Song.kt
index 603eab5..9b6313a 100644
--- a/app/src/main/java/com/example/mear/models/Song.kt
+++ b/app/src/main/java/com/example/mear/models/Song.kt
@@ -3,4 +3,5 @@ package com.example.mear.models
class Song (var id: Int = 3, var title: String = "", var album: String = "",
var albumArtist: String = "", var artist: String = "",
var genre: String = "", var year: Int = 0, var duration: Int = 0,
- var coverArtId: Int = 0)
+ var coverArtId: Int = 0, var downloaded: Boolean = false, var path: String = "",
+ var filename: String = "")
diff --git a/app/src/main/java/com/example/mear/repositories/TrackRepository.kt b/app/src/main/java/com/example/mear/repositories/TrackRepository.kt
index a5f11dc..4c67925 100644
--- a/app/src/main/java/com/example/mear/repositories/TrackRepository.kt
+++ b/app/src/main/java/com/example/mear/repositories/TrackRepository.kt
@@ -21,7 +21,8 @@ class TrackRepository(var context: Context? = null) {
private external fun retrieveSongs(token: Token, uri: String): Array
private external fun retrieveSong(token: Token, song: Song, uri: String): Song
- private external fun downloadSong(token: Token, song: Song, uri: String): Song
+
+ private external fun downloadSong(token: Token, song: Song, uri: String)
fun fetchSongs(token: Token, uri: String): Array {
@@ -33,10 +34,8 @@ class TrackRepository(var context: Context? = null) {
return retrieveSong(token, song, uri)
}
- fun fetchSongFile(token: Token, song: Song, uri: String): Song {
- val downloadedSong = downloadSong(token, song, uri)
-
- return downloadedSong
+ fun fetchSongFile(token: Token, song: Song, uri: String) {
+ downloadSong(token, song, uri)
}