update app config and sync behavior for release testing
This commit is contained in:
+4
-2
@@ -4,8 +4,8 @@ android {
|
||||
namespace = "net.moasdawiki.app"
|
||||
compileSdk = 36 // 36 = Android 16 Baklava
|
||||
defaultConfig {
|
||||
applicationId "net.moasdawiki.app"
|
||||
minSdk = 33 // 33 = Android 13 Tiramisu
|
||||
applicationId "space.hackenslacker.moasdawiki.app"
|
||||
minSdk = 29 // 29 = Android 10 Q
|
||||
targetSdk = 36 // should be same as compileSdk
|
||||
versionCode = 50
|
||||
versionName = "3.9.7.0"
|
||||
@@ -34,4 +34,6 @@ dependencies {
|
||||
implementation 'androidx.preference:preference:1.2.1'
|
||||
// Fix duplicate class error
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.3.0"
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
<provider
|
||||
android:name="net.moasdawiki.app.CalendarContentProvider"
|
||||
android:authorities="net.moasdawiki.app.provider"
|
||||
android:authorities="space.hackenslacker.moasdawiki.app.provider"
|
||||
android:exported="false"
|
||||
android:syncable="true"/>
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class CalendarSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
|
||||
static final String ACCOUNT_NAME = "MoasdaWiki";
|
||||
static final String ACCOUNT_TYPE = "net.moasdawiki";
|
||||
static final String PROVIDER_NAME = "net.moasdawiki.app.provider";
|
||||
static final String PROVIDER_NAME = "space.hackenslacker.moasdawiki.app.provider";
|
||||
|
||||
private static final String CALENDAR_NAME = "MoasdaWiki Events";
|
||||
private static final Uri CALENDAR_URI = CalendarContract.Calendars.CONTENT_URI;
|
||||
|
||||
@@ -44,13 +44,12 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.window.OnBackInvokedCallback;
|
||||
import android.window.OnBackInvokedDispatcher;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.view.menu.MenuBuilder;
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import net.moasdawiki.base.ServiceException;
|
||||
@@ -76,7 +75,7 @@ import java.util.concurrent.Executors;
|
||||
/**
|
||||
* Displays the main window with the embedded wiki browser.
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity implements OnBackInvokedCallback {
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = "MainActivity";
|
||||
private static final String SERVER_BASE_URL = "http://localhost:1/";
|
||||
@@ -116,7 +115,12 @@ public class MainActivity extends AppCompatActivity implements OnBackInvokedCall
|
||||
}
|
||||
});
|
||||
|
||||
getOnBackInvokedDispatcher().registerOnBackInvokedCallback(OnBackInvokedDispatcher.PRIORITY_DEFAULT, this);
|
||||
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
MainActivity.this.onBackInvoked();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,8 +50,10 @@ import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Connects to the configured MoasdaWiki server and downloads the wiki files.
|
||||
@@ -287,7 +289,8 @@ public class SynchronizeWikiClient {
|
||||
|
||||
// Antwort auswerten
|
||||
ListModifiedFilesResponseXml response = parseXml(responseXml, ListModifiedFilesResponseXml.class);
|
||||
int fileCount = response.fileList.size();
|
||||
List<String> filePathsToDownload = determineFilesToDownload(response.fileList);
|
||||
int fileCount = filePathsToDownload.size();
|
||||
Log.d(TAG, "Downloading " + fileCount + " files from server");
|
||||
if (fileCount == 0) {
|
||||
// no files to download, cancel process
|
||||
@@ -296,9 +299,9 @@ public class SynchronizeWikiClient {
|
||||
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
feedback.progress(i, fileCount);
|
||||
SingleFileXml serverFile = response.fileList.get(i);
|
||||
String filePath = filePathsToDownload.get(i);
|
||||
try {
|
||||
downloadFileFromServer(serverHostPort, serverSessionId, serverFile.filePath);
|
||||
downloadFileFromServer(serverHostPort, serverSessionId, filePath);
|
||||
}
|
||||
catch (ServiceException e) {
|
||||
Log.w(TAG, "Error reading file from server, ignoring it", e);
|
||||
@@ -321,6 +324,24 @@ public class SynchronizeWikiClient {
|
||||
return new SyncResult(true, true, false, fileCount);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
static List<String> determineFilesToDownload(@NonNull List<SingleFileXml> modifiedFiles) {
|
||||
List<String> filePathsToDownload = new ArrayList<>();
|
||||
for (SingleFileXml modifiedFile : modifiedFiles) {
|
||||
String filePath = modifiedFile.filePath;
|
||||
if (filePath != null && !filePathsToDownload.contains(filePath)) {
|
||||
filePathsToDownload.add(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
String appConfigFilePath = Settings.getConfigFileApp();
|
||||
if (!filePathsToDownload.contains(appConfigFilePath)) {
|
||||
filePathsToDownload.add(appConfigFilePath);
|
||||
}
|
||||
|
||||
return filePathsToDownload;
|
||||
}
|
||||
|
||||
public static class SyncResult {
|
||||
private final boolean sessionValid;
|
||||
private final boolean sessionAuthorized;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:contentAuthority="net.moasdawiki.app.provider"
|
||||
android:contentAuthority="space.hackenslacker.moasdawiki.app.provider"
|
||||
android:accountType="net.moasdawiki"
|
||||
android:userVisible="false"
|
||||
android:supportsUploading="false"
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* MoasdaWiki App
|
||||
* Copyright (C) 2008 - 2026 Herbert Reiter (herbert@moasdawiki.net)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 3 as published
|
||||
* by the Free Software Foundation (GPL-3.0-only).
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
|
||||
*/
|
||||
|
||||
package net.moasdawiki.app;
|
||||
|
||||
import net.moasdawiki.service.sync.SingleFileXml;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SynchronizeWikiClientTest {
|
||||
|
||||
@Test
|
||||
public void determineFilesToDownloadAddsConfigFileAppWhenMissing() {
|
||||
List<SingleFileXml> modifiedFiles = new ArrayList<>();
|
||||
modifiedFiles.add(file("/wiki/Home-App.txt"));
|
||||
|
||||
List<String> result = SynchronizeWikiClient.determineFilesToDownload(modifiedFiles);
|
||||
|
||||
Assert.assertTrue(result.contains("/wiki/Home-App.txt"));
|
||||
Assert.assertTrue(result.contains("/config-app.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determineFilesToDownloadDoesNotDuplicateConfigFileApp() {
|
||||
List<SingleFileXml> modifiedFiles = new ArrayList<>();
|
||||
modifiedFiles.add(file("/config-app.txt"));
|
||||
|
||||
List<String> result = SynchronizeWikiClient.determineFilesToDownload(modifiedFiles);
|
||||
|
||||
int count = 0;
|
||||
for (String filePath : result) {
|
||||
if ("/config-app.txt".equals(filePath)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(1, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void determineFilesToDownloadRemovesDuplicatesAndNullValues() {
|
||||
List<SingleFileXml> modifiedFiles = new ArrayList<>();
|
||||
modifiedFiles.add(file("/wiki/PageA.txt"));
|
||||
modifiedFiles.add(file("/wiki/PageA.txt"));
|
||||
modifiedFiles.add(file(null));
|
||||
|
||||
List<String> result = SynchronizeWikiClient.determineFilesToDownload(modifiedFiles);
|
||||
|
||||
int pageACount = 0;
|
||||
for (String filePath : result) {
|
||||
if ("/wiki/PageA.txt".equals(filePath)) {
|
||||
pageACount++;
|
||||
}
|
||||
Assert.assertNotNull(filePath);
|
||||
}
|
||||
Assert.assertEquals(1, pageACount);
|
||||
}
|
||||
|
||||
private static SingleFileXml file(String filePath) {
|
||||
SingleFileXml xml = new SingleFileXml();
|
||||
xml.filePath = filePath;
|
||||
return xml;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user