All dialogs now use proper toolbars

This commit is contained in:
Corewala 2022-01-08 17:10:58 -05:00
parent 42ad53708d
commit a4ecd82004
12 changed files with 136 additions and 274 deletions

View File

@ -5,12 +5,10 @@ import android.content.Intent
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.view.MenuInflater
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatDialog
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.MenuCompat
import androidx.core.view.forEach
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.BaseTransientBottomBar
@ -22,9 +20,6 @@ import corewala.buran.io.database.bookmarks.BookmarksDatasource
import corewala.buran.ui.CREATE_BOOKMARK_EXPORT_FILE_REQ
import corewala.buran.ui.CREATE_BOOKMARK_IMPORT_FILE_REQ
import corewala.visible
import kotlinx.android.synthetic.main.dialog_about.view.*
import kotlinx.android.synthetic.main.dialog_bookmarks.view.close_tab_dialog
import kotlinx.android.synthetic.main.dialog_history.view.*
import org.json.JSONObject
import java.io.BufferedReader
import java.io.InputStreamReader
@ -46,45 +41,44 @@ class BookmarksDialog(
setContentView(view)
view.close_tab_dialog.setOnClickListener {
view.bookmarks_toolbar.setNavigationIcon(R.drawable.vector_close)
view.bookmarks_toolbar.setNavigationOnClickListener {
dismiss()
}
view.bookmark_overflow.setOnClickListener { menu ->
val popup = PopupMenu(view.context, view.bookmark_overflow)
val inflater: MenuInflater = popup.menuInflater
inflater.inflate(R.menu.history_overflow_menu, popup.menu)
popup.setOnMenuItemClickListener { menuItem ->
if(menuItem.itemId == R.id.menu_action_import_bookmarks){
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.type = "application/json"
context.startActivityForResult(intent, CREATE_BOOKMARK_IMPORT_FILE_REQ)
}else if(menuItem.itemId == R.id.menu_action_export_bookmarks){
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = "application/json"
intent.putExtra(Intent.EXTRA_TITLE, "buran_bookmarks.json")
context.startActivityForResult(intent, CREATE_BOOKMARK_EXPORT_FILE_REQ)
view.bookmarks_toolbar.menu.forEach { menu ->
menu.setOnMenuItemClickListener { item ->
when(item.itemId){
R.id.menu_action_import_bookmarks -> {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.type = "application/json"
context.startActivityForResult(intent, CREATE_BOOKMARK_IMPORT_FILE_REQ)
}
R.id.menu_action_export_bookmarks -> {
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = "application/json"
intent.putExtra(Intent.EXTRA_TITLE, "buran_bookmarks.json")
context.startActivityForResult(intent, CREATE_BOOKMARK_EXPORT_FILE_REQ)
}
else -> {
}
}
true
}
MenuCompat.setGroupDividerEnabled(popup.menu, true)
popup.show()
}
//None as yet
/*
view.bookmarks_toolbar.inflateMenu(R.menu.add_bookmarks)
view.bookmarks_toolbar.setOnMenuItemClickListener { _ ->
true
}
*/
view.bookmarks_recycler.layoutManager = LinearLayoutManager(context)
bookmarksAdapter = BookmarksAdapter({ bookmark ->
@ -120,10 +114,7 @@ class BookmarksDialog(
Handler(Looper.getMainLooper()).post {
when {
/*
bookmarks.isEmpty() -> view.bookmarks_empty_layout.visible(true)
*/
else -> bookmarksAdapter.update(bookmarks)
}
}
@ -240,9 +231,7 @@ class BookmarksDialog(
bookmarkDatasource.add(bookmarkEntries.toTypedArray()){
bookmarkDatasource.get { bookmarks ->
Handler(Looper.getMainLooper()).post {
view.bookmarks_empty_layout.visible(false)
bookmarksAdapter.update(bookmarks)
when {
skipped > 0 -> {

View File

@ -1,20 +1,27 @@
package corewala.buran.ui.content_image
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.view.MenuInflater
import android.view.View
import androidx.appcompat.app.AppCompatDialog
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.forEach
import kotlinx.android.synthetic.main.dialog_content_image.view.*
import corewala.buran.R
import corewala.buran.io.GemState
import corewala.buran.ui.CREATE_BOOKMARK_EXPORT_FILE_REQ
import corewala.buran.ui.CREATE_BOOKMARK_IMPORT_FILE_REQ
import kotlinx.android.synthetic.main.dialog_bookmarks.view.*
import kotlinx.android.synthetic.main.dialog_content_text.view.*
import java.io.FileOutputStream
object ImageDialog {
fun show(context: Context, state: GemState.ResponseImage, onDownloadRequest: (state: GemState.ResponseImage) -> Unit){
val dialog = AppCompatDialog(context, R.style.AppTheme)
val view = View.inflate(context, R.layout.dialog_content_image, null)
@ -22,24 +29,24 @@ object ImageDialog {
view.image_view.setImageURI(state.cacheUri)
view.close_image_content_dialog.setOnClickListener {
view.image_toolbar.setNavigationIcon(R.drawable.vector_close)
view.image_toolbar.setNavigationOnClickListener {
dialog.dismiss()
}
view.image_overflow.setOnClickListener {
val overflowMenu = PopupMenu(context, view.image_overflow)
val inflater: MenuInflater = overflowMenu.menuInflater
inflater.inflate(R.menu.image_overflow_menu, overflowMenu.menu)
overflowMenu.setOnMenuItemClickListener { menuItem ->
if(menuItem.itemId == R.id.image_overflow_save_image){
onDownloadRequest(state)
view.image_toolbar.menu.forEach { menu ->
menu.setOnMenuItemClickListener { item ->
when(item.itemId){
R.id.image_overflow_save_image -> {
onDownloadRequest(state)
}
else -> {
}
}
true
}
overflowMenu.show()
}
dialog.show()
}

View File

@ -6,6 +6,7 @@ import androidx.appcompat.app.AppCompatDialog
import kotlinx.android.synthetic.main.dialog_content_text.view.*
import corewala.buran.R
import corewala.buran.io.GemState
import kotlinx.android.synthetic.main.dialog_bookmarks.view.*
object TextDialog {
@ -17,11 +18,13 @@ object TextDialog {
view.text_content.text = state.content
view.close_text_content_dialog.setOnClickListener {
view.text_toolbar.setNavigationIcon(R.drawable.vector_close)
view.text_toolbar.setNavigationOnClickListener {
dialog.dismiss()
}
dialog.show()
}
}

View File

@ -12,6 +12,7 @@ import kotlinx.android.synthetic.main.dialog_about.view.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import corewala.buran.R
import kotlinx.android.synthetic.main.dialog_content_text.view.*
import java.lang.StringBuilder
import java.security.SecureRandom
import java.security.Security
@ -27,7 +28,8 @@ object AboutDialog {
val view = View.inflate(context, R.layout.dialog_about, null)
dialog.setContentView(view)
view.close_tab_dialog.setOnClickListener {
view.about_toolbar.setNavigationIcon(R.drawable.vector_close)
view.about_toolbar.setNavigationOnClickListener {
dialog.dismiss()
}

View File

@ -3,49 +3,52 @@ package corewala.buran.ui.modals_menus.history
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.view.MenuInflater
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatDialog
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.MenuCompat
import androidx.core.view.forEach
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.dialog_about.view.close_tab_dialog
import kotlinx.android.synthetic.main.dialog_history.view.*
import corewala.buran.R
import corewala.buran.io.database.history.BuranHistory
import kotlinx.android.synthetic.main.dialog_bookmarks.view.*
object HistoryDialog {
fun show(context: Context, history: BuranHistory, onHistoryItem: (address: String) -> Unit){
val dialog = AppCompatDialog(context, R.style.AppTheme)
val view = View.inflate(context, R.layout.dialog_history, null)
dialog.setContentView(view)
view.close_tab_dialog.setOnClickListener {
view.history_toolbar.setNavigationIcon(R.drawable.vector_close)
view.history_toolbar.setNavigationOnClickListener {
dialog.dismiss()
}
view.history_overflow.setOnClickListener {
val popup = PopupMenu(view.context, view.history_overflow)
val inflater: MenuInflater = popup.menuInflater
inflater.inflate(R.menu.history_overflow_menu, popup.menu)
popup.setOnMenuItemClickListener { menuItem ->
if(menuItem.itemId == R.id.history_overflow_clear_history){
history.clear {
Handler(Looper.getMainLooper()).post {
dialog.dismiss()
Toast.makeText(context, context.getString(R.string.history_cleared), Toast.LENGTH_SHORT).show()
view.history_toolbar.menu.forEach { menu ->
menu.setOnMenuItemClickListener { item ->
when(item.itemId){
R.id.menu_action_clear_history -> {
history.clear {
Handler(Looper.getMainLooper()).post {
Toast.makeText(context, context.getString(R.string.history_cleared), Toast.LENGTH_SHORT).show()
}
}
}
}else if(menuItem.itemId == R.id.history_overflow_clear_runtime_cache){
dialog.dismiss()
Toast.makeText(context, context.getString(R.string.runtime_cache_cleared), Toast.LENGTH_SHORT).show()
R.id.menu_action_clear_runtime_cache -> {
Toast.makeText(context, context.getString(R.string.runtime_cache_cleared), Toast.LENGTH_SHORT).show()
}
else -> {
}
}
true
}
MenuCompat.setGroupDividerEnabled(popup.menu, true)
popup.show()
}
view.history_toolbar.setOnMenuItemClickListener { _ ->
true
}
view.history_recycler.layoutManager = LinearLayoutManager(context)

View File

@ -1,42 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:tools="http://schemas.android.com/tools">
<androidx.appcompat.widget.Toolbar
android:id="@+id/about_toolbar"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/default_margin"
android:layout_height="@dimen/bar_height"
app:title="@string/about"/>
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/default_margin">
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/close_tab_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_close" android:layout_marginTop="@dimen/button_margin"
android:layout_marginStart="@dimen/button_margin" android:layout_marginEnd="@dimen/button_margin"
android:layout_marginBottom="@dimen/button_margin"/>
<android.widget.TextView
android:id="@+id/header_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/close_tab_dialog"
android:layout_marginLeft="@dimen/screen_margin"
android:textSize="@dimen/h3_text_size"
android:text="@string/about"/>
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header">
android:layout_below="@+id/about_toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -118,8 +97,6 @@
android:alpha="0.5"
android:background="?attr/colorOnSurface" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -2,52 +2,21 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:id="@+id/header"
<androidx.appcompat.widget.Toolbar
android:id="@+id/bookmarks_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/default_margin">
android:layout_marginTop="@dimen/default_margin"
android:layout_height="@dimen/bar_height"
app:menu="@menu/bookmark_overflow_menu"
app:title="@string/bookmarks"/>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/close_tab_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_close" android:layout_marginTop="@dimen/button_margin"
android:layout_marginStart="@dimen/button_margin" android:layout_marginEnd="@dimen/button_margin"
android:layout_marginBottom="@dimen/button_margin"/>
<android.widget.TextView
android:id="@+id/header_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/close_tab_dialog"
android:layout_marginLeft="@dimen/screen_margin"
android:textSize="@dimen/h3_text_size"
android:text="@string/bookmarks"/>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/bookmark_overflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_overflow" android:layout_marginTop="@dimen/button_margin"
android:layout_marginStart="@dimen/button_margin" android:layout_marginEnd="@dimen/button_margin"
android:layout_marginBottom="@dimen/button_margin"/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/bookmarks_recycler"
android:layout_below="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:layout_below="@+id/bookmarks_toolbar"/>
<RelativeLayout
android:id="@+id/bookmarks_empty_layout"

View File

@ -1,52 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<corewala.buran.ui.content_image.TouchImageView
android:id="@+id/image_view"
android:scaleType="centerInside"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
/>
<RelativeLayout
android:id="@+id/header"
android:id="@+id/image_view"
android:scaleType="centerInside"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/default_margin">
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
/>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/close_image_content_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_margin="@dimen/button_margin"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_close"/>
<android.widget.TextView
android:id="@+id/header_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="48dp"
android:textSize="24sp"
android:text="@string/image"/>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/image_overflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_margin="@dimen/button_margin"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_overflow"/>
</RelativeLayout>
<androidx.appcompat.widget.Toolbar
android:id="@+id/image_toolbar"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/default_margin"
android:layout_height="@dimen/bar_height"
app:menu="@menu/image_overflow_menu"
app:title="@string/image"/>
</RelativeLayout>

View File

@ -1,53 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/default_margin">
<androidx.appcompat.widget.Toolbar
android:id="@+id/text_toolbar"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/default_margin"
android:layout_height="@dimen/bar_height"
app:title="@string/text"/>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/close_text_content_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_close" android:layout_marginTop="@dimen/button_margin"
android:layout_marginStart="@dimen/button_margin" android:layout_marginEnd="@dimen/button_margin"
android:layout_marginBottom="@dimen/button_margin"/>
<android.widget.TextView
android:id="@+id/header_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/close_text_content_dialog"
android:layout_marginLeft="@dimen/screen_margin"
android:textSize="@dimen/h3_text_size"
android:text="@string/text"/>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/history_overflow"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_margin="@dimen/button_margin"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_overflow" />
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/default_margin"
android:layout_below="@+id/header">
android:layout_below="@+id/text_toolbar">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/text_content"
@ -56,6 +24,6 @@
android:textSize="@dimen/default_text_size"
android:textIsSelectable="true"/>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>

View File

@ -1,51 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/default_margin">
<androidx.appcompat.widget.Toolbar
android:id="@+id/history_toolbar"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/default_margin"
android:layout_height="@dimen/bar_height"
app:menu="@menu/history_overflow_menu"
app:title="@string/history"/>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/close_tab_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_close" android:layout_marginTop="@dimen/button_margin"
android:layout_marginStart="@dimen/button_margin" android:layout_marginEnd="@dimen/button_margin"
android:layout_marginBottom="@dimen/button_margin"/>
<android.widget.TextView
android:id="@+id/header_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/close_tab_dialog"
android:layout_marginLeft="@dimen/screen_margin"
android:textSize="@dimen/h3_text_size"
android:text="@string/history"/>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/history_overflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/vector_overflow" android:layout_marginTop="@dimen/button_margin"
android:layout_marginStart="@dimen/button_margin" android:layout_marginEnd="@dimen/button_margin"
android:layout_marginBottom="@dimen/button_margin"/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/history_recycler"
android:layout_below="@+id/header"
android:layout_below="@+id/history_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

View File

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/history_overflow_clear_history"
android:title="@string/clear_history" />
<item android:id="@+id/history_overflow_clear_runtime_cache"
android:title="@string/clear_cache" />
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_action_clear_history"
android:title="@string/clear_history"
app:showAsAction="never"/>
<item android:id="@+id/menu_action_clear_runtime_cache"
android:title="@string/clear_cache"
app:showAsAction="never"/>
</menu>