mirror of
https://github.com/XorTroll/hb-appstore.git
synced 2024-11-27 04:00:58 +00:00
hook up sort, about buttons, and actually submit feedback
This commit is contained in:
parent
629bc94bba
commit
63fc2b782b
@ -1,9 +1,11 @@
|
||||
#include "AboutScreen.hpp"
|
||||
#include "../libs/get/src/Get.hpp"
|
||||
#include "../libs/get/src/Utils.hpp"
|
||||
#include "Button.hpp"
|
||||
#include <SDL2/SDL2_gfxPrimitives.h>
|
||||
#include <sstream>
|
||||
#include "MainDisplay.hpp"
|
||||
#include "Feedback.hpp"
|
||||
|
||||
AboutScreen::AboutScreen(Get* get)
|
||||
{
|
||||
@ -25,19 +27,19 @@ AboutScreen::AboutScreen(Get* get)
|
||||
|
||||
Button* cleanup = new Button("Cleanup Empty Folders", 'y', true, 21);
|
||||
cleanup->position(30, 500);
|
||||
// cleanup->action = std::bind(&AboutScreen::back, this);
|
||||
cleanup->action = std::bind(&AboutScreen::removeEmptyFolders, this);
|
||||
this->elements.push_back(cleanup);
|
||||
|
||||
Button* cache = new Button("Delete Image Cache", 'x', true, 21, cleanup->width);
|
||||
cache->position(30, cleanup->y + cleanup->height + 25);
|
||||
// cleanup->action = std::bind(&AboutScreen::back, this);
|
||||
cache->action = std::bind(&AboutScreen::wipeCache, this);
|
||||
this->elements.push_back(cache);
|
||||
|
||||
int MARGIN = 550;
|
||||
|
||||
Button* feedback = new Button("Leave Feedback", 'a', false, 17);
|
||||
feedback->position(MARGIN + 450, 65);
|
||||
// cleanup->action = std::bind(&AboutScreen::back, this);
|
||||
feedback->action = std::bind(&AboutScreen::launchFeedback, this);
|
||||
this->elements.push_back(feedback);
|
||||
|
||||
TextElement* title = new TextElement("Homebrew App Store", 35, &black);
|
||||
@ -82,3 +84,26 @@ void AboutScreen::back()
|
||||
MainDisplay::subscreen = NULL; // TODO: clean up memory?
|
||||
}
|
||||
|
||||
void AboutScreen::removeEmptyFolders()
|
||||
{
|
||||
remove_empty_dirs(ROOT_PATH, 0);
|
||||
}
|
||||
|
||||
void AboutScreen::wipeCache()
|
||||
{
|
||||
// clear out versions
|
||||
std::remove(".get/tmp/cache/versions.json");
|
||||
}
|
||||
|
||||
void AboutScreen::launchFeedback()
|
||||
{
|
||||
// find the package corresponding to us
|
||||
for (auto& package : this->get->packages)
|
||||
{
|
||||
if (package->pkg_name == "appstore")
|
||||
{
|
||||
MainDisplay::subscreen = new Feedback(package);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,13 @@ class AboutScreen : public Element
|
||||
public:
|
||||
AboutScreen(Get* get);
|
||||
Get* get = NULL;
|
||||
void back();
|
||||
void render(Element* parent);
|
||||
|
||||
// button bindings
|
||||
void back();
|
||||
void removeEmptyFolders();
|
||||
void wipeCache();
|
||||
void launchFeedback();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "Keyboard.hpp"
|
||||
#include <SDL2/SDL2_gfxPrimitives.h>
|
||||
|
||||
|
||||
AppList::AppList(Get* get, Sidebar* sidebar)
|
||||
{
|
||||
this->x = 400 - 260*(R-3);
|
||||
@ -152,26 +153,40 @@ void AppList::update()
|
||||
// if it's a search, do a search query through get rather than using all packages
|
||||
if (curCategoryValue == "_search")
|
||||
packages = get->search(this->sidebar->searchQuery);
|
||||
|
||||
// update
|
||||
for (int x=0; x<packages.size(); x++)
|
||||
if (packages[x]->status == UPDATE)
|
||||
sorted.push_back(packages[x]);
|
||||
|
||||
// installed
|
||||
for (int x=0; x<packages.size(); x++)
|
||||
if (packages[x]->status == INSTALLED)
|
||||
sorted.push_back(packages[x]);
|
||||
|
||||
// local
|
||||
for (int x=0; x<packages.size(); x++)
|
||||
if (packages[x]->status == LOCAL)
|
||||
sorted.push_back(packages[x]);
|
||||
// sort the packages list by whatever criteria is currently set
|
||||
applySortOrder(&packages);
|
||||
|
||||
if (this->sortMode == ALPHABETICAL)
|
||||
{
|
||||
// alphabetical sort order is the default view, so it puts updates and installed apps first
|
||||
|
||||
// update
|
||||
for (int x=0; x<packages.size(); x++)
|
||||
if (packages[x]->status == UPDATE)
|
||||
sorted.push_back(packages[x]);
|
||||
|
||||
// get
|
||||
for (int x=0; x<packages.size(); x++)
|
||||
if (packages[x]->status == GET)
|
||||
sorted.push_back(packages[x]);
|
||||
// installed
|
||||
for (int x=0; x<packages.size(); x++)
|
||||
if (packages[x]->status == INSTALLED)
|
||||
sorted.push_back(packages[x]);
|
||||
|
||||
// local
|
||||
for (int x=0; x<packages.size(); x++)
|
||||
if (packages[x]->status == LOCAL)
|
||||
sorted.push_back(packages[x]);
|
||||
|
||||
// get
|
||||
for (int x=0; x<packages.size(); x++)
|
||||
if (packages[x]->status == GET)
|
||||
sorted.push_back(packages[x]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// not alphabetical, just copy over to the sorted vector
|
||||
for (int x=0; x<packages.size(); x++)
|
||||
sorted.push_back(packages[x]);
|
||||
}
|
||||
|
||||
// total apps we're interested in so far
|
||||
int count = 0;
|
||||
@ -244,11 +259,46 @@ void AppList::update()
|
||||
settings->action = std::bind(&AppList::toggleKeyboard, this);
|
||||
this->elements.push_back(settings);
|
||||
}
|
||||
|
||||
// display the search type above if it's not the default one
|
||||
if (sortMode != ALPHABETICAL)
|
||||
{
|
||||
// TextElement* sort
|
||||
}
|
||||
}
|
||||
|
||||
void AppList::applySortOrder(std::vector<Package*>* p)
|
||||
{
|
||||
if (sortMode == ALPHABETICAL)
|
||||
std::sort(p->begin(), p->end(),
|
||||
[] (const auto& lhs, const auto& rhs) {
|
||||
return lhs->title.compare(rhs->title) < 0;
|
||||
});
|
||||
else if (sortMode == POPULARITY)
|
||||
std::sort(p->begin(), p->end(),
|
||||
[] (const auto& lhs, const auto& rhs) {
|
||||
return lhs->downloads > rhs->downloads;
|
||||
});
|
||||
else if (sortMode == RECENT)
|
||||
std::sort(p->begin(), p->end(),
|
||||
[] (const auto& lhs, const auto& rhs) {
|
||||
return lhs->updated_timestamp > rhs->updated_timestamp;
|
||||
});
|
||||
else if (sortMode == SIZE)
|
||||
std::sort(p->begin(), p->end(),
|
||||
[] (const auto& lhs, const auto& rhs) {
|
||||
return lhs->download_size < rhs->download_size;
|
||||
});
|
||||
else if (sortMode == RANDOM)
|
||||
{
|
||||
std::random_shuffle(p->begin(), p->end());
|
||||
}
|
||||
}
|
||||
|
||||
void AppList::cycleSort()
|
||||
{
|
||||
|
||||
this->sortMode = (this->sortMode + 1) % TOTAL_SORTS;
|
||||
this->update();
|
||||
}
|
||||
|
||||
void AppList::toggleKeyboard()
|
||||
|
@ -6,6 +6,14 @@
|
||||
#include "Keyboard.hpp"
|
||||
#include "../libs/get/src/Get.hpp"
|
||||
|
||||
#define TOTAL_SORTS 5 // alphabetical (with updates at top), downloads, last updated, size, shuffled
|
||||
#define ALPHABETICAL 0
|
||||
#define POPULARITY 1
|
||||
#define RECENT 2
|
||||
#define SIZE 3
|
||||
#define RANDOM 4
|
||||
|
||||
|
||||
class AppList : public ListElement
|
||||
{
|
||||
public:
|
||||
@ -20,6 +28,7 @@ public:
|
||||
|
||||
void toggleKeyboard();
|
||||
void cycleSort();
|
||||
void applySortOrder(std::vector<Package*>* packages);
|
||||
|
||||
bool touchMode = true;
|
||||
|
||||
@ -29,6 +38,8 @@ public:
|
||||
// default number of items per row TODO: save this value as config
|
||||
int R = 3;
|
||||
|
||||
int sortMode = RECENT;
|
||||
|
||||
void launchSettings();
|
||||
|
||||
};
|
||||
|
@ -82,9 +82,9 @@ void Button::render(Element* parent)
|
||||
if (dark)
|
||||
{
|
||||
SDL_SetRenderDrawColor(parent->renderer, 0x67, 0x6a, 0x6d, 0xFF);
|
||||
//#if defined(__WIIU__)
|
||||
// SDL_SetRenderDrawColor(parent->renderer, 0x3b, 0x3c, 0x4e, 0xFF);
|
||||
//#endif
|
||||
#if defined(__WIIU__)
|
||||
SDL_SetRenderDrawColor(parent->renderer, 0x3b, 0x3c, 0x4e, 0xFF);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
SDL_SetRenderDrawColor(parent->renderer, 0xee, 0xee, 0xee, 0xFF);
|
||||
|
@ -16,7 +16,8 @@ bool Element::process(InputEvents* event)
|
||||
|
||||
// call process on subelements
|
||||
for (int x=0; x<this->elements.size(); x++)
|
||||
ret |= this->elements[x]->process(event);
|
||||
if (this->elements.size() > x && this->elements[x])
|
||||
ret |= this->elements[x]->process(event);
|
||||
|
||||
ret |= this->needsRedraw;
|
||||
this->needsRedraw = false;
|
||||
|
@ -1,11 +1,16 @@
|
||||
#include "Feedback.hpp"
|
||||
#include "TextElement.hpp"
|
||||
#include "ImageElement.hpp"
|
||||
#include "ImageCache.hpp"
|
||||
#include "Button.hpp"
|
||||
#include "MainDisplay.hpp"
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <curl/easy.h>
|
||||
|
||||
Feedback::Feedback(Package* package)
|
||||
{
|
||||
this->package = package;
|
||||
|
||||
TextElement* elem = new TextElement((std::string("Leaving feedback for: \"") + package->title + "\"").c_str(), 25);
|
||||
elem->position(20, 20);
|
||||
elements.push_back(elem);
|
||||
@ -14,11 +19,11 @@ Feedback::Feedback(Package* package)
|
||||
icon->position(20, 120);
|
||||
elements.push_back(icon);
|
||||
|
||||
TextElement* feedback = new TextElement("hi", 17, NULL, false, 500);
|
||||
TextElement* feedback = new TextElement(this->message.c_str(), 17, NULL, false, 500);
|
||||
feedback->position(140, 140);
|
||||
elements.push_back(feedback);
|
||||
|
||||
this->keyboard = new Keyboard(NULL, feedback->text);
|
||||
this->keyboard = new Keyboard(NULL, &this->message);
|
||||
elements.push_back(keyboard);
|
||||
|
||||
Button* send = new Button("Submit", 'x', 24);
|
||||
@ -27,4 +32,39 @@ Feedback::Feedback(Package* package)
|
||||
quit->position(20, 400);
|
||||
elements.push_back(send);
|
||||
elements.push_back(quit);
|
||||
|
||||
send->action = std::bind(&Feedback::submit, this);
|
||||
quit->action = std::bind(&Feedback::back, this);
|
||||
}
|
||||
|
||||
void Feedback::submit()
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
#if defined(__WIIU__)
|
||||
const char* userKey = "wiiu_user";
|
||||
#else
|
||||
const char* userKey = "switch_user";
|
||||
#endif
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "http://switchbru.com/appstore/feedback");
|
||||
std::string fields = std::string("name=") + userKey + "&package=" + package->pkg_name + "&message=" + this->message;
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str());
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
// close this window
|
||||
this->back();
|
||||
}
|
||||
|
||||
void Feedback::back()
|
||||
{
|
||||
MainDisplay::subscreen = NULL; // todo: clean up memory
|
||||
}
|
||||
|
@ -11,6 +11,12 @@ class Feedback : public Element
|
||||
public:
|
||||
Feedback(Package* package);
|
||||
Keyboard* keyboard = NULL;
|
||||
Package* package = NULL;
|
||||
|
||||
std::string message = "";
|
||||
|
||||
void submit();
|
||||
void back();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -204,9 +204,9 @@ void MainDisplay::render(Element* parent)
|
||||
// set the background color
|
||||
MainDisplay::background(0x42, 0x45, 0x48);
|
||||
// MainDisplay::background(0x60, 0x7d, 0x8b);
|
||||
//#if defined(__WIIU__)
|
||||
// MainDisplay::background(0x54, 0x55, 0x6e);
|
||||
//#endif
|
||||
#if defined(__WIIU__)
|
||||
MainDisplay::background(0x54, 0x55, 0x6e);
|
||||
#endif
|
||||
|
||||
if (MainDisplay::subscreen)
|
||||
{
|
||||
|
@ -125,7 +125,7 @@ void Sidebar::render(Element* parent)
|
||||
|
||||
SDL_SetRenderDrawColor(parent->renderer, 0x67, 0x6a, 0x6d, 0xFF);
|
||||
//#if defined(__WIIU__)
|
||||
// SDL_SetRenderDrawColor(parent->renderer, 0x3b, 0x3c, 0x4e, 0xFF);
|
||||
SDL_SetRenderDrawColor(parent->renderer, 0x3b, 0x3c, 0x4e, 0xFF);
|
||||
//#endif
|
||||
|
||||
SDL_RenderFillRect(parent->renderer, &dimens);
|
||||
|
2
libs/get
2
libs/get
@ -1 +1 @@
|
||||
Subproject commit bdc771074e050c8006df037f92e204f0db3ec3de
|
||||
Subproject commit ab7580979baf9975009d2131f24db2a96be1b378
|
2
main.cpp
2
main.cpp
@ -8,7 +8,7 @@
|
||||
#include "libs/get/src/Utils.hpp"
|
||||
#include "libs/get/src/Get.hpp"
|
||||
|
||||
#if !defined(__WIIU__)
|
||||
#if defined(__WIIU__)
|
||||
#define DEFAULT_REPO "http://wiiubru.com/appstore"
|
||||
#else
|
||||
#define DEFAULT_REPO "http://switchbru.com/appstore"
|
||||
|
BIN
res/icon.png
Executable file → Normal file
BIN
res/icon.png
Executable file → Normal file
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 38 KiB |
Loading…
Reference in New Issue
Block a user