From bb70ed737d98abbd6164b66ac5bd667553b312bd Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 6 Jul 2017 19:26:38 -0400 Subject: Dev 1.1.5 - JS fixes & sharing intents (#32) * Add sharing intents * Fix up multiple js instances --- .../com/pitchedapps/frost/WebOverlayActivity.kt | 27 ++++++++++++++++++++++ .../kotlin/com/pitchedapps/frost/facebook/FbTab.kt | 4 ++-- .../kotlin/com/pitchedapps/frost/utils/Utils.kt | 2 +- .../frost/web/FrostWebViewClientMenu.kt | 7 +----- 4 files changed, 31 insertions(+), 9 deletions(-) (limited to 'app/src/main/kotlin/com') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt index 000a862e..9f203970 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt @@ -7,6 +7,8 @@ import android.support.design.widget.CoordinatorLayout import android.support.design.widget.Snackbar import android.support.v7.app.AppCompatActivity import android.support.v7.widget.Toolbar +import android.view.Menu +import android.view.MenuItem import android.webkit.ValueCallback import android.webkit.WebChromeClient import ca.allanwang.kau.permissions.kauOnRequestPermissionsResult @@ -14,6 +16,7 @@ import ca.allanwang.kau.swipe.kauSwipeOnCreate import ca.allanwang.kau.swipe.kauSwipeOnDestroy import ca.allanwang.kau.swipe.kauSwipeOnPostCreate import ca.allanwang.kau.utils.* +import com.mikepenz.community_material_typeface_library.CommunityMaterial import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.pitchedapps.frost.contracts.ActivityWebContract import com.pitchedapps.frost.contracts.FileChooserContract @@ -78,6 +81,7 @@ open class WebOverlayActivity : AppCompatActivity(), override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) val newUrl = intent.extras!!.getString(ARG_URL).formattedFbUrl + L.d("New intent") if (url != newUrl) { this.intent = intent frostWeb.web.baseUrl = newUrl @@ -126,4 +130,27 @@ open class WebOverlayActivity : AppCompatActivity(), super.onRequestPermissionsResult(requestCode, permissions, grantResults) kauOnRequestPermissionsResult(permissions, grantResults) } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.menu_web, menu) + toolbar.tint(Prefs.iconColor) + setMenuIcons(menu, Prefs.iconColor, + R.id.action_share to CommunityMaterial.Icon.cmd_share, + R.id.action_copy_link to GoogleMaterial.Icon.gmd_content_copy) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_copy_link -> copyToClipboard(frostWeb.web.url) + R.id.action_share -> { + val intent = Intent(Intent.ACTION_SEND) + intent.type = "text/plain" + intent.putExtra(Intent.EXTRA_TEXT, frostWeb.web.url) + startActivity(Intent.createChooser(intent, string(R.string.share))) + } + else -> return super.onOptionsItemSelected(item) + } + return true + } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt index f26581df..7e7a8f42 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt @@ -12,8 +12,8 @@ import com.pitchedapps.frost.web.FrostWebViewCore enum class FbTab(@StringRes val titleId: Int, val icon: IIcon, relativeUrl: String, val webClient: ((webCore: FrostWebViewCore) -> FrostWebViewClient)? = null) { FEED(R.string.feed, CommunityMaterial.Icon.cmd_newspaper, ""), - FEED_MOST_RECENT(R.string.most_recent, GoogleMaterial.Icon.gmd_history, "/?sk=h_chr"), - FEED_TOP_STORIES(R.string.top_stories, GoogleMaterial.Icon.gmd_star, "/?sk=h_nor"), + FEED_MOST_RECENT(R.string.most_recent, GoogleMaterial.Icon.gmd_history, "?sk=h_chr"), + FEED_TOP_STORIES(R.string.top_stories, GoogleMaterial.Icon.gmd_star, "?sk=h_nor"), PROFILE(R.string.profile, CommunityMaterial.Icon.cmd_account, "me"), EVENTS(R.string.events, GoogleMaterial.Icon.gmd_event_note, "events/upcoming"), FRIENDS(R.string.friends, GoogleMaterial.Icon.gmd_people, "friends/center/requests"), diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index a3124dea..9fee3571 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -17,7 +17,6 @@ import android.widget.FrameLayout import android.widget.TextView import ca.allanwang.kau.utils.* import com.afollestad.materialdialogs.MaterialDialog -import com.bumptech.glide.GlideBuilder import com.bumptech.glide.annotation.GlideModule import com.bumptech.glide.module.AppGlideModule import com.crashlytics.android.answers.Answers @@ -65,6 +64,7 @@ val String.formattedFbUrl: String fun Context.launchWebOverlay(url: String) { val argUrl = url.formattedFbUrl + L.v("Launch received $url") L.i("Launch web overlay: $argUrl") startActivity(WebOverlayActivity::class.java, false, intentBuilder = { putExtra(ARG_URL, argUrl) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt index 5d44b580..0f08bcf3 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt @@ -35,12 +35,7 @@ class FrostWebViewClientMenu(webCore: FrostWebViewCore) : FrostWebViewClient(web override fun onPageFinished(view: WebView, url: String) { super.onPageFinished(view, url) if (url == webCore.baseUrl && content == null) { - jsInject(JsAssets.MENU, callback = { -// jsInject(JsAssets.CLICK_A) //menu injection must be after or we will have a loop from the click listener - }) -// } else if (url == contentBaseUrl) { -// L.i("Inject content") -// jsInject(JsAssets.CLICK_A) + jsInject(JsAssets.MENU) } } -- cgit v1.2.3