mirror of https://github.com/Corewala/Buran
Bookmarks dialog behaves like other dialogs
This commit is contained in:
parent
60597a0b1c
commit
fbf13728eb
|
@ -5,10 +5,12 @@ import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatDialog
|
import androidx.appcompat.app.AppCompatDialog
|
||||||
import androidx.appcompat.widget.PopupMenu
|
import androidx.appcompat.widget.PopupMenu
|
||||||
|
import androidx.core.view.MenuCompat
|
||||||
import androidx.core.view.forEach
|
import androidx.core.view.forEach
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.google.android.material.snackbar.BaseTransientBottomBar
|
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_EXPORT_FILE_REQ
|
||||||
import corewala.buran.ui.CREATE_BOOKMARK_IMPORT_FILE_REQ
|
import corewala.buran.ui.CREATE_BOOKMARK_IMPORT_FILE_REQ
|
||||||
import corewala.visible
|
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 org.json.JSONObject
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
|
@ -41,44 +46,45 @@ class BookmarksDialog(
|
||||||
|
|
||||||
setContentView(view)
|
setContentView(view)
|
||||||
|
|
||||||
view.bookmarks_toolbar.setNavigationIcon(R.drawable.vector_close)
|
view.close_tab_dialog.setOnClickListener {
|
||||||
view.bookmarks_toolbar.setNavigationOnClickListener {
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
view.bookmarks_toolbar.menu.forEach { menu ->
|
view.bookmark_overflow.setOnClickListener { menu ->
|
||||||
menu.setOnMenuItemClickListener { item ->
|
val popup = PopupMenu(view.context, view.bookmark_overflow)
|
||||||
when(item.itemId){
|
val inflater: MenuInflater = popup.menuInflater
|
||||||
R.id.menu_action_import_bookmarks -> {
|
inflater.inflate(R.menu.history_overflow_menu, popup.menu)
|
||||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
|
popup.setOnMenuItemClickListener { menuItem ->
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
if(menuItem.itemId == R.id.menu_action_import_bookmarks){
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||||
intent.type = "application/json"
|
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
context.startActivityForResult(intent, CREATE_BOOKMARK_IMPORT_FILE_REQ)
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
}
|
intent.type = "application/json"
|
||||||
R.id.menu_action_export_bookmarks -> {
|
context.startActivityForResult(intent, CREATE_BOOKMARK_IMPORT_FILE_REQ)
|
||||||
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
|
}else if(menuItem.itemId == R.id.menu_action_export_bookmarks){
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
|
||||||
intent.type = "application/json"
|
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
intent.putExtra(Intent.EXTRA_TITLE, "buran_bookmarks.json")
|
intent.type = "application/json"
|
||||||
context.startActivityForResult(intent, CREATE_BOOKMARK_EXPORT_FILE_REQ)
|
intent.putExtra(Intent.EXTRA_TITLE, "buran_bookmarks.json")
|
||||||
}
|
context.startActivityForResult(intent, CREATE_BOOKMARK_EXPORT_FILE_REQ)
|
||||||
else -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
MenuCompat.setGroupDividerEnabled(popup.menu, true)
|
||||||
|
popup.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//None as yet
|
//None as yet
|
||||||
|
/*
|
||||||
view.bookmarks_toolbar.inflateMenu(R.menu.add_bookmarks)
|
view.bookmarks_toolbar.inflateMenu(R.menu.add_bookmarks)
|
||||||
view.bookmarks_toolbar.setOnMenuItemClickListener { _ ->
|
view.bookmarks_toolbar.setOnMenuItemClickListener { _ ->
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
view.bookmarks_recycler.layoutManager = LinearLayoutManager(context)
|
view.bookmarks_recycler.layoutManager = LinearLayoutManager(context)
|
||||||
|
|
||||||
bookmarksAdapter = BookmarksAdapter({ bookmark ->
|
bookmarksAdapter = BookmarksAdapter({ bookmark ->
|
||||||
|
@ -114,7 +120,10 @@ class BookmarksDialog(
|
||||||
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
Handler(Looper.getMainLooper()).post {
|
||||||
when {
|
when {
|
||||||
|
/*
|
||||||
bookmarks.isEmpty() -> view.bookmarks_empty_layout.visible(true)
|
bookmarks.isEmpty() -> view.bookmarks_empty_layout.visible(true)
|
||||||
|
|
||||||
|
*/
|
||||||
else -> bookmarksAdapter.update(bookmarks)
|
else -> bookmarksAdapter.update(bookmarks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,7 +240,9 @@ class BookmarksDialog(
|
||||||
bookmarkDatasource.add(bookmarkEntries.toTypedArray()){
|
bookmarkDatasource.add(bookmarkEntries.toTypedArray()){
|
||||||
bookmarkDatasource.get { bookmarks ->
|
bookmarkDatasource.get { bookmarks ->
|
||||||
Handler(Looper.getMainLooper()).post {
|
Handler(Looper.getMainLooper()).post {
|
||||||
|
|
||||||
view.bookmarks_empty_layout.visible(false)
|
view.bookmarks_empty_layout.visible(false)
|
||||||
|
|
||||||
bookmarksAdapter.update(bookmarks)
|
bookmarksAdapter.update(bookmarks)
|
||||||
when {
|
when {
|
||||||
skipped > 0 -> {
|
skipped > 0 -> {
|
||||||
|
|
|
@ -1,54 +1,71 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<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"/>
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/bookmarks_empty_layout"
|
android:id="@+id/header"
|
||||||
android:visibility="gone"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:paddingTop="@dimen/default_margin">
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:paddingBottom="60dp"
|
|
||||||
android:gravity="center_horizontal">
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageButton
|
||||||
android:layout_width="100dp"
|
android:id="@+id/close_tab_dialog"
|
||||||
android:layout_height="100dp"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/bookmarks_empty"
|
android:layout_centerVertical="true"
|
||||||
android:paddingTop="@dimen/default_margin_big"/>
|
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>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
Loading…
Reference in New Issue