Fix #888 Implement share card.

This commit is contained in:
Donovan Preston 2019-01-16 12:05:39 -05:00
parent 32a77180b0
commit af61434b72
3 changed files with 42 additions and 6 deletions

View file

@ -35,6 +35,11 @@ class WebAppInterface(private val mContext: MainActivity) {
fun beginOAuthFlow() { fun beginOAuthFlow() {
mContext.beginOAuthFlow(); mContext.beginOAuthFlow();
} }
@JavascriptInterface
fun shareUrl(url: String) {
mContext.shareUrl(url)
}
} }
class MainActivity : AppCompatActivity(), AdvancedWebView.Listener { class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
@ -94,6 +99,14 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
}) })
} }
fun shareUrl(url: String) {
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.type = "text/plain"
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
startActivity(Intent.createChooser(shareIntent, ""))
}
@SuppressLint("NewApi") @SuppressLint("NewApi")
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()

View file

@ -1,3 +1,5 @@
/* global Android */
const html = require('choo/html'); const html = require('choo/html');
const raw = require('choo/html/raw'); const raw = require('choo/html/raw');
const assets = require('../../common/assets'); const assets = require('../../common/assets');
@ -140,6 +142,26 @@ function archiveDetails(translate, archive) {
} }
module.exports = function(state, emit, archive) { module.exports = function(state, emit, archive) {
const copyOrShare =
typeof window.Android !== 'object'
? html`
<button
class="text-blue hover:text-blue-dark focus:text-blue-darker self-end font-medium flex items-center"
onclick=${copy}
>
<img src="${assets.get('copy-16.svg')}" class="mr-2" /> ${
state.translate('copyUrlHover')
}
</button>
`
: html`
<button
class="text-blue hover:text-blue-dark focus:text-blue-darker self-end font-medium flex items-center"
onclick=${share}
>
<img src="${assets.get('share-16.svg')}" class="mr-2" /> Share
</button>
`;
return html` return html`
<send-archive <send-archive
id="archive-${archive.id}" id="archive-${archive.id}"
@ -162,12 +184,7 @@ module.exports = function(state, emit, archive) {
</div> </div>
${archiveDetails(state.translate, archive)} ${archiveDetails(state.translate, archive)}
<hr class="w-full border-t my-4"> <hr class="w-full border-t my-4">
<button ${copyOrShare}
class="text-blue hover:text-blue-dark focus:text-blue-darker self-end font-medium flex items-center"
onclick=${copy}>
<img src="${assets.get('copy-16.svg')}" class="mr-2"/>
${state.translate('copyUrlHover')}
</button>
</send-archive>`; </send-archive>`;
function copy(event) { function copy(event) {
@ -185,6 +202,11 @@ module.exports = function(state, emit, archive) {
event.stopPropagation(); event.stopPropagation();
emit('delete', { file: archive, location: 'success-screen' }); emit('delete', { file: archive, location: 'success-screen' });
} }
function share(event) {
event.stopPropagation();
Android.shareUrl(archive.url);
}
}; };
module.exports.wip = function(state, emit) { module.exports.wip = function(state, emit) {

1
assets/share-16.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="#0A8DFF" d="M14.707 8.293l-3-3A1 1 0 0 0 11 5h-1V4a1 1 0 0 0-.293-.707l-3-3A1 1 0 0 0 6 0H3a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h3v3a2 2 0 0 0 2 2h5a2 2 0 0 0 2-2V9a1 1 0 0 0-.293-.707zM12.586 9H11V7.414zm-5-5H6V2.414zM6 7v2H3V2h2v2.5a.5.5 0 0 0 .5.5H8a2 2 0 0 0-2 2zm2 7V7h2v2.5a.5.5 0 0 0 .5.5H13v4z"/></svg>

After

Width:  |  Height:  |  Size: 398 B