mirror of
https://github.com/Corewala/Buran
synced 2025-03-15 08:29:15 +00:00
Bookmarks dialog behaves like other dialogs
This commit is contained in:
parent
60597a0b1c
commit
fbf13728eb
2 changed files with 89 additions and 61 deletions
|
@ -5,10 +5,12 @@ 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
|
||||
|
@ -20,6 +22,9 @@ 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
|
||||
|
@ -41,44 +46,45 @@ class BookmarksDialog(
|
|||
|
||||
setContentView(view)
|
||||
|
||||
view.bookmarks_toolbar.setNavigationIcon(R.drawable.vector_close)
|
||||
view.bookmarks_toolbar.setNavigationOnClickListener {
|
||||
view.close_tab_dialog.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
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 -> {
|
||||
|
||||
}
|
||||
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)
|
||||
}
|
||||
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 ->
|
||||
|
@ -114,7 +120,10 @@ class BookmarksDialog(
|
|||
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
when {
|
||||
/*
|
||||
bookmarks.isEmpty() -> view.bookmarks_empty_layout.visible(true)
|
||||
|
||||
*/
|
||||
else -> bookmarksAdapter.update(bookmarks)
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +240,9 @@ 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 -> {
|
||||
|
|
|
@ -1,54 +1,71 @@
|
|||
<?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:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/bookmarks_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginTop="@dimen/default_margin"
|
||||
android:layout_height="@dimen/bar_height"
|
||||
app:menu="@menu/bookmark_import_export"
|
||||
app:title="@string/bookmarks"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/bookmarks_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/bookmarks_toolbar"/>
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/bookmarks_empty_layout"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/header"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_centerInParent="true"
|
||||
android:paddingBottom="60dp"
|
||||
android:gravity="center_horizontal">
|
||||
android:paddingTop="@dimen/default_margin">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
<androidx.appcompat.widget.AppCompatImageButton
|
||||
android:id="@+id/close_tab_dialog"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/bookmarks_empty"
|
||||
android:paddingTop="@dimen/default_margin_big"/>
|
||||
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"/>
|
||||
|
||||
<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"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/bookmarks_empty_layout"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_centerInParent="true"
|
||||
android:paddingBottom="60dp"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/bookmarks_empty"
|
||||
android:paddingTop="@dimen/default_margin_big"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
</RelativeLayout>
|
Loading…
Add table
Reference in a new issue