diff --git a/.gradle/5.4.1/executionHistory/executionHistory.bin b/.gradle/5.4.1/executionHistory/executionHistory.bin
index 70a01e4..3ea66c5 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 4f6ff23..90a4971 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 68c6b45..89e8e8b 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 11615dc..d28ee0c 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 c603803..a7431fb 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 5047247..95cef8a 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 8c68a69..6def626 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 3f654d5..b665136 100644
Binary files a/.gradle/5.4.1/javaCompile/javaCompile.lock and b/.gradle/5.4.1/javaCompile/javaCompile.lock differ
diff --git a/.gradle/5.4.1/javaCompile/taskHistory.bin b/.gradle/5.4.1/javaCompile/taskHistory.bin
index b508ebc..ea8eb2e 100644
Binary files a/.gradle/5.4.1/javaCompile/taskHistory.bin and b/.gradle/5.4.1/javaCompile/taskHistory.bin differ
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
index 804728f..079ed10 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 982e5ca..adcc5cc 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 f343dbc..bd0fd02 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,6 +5,10 @@
+
+
+
+
@@ -108,27 +112,35 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
+
-
-
-
+
+
+
+
+
+
+
+
@@ -207,176 +219,117 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -410,13 +363,21 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -431,195 +392,34 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -753,7 +553,7 @@
-
+
@@ -762,20 +562,21 @@
-
+
-
-
+
+
-
+
+
-
+
@@ -793,41 +594,60 @@
- file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
- 87
-
-
-
-
- file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
- 75
-
-
-
-
- file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
- 83
+ 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
+
+
+
+
+ file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/LoginActivity.kt
+ 91
+
+
+
file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
- 56
+ 70
-
- file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 107
-
-
file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
- 20
+ 19
file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
- 30
+ 47
@@ -837,34 +657,29 @@
file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
- 55
+ 54
file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 111
+ 116
file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
- 74
+ 72
file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
- 65
+ 64
file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
- 94
+ 106
-
- file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
- 19
-
-
file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
39
@@ -872,65 +687,43 @@
file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
- 81
+ 94
file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 109
+ 114
file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 112
+ 117
-
- file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
- 114
-
-
file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
- 37
+ 51
file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
- 16
-
+ 37
+
- file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
- 26
-
+ file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
+ 47
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
+ 141
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -962,20 +755,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1098,9 +877,6 @@
-
-
-
@@ -1124,16 +900,36 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -1160,9 +956,124 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -1170,113 +1081,46 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9f1cde4..328d5d8 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -10,7 +10,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
diff --git a/app/src/main/cpp/BaseRepository.cpp b/app/src/main/cpp/BaseRepository.cpp
index f1de0d0..14f2ebe 100644
--- a/app/src/main/cpp/BaseRepository.cpp
+++ b/app/src/main/cpp/BaseRepository.cpp
@@ -15,7 +15,6 @@ namespace repository { namespace local {
const auto dbPath = pathOfDatabase(appPath);
SQLite::Database db(dbPath, SQLite::OPEN_READONLY);
- //SQLite::Database db(m_tableName, SQLite::OPEN_READONLY);
return true;
} catch (std::exception& ex) {
auto msg = ex.what();
@@ -39,7 +38,7 @@ namespace repository { namespace local {
auto msg = ex.what();
}
- return false;
+ return true;
}
@@ -47,11 +46,8 @@ namespace repository { namespace local {
{
try {
const auto dbPath = pathOfDatabase(appPath);
- //std::fstream cret(dbPath, std::ios::out);
- //cret.close();
SQLite::Database db(dbPath, SQLite::OPEN_CREATE | SQLite::OPEN_READWRITE);
- //SQLite::Database db(m_tableName, SQLite::OPEN_CREATE);
} catch (std::exception& ex) {
auto msg = ex.what();
}
diff --git a/app/src/main/cpp/Demo.cpp b/app/src/main/cpp/Demo.cpp
index 605f9cb..5a749f5 100644
--- a/app/src/main/cpp/Demo.cpp
+++ b/app/src/main/cpp/Demo.cpp
@@ -30,24 +30,23 @@
#include "UserRepository.h"
-model::Song retrieveSong(const std::string&, const std::string&);
+model::Song retrieveSong(const std::string&, const std::string&, const int);
+
+model::User retrieveCredentials(const std::string&);
std::string fetchToken(const std::string&, const std::string&, const std::string&);
+bool doesDatabaseExist(const std::string&);
+bool userCredentialExist(const std::string&);
+
void saveCredentials(const model::User&, const std::string&);
-model::Song retrieveSong(const std::string& token, const std::string& baseUri)
+model::Song retrieveSong(const std::string& token, const std::string& baseUri, const int songId)
{
repository::SongRepository songRepo;
- model::Song song;
- song.id = 1;
- song.title = "Smooth";
- song.album = "Amaze";
- song.artist = "The Herb";
- song.genre = "Blazing";
- song.duration = 420;
- song.year = 420;
+ model::Song song(songId, "Smooth", "Amaze", "The Herb", "Blazing",
+ 420, 420);
song = songRepo.retrieveSong(token, baseUri, song);
@@ -55,6 +54,15 @@ model::Song retrieveSong(const std::string& token, const std::string& baseUri)
}
+model::User retrieveCredentials(const std::string& dataPath)
+{
+ repository::local::UserRepository userRepo;
+ auto user = userRepo.retrieveUserCredentials(dataPath);
+
+ return user;
+}
+
+
std::string fetchToken(const std::string& username, const std::string& password,
const std::string& apiUri)
{
@@ -68,6 +76,22 @@ std::string fetchToken(const std::string& username, const std::string& password,
}
+bool doesDatabaseExist(const std::string& dataPath)
+{
+ repository::local::UserRepository userRepo;
+ const auto result = userRepo.databaseExist(dataPath);
+
+ return result;
+}
+
+bool userCredentialExist(const std::string& dataPath)
+{
+ repository::local::UserRepository userRepo;
+
+ return userRepo.isTableEmpty(dataPath);
+}
+
+
void iterateDirectory(const std::string& path)
{
/**
@@ -85,58 +109,37 @@ void iterateDirectory(const std::string& path)
void saveCredentials(const model::User& user, const std::string& appDirectory)
{
- std::string filePath(appDirectory);
- filePath.append("/");
repository::local::UserRepository userRepo;
- if (!userRepo.databaseExist(filePath)) {
- userRepo.initializedDatabase(filePath);
+ if (!userRepo.databaseExist(appDirectory)) {
+ userRepo.initializedDatabase(appDirectory);
}
- if (!userRepo.doesUserTableExist(filePath)) {
- userRepo.createUserTable(filePath);
+ if (!userRepo.doesUserTableExist(appDirectory)) {
+ userRepo.createUserTable(appDirectory);
}
- if (userRepo.isTableEmpty(filePath)) {
- userRepo.deleteUserTable(filePath);
+ if (userRepo.isTableEmpty(appDirectory)) {
+ userRepo.deleteUserTable(appDirectory);
}
- userRepo.saveUserCred(user, filePath);
-}
-
-
-extern "C"
-JNIEXPORT jstring
-JNICALL
-Java_com_example_mear_activities_DemoStreamActivity_logUser(
- JNIEnv *env,
- jobject thisObj,
- jstring username,
- jstring password,
- jstring apiUri ) {
-
- const std::string usr = env->GetStringUTFChars(username, NULL);
- const std::string pass = env->GetStringUTFChars(password, NULL);
- const std::string api = env->GetStringUTFChars(apiUri, NULL);
-
- auto token = fetchToken(usr, pass, api);
-
- return env->NewStringUTF(token.c_str());
+ userRepo.saveUserCred(user, appDirectory);
}
extern "C"
JNIEXPORT jobject
JNICALL
-Java_com_example_mear_activities_DemoStreamActivity_retrieveSong(
+Java_com_example_mear_activities_LoginActivity_retrieveSong(
JNIEnv *env,
jobject thisObj,
jstring token,
- jstring apiUri
- )
+ jstring apiUri,
+ jint idOfSong
+)
{
const std::string tok = env->GetStringUTFChars(token, NULL);
const std::string baseUri = env->GetStringUTFChars(apiUri, NULL);
- auto song = retrieveSong(tok, baseUri);
+ auto song = retrieveSong(tok, baseUri, idOfSong);
jclass songClass = env->FindClass( "com/example/mear/models/Song");
jmethodID jconstructor = env->GetMethodID( songClass, "", "()V" );
@@ -169,11 +172,87 @@ Java_com_example_mear_activities_DemoStreamActivity_retrieveSong(
return songObj;
}
+extern "C"
+JNIEXPORT jobject
+JNICALL
+Java_com_example_mear_activities_LoginActivity_retrieveUserCredentials(
+ JNIEnv *env,
+ jobject thisObj,
+ jstring dataPath
+) {
+ jclass userClass = env->FindClass("com/example/mear/models/User");
+ jmethodID userContructor = env->GetMethodID(userClass, "", "()V");
+ jobject userObj = env->NewObject(userClass, userContructor);
+
+ const std::string dataPathStr = env->GetStringUTFChars(dataPath, nullptr);
+ auto user = retrieveCredentials(dataPathStr);
+
+ jmethodID usernameId = env->GetMethodID(userClass, "setUsername", "(Ljava/lang/String;)V");
+ jmethodID passwordId = env->GetMethodID(userClass, "setPassword", "(Ljava/lang/String;)V");
+
+ jstring username = env->NewStringUTF(user.username.c_str());
+ jstring password = env->NewStringUTF(user.password.c_str());
+
+ env->CallVoidMethod(userObj, usernameId, username);
+ env->CallVoidMethod(userObj, passwordId, password);
+
+ return userObj;
+}
+
+
+extern "C"
+JNIEXPORT jstring
+JNICALL
+Java_com_example_mear_activities_LoginActivity_logUser(
+ JNIEnv *env,
+ jobject thisObj,
+ jstring username,
+ jstring password,
+ jstring apiUri ) {
+
+ const std::string usr = env->GetStringUTFChars(username, NULL);
+ const std::string pass = env->GetStringUTFChars(password, NULL);
+ const std::string api = env->GetStringUTFChars(apiUri, NULL);
+
+ auto token = fetchToken(usr, pass, api);
+
+ return env->NewStringUTF(token.c_str());
+}
+
+
+extern "C"
+JNIEXPORT jboolean
+JNICALL
+Java_com_example_mear_activities_LoginActivity_isUserTableEmpty(
+ JNIEnv *env,
+ jobject thisObj,
+ jstring dataPath
+ ) {
+ const std::string dataPathStr = env->GetStringUTFChars(dataPath, NULL);
+ jboolean result = userCredentialExist(dataPathStr);
+
+ return result;
+}
+
+extern "C"
+JNIEXPORT jboolean
+JNICALL
+Java_com_example_mear_activities_LoginActivity_doesDatabaseExist(
+ JNIEnv *env,
+ jobject thidObj,
+ jstring dataPath
+ ) {
+ const std::string dataPathStr = env->GetStringUTFChars(dataPath, NULL);
+ jboolean result = doesDatabaseExist(dataPathStr);
+
+ return result;
+}
+
extern "C"
JNIEXPORT void
JNICALL
-Java_com_example_mear_activities_DemoStreamActivity_pathIteratorDemo(
+Java_com_example_mear_activities_LoginActivity_pathIteratorDemo(
JNIEnv *env,
jobject thisObj,
jstring path
@@ -187,21 +266,18 @@ Java_com_example_mear_activities_DemoStreamActivity_pathIteratorDemo(
extern "C"
JNIEXPORT void
JNICALL
-Java_com_example_mear_activities_DemoStreamActivity_saveUserCredentials(
+Java_com_example_mear_activities_LoginActivity_saveUserCredentials(
JNIEnv *env,
jobject thisObj,
jstring username,
jstring password,
jstring appDirectory
) {
-
const std::string usernameStr = env->GetStringUTFChars(username, NULL);
const std::string passwordStr = env->GetStringUTFChars(password, NULL);
const std::string appDirectoryStr = env->GetStringUTFChars(appDirectory, NULL);
- model::User user;
- user.username = usernameStr;
- user.password = passwordStr;
+ model::User user(usernameStr, passwordStr);
saveCredentials(user, appDirectoryStr);
}
diff --git a/app/src/main/cpp/UserRepository.cpp b/app/src/main/cpp/UserRepository.cpp
index f800dea..6fa4aeb 100644
--- a/app/src/main/cpp/UserRepository.cpp
+++ b/app/src/main/cpp/UserRepository.cpp
@@ -19,7 +19,6 @@ namespace repository { namespace local {
try {
const auto dbPath = pathOfDatabase(appPath);
SQLite::Database db(dbPath, SQLite::OPEN_READONLY);
- //SQLite::Database db(m_tableName, SQLite::OPEN_READONLY);
std::string queryString("SELECT * FROM ");
queryString.append(m_tableName);
@@ -50,7 +49,6 @@ namespace repository { namespace local {
try {
const auto dbPath = pathOfDatabase(appPath);
SQLite::Database db(dbPath, SQLite::OPEN_READONLY);
- //SQLite::Database db(m_tableName, SQLite::OPEN_READONLY);
return db.tableExists(m_tableName);
} catch (std::exception& ex) {
@@ -66,7 +64,6 @@ namespace repository { namespace local {
try {
const auto dbPath = pathOfDatabase(appPath);
SQLite::Database db(dbPath, SQLite::OPEN_READWRITE);
- //SQLite::Database db(m_tableName, SQLite::OPEN_READWRITE);
std::string queryString("CREATE TABLE ");
queryString.append(m_tableName);
@@ -97,7 +94,6 @@ namespace repository { namespace local {
try {
const auto dbPath = pathOfDatabase(appPath);
SQLite::Database db(dbPath, SQLite::OPEN_READWRITE);
- //SQLite::Database db(m_tableName, SQLite::OPEN_READWRITE);
std::string queryString("INSERT INTO ");
queryString.append(m_tableName);
queryString.append(" (Username, Password) VALUES (?, ?)");
diff --git a/app/src/main/cpp/UserRepository.h b/app/src/main/cpp/UserRepository.h
index 666ed16..df33540 100644
--- a/app/src/main/cpp/UserRepository.h
+++ b/app/src/main/cpp/UserRepository.h
@@ -19,6 +19,7 @@ namespace repository { namespace local {
model::User retrieveUserCredentials(const std::string&);
+ bool isEmpty(const std::string&);
bool doesUserTableExist(const std::string&);
void createUserTable(const std::string&);
diff --git a/app/src/main/cpp/model/Song.h b/app/src/main/cpp/model/Song.h
index f7a848d..de4f710 100644
--- a/app/src/main/cpp/model/Song.h
+++ b/app/src/main/cpp/model/Song.h
@@ -10,8 +10,22 @@
namespace model {
-struct Song
+class Song
{
+public:
+ Song() = default;
+ 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&& genre,
+ const int duration, const int year) :
+ id(id), title(std::move(title)), artist(std::move(artist)),
+ album(std::move(album)), genre(std::move(genre)), duration(duration),
+ year(year) { }
+
int id;
std::string title;
std::string artist;
diff --git a/app/src/main/cpp/model/Token.h b/app/src/main/cpp/model/Token.h
index a702cf0..02665a6 100644
--- a/app/src/main/cpp/model/Token.h
+++ b/app/src/main/cpp/model/Token.h
@@ -6,14 +6,17 @@
#define MEAR_TOKEN_H
#include
+#include
namespace model {
class Token
{
public:
- Token(const std::string& token) : token(token) { }
+ Token(const std::string& accessToken) : accessToken(accessToken) { }
+ Token(const std::string&& accessToken) :
+ accessToken(std::move(accessToken)) { }
- std::string token;
+ std::string accessToken;
};
}
diff --git a/app/src/main/cpp/model/User.h b/app/src/main/cpp/model/User.h
index a04fe79..8ed1a30 100644
--- a/app/src/main/cpp/model/User.h
+++ b/app/src/main/cpp/model/User.h
@@ -5,13 +5,18 @@
#ifndef MEAR_USER_H
#define MEAR_USER_H
+#include
+#include
namespace model {
-struct User
+class User
{
+public:
User() = default;
User(const std::string& user, const std::string& pass) :
username(user), password(pass) { }
+ User(const std::string&& user, const std::string&& pass) :
+ username(std::move(user)), password(std::move(pass)) {}
std::string username;
std::string password;
diff --git a/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt b/app/src/main/java/com/example/mear/activities/LoginActivity.kt
similarity index 60%
rename from app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
rename to app/src/main/java/com/example/mear/activities/LoginActivity.kt
index bd9efc6..641782f 100644
--- a/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
+++ b/app/src/main/java/com/example/mear/activities/LoginActivity.kt
@@ -3,16 +3,16 @@ package com.example.mear.activities
import android.os.Bundle
import android.os.Environment
import android.support.design.widget.Snackbar
-import android.support.v7.app.AppCompatActivity
import com.example.mear.R
-import kotlinx.android.synthetic.main.activity_demo_stream.*
-import kotlinx.android.synthetic.main.content_demo_stream.*
+import kotlinx.android.synthetic.main.activity_login.*
+import kotlinx.android.synthetic.main.content_login.*
import org.jetbrains.anko.toast
import com.example.mear.models.Song
+import com.example.mear.models.User
-class DemoStreamActivity : BaseServiceActivity() {
+class LoginActivity : BaseServiceActivity() {
companion object {
init {
@@ -21,22 +21,31 @@ class DemoStreamActivity : BaseServiceActivity() {
}
- private var token: String? = null
+ private external fun retrieveSong(tok: String, api: String, songId: Int): Song
+ private external fun retrieveUserCredentials(path: String): User
- // TODO: add external call to retrieve User credentials
private external fun logUser(usr: String, pass: String, api: String): String
- private external fun retrieveSong(tok: String, api: String): Song
- //private external fun testSongStream(tok: String, id: Int)
+
+ private external fun doesDatabaseExist(path: String): Boolean
+ private external fun isUserTableEmpty(path: String): Boolean
+
private external fun pathIteratorDemo(path: String)
private external fun saveUserCredentials(username: String, password: String, appDir: String)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_demo_stream)
+ setContentView(R.layout.activity_login)
setSupportActionBar(toolbar)
+ val pa = appDirectory()
+ if (doesDatabaseExist(pa) && !isUserTableEmpty(pa)) {
+ val usr = retrieveUserCredentials(pa)
+ username.setText(usr.username)
+ password.setText(usr.password)
+ }
+
doBindService()
demoStream.setOnClickListener {
@@ -69,19 +78,14 @@ class DemoStreamActivity : BaseServiceActivity() {
apiUriStr = ""
}
- token = logUser(usernameStr, passwordStr, apiUriStr)
+ val token = logUser(usernameStr, passwordStr, apiUriStr)
try {
-
- val s = retrieveSong(token!!, apiUriStr)
- musicService!!.icarusPlaySong(this.applicationContext, token!!, apiUriStr, s)
- val dir = Environment.getExternalStorageDirectory().absolutePath + "/music"
- val appRelPath: String = resources.getString(R.string.app_relative_path)
- var inStoragePath = Environment.getDataDirectory().toString()
- inStoragePath += "/data/$appRelPath"
-
- if (saveCred) {
- saveUserCredentials(usernameStr, passwordStr, inStoragePath)
+ val songId = 4
+ val song = retrieveSong(token, apiUriStr, songId)
+ val pa = appDirectory()
+ if (saveCred && isUserTableEmpty(pa)) {
+ saveUserCredentials(usernameStr, passwordStr, pa)
}
}
catch (ex: Exception) {
@@ -89,6 +93,13 @@ class DemoStreamActivity : BaseServiceActivity() {
}
}
+
+ private fun appDirectory(): String {
+ return Environment.getDataDirectory().toString() + "/data/" +
+ resources.getString(R.string.app_relative_path)
+ }
+
+
private fun validFields(): Boolean {
if (username.text.isEmpty()) {
return false
diff --git a/app/src/main/java/com/example/mear/constants/AppDataPath.kt b/app/src/main/java/com/example/mear/constants/AppDataPath.kt
new file mode 100644
index 0000000..b76cb7d
--- /dev/null
+++ b/app/src/main/java/com/example/mear/constants/AppDataPath.kt
@@ -0,0 +1,13 @@
+package com.example.mear.constants
+
+import android.os.Bundle
+import android.content.res.Resources
+import android.os.Environment
+import com.example.mear.R
+
+import kotlinx.android.synthetic.main.activity_login.*
+import kotlinx.android.synthetic.main.content_login.*
+
+object AppDataPath {
+ val APP_DATA_PATH: String = Environment.getDataDirectory().toString()
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/mear/models/Token.kt b/app/src/main/java/com/example/mear/models/Token.kt
new file mode 100644
index 0000000..09c0c31
--- /dev/null
+++ b/app/src/main/java/com/example/mear/models/Token.kt
@@ -0,0 +1,3 @@
+package com.example.mear.models
+
+class Token (var accessToken: String = "")
diff --git a/app/src/main/java/com/example/mear/models/User.kt b/app/src/main/java/com/example/mear/models/User.kt
new file mode 100644
index 0000000..ddcb41e
--- /dev/null
+++ b/app/src/main/java/com/example/mear/models/User.kt
@@ -0,0 +1,3 @@
+package com.example.mear.models
+
+class User (var username: String = "", var password: String = "")
diff --git a/app/src/main/res/layout/activity_demo_stream.xml b/app/src/main/res/layout/activity_login.xml
similarity index 92%
rename from app/src/main/res/layout/activity_demo_stream.xml
rename to app/src/main/res/layout/activity_login.xml
index ac123fb..f7d6e4c 100644
--- a/app/src/main/res/layout/activity_demo_stream.xml
+++ b/app/src/main/res/layout/activity_login.xml
@@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".activities.DemoStreamActivity">
+ tools:context=".activities.LoginActivity">
-
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/content_demo_stream.xml b/app/src/main/res/layout/content_login.xml
similarity index 94%
rename from app/src/main/res/layout/content_demo_stream.xml
rename to app/src/main/res/layout/content_login.xml
index 166097b..cf822be 100644
--- a/app/src/main/res/layout/content_demo_stream.xml
+++ b/app/src/main/res/layout/content_login.xml
@@ -5,8 +5,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
- tools:context=".activities.DemoStreamActivity"
- tools:showIn="@layout/activity_demo_stream">
+ tools:context=".activities.LoginActivity"
+ tools:showIn="@layout/activity_login">
@@ -40,7 +39,6 @@
android:ems="10"
android:hint="password"
android:inputType="textPassword"
- android:text="demolaugh"
app:layout_constraintBottom_toTopOf="@+id/apiUri"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
@@ -53,6 +51,7 @@
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" />