diff --git a/.gradle/5.4.1/executionHistory/executionHistory.lock b/.gradle/5.4.1/executionHistory/executionHistory.lock
index 90a4971..eab5f0f 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.lock b/.gradle/5.4.1/fileHashes/fileHashes.lock
index d28ee0c..3e2cc2c 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/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
index 079ed10..93a000a 100644
Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ
diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index adcc5cc..83c4056 100644
Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index bd0fd02..f94c2be 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -112,18 +112,10 @@
-
-
-
-
+
+
-
-
-
-
-
-
@@ -131,16 +123,11 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
@@ -219,112 +206,130 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
@@ -369,15 +372,22 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -392,9 +402,9 @@
-
-
+
+
@@ -405,20 +415,13 @@
-
+
-
-
-
-
-
-
-
-
-
+
+
@@ -441,6 +444,9 @@
+
+
+
@@ -545,7 +551,14 @@
1570328051146
-
+
+ 1570499060130
+
+
+
+ 1570499060130
+
+
@@ -569,7 +582,7 @@
-
+
@@ -582,7 +595,8 @@
-
+
+
@@ -595,45 +609,15 @@
file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/LoginActivity.kt
- 78
-
-
-
-
- file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/LoginActivity.kt
- 86
-
-
-
-
- file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/LoginActivity.kt
- 42
-
-
-
-
- file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/LoginActivity.kt
- 87
-
-
-
-
- file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/LoginActivity.kt
- 43
-
-
-
-
- file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/LoginActivity.kt
- 44
+ 45
file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/LoginActivity.kt
- 91
+ 85
-
+
file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
@@ -662,7 +646,7 @@
file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 116
+ 165
@@ -692,12 +676,12 @@
file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 114
+ 163
file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 117
+ 166
@@ -712,161 +696,38 @@
file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 47
+ 95
file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 141
+ 217
+
+ file://$PROJECT_DIR$/app/src/main/cpp/SongRepository.cpp
+ 29
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/SongRepository.cpp
+ 13
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
+ 50
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/SongRepository.cpp
+ 55
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -927,42 +788,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -970,10 +795,6 @@
-
-
-
-
@@ -1008,14 +829,6 @@
-
-
-
-
-
-
-
-
@@ -1033,17 +846,10 @@
-
+
-
-
-
-
-
-
-
-
-
+
+
@@ -1054,10 +860,10 @@
-
+
-
-
+
+
@@ -1071,23 +877,166 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1099,30 +1048,42 @@
-
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 328d5d8..1c7e68a 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,6 +2,9 @@
+
+
+
+
-
-
-
\ No newline at end of file
diff --git a/app/src/main/cpp/Demo.cpp b/app/src/main/cpp/Demo.cpp
index 5a749f5..ad25924 100644
--- a/app/src/main/cpp/Demo.cpp
+++ b/app/src/main/cpp/Demo.cpp
@@ -24,11 +24,15 @@
#include
#include "model/Song.h"
+#include "model/Token.h"
#include "model/User.h"
#include "SongRepository.h"
#include "Tok.h"
#include "UserRepository.h"
+std::vector retrieveSongs(const model::Token&, const std::string&);
+
+jobject songToObj(JNIEnv *env, const model::Song&);
model::Song retrieveSong(const std::string&, const std::string&, const int);
@@ -42,6 +46,50 @@ bool userCredentialExist(const std::string&);
void saveCredentials(const model::User&, const std::string&);
+std::vector retrieveSongs(const model::Token& token, const std::string& baseUri)
+{
+ std::vector songs;
+ repository::SongRepository songRepo;
+ songs = songRepo.fetchSongs(token, baseUri);
+
+ return songs;
+}
+
+
+jobject songToObj(JNIEnv *env, const model::Song& song)
+{
+ jclass songClass = env->FindClass( "com/example/mear/models/Song");
+ jmethodID jconstructor = env->GetMethodID( songClass, "", "()V" );
+ jobject songObj = env->NewObject( songClass, jconstructor );
+
+ jmethodID songId = env->GetMethodID( songClass, "setId", "(I)V" );
+ jmethodID songTitle = env->GetMethodID( songClass, "setTitle", "(Ljava/lang/String;)V" );
+ jmethodID songAlbum = env->GetMethodID( songClass, "setAlbum", "(Ljava/lang/String;)V" );
+ jmethodID songArtist = env->GetMethodID( songClass, "setArtist", "(Ljava/lang/String;)V" );
+ jmethodID songGenre = env->GetMethodID( songClass, "setGenre", "(Ljava/lang/String;)V" );
+ jmethodID songDuration = env->GetMethodID( songClass, "setDuration", "(I)V" );
+ jmethodID songYear = env->GetMethodID( songClass, "setYear", "(I)V" );
+
+ jint id = song.id;
+ jstring title = env->NewStringUTF(song.title.c_str());
+ jstring album = env->NewStringUTF(song.album.c_str());
+ jstring artist = env->NewStringUTF(song.artist.c_str());
+ jstring genre = env->NewStringUTF(song.genre.c_str());
+ jint duration = song.duration;
+ jint year = song.year;
+
+ env->CallVoidMethod( songObj, songId, id );
+ env->CallVoidMethod(songObj, songTitle, title);
+ env->CallVoidMethod(songObj, songAlbum, album);
+ env->CallVoidMethod(songObj, songArtist, artist);
+ env->CallVoidMethod(songObj, songGenre, genre);
+ env->CallVoidMethod(songObj, songDuration, duration);
+ env->CallVoidMethod(songObj, songYear, year);
+
+ return songObj;
+}
+
+
model::Song retrieveSong(const std::string& token, const std::string& baseUri, const int songId)
{
repository::SongRepository songRepo;
@@ -49,6 +97,7 @@ model::Song retrieveSong(const std::string& token, const std::string& baseUri, c
420, 420);
song = songRepo.retrieveSong(token, baseUri, song);
+ auto songs = songRepo.fetchSongs(model::Token(token), baseUri);
return song;
}
@@ -126,6 +175,33 @@ void saveCredentials(const model::User& user, const std::string& appDirectory)
}
+extern "C"
+JNIEXPORT jobjectArray
+JNICALL
+Java_com_example_mear_activities_IcarusSongActivity_retrieveSongs(
+ JNIEnv *env,
+ jobject thisOnj,
+ jobject token,
+ jstring baseUri
+ ) {
+ jclass songClass = env->FindClass( "com/example/mear/models/Song");
+ jclass tokenClass = env->FindClass("com/example/mear/models/Token");
+ jobjectArray songs = env->NewObjectArray(2, songClass, nullptr);
+ auto tok = env->CallObjectMethod(token, env->GetMethodID(tokenClass, "setAccessToken", "(Ljava/lang/String;)V"));
+ std::string tokStr = env->GetStringUTFChars((jstring)tok, nullptr);
+ model::Token tk(tokStr);
+ const std::string uri = env->GetStringUTFChars(baseUri, nullptr);
+
+ auto allSongs = retrieveSongs(tk, uri);
+ for (auto i = 0; i != allSongs.size(); ++i) {
+ auto song = songToObj(env, allSongs[i]);
+ env->SetObjectArrayElement(songs, i, song);
+ }
+
+ return songs;
+}
+
+
extern "C"
JNIEXPORT jobject
JNICALL
diff --git a/app/src/main/cpp/SongRepository.cpp b/app/src/main/cpp/SongRepository.cpp
index 757a54c..90830d2 100644
--- a/app/src/main/cpp/SongRepository.cpp
+++ b/app/src/main/cpp/SongRepository.cpp
@@ -8,12 +8,53 @@
#include
namespace repository {
- // TODO: implement this
- std::vector SongRepository::fetchSongs(const std::string& token,
+ std::vector SongRepository::fetchSongs(const model::Token& token,
const std::string& uri)
{
+ std::string fullUri(uri);
+ if (fullUri.at(fullUri.size()-1) != '/') {
+ fullUri.append("/");
+ }
+ fullUri.append("api/v1/song");
std::vector songs;
+ CURL *curl;
+ CURLcode res;
+ struct curl_slist *chunk = nullptr;
+ curl = curl_easy_init();
+
+ if (!curl) {
+ return songs;
+ }
+
+ constexpr auto EXPECTED_CHAR_AMOUNT = 100000;
+ auto resp = std::make_unique(EXPECTED_CHAR_AMOUNT);
+
+ std::string authInfo("Authorization: Bearer ");
+ authInfo.append(token.accessToken);
+ chunk = curl_slist_append(chunk, authInfo.c_str());
+
+ curl_easy_setopt(curl, CURLOPT_URL, fullUri.c_str());
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, respBodyRetriever);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, resp.get());
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
+
+ res = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
+
+ if (res == CURLE_OK) {
+ auto songsJson = nlohmann::json::parse(resp.get());
+ for (auto& songJson: songsJson) {
+ model::Song song(songJson["id"].get(), songJson["title"].get(),
+ songJson["artist"].get(), songJson["album"].get(),
+ songJson["genre"].get(), songJson["duration"].get(),
+ songJson["year"].get());
+
+ songs.push_back(song);
+ }
+ }
+
return songs;
}
diff --git a/app/src/main/cpp/SongRepository.h b/app/src/main/cpp/SongRepository.h
index 603c1f6..8f7ba08 100644
--- a/app/src/main/cpp/SongRepository.h
+++ b/app/src/main/cpp/SongRepository.h
@@ -9,12 +9,13 @@
#include
#include "model/Song.h"
+#include "model/Token.h"
namespace repository {
class SongRepository {
public:
- std::vector fetchSongs(const std::string&, const std::string&);
+ std::vector fetchSongs(const model::Token&, const std::string&);
model::Song retrieveSong(const std::string&, const int);
model::Song retrieveSong(const std::string&, const std::string&, const int);
diff --git a/app/src/main/java/com/example/mear/activities/IcarusSongActivity.kt b/app/src/main/java/com/example/mear/activities/IcarusSongActivity.kt
new file mode 100644
index 0000000..5b192f9
--- /dev/null
+++ b/app/src/main/java/com/example/mear/activities/IcarusSongActivity.kt
@@ -0,0 +1,59 @@
+package com.example.mear.activities
+
+import android.os.Build
+import android.os.Bundle
+import android.support.annotation.RequiresApi
+import android.support.v7.widget.LinearLayoutManager
+import android.support.v7.app.AppCompatActivity
+import android.support.v7.widget.SearchView
+
+import kotlinx.android.synthetic.main.activity_icarus_song.*
+import kotlinx.android.synthetic.main.content_song_view.*
+
+import com.example.mear.activities.BaseServiceActivity
+import com.example.mear.adapters.RecyclerAdapter
+import com.example.mear.models.TrackItems
+import com.example.mear.models.Song
+import com.example.mear.R
+import com.example.mear.repositories.TrackRepository
+
+
+class IcarusSongActivity : BaseServiceActivity() {
+
+ private lateinit var adapter: RecyclerAdapter
+ private lateinit var linearLayoutManager: LinearLayoutManager
+
+ private var songs: ArrayList? = null
+
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_icarus_song)
+ setSupportActionBar(toolbar)
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
+
+ try {
+ val colr = R.color.track_seek
+ window.statusBarColor = resources.getColor(R.color.track_seek)
+ doBindService()
+ initializeAdapter()
+ //initializeSongSearchListener()
+ }
+ catch (ex: Exception) {
+ val msg = ex.message
+ }
+ }
+
+
+ private fun initializeAdapter() {
+ try {
+ linearLayoutManager = LinearLayoutManager(this)
+ trackList.layoutManager = linearLayoutManager
+
+ songs!!.sortedWith(compareBy{it.title})
+ }
+ catch (ex: Exception) {
+ val msg = ex.message
+ }
+ }
+}
diff --git a/app/src/main/java/com/example/mear/activities/LoginActivity.kt b/app/src/main/java/com/example/mear/activities/LoginActivity.kt
index 641782f..363702b 100644
--- a/app/src/main/java/com/example/mear/activities/LoginActivity.kt
+++ b/app/src/main/java/com/example/mear/activities/LoginActivity.kt
@@ -1,5 +1,6 @@
package com.example.mear.activities
+import android.content.Intent
import android.os.Bundle
import android.os.Environment
import android.support.design.widget.Snackbar
@@ -87,6 +88,7 @@ class LoginActivity : BaseServiceActivity() {
if (saveCred && isUserTableEmpty(pa)) {
saveUserCredentials(usernameStr, passwordStr, pa)
}
+ //startActivity(Intent(this, IcarusSongActivity::class.java))
}
catch (ex: Exception) {
val msg = ex.message
diff --git a/app/src/main/res/layout/activity_icarus_song.xml b/app/src/main/res/layout/activity_icarus_song.xml
new file mode 100644
index 0000000..21b6dcf
--- /dev/null
+++ b/app/src/main/res/layout/activity_icarus_song.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/content_login.xml b/app/src/main/res/layout/content_login.xml
index cf822be..d533f01 100644
--- a/app/src/main/res/layout/content_login.xml
+++ b/app/src/main/res/layout/content_login.xml
@@ -51,7 +51,6 @@
android:ems="10"
android:hint="apiUri"
android:inputType="textPersonName"
- android:text="https://www.soaricarus.com"
app:layout_constraintBottom_toTopOf="@+id/saveUserCred"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />