Limiting last played count to 50

This commit is contained in:
pjft 2018-02-27 22:40:23 +00:00
parent 32258e1f00
commit d3cc0a77ef
2 changed files with 23 additions and 1 deletions

View file

@ -16,6 +16,8 @@
std::string myCollectionsName = "collections";
#define LAST_PLAYED_MAX 50
/* Handling the getting, initialization, deinitialization, saving and deletion of
* a CollectionSystemManager Instance */
CollectionSystemManager* CollectionSystemManager::sInstance = NULL;
@ -277,7 +279,23 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS
}
}
rootFolder->sort(getSortTypeFromString(mCollectionSystemDeclsIndex[name].defaultSort));
ViewController::get()->onFileChanged(rootFolder, FILE_SORTED);
if (name == "recent")
{
trimCollectionCount(rootFolder, LAST_PLAYED_MAX);
ViewController::get()->onFileChanged(rootFolder, FILE_METADATA_CHANGED);
}
else
ViewController::get()->onFileChanged(rootFolder, FILE_SORTED);
}
}
void CollectionSystemManager::trimCollectionCount(FileData* rootFolder, int limit)
{
SystemData* curSys = rootFolder->getSystem();
while (rootFolder->getChildren().size() > limit)
{
CollectionFileData* gameToRemove = (CollectionFileData*)rootFolder->getChildrenListToDisplay().back();
ViewController::get()->getGameListView(curSys).get()->remove(gameToRemove, false);
}
}
@ -713,6 +731,8 @@ void CollectionSystemManager::populateAutoCollection(CollectionSystemData* sysDa
}
}
rootFolder->sort(getSortTypeFromString(sysDecl.defaultSort));
if (sysDecl.type == AUTO_LAST_PLAYED)
trimCollectionCount(rootFolder, LAST_PLAYED_MAX);
sysData->isPopulated = true;
}

View file

@ -103,6 +103,8 @@ private:
std::vector<std::string> getCollectionThemeFolders(bool custom);
std::vector<std::string> getUserCollectionThemeFolders();
void trimCollectionCount(FileData* rootFolder, int limit);
bool themeFolderExists(std::string folder);
bool includeFileInAutoCollections(FileData* file);