pull/1172/head
parent
9c60381310
commit
751b0d234c
@ -0,0 +1,86 @@ |
||||
package io.legado.app.ui.book.toc |
||||
|
||||
import android.os.Bundle |
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.fragment.app.FragmentManager |
||||
import androidx.lifecycle.lifecycleScope |
||||
import io.legado.app.R |
||||
import io.legado.app.base.BaseDialogFragment |
||||
import io.legado.app.data.appDb |
||||
import io.legado.app.data.entities.Bookmark |
||||
import io.legado.app.databinding.DialogBookmarkBinding |
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding |
||||
import kotlinx.coroutines.Dispatchers.IO |
||||
import kotlinx.coroutines.launch |
||||
import kotlinx.coroutines.withContext |
||||
|
||||
class BookmarkDialog : BaseDialogFragment() { |
||||
|
||||
companion object { |
||||
|
||||
fun start(fragmentManager: FragmentManager, bookmark: Bookmark) { |
||||
BookmarkDialog().apply { |
||||
arguments = Bundle().apply { |
||||
putParcelable("bookmark", bookmark) |
||||
} |
||||
}.show(fragmentManager, "bookMarkDialog") |
||||
} |
||||
|
||||
} |
||||
|
||||
private val binding by viewBinding(DialogBookmarkBinding::bind) |
||||
|
||||
override fun onStart() { |
||||
super.onStart() |
||||
dialog?.window?.setLayout( |
||||
ViewGroup.LayoutParams.MATCH_PARENT, |
||||
ViewGroup.LayoutParams.WRAP_CONTENT |
||||
) |
||||
} |
||||
|
||||
override fun onCreateView( |
||||
inflater: LayoutInflater, |
||||
container: ViewGroup?, |
||||
savedInstanceState: Bundle? |
||||
): View? { |
||||
return inflater.inflate(R.layout.dialog_bookmark, container) |
||||
} |
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
||||
val bookmark = arguments?.getParcelable<Bookmark>("bookmark") |
||||
bookmark ?: let { |
||||
dismiss() |
||||
return |
||||
} |
||||
binding.run { |
||||
tvChapterName.text = bookmark.chapterName |
||||
editBookText.setText(bookmark.bookText) |
||||
editContent.setText(bookmark.content) |
||||
tvCancel.setOnClickListener { |
||||
dismiss() |
||||
} |
||||
tvOk.setOnClickListener { |
||||
bookmark.bookText = editBookText.text?.toString() ?: "" |
||||
bookmark.content = editContent.text?.toString() ?: "" |
||||
lifecycleScope.launch { |
||||
withContext(IO) { |
||||
appDb.bookmarkDao.insert(bookmark) |
||||
} |
||||
dismiss() |
||||
} |
||||
} |
||||
tvFooterLeft.setOnClickListener { |
||||
lifecycleScope.launch { |
||||
withContext(IO) { |
||||
appDb.bookmarkDao.delete(bookmark) |
||||
} |
||||
dismiss() |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -1,48 +1,107 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:layout_marginTop="48dp" |
||||
android:layout_marginBottom="48dp" |
||||
android:overScrollMode="ifContentScrolls"> |
||||
android:layout_height="wrap_content" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:orientation="vertical"> |
||||
|
||||
<LinearLayout |
||||
<androidx.appcompat.widget.Toolbar |
||||
android:id="@+id/tool_bar" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical"> |
||||
android:theme="?attr/actionBarStyle" |
||||
app:title="@string/bookmark" |
||||
app:popupTheme="@style/AppTheme.PopupOverlay" |
||||
app:titleTextAppearance="@style/ToolbarTitle" /> |
||||
|
||||
<io.legado.app.ui.widget.text.TextInputLayout |
||||
<TextView |
||||
android:id="@+id/tv_chapter_name" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="16dp" |
||||
android:paddingRight="16dp" |
||||
android:textColor="@color/primaryText" /> |
||||
|
||||
<androidx.core.widget.NestedScrollView |
||||
android:layout_width="match_parent" |
||||
android:layout_height="0dp" |
||||
android:layout_weight="1"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="16dp" |
||||
android:paddingTop="3dp" |
||||
android:paddingRight="16dp"> |
||||
android:orientation="vertical" |
||||
android:padding="16dp"> |
||||
|
||||
<io.legado.app.ui.widget.text.EditText |
||||
android:id="@+id/edit_book_text" |
||||
<io.legado.app.ui.widget.text.TextInputLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:maxLines="6" |
||||
android:hint="@string/content" /> |
||||
android:paddingTop="3dp"> |
||||
|
||||
</io.legado.app.ui.widget.text.TextInputLayout> |
||||
<io.legado.app.ui.widget.text.EditText |
||||
android:id="@+id/edit_book_text" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:hint="@string/content" /> |
||||
|
||||
<io.legado.app.ui.widget.text.TextInputLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="16dp" |
||||
android:paddingTop="3dp" |
||||
android:paddingRight="16dp"> |
||||
</io.legado.app.ui.widget.text.TextInputLayout> |
||||
|
||||
<io.legado.app.ui.widget.text.EditText |
||||
android:id="@+id/edit_view" |
||||
<io.legado.app.ui.widget.text.TextInputLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:maxLines="6" |
||||
android:hint="@string/note_content" /> |
||||
android:paddingTop="3dp"> |
||||
|
||||
<io.legado.app.ui.widget.text.EditText |
||||
android:id="@+id/edit_content" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:hint="@string/note_content" /> |
||||
|
||||
</io.legado.app.ui.widget.text.TextInputLayout> |
||||
|
||||
</LinearLayout> |
||||
|
||||
</androidx.core.widget.NestedScrollView> |
||||
|
||||
</io.legado.app.ui.widget.text.TextInputLayout> |
||||
<com.google.android.flexbox.FlexboxLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:paddingLeft="12dp" |
||||
android:paddingRight="12dp" |
||||
app:flexWrap="wrap" |
||||
app:justifyContent="space_between"> |
||||
|
||||
<io.legado.app.ui.widget.text.AccentTextView |
||||
android:id="@+id/tv_footer_left" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:padding="12dp" |
||||
android:text="@string/delete" |
||||
tools:ignore="RtlHardcoded" /> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="horizontal"> |
||||
|
||||
<io.legado.app.ui.widget.text.AccentTextView |
||||
android:id="@+id/tv_cancel" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:padding="12dp" |
||||
android:text="@string/cancel" |
||||
tools:ignore="RtlHardcoded" /> |
||||
|
||||
<io.legado.app.ui.widget.text.AccentTextView |
||||
android:id="@+id/tv_ok" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:padding="12dp" |
||||
android:text="@string/ok" |
||||
tools:ignore="RtlHardcoded" /> |
||||
|
||||
</LinearLayout> |
||||
</LinearLayout> |
||||
|
||||
</ScrollView> |
||||
</com.google.android.flexbox.FlexboxLayout> |
||||
</LinearLayout> |
||||
|
Loading…
Reference in new issue