Finally got around to adding the song downloading functionality
This commit is contained in:
@@ -11,15 +11,8 @@ cmake_minimum_required(VERSION 3.10)
|
||||
# Gradle automatically packages shared libraries with your APK.
|
||||
|
||||
|
||||
# set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
|
||||
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
# 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 (HEADERS
|
||||
Demo.hpp
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#define MEAR_DEMO_H
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
@@ -402,8 +403,34 @@ Java_com_example_mear_repositories_TrackRepository_retrieveSongsIncludingDownloa
|
||||
auto allSongs = retrieveSongs(tk, uri);
|
||||
jobjectArray songs = env->NewObjectArray(allSongs.size(), songClass, nullptr);
|
||||
auto i = 0;
|
||||
|
||||
repository::local::SongRepository localSongRepo(appPath);
|
||||
auto localSongs = (localSongRepo.isTableEmpty(appPath)) ?
|
||||
localSongRepo.retrieveAllSongs(appPath) : std::vector<model::Song>();
|
||||
|
||||
for (auto& sng: allSongs) {
|
||||
try {
|
||||
if (localSongs.size() > 0) {
|
||||
auto result = std::any_of(localSongs.begin(), localSongs.end(),
|
||||
[&](model::Song s) {
|
||||
auto result = s.artist.compare(sng.artist) == 0 &&
|
||||
s.title.compare(sng.title) == 0 &&
|
||||
s.album.compare(sng.album) == 0 &&
|
||||
s.albumArtist.compare(sng.albumArtist) == 0;
|
||||
|
||||
if (result) {
|
||||
auto song = songToObj<model::Song>(env, s);
|
||||
env->SetObjectArrayElement(songs, i++, song);
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
if (result) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
auto song = songToObj<model::Song>(env, sng);
|
||||
env->SetObjectArrayElement(songs, i++, song);
|
||||
} catch (std::exception& ex) {
|
||||
@@ -750,7 +777,6 @@ Java_com_example_mear_repositories_TrackRepository_downloadSong(
|
||||
jobject songObj,
|
||||
jstring pathStr
|
||||
) {
|
||||
// TODO: left off here
|
||||
auto tokenClass = env->GetObjectClass(tokenObj);
|
||||
auto accessTokenId = env->GetFieldID(tokenClass, "accessToken", "Ljava/lang/String;");
|
||||
auto accessTokenVal = (jstring) env->GetObjectField(tokenObj, accessTokenId);
|
||||
|
||||
@@ -52,6 +52,7 @@ namespace repository { namespace local {
|
||||
queryStr.append(m_tableName);
|
||||
|
||||
SQLite::Statement query(db, queryStr);
|
||||
auto r = query.exec();
|
||||
|
||||
const auto result = query.hasRow();
|
||||
|
||||
|
||||
@@ -183,11 +183,21 @@ namespace repository {
|
||||
m_tableName = songTable();
|
||||
}
|
||||
|
||||
template<typename Str = std::string>
|
||||
SongRepository(const Str& val) {
|
||||
m_tableName = songTable();
|
||||
if (!databaseExist(val)) {
|
||||
initializedDatabase(val);
|
||||
}
|
||||
if (!doesTableExist(val)) {
|
||||
createSongTable(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::vector<Song> retrieveAllSongs(const std::string& appPath) {
|
||||
std::vector<Song> downloadedSongs;
|
||||
try {
|
||||
// TODO: left off here
|
||||
const auto dbPath = pathOfDatabase(appPath);
|
||||
SQLite::Database db(dbPath, SQLite::OPEN_READONLY);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user