Export/import finished.
This commit is contained in:
parent
514a9ae0e4
commit
9021b03732
@ -7,6 +7,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -24,6 +25,8 @@ public class ActivityMaintenance extends Activity
|
|||||||
final static int requestCodeExport = 1002;
|
final static int requestCodeExport = 1002;
|
||||||
final static int requestCodeMoreSettings = 6000;
|
final static int requestCodeMoreSettings = 6000;
|
||||||
|
|
||||||
|
final static String prefsFileName = "com.jens.automation2_preferences.xml";
|
||||||
|
|
||||||
TextView tvFileStoreLocation;
|
TextView tvFileStoreLocation;
|
||||||
Button bVolumeTest, bMoreSettings, bSettingsSetToDefault, bShareConfigAndLog, bImportConfiguration, bExportConfiguration;
|
Button bVolumeTest, bMoreSettings, bSettingsSetToDefault, bShareConfigAndLog, bImportConfiguration, bExportConfiguration;
|
||||||
|
|
||||||
@ -136,46 +139,106 @@ public class ActivityMaintenance extends Activity
|
|||||||
{
|
{
|
||||||
// https://stackoverflow.com/questions/46237558/android-strange-behavior-of-documentfile-inputstream
|
// https://stackoverflow.com/questions/46237558/android-strange-behavior-of-documentfile-inputstream
|
||||||
|
|
||||||
|
File dstRules = new File(Miscellaneous.getWriteableFolder() + "/" + XmlFileInterface.settingsFileName);
|
||||||
|
File dstPrefs = new File(Miscellaneous.getWriteableFolder() + "/../shared_prefs/" + prefsFileName);
|
||||||
|
|
||||||
DocumentFile directory = DocumentFile.fromTreeUri(this, uriTree);
|
DocumentFile directory = DocumentFile.fromTreeUri(this, uriTree);
|
||||||
for(DocumentFile file : directory.listFiles())
|
|
||||||
|
int applicableFilesFound = 0;
|
||||||
|
int filesImported = 0;
|
||||||
|
|
||||||
|
if(directory.listFiles().length > 0)
|
||||||
{
|
{
|
||||||
if(file.canRead() && file.getName().equals(XmlFileInterface.settingsFileName))
|
for (DocumentFile file : directory.listFiles())
|
||||||
|
{
|
||||||
|
if (file.getName().equals(XmlFileInterface.settingsFileName))
|
||||||
|
{
|
||||||
|
applicableFilesFound++;
|
||||||
|
|
||||||
|
if(file.canRead())
|
||||||
{
|
{
|
||||||
// import rules, locations, etc.
|
// import rules, locations, etc.
|
||||||
if(Miscellaneous.copyDocumentFileToFile(file, new File(Miscellaneous.getWriteableFolder() + "/" + XmlFileInterface.settingsFileName + "2")))
|
if (Miscellaneous.copyDocumentFileToFile(file, dstRules))
|
||||||
{
|
filesImported++;
|
||||||
// reload file
|
|
||||||
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.rulesImportedSuccessfully), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.rulesImportError), Toast.LENGTH_LONG).show();
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.rulesImportError), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
else if(false && file.canRead() && file.getName().equals(XmlFileInterface.settingsFileName))
|
}
|
||||||
|
else if (file.getName().equals(prefsFileName))
|
||||||
|
{
|
||||||
|
applicableFilesFound++;
|
||||||
|
|
||||||
|
if(file.canRead())
|
||||||
{
|
{
|
||||||
// import rules, locations, etc.
|
// import rules, locations, etc.
|
||||||
|
if (Miscellaneous.copyDocumentFileToFile(file, dstPrefs))
|
||||||
|
filesImported++;
|
||||||
|
else
|
||||||
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.prefsImportError), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(applicableFilesFound > 0)
|
||||||
|
{
|
||||||
|
if(filesImported == 0)
|
||||||
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.noFilesImported), Toast.LENGTH_LONG).show();
|
||||||
|
else if(filesImported < applicableFilesFound)
|
||||||
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.notAllFilesImported), Toast.LENGTH_LONG).show();
|
||||||
|
else if (filesImported == applicableFilesFound)
|
||||||
|
{
|
||||||
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.configurationImportedSuccessfully), Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
XmlFileInterface.readFile();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("e", "Reading import", "Rules re-read failed: " + Log.getStackTraceString(e), 1);
|
||||||
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.errorReadingPoisAndRulesFromFile), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings.readFromPersistentStorage(ActivityMaintenance.this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.noFilesImported), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.noApplicableFilesFoundInDirectory), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.noApplicableFilesFoundInDirectory), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
void exportFiles(Uri uriTree)
|
void exportFiles(Uri uriTree)
|
||||||
{
|
{
|
||||||
DocumentFile directory = DocumentFile.fromTreeUri(this, uriTree);
|
DocumentFile directory = DocumentFile.fromTreeUri(this, uriTree);
|
||||||
|
|
||||||
File src = new File(Miscellaneous.getWriteableFolder() + "/" + XmlFileInterface.settingsFileName);
|
File srcRules = new File(Miscellaneous.getWriteableFolder() + "/" + XmlFileInterface.settingsFileName);
|
||||||
|
File srcPrefs = new File(Miscellaneous.getWriteableFolder() + "/../shared_prefs/" + prefsFileName);
|
||||||
|
|
||||||
DocumentFile dst = directory.createFile("text/xml", XmlFileInterface.settingsFileName);
|
// Clean up
|
||||||
|
for(DocumentFile file : directory.listFiles())
|
||||||
|
{
|
||||||
|
if(file.getName().equals(XmlFileInterface.settingsFileName) && file.canWrite())
|
||||||
|
file.delete();
|
||||||
|
else if(file.getName().equals(prefsFileName) && file.canWrite())
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
|
||||||
if(dst.canWrite())
|
DocumentFile dstRules = directory.createFile("text/xml", XmlFileInterface.settingsFileName);
|
||||||
|
DocumentFile dstPrefs = directory.createFile("text/xml", prefsFileName);
|
||||||
|
|
||||||
|
if(dstRules.canWrite() && dstPrefs.canWrite())
|
||||||
{
|
{
|
||||||
// import rules, locations, etc.
|
if(Miscellaneous.copyFileToDocumentFile(srcRules, dstRules) && Miscellaneous.copyFileToDocumentFile(srcPrefs, dstPrefs))
|
||||||
if(Miscellaneous.copyFileToDocumentFile(src, dst))
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.configurationExportedSuccessfully), Toast.LENGTH_LONG).show();
|
||||||
{
|
else
|
||||||
// reload file
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.ConfigurationExportError), Toast.LENGTH_LONG).show();
|
||||||
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.rulesExportedSuccessfully), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.rulesExportError), Toast.LENGTH_LONG).show();
|
Toast.makeText(ActivityMaintenance.this, getResources().getString(R.string.ConfigurationExportError), Toast.LENGTH_LONG).show();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AlertDialog getDefaultSettingsDialog(final Context context)
|
private static AlertDialog getDefaultSettingsDialog(final Context context)
|
||||||
|
@ -42,6 +42,12 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/defaultSettings" />
|
android:text="@string/defaultSettings" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/bShareConfigAndLog"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/shareConfigAndLogFilesWithDev" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvFileStoreLocation"
|
android:id="@+id/tvFileStoreLocation"
|
||||||
android:layout_marginVertical="@dimen/default_margin"
|
android:layout_marginVertical="@dimen/default_margin"
|
||||||
@ -50,10 +56,4 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/bShareConfigAndLog"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/shareConfigAndLogFilesWithDev" />
|
|
||||||
|
|
||||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
@ -597,7 +597,7 @@
|
|||||||
<string name="filesHaveBeenMovedTo">Automation benutzt jetzt ein anderes Verzeichnis, um Ihre Daten zu speichern. Alle Ihre Automation-Dateien wurden hierhin verschoben: \"%s\". Die Berechtigung für den externen Speicher wird nun nicht mehr benötigt; Sie können Sie entfernen. In einer künftigen Version wird sie entfernt werden.</string>
|
<string name="filesHaveBeenMovedTo">Automation benutzt jetzt ein anderes Verzeichnis, um Ihre Daten zu speichern. Alle Ihre Automation-Dateien wurden hierhin verschoben: \"%s\". Die Berechtigung für den externen Speicher wird nun nicht mehr benötigt; Sie können Sie entfernen. In einer künftigen Version wird sie entfernt werden.</string>
|
||||||
<string name="locationEngineDisabledShort">Die Position kann nicht mehr bestimmt werden.</string>
|
<string name="locationEngineDisabledShort">Die Position kann nicht mehr bestimmt werden.</string>
|
||||||
<string name="locationEngineDisabledLong">Leider kann die Position nicht mehr bestimmt werden. Großer Dank dafür geht an Google für seine unendliche Weisheit und Großzügigkeit.\\n\\nBeginnend mit Android 10 wurde eine neue Berechtigung eingeführt, die benötigt wird, um als App die Position auch im Hintergrund bestimmen zu können, was, für eine App wie diese, natürlich notwendig ist.\\n\\nWährend ich das grundsätzlich für eine gute Idee halte, gilt das nicht für die Schikanen, die man Entwicklern damit zumutet.\\n\\nWenn man eine App entwickelt, kann man versuchen sich für diese Berechtigung zu qualifizieren, indem man einen Katalog von Bedingungen erfüllt. Leider wurden neue Versionen meiner Anwendung über einen Zeitraum von drei Monaten immer wieder abgelehnt.\\n\\nDas lief auf die immer gleiche Art ab:\\n\\nIch habe eine neue Version eingereicht, die all diese Anforderungen erfüllt hat.\\n\\nGoogles miserabler Entwickler-Support behauptete ich würde sie nicht einhalten.\\n\\nIch habe Beweise geliefert, daß ich alles einhalte.<br />Ich bekam eine Antwort wie "Ich kann Ihnen nicht weiterhelfen.\\n\\nIrgendwann habe ich aufgegeben.\\n\\nDie Folge davon ist nun, daß die Google Play Version keine Positionsbestimmung mehr im Hintergrund durchführen kann. Meine einzige Alternative wäre es gewesen, daß die ganze Anwendung aus dem Store fliegt.\\n\\nDas tut mir sehr leid, aber ich habe mein Bestes gegeben mit einem Kunden\"dienst\" zu diskutieren, der mehrfach beim Turing-Test durchgefallen ist.\\n\\nDie gute Nachricht: Die Anwendung kann es immer noch!\\n\\nAutomation ist nun Open Source Software und kann ab sofort bei F-Droid heruntergeladen werden. F-Droid ist ein freier Appstore, der Ihre Privatsphäre respektiert - statt nur so zu tun wie Google das macht.\\n\\nSichern Sie Ihre Konfiguratinsdatei, deinstallieren Sie dazu diese Anwendung, installieren sie von F-Droid neu, Konfigurationsdatei zurückspielen und fertig.\\n\\nKlicken Sie hier, um mehr herauszufinden:</string>
|
<string name="locationEngineDisabledLong">Leider kann die Position nicht mehr bestimmt werden. Großer Dank dafür geht an Google für seine unendliche Weisheit und Großzügigkeit.\\n\\nBeginnend mit Android 10 wurde eine neue Berechtigung eingeführt, die benötigt wird, um als App die Position auch im Hintergrund bestimmen zu können, was, für eine App wie diese, natürlich notwendig ist.\\n\\nWährend ich das grundsätzlich für eine gute Idee halte, gilt das nicht für die Schikanen, die man Entwicklern damit zumutet.\\n\\nWenn man eine App entwickelt, kann man versuchen sich für diese Berechtigung zu qualifizieren, indem man einen Katalog von Bedingungen erfüllt. Leider wurden neue Versionen meiner Anwendung über einen Zeitraum von drei Monaten immer wieder abgelehnt.\\n\\nDas lief auf die immer gleiche Art ab:\\n\\nIch habe eine neue Version eingereicht, die all diese Anforderungen erfüllt hat.\\n\\nGoogles miserabler Entwickler-Support behauptete ich würde sie nicht einhalten.\\n\\nIch habe Beweise geliefert, daß ich alles einhalte.<br />Ich bekam eine Antwort wie "Ich kann Ihnen nicht weiterhelfen.\\n\\nIrgendwann habe ich aufgegeben.\\n\\nDie Folge davon ist nun, daß die Google Play Version keine Positionsbestimmung mehr im Hintergrund durchführen kann. Meine einzige Alternative wäre es gewesen, daß die ganze Anwendung aus dem Store fliegt.\\n\\nDas tut mir sehr leid, aber ich habe mein Bestes gegeben mit einem Kunden\"dienst\" zu diskutieren, der mehrfach beim Turing-Test durchgefallen ist.\\n\\nDie gute Nachricht: Die Anwendung kann es immer noch!\\n\\nAutomation ist nun Open Source Software und kann ab sofort bei F-Droid heruntergeladen werden. F-Droid ist ein freier Appstore, der Ihre Privatsphäre respektiert - statt nur so zu tun wie Google das macht.\\n\\nSichern Sie Ihre Konfiguratinsdatei, deinstallieren Sie dazu diese Anwendung, installieren sie von F-Droid neu, Konfigurationsdatei zurückspielen und fertig.\\n\\nKlicken Sie hier, um mehr herauszufinden:</string>
|
||||||
<string name="filesStoredAt">Konfigurations- und Logdateien werden hier gespeichert: %1$s</string>
|
<string name="filesStoredAt">Konfigurations- und Logdateien werden hier gespeichert: %1$s. Klicken Sie hier auf diesen Text, um dieses Verzeichnis in einem Datei-Explorer zu öffnen. Leider funktioniert das nur auf gerooteten Geräten.\n\nFür alle anderen Geräte: Benutzen Sie einfach den Export Button, wenn Sie eine Sicherung anlegen wollen.</string>
|
||||||
<string name="directionStringEquals">ist gleich</string>
|
<string name="directionStringEquals">ist gleich</string>
|
||||||
<string name="directionStringContains">enthält</string>
|
<string name="directionStringContains">enthält</string>
|
||||||
<string name="directionStringStartsWith">beginnt mit</string>
|
<string name="directionStringStartsWith">beginnt mit</string>
|
||||||
|
@ -610,7 +610,7 @@
|
|||||||
<string name="locationDisabled">Location disabled</string>
|
<string name="locationDisabled">Location disabled</string>
|
||||||
<string name="locationEngineDisabledShort">Location cannot be determined anymore. Click here to find out why.</string>
|
<string name="locationEngineDisabledShort">Location cannot be determined anymore. Click here to find out why.</string>
|
||||||
<string name="locationEngineDisabledLong">Unfortunately your location cannot be determined anymore. A debt of gratitude is owed to Google for its infinite wisdom and amiableness.\\n\\nLet me explain this further. Starting with Android 10 a new permission was introduced that is needed to determine your location in the background (which of course is required for an app like this). Whilst I consider that a good idea in general the chicanery it involves for developers is not.\\n\\nWhen developing an app you can try to qualify for this permission by abiding to a catalog of requirements. Unfortunately new versions of my app have been rejected over a period of three months. I fulfilled all those requirements, Google\'s shitty development support claimed I would not. After giving them proof that I did after all - I got a response like \"I cannot help you anymore\". Eventually I gave up. \\n\\nAs a consequence the Google Play version can NOT use your location as a trigger anymore. My only alternative option would have been to have this application removed from the store entirely.\\n\\nI\'m very sorry about that, but I\'ve tried my best arguing with a \"support\" that repeatedly failed to pass the Turing test.\\n\\nThe good news: You can still have it all!\\n\\nAutomation is now open source and can be found in F-Droid. That is an app store that really cares about your privacy - rather than just acting like that. Simply backup your config file, uninstall this app, install it again from F-Droid, restore your config file - done.\\n\\nClick here to find out more:</string>
|
<string name="locationEngineDisabledLong">Unfortunately your location cannot be determined anymore. A debt of gratitude is owed to Google for its infinite wisdom and amiableness.\\n\\nLet me explain this further. Starting with Android 10 a new permission was introduced that is needed to determine your location in the background (which of course is required for an app like this). Whilst I consider that a good idea in general the chicanery it involves for developers is not.\\n\\nWhen developing an app you can try to qualify for this permission by abiding to a catalog of requirements. Unfortunately new versions of my app have been rejected over a period of three months. I fulfilled all those requirements, Google\'s shitty development support claimed I would not. After giving them proof that I did after all - I got a response like \"I cannot help you anymore\". Eventually I gave up. \\n\\nAs a consequence the Google Play version can NOT use your location as a trigger anymore. My only alternative option would have been to have this application removed from the store entirely.\\n\\nI\'m very sorry about that, but I\'ve tried my best arguing with a \"support\" that repeatedly failed to pass the Turing test.\\n\\nThe good news: You can still have it all!\\n\\nAutomation is now open source and can be found in F-Droid. That is an app store that really cares about your privacy - rather than just acting like that. Simply backup your config file, uninstall this app, install it again from F-Droid, restore your config file - done.\\n\\nClick here to find out more:</string>
|
||||||
<string name="filesStoredAt">Config and log files are stored in folder %1$s. Click on this text to open a file explorer. Unfortunately this will only work with a rooted device or a debug version. If you want to send me or yourself the config- and logfiles you can use the below button.</string>
|
<string name="filesStoredAt">Config and log files are stored in folder %1$s. Click on this text to open a file explorer. Unfortunately this will only work on a rooted device.\n\nFOR ALL OTHER DEVICES: Simply use the export button to make a backup.</string>
|
||||||
<string name="notification">Notification</string>
|
<string name="notification">Notification</string>
|
||||||
<string name="title">Title</string>
|
<string name="title">Title</string>
|
||||||
<string name="text">Text</string>
|
<string name="text">Text</string>
|
||||||
@ -650,8 +650,13 @@
|
|||||||
<string name="importConfiguration">Import configuration</string>
|
<string name="importConfiguration">Import configuration</string>
|
||||||
<string name="exportConfiguration">Export configuration</string>
|
<string name="exportConfiguration">Export configuration</string>
|
||||||
<string name="moreSettings">More settings</string>
|
<string name="moreSettings">More settings</string>
|
||||||
|
<string name="configurationExportedSuccessfully">Configuration exported successfully.</string>
|
||||||
|
<string name="ConfigurationExportError">There was an error while exporting the configuration.</string>
|
||||||
<string name="rulesImportedSuccessfully">Rules and locations have been imported successfully.</string>
|
<string name="rulesImportedSuccessfully">Rules and locations have been imported successfully.</string>
|
||||||
<string name="rulesImportError">There was an error importing rules and locations.</string>
|
<string name="rulesImportError">There was an error importing rules and locations.</string>
|
||||||
<string name="rulesExportedSuccessfully">Rules and locations exported successfully.</string>
|
<string name="configurationImportedSuccessfully">Configuration imported successfully.</string>
|
||||||
<string name="rulesExportError">Error exporting rules and locations.</string>
|
<string name="prefsImportError">There was an error importing the preferences.</string>
|
||||||
|
<string name="noApplicableFilesFoundInDirectory">No applicable files could be found in that directory.</string>
|
||||||
|
<string name="noFilesImported">No file could be imported.</string>
|
||||||
|
<string name="notAllFilesImported">Not all applicable files could be imported.</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user