1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

code review

This commit is contained in:
Laserlicht
2025-09-03 20:58:30 +02:00
parent 0847485345
commit aada2eccf7
6 changed files with 17 additions and 14 deletions

View File

@@ -57,12 +57,12 @@ public class ActivityLauncher extends org.qtproject.qt5.android.bindings.QtActiv
startActivityForResult(intent, PICK_EXTERNAL_VCMI_DATA_TO_COPY);
}
public void setScreensaverEnabled(boolean on)
public void keepScreenOn(boolean isEnabled)
{
if(on)
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
else
if(isEnabled)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
else
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
public void onLaunchGameBtnPressed()

View File

@@ -27,6 +27,6 @@ const char *frameworksPath();
const char *bundleIdentifier();
bool isOsVersionAtLeast(unsigned int osMajorVersion);
void setScreensaverEnabled(bool isEnabled);
void keepScreenOn(bool isEnabled);
}
#pragma GCC visibility pop

View File

@@ -53,8 +53,8 @@ bool isOsVersionAtLeast(unsigned int osMajorVersion)
return NSProcessInfo.processInfo.operatingSystemVersion.majorVersion >= osMajorVersion;
}
void setScreensaverEnabled(bool isEnabled)
void keepScreenOn(bool isEnabled)
{
UIApplication.sharedApplication.idleTimerDisabled = isEnabled ? NO : YES;
UIApplication.sharedApplication.idleTimerDisabled = isEnabled ? YES : NO;
}
}

View File

@@ -117,15 +117,15 @@ MainWindow * getMainWindow()
}
void keepScreenOn(bool on)
void keepScreenOn(bool isEnabled)
{
#if defined(VCMI_ANDROID)
QtAndroid::runOnAndroidThread([on]
QtAndroid::runOnAndroidThread([isEnabled]
{
QtAndroid::androidActivity().callMethod<void>("setScreensaverEnabled", "(Z)V", !on);
QtAndroid::androidActivity().callMethod<void>("keepScreenOn", "(Z)V", isEnabled);
});
#elif defined(VCMI_IOS)
iOS_utils::setScreensaverEnabled(!on);
iOS_utils::keepScreenOn(isEnabled);
#endif
}
}

View File

@@ -23,5 +23,5 @@ QString getRealPath(QString path);
void performNativeCopy(QString src, QString dst);
void revealDirectoryInFileBrowser(QString path);
MainWindow * getMainWindow();
void keepScreenOn(bool on);
void keepScreenOn(bool isEnabled);
}

View File

@@ -807,7 +807,6 @@ void CModListView::downloadProgress(qint64 current, qint64 max)
void CModListView::extractionProgress(qint64 current, qint64 max)
{
Helper::keepScreenOn(true);
// display progress, in extracted files
ui->progressBar->setVisible(true);
ui->progressBar->setMaximum(max);
@@ -854,12 +853,12 @@ void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFi
if(doInstallFiles)
installFiles(savedFiles);
Helper::keepScreenOn(false);
hideProgressBar();
}
void CModListView::hideProgressBar()
{
Helper::keepScreenOn(false);
if(dlManager == nullptr) // it was not recreated meanwhile
{
ui->progressWidget->setVisible(false);
@@ -983,6 +982,8 @@ void CModListView::installFiles(QStringList files)
float prog = 0.0;
Helper::keepScreenOn(true);
auto futureExtract = std::async(std::launch::async, [this, exe, &prog]()
{
ChroniclesExtractor ce(this, [&prog](float progress) { prog = progress; });
@@ -998,6 +999,7 @@ void CModListView::installFiles(QStringList files)
if(futureExtract.get())
{
Helper::keepScreenOn(false);
hideProgressBar();
ui->abortButton->setEnabled(true);
ui->progressWidget->setVisible(false);
@@ -1236,6 +1238,7 @@ void CModListView::on_abortButton_clicked()
{
delete dlManager;
dlManager = nullptr;
Helper::keepScreenOn(false);
hideProgressBar();
}