diff --git a/.gitmodules b/.gitmodules
index a0bacc2..dc62956 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
[submodule "app/src/main/cpp/3rdparty/json"]
path = app/src/main/cpp/3rdparty/json
url = https://github.com/nlohmann/json
+[submodule "app/src/main/cpp/3rdparty/SQLiteCpp"]
+ path = app/src/main/cpp/3rdparty/SQLiteCpp
+ url = https://github.com/SRombauts/SQLiteCpp
diff --git a/.gradle/4.10.1/fileChanges/last-build.bin b/.gradle/4.10.1/fileChanges/last-build.bin
new file mode 100644
index 0000000..f76dd23
Binary files /dev/null and b/.gradle/4.10.1/fileChanges/last-build.bin differ
diff --git a/.gradle/4.10.1/fileHashes/fileHashes.bin b/.gradle/4.10.1/fileHashes/fileHashes.bin
new file mode 100644
index 0000000..bfc6a51
Binary files /dev/null and b/.gradle/4.10.1/fileHashes/fileHashes.bin differ
diff --git a/.gradle/4.10.1/fileHashes/fileHashes.lock b/.gradle/4.10.1/fileHashes/fileHashes.lock
new file mode 100644
index 0000000..4b25812
Binary files /dev/null and b/.gradle/4.10.1/fileHashes/fileHashes.lock differ
diff --git a/.gradle/4.10.1/gc.properties b/.gradle/4.10.1/gc.properties
new file mode 100644
index 0000000..e69de29
diff --git a/.gradle/5.4.1/executionHistory/executionHistory.bin b/.gradle/5.4.1/executionHistory/executionHistory.bin
new file mode 100644
index 0000000..70a01e4
Binary files /dev/null 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
new file mode 100644
index 0000000..4f6ff23
Binary files /dev/null and b/.gradle/5.4.1/executionHistory/executionHistory.lock differ
diff --git a/.gradle/5.4.1/fileChanges/last-build.bin b/.gradle/5.4.1/fileChanges/last-build.bin
new file mode 100644
index 0000000..f76dd23
Binary files /dev/null and b/.gradle/5.4.1/fileChanges/last-build.bin differ
diff --git a/.gradle/5.4.1/fileContent/fileContent.lock b/.gradle/5.4.1/fileContent/fileContent.lock
new file mode 100644
index 0000000..9774190
Binary files /dev/null and b/.gradle/5.4.1/fileContent/fileContent.lock differ
diff --git a/.gradle/5.4.1/fileHashes/fileHashes.bin b/.gradle/5.4.1/fileHashes/fileHashes.bin
new file mode 100644
index 0000000..68c6b45
Binary files /dev/null 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
new file mode 100644
index 0000000..11615dc
Binary files /dev/null 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
new file mode 100644
index 0000000..c603803
Binary files /dev/null and b/.gradle/5.4.1/fileHashes/resourceHashesCache.bin differ
diff --git a/.gradle/5.4.1/gc.properties b/.gradle/5.4.1/gc.properties
new file mode 100644
index 0000000..e69de29
diff --git a/.gradle/5.4.1/javaCompile/classAnalysis.bin b/.gradle/5.4.1/javaCompile/classAnalysis.bin
new file mode 100644
index 0000000..5047247
Binary files /dev/null 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
new file mode 100644
index 0000000..8c68a69
Binary files /dev/null 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
new file mode 100644
index 0000000..3f654d5
Binary files /dev/null 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
new file mode 100644
index 0000000..b508ebc
Binary files /dev/null and b/.gradle/5.4.1/javaCompile/taskHistory.bin differ
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
new file mode 100644
index 0000000..804728f
Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ
diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties
new file mode 100644
index 0000000..641a9c2
--- /dev/null
+++ b/.gradle/buildOutputCleanup/cache.properties
@@ -0,0 +1,2 @@
+#Sun Sep 29 21:26:55 EDT 2019
+gradle.version=5.4.1
diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin
new file mode 100644
index 0000000..9ef6dd2
Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ
diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties
new file mode 100644
index 0000000..e69de29
diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index c7fb425..982e5ca 100644
Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index a364d89..3d15997 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,6 +2,8 @@
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index e5f17fb..f343dbc 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -107,19 +107,28 @@
1564017826053
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
@@ -183,7 +192,17 @@
-
+
+
+
+
+
+
+
+
+
+
+
@@ -191,29 +210,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
@@ -221,7 +241,7 @@
-
+
@@ -241,7 +261,7 @@
-
+
@@ -249,39 +269,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -291,15 +278,11 @@
-
-
-
-
-
+
-
-
+
+
@@ -307,11 +290,82 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -350,13 +404,19 @@
-
-
-
+
+
+
+
+
+
+
+
+
@@ -371,20 +431,194 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -407,6 +641,10 @@
+
+
+
+
1570311037656
-
+
+ 1570328051146
+
+
+
+ 1570328051146
+
+
@@ -508,12 +753,12 @@
-
+
-
+
@@ -522,20 +767,21 @@
-
+
-
-
+
+
-
+
-
+
-
+
+
@@ -548,21 +794,116 @@
file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
- 76
+ 87
file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
- 68
+ 75
file://$PROJECT_DIR$/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
- 71
+ 83
-
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
+ 56
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
+ 107
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
+ 20
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
+ 30
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
+ 49
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
+ 55
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
+ 111
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
+ 74
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
+ 65
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
+ 94
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
+ 19
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
+ 39
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
+ 81
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
+ 109
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
+ 112
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/Demo.cpp
+ 114
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
+ 37
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/BaseRepository.cpp
+ 16
+
+
+
+ file://$PROJECT_DIR$/app/src/main/cpp/UserRepository.cpp
+ 26
+
@@ -576,10 +917,6 @@
-
-
-
-
@@ -653,10 +990,6 @@
-
-
-
-
@@ -727,9 +1060,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -737,6 +1098,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -747,30 +1118,22 @@
-
-
-
-
-
-
+
+
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
@@ -790,23 +1153,16 @@
-
+
-
-
-
-
-
-
-
-
+
@@ -814,8 +1170,19 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -824,27 +1191,92 @@
-
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/app.iml b/app/app.iml
index 934907e..d6d2051 100644
--- a/app/app.iml
+++ b/app/app.iml
@@ -64,6 +64,9 @@
+
+
+
diff --git a/app/src/main/cpp/3rdparty/SQLiteCpp b/app/src/main/cpp/3rdparty/SQLiteCpp
new file mode 160000
index 0000000..629497e
--- /dev/null
+++ b/app/src/main/cpp/3rdparty/SQLiteCpp
@@ -0,0 +1 @@
+Subproject commit 629497ed607a741fdb5e1defa8c8bb5378bfa6d5
diff --git a/app/src/main/cpp/BaseRepository.cpp b/app/src/main/cpp/BaseRepository.cpp
new file mode 100644
index 0000000..f1de0d0
--- /dev/null
+++ b/app/src/main/cpp/BaseRepository.cpp
@@ -0,0 +1,75 @@
+//
+// Created by brahmix on 10/6/19.
+//
+
+#include "BaseRepository.h"
+
+#include
+
+#include
+
+namespace repository { namespace local {
+ bool BaseRepository::databaseExist(const std::string& appPath)
+ {
+ try {
+ 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();
+ }
+
+ return false;
+ }
+
+ bool BaseRepository::isTableEmpty(const std::string& appPath)
+ {
+ try {
+ const auto dbPath = pathOfDatabase(appPath);
+ SQLite::Database db(dbPath, SQLite::OPEN_READONLY);
+ std::string queryStr("SELECT * FROM ");
+ queryStr.append(m_tableName);
+
+ SQLite::Statement query(db, queryStr);
+
+ return query.hasRow();
+ } catch (std::exception& ex) {
+ auto msg = ex.what();
+ }
+
+ return false;
+ }
+
+
+ void BaseRepository::initializedDatabase(const std::string& appPath)
+ {
+ 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();
+ }
+ }
+
+
+ std::string BaseRepository::pathOfDatabase(const std::string& appPath)
+ {
+ std::string dbPath(appPath);
+ auto lastChar = dbPath.at(dbPath.size()-1);
+ if (lastChar != '/') {
+ dbPath.append("/");
+ }
+
+ dbPath.append(m_databaseName);
+
+ return dbPath;
+ }
+
+
+}}
\ No newline at end of file
diff --git a/app/src/main/cpp/BaseRepository.h b/app/src/main/cpp/BaseRepository.h
new file mode 100644
index 0000000..52f804e
--- /dev/null
+++ b/app/src/main/cpp/BaseRepository.h
@@ -0,0 +1,28 @@
+//
+// Created by brahmix on 10/6/19.
+//
+
+#ifndef MEAR_BASEREPOSITORY_H
+#define MEAR_BASEREPOSITORY_H
+
+#include
+#include
+
+namespace repository { namespace local {
+ class BaseRepository {
+ public:
+ bool databaseExist(const std::string&);
+ bool isTableEmpty(const std::string&);
+
+ void initializedDatabase(const std::string&);
+ protected:
+ std::string pathOfDatabase(const std::string&);
+
+ const std::string m_databaseName = "mear.db3";
+ std::string m_tableName;
+ private:
+ };
+} }
+
+
+#endif //MEAR_BASEREPOSITORY_H
diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt
index b93950c..6e92002 100644
--- a/app/src/main/cpp/CMakeLists.txt
+++ b/app/src/main/cpp/CMakeLists.txt
@@ -3,7 +3,7 @@
# Sets the minimum version of CMake required to build the native library.
-cmake_minimum_required(VERSION 3.4.1)
+cmake_minimum_required(VERSION 3.6.0)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
@@ -14,24 +14,35 @@ cmake_minimum_required(VERSION 3.4.1)
# set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=c++17")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -O0 -std=c++17")
+set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -std=c++17 -DNDEBUG")
set (SOURCES
+ BaseRepository.cpp
Demo.cpp
SongRepository.cpp
Tok.cpp
+ TokenRepository.cpp
+ UserRepository.cpp
)
set (HEADERS
+ BaseRepository.h
model/Song.h
+ model/Token.h
model/User.h
SongRepository.h
Tok.h
+ TokenRepository.h
+ UserRepository.h
)
set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/json)
+add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/3rdparty/SQLiteCpp)
add_library(native-lib SHARED
@@ -42,12 +53,6 @@ add_library(native-lib SHARED
)
-# Searches for a specified prebuilt library and stores the path as a
-# variable. Because CMake includes system libraries in the search path by
-# default, you only need to specify the name of the public NDK library
-# you want to add. CMake verifies that the library exists before
-# completing its build.
-
find_library(log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
@@ -59,39 +64,33 @@ set (CURL_LIBRARY
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/android/${ANDROID_ABI}
)
-set (BASS_LIBRARY
- ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/bass/${ANDROID_ABI}
- )
set (CURL_INCLUDE_DIR
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/android/include/curl
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/android/include
)
-set (BASS_INCLUDE_DIR
- ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/bass/include
- )
+
+set(SQLITECPP_INCLUDE
+ ${CMAKE_CURRENT_LIST_DIR}/3rdparty/SQLiteCpp/include
+)
add_library(boo STATIC IMPORTED)
-#add_library(bass SHARED IMPORTED)
set_target_properties(boo PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/android/${ANDROID_ABI}/libcurl.a"
)
-#set_target_properties(bass PROPERTIES IMPORTED_LOCATION
-# "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/bass/${ANDROID_ABI}/libbass.so"
-# )
-include_directories(${CURL_INCLUDE_DIR}) #${BASS_INCLUDE_DIR})
-
-# Specifies libraries CMake should link to your target library. You
-# can link multiple libraries, such as libraries you define in this
-# build script, prebuilt third-party libraries, or system libraries.
+include_directories(${CURL_INCLUDE_DIR} ${SQLITECPP_INCLUDE}) #${BASS_INCLUDE_DIR})
target_link_libraries(native-lib PRIVATE
nlohmann_json::nlohmann_json
boo
#bass
+ SQLiteCpp
+ sqlite3
+ #pthread
+ dl
${log-lib}
z
)
\ No newline at end of file
diff --git a/app/src/main/cpp/Demo.cpp b/app/src/main/cpp/Demo.cpp
index cb924e9..605f9cb 100644
--- a/app/src/main/cpp/Demo.cpp
+++ b/app/src/main/cpp/Demo.cpp
@@ -3,12 +3,15 @@
//
#include
+#include
+#include
#include
#include
#include
#include
#include
#include
+#include
#include
#include
@@ -18,17 +21,21 @@
#include
#include
+#include
#include "model/Song.h"
#include "model/User.h"
#include "SongRepository.h"
#include "Tok.h"
+#include "UserRepository.h"
model::Song retrieveSong(const std::string&, const std::string&);
std::string fetchToken(const std::string&, const std::string&, const std::string&);
+void saveCredentials(const model::User&, const std::string&);
+
model::Song retrieveSong(const std::string& token, const std::string& baseUri)
{
@@ -76,6 +83,26 @@ 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.doesUserTableExist(filePath)) {
+ userRepo.createUserTable(filePath);
+ }
+
+ if (userRepo.isTableEmpty(filePath)) {
+ userRepo.deleteUserTable(filePath);
+ }
+
+ userRepo.saveUserCred(user, filePath);
+}
+
extern "C"
JNIEXPORT jstring
@@ -143,7 +170,6 @@ Java_com_example_mear_activities_DemoStreamActivity_retrieveSong(
}
-
extern "C"
JNIEXPORT void
JNICALL
@@ -156,3 +182,26 @@ Java_com_example_mear_activities_DemoStreamActivity_pathIteratorDemo(
const std::string pathStr = env->GetStringUTFChars(path, NULL);
iterateDirectory(pathStr);
}
+
+
+extern "C"
+JNIEXPORT void
+JNICALL
+Java_com_example_mear_activities_DemoStreamActivity_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;
+
+ saveCredentials(user, appDirectoryStr);
+}
diff --git a/app/src/main/cpp/TokenRepository.cpp b/app/src/main/cpp/TokenRepository.cpp
new file mode 100644
index 0000000..7d670f2
--- /dev/null
+++ b/app/src/main/cpp/TokenRepository.cpp
@@ -0,0 +1,5 @@
+//
+// Created by brahmix on 10/6/19.
+//
+
+#include "TokenRepository.h"
diff --git a/app/src/main/cpp/TokenRepository.h b/app/src/main/cpp/TokenRepository.h
new file mode 100644
index 0000000..8fc8dfc
--- /dev/null
+++ b/app/src/main/cpp/TokenRepository.h
@@ -0,0 +1,14 @@
+//
+// Created by brahmix on 10/6/19.
+//
+
+#ifndef MEAR_TOKENREPOSITORY_H
+#define MEAR_TOKENREPOSITORY_H
+
+
+class TokenRepository {
+
+};
+
+
+#endif //MEAR_TOKENREPOSITORY_H
diff --git a/app/src/main/cpp/UserRepository.cpp b/app/src/main/cpp/UserRepository.cpp
new file mode 100644
index 0000000..f800dea
--- /dev/null
+++ b/app/src/main/cpp/UserRepository.cpp
@@ -0,0 +1,122 @@
+//
+// Created by brahmix on 10/6/19.
+//
+
+#include "UserRepository.h"
+
+#include
+
+namespace repository { namespace local {
+ UserRepository::UserRepository()
+ {
+ m_tableName = userTable();
+ }
+
+
+ model::User UserRepository::retrieveUserCredentials(const std::string &appPath)
+ {
+ model::User user;
+ 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);
+ queryString.append(" LIMIT 1");
+
+ SQLite::Statement query(db, queryString);
+
+ auto result = query.executeStep();
+
+ auto valZero = query.getColumn(1);
+ auto valOne = query.getColumn(2);
+
+ user.username = valZero.getString();
+ user.password = valOne.getString();
+
+ return user;
+
+ } catch (std::exception& ex) {
+ auto msg = ex.what();
+ }
+
+ return user;
+ }
+
+
+ bool UserRepository::doesUserTableExist(const std::string &appPath)
+ {
+ 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) {
+ auto msg = ex.what();
+ }
+
+ return false;
+ }
+
+
+ void UserRepository::createUserTable(const std::string &appPath)
+ {
+ 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);
+ queryString.append(" (Id INTEGER PRIMARY KEY, Username TEXT, Password TEXT)");
+ db.exec(queryString);
+ } catch (std::exception& ex) {
+ auto msg = ex.what();
+ }
+ }
+
+ void UserRepository::deleteUserTable(const std::string& appPath)
+ {
+ try {
+ const auto dbPath = pathOfDatabase(appPath);
+ SQLite::Database db(dbPath, SQLite::OPEN_READWRITE);
+
+ std::string queryStr("DELETE FROM ");
+ queryStr.append(m_tableName);
+
+ db.exec(queryStr);
+ } catch (std::exception& ex) {
+ auto msg = ex.what();
+ }
+ }
+
+ void UserRepository::saveUserCred(const model::User & user, const std::string& appPath)
+ {
+ 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 (?, ?)");
+
+ SQLite::Statement query(db, queryString);
+ query.bind(1, user.username);
+ query.bind(2, user.password);
+
+ query.exec();
+ } catch (std::exception& ex) {
+ auto msg = ex.what();
+ }
+ }
+
+
+ std::string UserRepository::userTable()
+ {
+ constexpr auto table = "User";
+
+ return table;
+ }
+}}
diff --git a/app/src/main/cpp/UserRepository.h b/app/src/main/cpp/UserRepository.h
new file mode 100644
index 0000000..666ed16
--- /dev/null
+++ b/app/src/main/cpp/UserRepository.h
@@ -0,0 +1,33 @@
+//
+// Created by brahmix on 10/6/19.
+//
+
+#ifndef MEAR_USERREPOSITORY_H
+#define MEAR_USERREPOSITORY_H
+
+#include
+
+#include "BaseRepository.h"
+#include "model/User.h"
+
+
+namespace repository { namespace local {
+
+ class UserRepository : public BaseRepository {
+ public:
+ UserRepository();
+
+ model::User retrieveUserCredentials(const std::string&);
+
+ bool doesUserTableExist(const std::string&);
+
+ void createUserTable(const std::string&);
+ void deleteUserTable(const std::string&);
+ void saveUserCred(const model::User&, const std::string&);
+ private:
+ std::string userTable();
+ };
+
+}}
+
+#endif //MEAR_USERREPOSITORY_H
diff --git a/app/src/main/cpp/model/Token.h b/app/src/main/cpp/model/Token.h
new file mode 100644
index 0000000..a702cf0
--- /dev/null
+++ b/app/src/main/cpp/model/Token.h
@@ -0,0 +1,20 @@
+//
+// Created by brahmix on 10/6/19.
+//
+
+#ifndef MEAR_TOKEN_H
+#define MEAR_TOKEN_H
+
+#include
+
+namespace model {
+ class Token
+ {
+ public:
+ Token(const std::string& token) : token(token) { }
+
+ std::string token;
+ };
+}
+
+#endif //MEAR_TOKEN_H
diff --git a/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt b/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
index 9120f4d..bd9efc6 100644
--- a/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
+++ b/app/src/main/java/com/example/mear/activities/DemoStreamActivity.kt
@@ -24,10 +24,12 @@ class DemoStreamActivity : BaseServiceActivity() {
private var token: String? = null
+ // 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 pathIteratorDemo(path: String)
+ private external fun saveUserCredentials(username: String, password: String, appDir: String)
override fun onCreate(savedInstanceState: Bundle?) {
@@ -57,21 +59,30 @@ class DemoStreamActivity : BaseServiceActivity() {
return
}
- var usernameStr = username.text.toString()
- var passwordStr = password.text.toString()
+ val saveCred = saveUserCred.isChecked
+
+ val usernameStr = username.text.toString()
+ val passwordStr = password.text.toString()
var apiUriStr = apiUri.text.toString()
+ if (apiUriStr.isEmpty()) {
+ apiUriStr = ""
+ }
+
token = logUser(usernameStr, passwordStr, apiUriStr)
try {
- var s = retrieveSong(token!!, apiUriStr)
+ val s = retrieveSong(token!!, apiUriStr)
musicService!!.icarusPlaySong(this.applicationContext, token!!, apiUriStr, s)
val dir = Environment.getExternalStorageDirectory().absolutePath + "/music"
- pathIteratorDemo(dir)
- var currentTrack = musicService!!.getCurrentTrack()
- val title = currentTrack.title
- val artist = currentTrack.artist
+ val appRelPath: String = resources.getString(R.string.app_relative_path)
+ var inStoragePath = Environment.getDataDirectory().toString()
+ inStoragePath += "/data/$appRelPath"
+
+ if (saveCred) {
+ saveUserCredentials(usernameStr, passwordStr, inStoragePath)
+ }
}
catch (ex: Exception) {
val msg = ex.message
diff --git a/app/src/main/res/layout/content_demo_stream.xml b/app/src/main/res/layout/content_demo_stream.xml
index aa9f0df..166097b 100644
--- a/app/src/main/res/layout/content_demo_stream.xml
+++ b/app/src/main/res/layout/content_demo_stream.xml
@@ -49,11 +49,11 @@
android:id="@+id/apiUri"
android:layout_width="245dp"
android:layout_height="43dp"
- android:layout_marginBottom="76dp"
+ android:layout_marginBottom="16dp"
android:ems="10"
android:hint="apiUri"
android:inputType="textPersonName"
- app:layout_constraintBottom_toTopOf="@+id/login"
+ app:layout_constraintBottom_toTopOf="@+id/saveUserCred"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
@@ -68,4 +68,14 @@
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent" />
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 3cd8078..bb4b28a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,4 +1,5 @@
+ com.example.mear
Mear
Pre-development release
amazing-username - Kun Deng