pull/653/merge
Varun Patil 2023-10-02 10:09:40 -07:00
parent 53f8d248b7
commit 582035df16
5 changed files with 27 additions and 111 deletions

View File

@ -1,55 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Memories</title>
<link rel="stylesheet" href="styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div id="main" class="container animatable">
<img src="memories.svg" alt="Memories Logo" class="logo" />
<p id="waiting" class="animatable">
Waiting for login to complete <br />
Keep this page open in the background
</p>
<div id="sync" class="p animatable invisible">
You are now logged in to the server!
<br /><br />
You can set up automatic uploads from this device using the Nextcloud
mobile app. Click the button below to download the app, or skip this
step and continue.
<br />
<a
class="m-button login-button"
href="https://play.google.com/store/apps/details?id=com.nextcloud.client"
>
Set up automatic upload
</a>
<br />
<p id="conn-error" class="error"></p>
<button class="m-button link" onclick="openLocal()">Continue</button>
</div>
<div id="local-folders" class="p animatable invisible">
Choose the folders on this device to show on your timeline. If no folders
are visible here, you may need to grant the app storage permissions, or
wait for the app to index your files.
<br /><br />
You can always change this in settings. Note that this does not affect
automatic uploads.
<br />
<div id="folder-list"></div>
<button class="m-button" onclick="start()">Continue</button>
</div>
</div>
<script src="sync.js"></script>
</body>
</html>

View File

@ -1,51 +0,0 @@
const main = document.getElementById("main");
const waiting = document.getElementById("waiting");
const sync = document.getElementById("sync");
const localFolders = document.getElementById("local-folders");
// Waiting page => sync page
window.loggedIn = async () => {
waiting.classList.add("invisible");
await new Promise((resolve) => setTimeout(resolve, 700));
waiting.remove();
sync.classList.remove("invisible");
};
// Local list of folders
let localList = null;
async function openLocal() {
// Get the list of local folders for next screen
localList = JSON.parse(window.nativex?.configGetLocalFolders());
// Add HTML for folders list
document.getElementById("folder-list").innerHTML = localList
.map(
(folder) => `
<div class="folder-choose">
<input type="checkbox" id="folder-${folder.id}" ${folder.enabled ? "checked" : ""}>
<label for="${folder.id}">${folder.name}</label>
</div>
`
)
.join("");
// Show the folders list
sync.classList.add("invisible");
await new Promise((resolve) => setTimeout(resolve, 700));
sync.remove();
localFolders.classList.remove("invisible");
}
// Open main app
async function start() {
// Mark all checked as enabled
if (localList) {
localList.forEach((f) => (f.enabled = document.getElementById(`folder-${f.id}`).checked));
window.nativex?.configSetLocalFolders(JSON.stringify(localList));
}
// Start the app
main.classList.add("invisible");
await new Promise((resolve) => setTimeout(resolve, 700));
window.nativex?.reload();
}

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Memories</title>
<link rel="stylesheet" href="styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div id="main" class="container">
<img src="memories.svg" alt="Memories Logo" class="logo" />
<p id="waiting">
Waiting for login to complete <br />
Keep this page open in the background
</p>
</div>
</body>
</html>

View File

@ -56,7 +56,7 @@ class AccountService(private val mCtx: MainActivity, private val mHttp: HttpServ
*/ */
private fun pollLogin(pollUrl: String, pollToken: String, baseUrl: String) { private fun pollLogin(pollUrl: String, pollToken: String, baseUrl: String) {
mCtx.binding.webview.post { mCtx.binding.webview.post {
mCtx.binding.webview.loadUrl("file:///android_asset/sync.html") mCtx.binding.webview.loadUrl("file:///android_asset/waiting.html")
} }
var pollCount = 0 var pollCount = 0
@ -84,7 +84,7 @@ class AccountService(private val mCtx: MainActivity, private val mHttp: HttpServ
storeCredentials(baseUrl, loginName, appPassword) storeCredentials(baseUrl, loginName, appPassword)
// Go to next screen // Go to next screen
mCtx.binding.webview.evaluateJavascript("window.loggedIn()", {}) mHttp.loadWebView(mCtx.binding.webview, "nxsetup")
} }
return return

View File

@ -51,16 +51,20 @@ class HttpService {
/** /**
* Load a webview at the default page * Load a webview at the default page
* @param webView The webview to load * @param webView The webview to load
* @param subpath The subpath to load
* @return Host URL if authenticated, null otherwise * @return Host URL if authenticated, null otherwise
*/ */
fun loadWebView(webView: WebView): String? { fun loadWebView(webView: WebView, subpath: String? = null): String? {
// Load app interface if authenticated // Load app interface if authenticated
if (authHeader != null && memoriesUrl != null) { if (authHeader != null && memoriesUrl != null) {
var url = memoriesUrl
if (subpath != null) url += subpath
// Get host name // Get host name
val host = Uri.parse(memoriesUrl).host val host = Uri.parse(url).host
// Set authorization header // Set authorization header
webView.loadUrl(memoriesUrl!!, mapOf("Authorization" to authHeader)) webView.loadUrl(url!!, mapOf("Authorization" to authHeader))
return host return host
} }