24
1
Fork 0

Update the android ui to work with the new desktop ui components.

This commit is contained in:
Donovan Preston 2018-11-14 14:20:32 -05:00
parent 1d09a2e694
commit 3dc0ca933b
6 changed files with 230 additions and 296 deletions

View File

@ -19,18 +19,32 @@ window.DEFAULTS = {
EXPIRE_SECONDS: 3600
};
const choo = require('choo');
const html = require('choo/html');
const assets = require('../common/assets');
const header = require('../app/ui/header');
const locale = require('../common/locales');
const home = require('../app/ui/home');
const app = choo();
import choo from 'choo';
import html from 'choo/html';
import Raven from 'raven-js';
import assets from '../common/assets';
import header from '../app/ui/header';
import locale from '../common/locales';
import storage from '../app/storage';
import controller from '../app/controller';
import User from './user';
import intents from './stores/intents';
import home from './pages/home';
import upload from './pages/upload';
import share from './pages/share';
import preferences from './pages/preferences';
import error from './pages/error';
if (navigator.userAgent === 'Send Android') {
assets.setPrefix('/android_asset');
}
const app = choo();
//app.use(state);
app.use(controller);
app.use(intents);
function body(main) {
return function(state, emit) {
return html`
@ -56,12 +70,14 @@ function body(main) {
};
}
app.use(require('./stores/state').default);
app.use((state, emitter) => {
state.translate = locale.getTranslator();
state.capabilities = {
account: true
}; //TODO
state.storage = storage;
state.user = new User(storage);
state.raven = Raven;
window.finishLogin = async function(accountInfo) {
await state.user.finishLogin(accountInfo);
@ -72,14 +88,11 @@ app.use((state, emitter) => {
window.appState = state;
window.appEmit = emitter.emit.bind(emitter);
});
app.use(require('../app/controller').default);
app.use(require('./stores/intents').default);
app.route('/', body(home));
app.route('/options', require('./pages/options').default);
app.route('/upload', require('./pages/upload').default);
app.route('/share/:id', require('./pages/share').default);
app.route('/preferences', require('./pages/preferences').default);
app.route('/error', require('./pages/error').default);
app.route('/upload', upload);
app.route('/share/:id', share);
app.route('/preferences', preferences);
app.route('/error', error);
//app.route('/debugging', require('./pages/debugging').default);
// add /api/filelist
app.mount('body');

View File

@ -131,9 +131,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_split_apk_resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint_jar" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
@ -146,7 +144,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split_list" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/splits-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/kotlin" />

View File

@ -149,7 +149,7 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
mToCall = "finishLogin(${toPass})"
this@MainActivity.runOnUiThread({
// But then we also reload this here because we need to make sure onPageFinished runs after mToCall has been set.
// We can't guarantee that onPageFinished has already been called at this point.
// We can't guarantee that onPageFinished wasn't already called at this point.
mWebView!!.loadUrl("file:///android_asset/android.html")
})
@ -181,11 +181,9 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
if (mToCall != null) {
this@MainActivity.runOnUiThread({
mWebView?.evaluateJavascript(mToCall, fun (value: String) {
// noop
mToCall = null
})
})
mToCall = null
}
}

View File

@ -1,42 +1,60 @@
const html = require('choo/html');
const { list } = require('../../app/utils');
const archiveTile = require('../../app/ui/archiveTile');
const modal = require('../../app/ui/modal');
const intro = require('../../app/ui/intro');
const assets = require('../../common/assets');
export default function mainPage(state, emit) {
function clickPreferences(event) {
module.exports = function(state, emit) {
function onchange(event) {
event.preventDefault();
emit('pushState', '/preferences');
const newFiles = Array.from(event.target.files);
emit('addFiles', { files: newFiles });
}
function uploadFile(event) {
event.preventDefault();
const target = event.target;
const file = target.files[0];
if (file.size === 0) {
return;
}
emit('pushState', '/options');
emit('addFiles', { files: [file] });
function onclick() {
document.getElementById('file-upload').click();
}
return html`<body>
<div id="white">
<div id="centering">
<img id="top-banner" src=${state.getAsset('top-banner.png')} />
<a id="hamburger" href="#" onclick=${clickPreferences}>
<img src=${state.getAsset('preferences.png')} />
</a>
<img src=${state.getAsset('encrypted-envelope.png')} />
<h4>Private, Encrypted File Sharing</h4>
<div>
Send files through a safe, private, and encrypted link that automatically expires to ensure your stuff does not remain online forever.
const archives = state.storage.files
.map(archive => archiveTile(state, emit, archive))
.reverse();
let content = '';
let button = html`
<img
onclick="${onclick}"
style="padding: 1em"
src="${assets.get('addfile.svg')}"
/>
`;
if (state.uploading) {
content = archiveTile.uploading(state, emit);
} else if (state.archive) {
content = archiveTile.wip(state, emit);
button = '';
} else {
content =
archives.length < 1
? intro(state)
: list(archives, 'list-reset h-full overflow-y-scroll', 'mb-3');
}
return html`
<main class="main relative">
${state.modal && modal(state, emit)} ${content}
<div class="fixed pin-r pin-b">
${button}
<input
id="file-upload"
class="hidden"
type="file"
multiple
onchange="${onchange}"
onclick="${e => e.stopPropagation()}"
/>
</div>
<div id="spacer">
</div>
<label id="label" for="input">
<img src=${state.getAsset('cloud-upload.png')} />
</label>
<input id="input" name="input" type="file" onchange=${uploadFile} />
</div>
</div>
</body>`;
}
</main>
`;
};

View File

@ -1,92 +0,0 @@
/* globals DEFAULTS */
const html = require('choo/html');
export default function options(state, emit) {
function clickCancel(event) {
event.preventDefault();
emit('pushState', '/');
}
async function submitForm(event) {
event.preventDefault();
if (this.addPassword.checked) {
if (this.password.value !== this.confirmPassword.value) {
state.passwordDoesNotMatchError = true;
emit('render');
return;
} else {
state.passwordDoesNotMatchError = false;
}
}
state.timeLimit = parseInt(event.target.maxTime);
emit('upload', {
type: 'click',
dlimit: parseInt(event.target.numDownloads.value),
password: event.target.password.value
});
emit('pushState', '/upload');
}
function addPasswordChange(event) {
const pw = document.getElementById('password-section');
if (event.target.checked) {
pw.style.display = 'block';
} else {
pw.style.display = 'none';
}
}
const passwordDoesNotMatchDisplayStyle = state.passwordDoesNotMatchError
? 'display: block'
: 'display: none';
const passwordChecked = state.passwordDoesNotMatchError ? true : false;
return html`<body>
<div id="white">
<div id="options">
<a onclick=${clickCancel} class="cancel" href="#">
cancel
</a>
<h5>Selected files</h5>
<ul>
<li>file</li>
</ul>
<div id="options-controls">
<form onsubmit=${submitForm}>
<div id="expires-after-section">
<h5>Expires after</h5>
<select name="numDownloads">
${DEFAULTS.DOWNLOAD_COUNTS.map(i => {
return html`<option value="${i}">${i} download${
i > 1 ? 's' : ''
}</option>`;
})}
</select>
or
<select name="maxTime">
<option value="300">5 minutes</option>
<option value="3600">1 hour</option>
<option value="86400" selected="true">24 hours</option>
<option value="604800">7 days</option>
</select>
</div>
<div id="set-password-section">
<input onchange=${addPasswordChange} name="addPassword" autocomplete="off" type="checkbox" checked=${passwordChecked}>
<label for="addPassword">Protect with password</label>
<div id="password-section" style=${passwordDoesNotMatchDisplayStyle}>
<div style=${passwordDoesNotMatchDisplayStyle}>
Passwords must match.
</div>
<h5>Password:</h5>
<input name="password" type="password" />
<h5>Confirm password:</h5>
<input name="confirmPassword" type="password" />
</div>
</div>
<button>Send</button>
</form>
</div>
</div>
</div>
</body>`;
}

296
package-lock.json generated

File diff suppressed because it is too large Load Diff