[core, android] Initial playtime implementation #2535

Open
inix wants to merge 10 commits from inix/eden:playtime-android into master
4 changed files with 45 additions and 2 deletions
Showing only changes of commit db49d1a20c - Show all commits

View file

@ -13,6 +13,9 @@
#include "core/hle/service/acc/profile_manager.h"
#include "play_time_manager.h"
#include <fmt/format.h>
#include <algorithm>
namespace PlayTime {
namespace {
@ -164,4 +167,37 @@ void PlayTimeManager::ResetProgramPlayTime(u64 program_id) {
Save();
}
std::string PlayTimeManager::GetReadablePlayTime(u64 time_seconds) {
if (time_seconds == 0) {
return {};
}
const auto time_minutes = std::max(static_cast<double>(time_seconds) / 60.0, 1.0);
const auto time_hours = static_cast<double>(time_seconds) / 3600.0;
const bool is_minutes = time_minutes < 60.0;
if (is_minutes) {
return fmt::format("{:.0f} m", time_minutes);
} else {
const bool has_remainder = time_seconds % 60 != 0;
if (has_remainder) {
return fmt::format("{:.1f} h", time_hours);
} else {
return fmt::format("{:.0f} h", time_hours);
}
}
}
std::string PlayTimeManager::GetPlayTimeHours(u64 time_seconds) {
return fmt::format("{}", time_seconds / 3600);
}
std::string PlayTimeManager::GetPlayTimeMinutes(u64 time_seconds) {
return fmt::format("{}", (time_seconds % 3600) / 60);
}
std::string PlayTimeManager::GetPlayTimeSeconds(u64 time_seconds) {
return fmt::format("{}", time_seconds % 60);
}
} // namespace PlayTime

View file

@ -38,6 +38,11 @@ public:
void Start();
void Stop();
static std::string GetReadablePlayTime(u64 time_seconds);
static std::string GetPlayTimeHours(u64 time_seconds);
static std::string GetPlayTimeMinutes(u64 time_seconds);
static std::string GetPlayTimeSeconds(u64 time_seconds);
private:
void AutoTimestamp(std::stop_token stop_token);
void Save();

View file

@ -201,6 +201,8 @@ add_executable(yuzu
precompiled_headers.h
startup_checks.cpp
startup_checks.h
set_play_time_dialog.cpp
set_play_time_dialog.h
util/clickable_label.cpp
util/clickable_label.h
util/controller_navigation.cpp

View file

@ -21,7 +21,7 @@
#include "common/common_types.h"
#include "common/logging/log.h"
#include "common/string_util.h"
#include "qt_common/qt_playtime_manager.h"
#include "frontend_common/play_time_manager.h"
#include "qt_common/uisettings.h"
#include "yuzu/util/util.h"
@ -241,7 +241,7 @@ public:
void setData(const QVariant& value, int role) override {
qulonglong time_seconds = value.toULongLong();
GameListItem::setData(QtCommon::PlayTimeManager::ReadablePlayTime(time_seconds), Qt::DisplayRole);
GameListItem::setData(QString::fromStdString(PlayTime::PlayTimeManager::GetReadablePlayTime(time_seconds)), Qt::DisplayRole);
GameListItem::setData(value, PlayTimeRole);
}