1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Mobile: Improved loading of images. Added privacy policy url.

This commit is contained in:
Laurent Cozic 2017-11-20 18:25:23 +00:00
parent e2cbef1538
commit 37de5fd4b3
6 changed files with 42 additions and 31 deletions

View File

@ -90,8 +90,8 @@ android {
applicationId "net.cozic.joplin"
minSdkVersion 16
targetSdkVersion 22
versionCode 57
versionName "0.10.44"
versionCode 58
versionName "0.10.45"
ndk {
abiFilters "armeabi-v7a", "x86"
}

View File

@ -77,24 +77,7 @@ class MdToHtml {
this.loadedResources_[id] = {};
const resource = await Resource.load(id);
if (!resource) {
console.warn('Could not load resource ' + id);
return;
}
try {
resource.base64 = await shim.readLocalFileBase64(Resource.fullPath(resource));
} catch (error) {
console.warn('Could not load resource file: ' + id, Resource.fullPath(resource), error);
return;
}
let newResources = Object.assign({}, this.loadedResources_);
newResources[id] = resource;
this.loadedResources_ = newResources;
console.info('Resource loaded: ', resource.title);
this.loadedResources_[id] = resource;
if (options.onResourceLoaded) options.onResourceLoaded();
}
@ -107,22 +90,22 @@ class MdToHtml {
}
const resourceId = Resource.urlToId(href);
if (!this.loadedResources_[resourceId]) {
const resource = this.loadedResources_[resourceId];
if (!resource) {
loadResource(resourceId);
return '';
}
const r = this.loadedResources_[resourceId];
if (!r.base64) return '';
if (!resource.id) return ''; // Resource is being loaded
const mime = r.mime.toLowerCase();
const mime = resource.mime ? resource.mime.toLowerCase() : '';
if (mime == 'image/png' || mime == 'image/jpg' || mime == 'image/jpeg' || mime == 'image/gif') {
const src = 'data:' + r.mime + ';base64,' + r.base64;
const src = './' + Resource.filename(resource);
let output = '<img title="' + htmlentities(title) + '" src="' + src + '"/>';
return output;
}
return '[Image: ' + htmlentities(r.title) + ' (' + htmlentities(mime) + ')]';
return '[Image: ' + htmlentities(resource.title) + ' (' + htmlentities(mime) + ')]';
}
renderOpenLink_(attrs, options) {

View File

@ -105,8 +105,8 @@ class Dropdown extends React.Component {
return (
<View style={{flex: 1, flexDirection: 'column' }}>
<TouchableOpacity style={headerWrapperStyle} ref={(ref) => this.headerRef_ = ref} onPress={() => { this.setState({ listVisible: true }) }}>
<Text style={headerArrowStyle}>{'▼'}</Text>
<Text ellipsizeMode="tail" numberOfLines={1} style={headerStyle}>{headerLabel}</Text>
<Text style={headerArrowStyle}>{'▼'}</Text>
</TouchableOpacity>
<Modal transparent={true} visible={this.state.listVisible} onRequestClose={() => { closeList(); }} >
<TouchableWithoutFeedback onPressOut={() => { closeList() }}>

View File

@ -2,6 +2,7 @@ const React = require('react'); const Component = React.Component;
const { Platform, WebView, View, Linking } = require('react-native');
const { globalStyle } = require('lib/components/global-style.js');
const { Resource } = require('lib/models/resource.js');
const { Setting } = require('lib/models/setting.js');
const { reg } = require('lib/registry.js');
const MdToHtml = require('lib/MdToHtml.js');
@ -82,7 +83,8 @@ class NoteBodyViewer extends Component {
<WebView
scalesPageToFit={Platform.OS !== 'ios'}
style={webViewStyle}
source={{ html: html }}
{/* baseUrl is where the images will be loaded from. So images must use a path relative to resourceDir. */}
source={{ html: html, baseUrl: 'file://' + Setting.value('resourceDir') + '/' }}
onLoadEnd={() => this.onLoadEnd()}
onError={(e) => reg.logger().error('WebView error', e) }
onMessage={(event) => {

View File

@ -1,5 +1,5 @@
const React = require('react'); const Component = React.Component;
const { View, Switch, Slider, StyleSheet, Text, Button, ScrollView } = require('react-native');
const { TouchableOpacity, Linking, View, Switch, Slider, StyleSheet, Text, Button, ScrollView } = require('react-native');
const { connect } = require('react-redux');
const { ScreenHeader } = require('lib/components/screen-header.js');
const { _, setLocale } = require('lib/locale.js');
@ -62,6 +62,12 @@ class ConfigScreenComponent extends BaseScreenComponent {
styles.switchSettingContainer.flexDirection = 'row';
styles.switchSettingContainer.justifyContent = 'space-between';
styles.linkText = Object.assign({}, styles.settingText);
styles.linkText.borderBottomWidth = 1;
styles.linkText.borderBottomColor = theme.color;
styles.linkText.flex = 0;
styles.linkText.fontWeight = 'normal';
styles.switchSettingControl = Object.assign({}, styles.settingControl);
delete styles.switchSettingControl.color;
//styles.switchSettingControl.width = '20%';
@ -149,6 +155,22 @@ class ConfigScreenComponent extends BaseScreenComponent {
if (!comp) continue;
settingComps.push(comp);
}
settingComps.push(
<View key="website_link" style={this.styles().settingContainer}>
<TouchableOpacity onPress={() => { Linking.openURL('http://joplin.cozic.net/') }}>
<Text key="label" style={this.styles().linkText}>Joplin Website</Text>
</TouchableOpacity>
</View>
);
settingComps.push(
<View key="privacy_link" style={this.styles().settingContainer}>
<TouchableOpacity onPress={() => { Linking.openURL('http://joplin.cozic.net/privacy/') }}>
<Text key="label" style={this.styles().linkText}>Privacy Policy</Text>
</TouchableOpacity>
</View>
);
//style={this.styles().body}

View File

@ -33,10 +33,14 @@ class Resource extends BaseItem {
return super.serialize(item, 'resource', fieldNames);
}
static fullPath(resource) {
static filename(resource) {
let extension = resource.mime ? mime.toFileExtension(resource.mime) : '';
extension = extension ? '.' + extension : '';
return Setting.value('resourceDir') + '/' + resource.id + extension;
return resource.id + extension;
}
static fullPath(resource) {
return Setting.value('resourceDir') + '/' + this.filename(resource);
}
static markdownTag(resource) {