mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-09-19 23:21:34 +02:00
Feature/contextual overlays (#295)
* Update theme * Update theme * Compile compacts * Update changelog * Update theme * Add overlay context items and their bindings * Replace default with null and add changelog
This commit is contained in:
parent
9c4ff00638
commit
2fe3422895
@ -48,6 +48,7 @@ import com.pitchedapps.frost.contracts.FileChooserContract
|
||||
import com.pitchedapps.frost.contracts.FileChooserDelegate
|
||||
import com.pitchedapps.frost.dbflow.loadFbCookie
|
||||
import com.pitchedapps.frost.dbflow.loadFbTabs
|
||||
import com.pitchedapps.frost.enums.OverlayContext
|
||||
import com.pitchedapps.frost.enums.Theme
|
||||
import com.pitchedapps.frost.facebook.FbCookie
|
||||
import com.pitchedapps.frost.facebook.FbCookie.switchUser
|
||||
|
@ -20,6 +20,7 @@ import com.pitchedapps.frost.R
|
||||
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
|
||||
@ -53,7 +54,7 @@ class WebOverlayBasicActivity : WebOverlayActivityBase(true)
|
||||
*/
|
||||
class WebOverlayActivity : WebOverlayActivityBase(false)
|
||||
|
||||
open class WebOverlayActivityBase(val forceBasicAgent: Boolean) : KauBaseActivity(),
|
||||
open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : KauBaseActivity(),
|
||||
ActivityWebContract, FileChooserContract by FileChooserDelegate() {
|
||||
|
||||
val toolbar: Toolbar by bindView(R.id.overlay_toolbar)
|
||||
@ -69,6 +70,9 @@ open class WebOverlayActivityBase(val forceBasicAgent: Boolean) : KauBaseActivit
|
||||
val userId: Long
|
||||
get() = intent.extras?.getLong(ARG_USER_ID, Prefs.userId) ?: Prefs.userId
|
||||
|
||||
val overlayContext: OverlayContext?
|
||||
get() = intent.extras?.getSerializable(ARG_OVERLAY_CONTEXT) as OverlayContext?
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (urlTest == null) {
|
||||
@ -157,6 +161,7 @@ open class WebOverlayActivityBase(val forceBasicAgent: Boolean) : KauBaseActivit
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_web, menu)
|
||||
overlayContext?.onMenuCreate(this, menu)
|
||||
toolbar.tint(Prefs.iconColor)
|
||||
setMenuIcons(menu, Prefs.iconColor,
|
||||
R.id.action_share to CommunityMaterial.Icon.cmd_share,
|
||||
@ -168,7 +173,8 @@ open class WebOverlayActivityBase(val forceBasicAgent: Boolean) : KauBaseActivit
|
||||
when (item.itemId) {
|
||||
R.id.action_copy_link -> copyToClipboard(frostWeb.web.url)
|
||||
R.id.action_share -> shareText(frostWeb.web.url)
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
else -> if (!OverlayContext.onOptionsItemSelected(frostWeb.web, item.itemId))
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package com.pitchedapps.frost.enums
|
||||
|
||||
import android.content.Context
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import ca.allanwang.kau.utils.toDrawable
|
||||
import com.mikepenz.iconics.typeface.IIcon
|
||||
import com.pitchedapps.frost.R
|
||||
import com.pitchedapps.frost.facebook.FbItem
|
||||
import com.pitchedapps.frost.web.FrostWebViewCore
|
||||
|
||||
/**
|
||||
* Created by Allan Wang on 2017-09-16.
|
||||
*
|
||||
* Options for [WebOverlayActivityBase] to give more info as to what kind of
|
||||
* overlay is present.
|
||||
*
|
||||
* For now, this is able to add new menu options upon first load
|
||||
*/
|
||||
enum class OverlayContext(private val menuItem: FrostMenuItem?) {
|
||||
|
||||
NOTIFICATION(FrostMenuItem(R.id.action_notification, FbItem.NOTIFICATIONS.icon, R.string.notifications) { webview ->
|
||||
webview.loadUrl(FbItem.NOTIFICATIONS.url, true)
|
||||
}),
|
||||
MESSAGE(FrostMenuItem(R.id.action_messages, FbItem.MESSAGES.icon, R.string.messages) { webview ->
|
||||
webview.loadUrl(FbItem.MESSAGES.url, true)
|
||||
});
|
||||
|
||||
/**
|
||||
* Inject the [menuItem] in the order that they are given at the front of the menu
|
||||
*/
|
||||
fun onMenuCreate(context: Context, menu: Menu) {
|
||||
menuItem?.addToMenu(context, menu, 0)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val values = OverlayContext.values() //save one instance
|
||||
/**
|
||||
* Execute selection call for an item by id
|
||||
* Returns [true] if selection was consumed, [false] otherwise
|
||||
*/
|
||||
fun onOptionsItemSelected(webview: FrostWebViewCore, id: Int): Boolean {
|
||||
val consumer = values.firstOrNull { id == it.menuItem?.id } ?: return false
|
||||
consumer.menuItem!!.onClick(webview)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frame for an injectable menu item
|
||||
*/
|
||||
class FrostMenuItem(
|
||||
val id: Int,
|
||||
val iicon: IIcon,
|
||||
val stringRes: Int,
|
||||
val showAsAction: Int = MenuItem.SHOW_AS_ACTION_ALWAYS,
|
||||
val onClick: (webview: FrostWebViewCore) -> Unit) {
|
||||
fun addToMenu(context: Context, menu: Menu, index: Int) {
|
||||
val item = menu.add(Menu.NONE, id, index, stringRes)
|
||||
item.icon = iicon.toDrawable(context, 18)
|
||||
item.setShowAsAction(showAsAction)
|
||||
}
|
||||
}
|
@ -21,11 +21,9 @@ import com.pitchedapps.frost.BuildConfig
|
||||
import com.pitchedapps.frost.R
|
||||
import com.pitchedapps.frost.activities.FrostWebActivity
|
||||
import com.pitchedapps.frost.dbflow.CookieModel
|
||||
import com.pitchedapps.frost.enums.OverlayContext
|
||||
import com.pitchedapps.frost.facebook.formattedFbUrl
|
||||
import com.pitchedapps.frost.utils.ARG_USER_ID
|
||||
import com.pitchedapps.frost.utils.L
|
||||
import com.pitchedapps.frost.utils.Prefs
|
||||
import com.pitchedapps.frost.utils.withRoundIcon
|
||||
import com.pitchedapps.frost.utils.*
|
||||
import org.jetbrains.anko.runOnUiThread
|
||||
|
||||
/**
|
||||
@ -96,6 +94,7 @@ data class NotificationContent(val data: CookieModel,
|
||||
val text: String,
|
||||
val timestamp: Long,
|
||||
val profileUrl: String) {
|
||||
|
||||
fun createNotification(context: Context) = createNotification(context, FROST_NOTIFICATION_GROUP)
|
||||
|
||||
fun createMessageNotification(context: Context) = createNotification(context, FROST_MESSAGE_NOTIFICATION_GROUP)
|
||||
@ -104,6 +103,8 @@ data class NotificationContent(val data: CookieModel,
|
||||
val intent = Intent(context, FrostWebActivity::class.java)
|
||||
intent.data = Uri.parse(href.formattedFbUrl)
|
||||
intent.putExtra(ARG_USER_ID, data.id)
|
||||
val overlayContext = if (groupPrefix == FROST_MESSAGE_NOTIFICATION_GROUP) OverlayContext.MESSAGE else OverlayContext.NOTIFICATION
|
||||
intent.putExtra(ARG_OVERLAY_CONTEXT, overlayContext)
|
||||
val group = "${groupPrefix}_${data.id}"
|
||||
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
|
||||
val ringtone = if (groupPrefix == FROST_MESSAGE_NOTIFICATION_GROUP) Prefs.messageRingtone else Prefs.notificationRingtone
|
||||
|
@ -41,6 +41,7 @@ const val ARG_URL = "arg_url"
|
||||
const val ARG_USER_ID = "arg_user_id"
|
||||
const val ARG_IMAGE_URL = "arg_image_url"
|
||||
const val ARG_TEXT = "arg_text"
|
||||
const val ARG_OVERLAY_CONTEXT = "arg_overlay_context"
|
||||
|
||||
fun Context.launchNewTask(clazz: Class<out Activity>, cookieList: ArrayList<CookieModel> = arrayListOf(), clearStack: Boolean = false) {
|
||||
startActivity(clazz, clearStack, intentBuilder = {
|
||||
|
@ -1,7 +1,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.pitchedapps.myapplication.MainActivity">
|
||||
tools:context="com.pitchedapps.frost.activities.MainActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_search"
|
||||
|
@ -1,7 +1,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.pitchedapps.myapplication.MainActivity">
|
||||
tools:context="com.pitchedapps.frost.activities.SettingsActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_email"
|
||||
|
@ -1,8 +1,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.pitchedapps.myapplication.MainActivity">
|
||||
|
||||
tools:context="com.pitchedapps.frost.activities.WebOverlayActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_copy_link"
|
||||
@ -14,6 +13,6 @@
|
||||
android:id="@+id/action_share"
|
||||
android:orderInCategory="200"
|
||||
android:title="@string/kau_share"
|
||||
app:showAsAction="always" />
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
||||
|
||||
|
@ -9,4 +9,9 @@
|
||||
<item name="intro_title" type="id" />
|
||||
<item name="intro_image" type="id" />
|
||||
<item name="intro_desc" type="id" />
|
||||
|
||||
<!--Extra menu ids; see OverlayContext-->
|
||||
<item name="action_notification" type="id" />
|
||||
<item name="action_messages" type="id" />
|
||||
<item name="action_frost" type="id" />
|
||||
</resources>
|
@ -15,7 +15,7 @@
|
||||
<item text="Add full support for messaging in overlays. We will dynamically launch new overlays when required to." />
|
||||
<item text="Prevent bad messenger intent from launching" />
|
||||
<item text="Add toggle for recents feed. Aggressive loading removes extra posts that are not really recent, whereas disabling it will show exactly what you get on Facebook" />
|
||||
<item text="" />
|
||||
<item text="Add contextual menu items. Easily go to your full list of notifications or messages from the overlay." />
|
||||
<item text="" />
|
||||
<item text="" />
|
||||
|
||||
|
@ -2,6 +2,11 @@
|
||||
|
||||
## Beta Updates
|
||||
* Almost until release day!
|
||||
* Add full support for messaging in overlays. We will dynamically launch new overlays when required to.
|
||||
* Prevent bad messenger intent from launching
|
||||
* Add toggle for recents feed. Aggressive loading removes extra posts that are not really recent, whereas disabling it will show exactly what you get on Facebook
|
||||
|
||||
## v1.4.13
|
||||
* Prevent image loading from trimming too many characters
|
||||
* Fix most recent mode for news feed
|
||||
* Add link to disable video autoplay in settings > newsfeed
|
||||
|
Loading…
Reference in New Issue
Block a user