diff options
author | Allan Wang <me@allanwang.ca> | 2017-07-08 03:03:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-08 03:03:55 -0400 |
commit | b10a745c7f0f46f4f014e1ba7fa71172d7442b83 (patch) | |
tree | ef2516b69fb04ec0f565c5bb569fd5d80b7bd262 /app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt | |
parent | 6adfc496374eb88919f70a240eb15a726d2c18e0 (diff) | |
download | frost-b10a745c7f0f46f4f014e1ba7fa71172d7442b83.tar.gz frost-b10a745c7f0f46f4f014e1ba7fa71172d7442b83.tar.bz2 frost-b10a745c7f0f46f4f014e1ba7fa71172d7442b83.zip |
Dev-1.1.7 (#39) - feature overload + context menuv1.2
* Address some crashlytics issues
* Add text scaling
* Kau fixes and cleanup
* WIP formatter
* Create in house url formatter
* Update context menu
* Update themes
* Test proguard without R
* Implement sharing and clean up context menu
* Disable viewpager swipe on long press
* Test keeping lib strings
* Update changelog and proguard
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt new file mode 100644 index 00000000..67c20a5a --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt @@ -0,0 +1,45 @@ +package com.pitchedapps.frost.utils + +import android.content.Context +import ca.allanwang.kau.utils.copyToClipboard +import ca.allanwang.kau.utils.shareText +import ca.allanwang.kau.utils.string +import com.pitchedapps.frost.MainActivity +import com.pitchedapps.frost.R + +/** + * Created by Allan Wang on 2017-07-07. + */ +fun Context.showWebContextMenu(wc: WebContext) { + + var title = wc.url + title = title.substring(title.indexOf("m/") + 1) //just so if defaults to 0 in case it's not .com/ + if (title.length > 100) title = title.substring(0, 100) + '\u2026' + + materialDialogThemed { + title(title) + items(WebContextType.values.map { this@showWebContextMenu.string(it.textId) }) + itemsCallback { + _, _, position, _ -> + WebContextType[position].onClick(this@showWebContextMenu, wc) + } + dismissListener { + //showing the dialog interrupts the touch down event, so we must ensure that the viewpager's swipe is enabled + (this@showWebContextMenu as? MainActivity)?.viewPager?.enableSwipe = true + } + } +} + +class WebContext(val url: String, val text: String) + +enum class WebContextType(val textId: Int, val onClick: (c: Context, wc: WebContext) -> Unit) { + COPY_LINK(R.string.copy_link, { c, wc -> c.copyToClipboard(wc.url) }), + COPY_TEXT(R.string.copy_text, { c, wc -> c.copyToClipboard(wc.text) }), + SHARE_LINK(R.string.share_link, { c, wc -> c.shareText(wc.url) }) + ; + + companion object { + val values = values() + operator fun get(index: Int) = values[index] + } +}
\ No newline at end of file |