1
0
Fork 0
mirror of https://git.sr.ht/~oppen/ariane synced 2024-12-27 02:10:30 +00:00

link contextual popup implemented

This commit is contained in:
Öppen 2020-08-18 11:40:10 +01:00
parent 0765d85e52
commit 4ea369610a
5 changed files with 50 additions and 2 deletions

View file

@ -1,5 +1,8 @@
package oppen.tva.ui
import android.R.attr.label
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Intent
import android.net.Uri
import android.os.Bundle
@ -8,11 +11,13 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar
import oppen.alert
import oppen.tva.R
import oppen.tva.databinding.ActivityTvaBinding
import oppen.tva.io.TvaState
import oppen.tva.io.history.CacheInterface
import oppen.tva.ui.tabs.NewTabPopup
import oppen.tva.ui.tabs.TabsDialog
import oppen.visibleRetainingSpace
@ -28,7 +33,19 @@ class TvaActivity : AppCompatActivity() {
R.id.link_menu_open_in_new_tab -> {
model.newTab(uri)
}
R.id.link_menu_copy -> "Not implemented yet".alert(this)
R.id.link_menu_copy -> {
val clipboard = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText(getString(R.string.gemini_address), uri.toString())
clipboard.setPrimaryClip(clip)
Snackbar.make(binding.root, getString(R.string.address_copied_to_clipboard), Snackbar.LENGTH_SHORT).setAction(R.string.share) {
Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, uri.toString())
type = "text/plain"
startActivity(Intent.createChooser(this, null))
}
}.show()
}
}
}
}else{

View file

@ -0,0 +1,22 @@
package oppen.tva.ui.overflow
import android.view.MenuInflater
import android.view.View
import androidx.appcompat.widget.PopupMenu
import oppen.tva.R
class OverflowPopup {
fun show(view: View?, onMenuOption: (menuId: Int) -> Unit){
if(view != null) {
val popup = PopupMenu(view.context, view)
val inflater: MenuInflater = popup.menuInflater
inflater.inflate(R.menu.overflow_menu, popup.menu)
popup.setOnMenuItemClickListener { menuItem ->
onMenuOption(menuItem.itemId)
true
}
popup.show()
}
}
}

View file

@ -1,4 +1,4 @@
package oppen.tva.ui
package oppen.tva.ui.tabs
import android.view.MenuInflater
import android.view.View

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/overflow_menu_about"
android:title="@string/about" />
</menu>

View file

@ -3,4 +3,8 @@
<string name="gemini_protocol">gemini://</string>
<string name="open_in_new_tab">Open in new tab</string>
<string name="copy_address">Copy address</string>
<string name="about">About</string>
<string name="address_copied_to_clipboard">Link copied to clipboard</string>
<string name="gemini_address">Gemini address</string>
<string name="share">Share</string>
</resources>