Working on setting a song on repeat
This commit is contained in:
@@ -22,6 +22,8 @@ set (SOURCES
|
||||
APIRepository.cpp
|
||||
BaseRepository.cpp
|
||||
Demo.cpp
|
||||
RepeatRepository.cpp
|
||||
ShuffleRepository.cpp
|
||||
SongRepository.cpp
|
||||
Tok.cpp
|
||||
TokenRepository.cpp
|
||||
@@ -36,6 +38,10 @@ set (HEADERS
|
||||
model/Song.h
|
||||
model/Token.h
|
||||
model/User.h
|
||||
RepeatRepository.h
|
||||
RepeatTypes.h
|
||||
ShuffleRepository.h
|
||||
ShuffleTypes.h
|
||||
SongRepository.h
|
||||
Tok.h
|
||||
TokenRepository.h
|
||||
@@ -50,16 +56,12 @@ add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/3rdparty/SQLiteCpp)
|
||||
|
||||
|
||||
add_library(native-lib SHARED
|
||||
|
||||
# Provides a relative path to your source file(s).
|
||||
${SOURCES}
|
||||
${HEADERS}
|
||||
)
|
||||
|
||||
|
||||
find_library(log-lib
|
||||
# Specifies the name of the NDK library that
|
||||
# you want CMake to locate.
|
||||
log
|
||||
)
|
||||
|
||||
@@ -84,16 +86,13 @@ set_target_properties(boo PROPERTIES IMPORTED_LOCATION
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/android/${ANDROID_ABI}/libcurl.a"
|
||||
)
|
||||
|
||||
include_directories(${CURL_INCLUDE_DIR} ${SQLITECPP_INCLUDE}) #${BASS_INCLUDE_DIR})
|
||||
include_directories(${CURL_INCLUDE_DIR} ${SQLITECPP_INCLUDE})
|
||||
|
||||
target_link_libraries(native-lib PRIVATE
|
||||
|
||||
nlohmann_json::nlohmann_json
|
||||
boo
|
||||
#bass
|
||||
SQLiteCpp
|
||||
sqlite3
|
||||
#pthread
|
||||
dl
|
||||
${log-lib}
|
||||
z
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// Created by brahmix on 10/21/19.
|
||||
//
|
||||
|
||||
#include "RepeatRepository.h"
|
||||
|
||||
namespace repository { namespace local {
|
||||
RepeatRepository::RepeatRepository() {
|
||||
m_tableName = repeatTable();
|
||||
}
|
||||
|
||||
|
||||
RepeatTypes RepeatRepository::retrieveRepeatMode(const std::string& path) {
|
||||
try {
|
||||
auto db = getDbConn(path, ConnType::ReadOnly);
|
||||
std::string queryString("SELECT * FROM ");
|
||||
queryString.append(m_tableName);
|
||||
queryString.append(" LIMIT 1");
|
||||
|
||||
SQLite::Statement query(db, queryString);
|
||||
|
||||
const auto result = query.executeStep();
|
||||
|
||||
return static_cast<RepeatTypes>(query.getColumn(1).getInt());
|
||||
} catch (std::exception& ex) {
|
||||
auto msg = ex.what();
|
||||
}
|
||||
|
||||
return RepeatTypes::RepeatOff;
|
||||
}
|
||||
|
||||
|
||||
void RepeatRepository::createRepeatTable(const std::string& path) {
|
||||
try {
|
||||
auto db = getDbConn(path, ConnType::ReadWrite);
|
||||
std::string queryString("CREATE TABLE ");
|
||||
queryString.append(m_tableName);
|
||||
queryString.append(" (Id INTEGER PRIMARY KEY, RepeatMode INT)");
|
||||
|
||||
db.exec(queryString);
|
||||
} catch (std::exception& ex) {
|
||||
auto msg = ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RepeatRepository::updateRepeat(const std::string& path) {
|
||||
try {
|
||||
auto db = getDbConn(path, ConnType::ReadWrite);
|
||||
|
||||
if (isTableEmpty(path)) {
|
||||
std::string queryString("INSERT INTO ");
|
||||
queryString.append(m_tableName);
|
||||
queryString.append(" (RepeatMode) VALUES (?)");
|
||||
|
||||
SQLite::Statement query(db, queryString);
|
||||
query.bind(1, static_cast<int>(RepeatTypes::RepeatOff));
|
||||
query.exec();
|
||||
} else {
|
||||
std::string queryString("UPDATE ");
|
||||
queryString.append(m_tableName);
|
||||
queryString.append(" SET RepeatMode = ?");
|
||||
|
||||
auto repeatMode = retrieveRepeatMode(path);
|
||||
SQLite::Statement query(db, queryString);
|
||||
|
||||
switch (repeatMode) {
|
||||
case RepeatTypes::RepeatOff:
|
||||
query.bind(1, static_cast<int>(RepeatTypes::RepeatSong));
|
||||
break;
|
||||
case RepeatTypes::RepeatSong:
|
||||
query.bind(1, static_cast<int>(RepeatTypes::RepeatOff));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
query.exec();
|
||||
}
|
||||
} catch (std::exception& ex) {
|
||||
auto msg = ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string RepeatRepository::repeatTable() { return "Repeat"; }
|
||||
}}
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by brahmix on 10/21/19.
|
||||
//
|
||||
|
||||
#ifndef MEAR_REPEATREPOSITORY_H
|
||||
#define MEAR_REPEATREPOSITORY_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "BaseRepository.h"
|
||||
#include "RepeatTypes.h"
|
||||
|
||||
namespace repository { namespace local {
|
||||
class RepeatRepository : public BaseRepository {
|
||||
public:
|
||||
RepeatRepository();
|
||||
|
||||
RepeatTypes retrieveRepeatMode(const std::string&);
|
||||
|
||||
void createRepeatTable(const std::string&);
|
||||
void updateRepeat(const std::string&);
|
||||
private:
|
||||
constexpr std::string repeatTable() noexcept;
|
||||
};
|
||||
}}
|
||||
|
||||
|
||||
#endif //MEAR_REPEATREPOSITORY_H
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by brahmix on 10/21/19.
|
||||
//
|
||||
|
||||
#ifndef MEAR_REPEATTYPES_H
|
||||
#define MEAR_REPEATTYPES_H
|
||||
|
||||
|
||||
enum class RepeatTypes {
|
||||
RepeatSong = 0,
|
||||
RepeatOff
|
||||
};
|
||||
|
||||
|
||||
#endif //MEAR_REPEATTYPES_H
|
||||
@@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by brahmix on 10/21/19.
|
||||
//
|
||||
|
||||
#include "ShuffleRepository.h"
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by brahmix on 10/21/19.
|
||||
//
|
||||
|
||||
#ifndef MEAR_SHUFFLEREPOSITORY_H
|
||||
#define MEAR_SHUFFLEREPOSITORY_H
|
||||
|
||||
|
||||
class ShuffleRepository {
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //MEAR_SHUFFLEREPOSITORY_H
|
||||
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by brahmix on 10/21/19.
|
||||
//
|
||||
|
||||
#ifndef MEAR_SHUFFLETYPES_H
|
||||
#define MEAR_SHUFFLETYPES_H
|
||||
|
||||
enum class ShuffleTypes {
|
||||
ShuffleQueue = 0,
|
||||
ShuffleOff
|
||||
};
|
||||
|
||||
#endif //MEAR_SHUFFLETYPES_H
|
||||
Reference in New Issue
Block a user