Commit a2bd34cb authored by Sharaf Zaman's avatar Sharaf Zaman

Android: Save state when app goes in background

This starts saving files synchronously. So, the progress
isn't lost.

Maniphest: T10784
parent 60539c69
......@@ -140,6 +140,21 @@ void resetRotation()
} // namespace
#endif
#ifdef Q_OS_ANDROID
extern "C" JNIEXPORT void JNICALL
Java_org_krita_android_JNIWrappers_saveState(JNIEnv* /*env*/,
jobject /*obj*/,
jint /*n*/)
{
KisPart *kisPart = KisPart::instance();
QList<QPointer<KisDocument>> list = kisPart->documents();
for (auto doc: list)
{
doc->autoSaveOnPause();
}
}
#endif
#ifdef Q_OS_ANDROID
__attribute__ ((visibility ("default")))
#endif
......
......@@ -123,7 +123,6 @@
#include <KisMirrorAxisConfig.h>
// Define the protocol used here for embedded documents' URL
// This used to "store" but QUrl didn't like it,
// so let's simply make it "tar" !
......@@ -1341,6 +1340,52 @@ bool KisDocument::openFile()
return true;
}
void KisDocument::autoSaveOnPause()
{
if (!d->modified || !d->modifiedAfterAutosave) return;
const QString autoSaveFileName = generateAutoSaveFileName(localFilePath());
bool started = initiateSavingSynchronously(
KritaUtils::ExportFileJob(
autoSaveFileName, nativeFormatMimeType(),
KritaUtils::SaveIsExporting | KritaUtils::SaveInAutosaveMode));
// FIXME?: when the document is pushed to background while it is being
// drawn on, it doesn't get saved. One possible solution could be to block
// and emit signal when it finishes.
if (started)
{
d->modifiedAfterAutosave = false;
}
else
{
qDebug() << "Could not auto-save when paused";
}
}
bool KisDocument::initiateSavingSynchronously(const KritaUtils::ExportFileJob& job)
{
KIS_ASSERT_RECOVER_RETURN_VALUE(job.isValid(), false)
QUrl url("file:/" + job.filePath);
bool started = exportDocumentSync(url, job.mimeType);
if (!started)
{
d->savingMutex.unlock();
// KisCloneDocumentStroke *stroke = new KisCloneDocumentStroke(this);
// KisStrokeId strokeId = d->image->startStroke(stroke);
// d->image->endStroke(strokeId);
// d->image->unlock();
// try again
started = exportDocumentSync(url, job.mimeType);
}
return started;
}
// shared between openFile and koMainWindow's "create new empty document" code
void KisDocument::setMimeTypeAfterLoading(const QString& mimeType)
{
......
......@@ -494,6 +494,8 @@ private:
bool showWarnings,
KisPropertiesConfigurationSP exportConfiguration);
bool initiateSavingSynchronously(const KritaUtils::ExportFileJob& job);
/**
* Activate/deactivate/configure the autosave feature.
* @param delay in seconds, 0 to disable
......@@ -625,6 +627,10 @@ public:
*/
QRectF documentBounds() const;
/**
* @brief Start saving when android activity is pushed to the background
*/
void autoSaveOnPause();
Q_SIGNALS:
void completed();
......
package org.krita.android;
class JNIWrappers {
public static native void saveState();
}
......@@ -7,13 +7,27 @@ import org.qtproject.qt5.android.bindings.QtActivity;
public class MainActivity extends QtActivity {
public boolean isStartup = true;
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
new ConfigsManager().handleAssets(this);
}
@Override
public void onPause() {
super.onPause();
// onPause() _is_ called when the app starts. If the native lib
// isn't loaded, it crashes.
if (!isStartup) {
JNIWrappers.saveState();
}
else {
isStartup = false;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment