diff options
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt | 49 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt | 2 |
2 files changed, 47 insertions, 4 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt index de806779..aa8b87de 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt @@ -21,11 +21,11 @@ import com.pitchedapps.frost.contracts.ActivityWebContract import com.pitchedapps.frost.contracts.FileChooserContract import com.pitchedapps.frost.contracts.FileChooserDelegate import com.pitchedapps.frost.enums.OverlayContext -import com.pitchedapps.frost.facebook.FbCookie -import com.pitchedapps.frost.facebook.USER_AGENT_BASIC -import com.pitchedapps.frost.facebook.formattedFbUrl +import com.pitchedapps.frost.facebook.* import com.pitchedapps.frost.utils.* import com.pitchedapps.frost.web.FrostWebView +import io.reactivex.disposables.Disposable +import okhttp3.HttpUrl /** @@ -41,7 +41,48 @@ import com.pitchedapps.frost.web.FrostWebView * Used by notifications. Unlike the other overlays, this runs as a singleInstance * Going back will bring you back to the previous app */ -class FrostWebActivity : WebOverlayActivityBase(false) +class FrostWebActivity : WebOverlayActivityBase(false) { + + override fun onCreate(savedInstanceState: Bundle?) { + val requiresAction = !parseActionSend() + super.onCreate(savedInstanceState) + if (requiresAction) { + /* + * Signifies that we need to let the user know of a bad url + * We will subscribe to the load cycle once, + * and pop a dialog giving the user the option to copy the shared text + */ + var disposable: Disposable? = null + disposable = frostWeb.web.refreshObservable.subscribe { + disposable?.dispose() + materialDialogThemed { + title(R.string.invalid_share_url) + content(R.string.invalid_share_url_desc) + } + } + } + } + + /** + * Attempts to parse the action url + * Returns [true] if no action exists or if the action has been consumed, [false] if we need to notify the user of a bad action + */ + private fun parseActionSend(): Boolean { + if (intent.action != Intent.ACTION_SEND || intent.type != "text/plain") return true + val text = intent.getStringExtra(Intent.EXTRA_TEXT) ?: return true + val url = HttpUrl.parse(text)?.toString() + if (url == null) { + L.i("Attempted to share a non-url", text) + copyToClipboard(text, "Text to Share", showToast = false) + intent.putExtra(ARG_URL, FbItem.FEED.url) + return false + } else { + L.i("Sharing url through overlay", url) + intent.putExtra(ARG_URL, "${FB_URL_BASE}/sharer/sharer.php?u=$url") + return true + } + } +} /** * Variant that forces a basic user agent. This is largely internal, diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt index 566bffde..e161533a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt @@ -32,6 +32,8 @@ import java.lang.ref.WeakReference * Created by Allan Wang on 2017-08-04. * * With reference to the <a href="https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/Progress.java">OkHttp3 sample</a> + * + * TODO delete this file; we've moved to our downloader service for now and will create our own player soon */ fun Context.frostDownload(url: String) { L.d("Received download request", "Download $url") |