aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-09-16 22:45:25 -0400
committerGitHub <noreply@github.com>2017-09-16 22:45:25 -0400
commite55fac98ef50a55f0064111cb767d1d7e3959bcc (patch)
tree3036c20343f5988ac04dfa2a225f991ac23ed8d5 /app/src/main/kotlin/com/pitchedapps
parent86838453bb1d712cd9ebe580333e188a02b60f5a (diff)
downloadfrost-e55fac98ef50a55f0064111cb767d1d7e3959bcc.tar.gz
frost-e55fac98ef50a55f0064111cb767d1d7e3959bcc.tar.bz2
frost-e55fac98ef50a55f0064111cb767d1d7e3959bcc.zip
Feature/share links (#297)
* Add base for receiving plain text * Update theme for links * Theme bottom bar * Add warning for plain text * Compile all themes
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt49
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Downloader.kt2
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")