Skip to content

Commit

Permalink
feat: move IO add button to toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Apr 1, 2024
1 parent b803955 commit 31cd836
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
19 changes: 18 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/pages/ImageOcclusion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,35 @@ package com.ichi2.anki.pages
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.webkit.WebView
import androidx.core.os.bundleOf
import com.google.android.material.appbar.MaterialToolbar
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.anki.ImageOcclusionActivity
import com.ichi2.anki.R
import org.json.JSONObject

class ImageOcclusion : PageFragment() {
class ImageOcclusion : PageFragment(R.layout.image_occlusion) {

override val title: String
get() = TR.notetypesImageOcclusionName()
override val pageName = "image-occlusion"

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

view.findViewById<MaterialToolbar>(R.id.toolbar).apply {
setOnMenuItemClickListener {
if (it.itemId == R.id.action_add) {
webView.evaluateJavascript("anki.imageOcclusion.addNote()", null)
}
return@setOnMenuItemClickListener true
}
setNavigationOnClickListener { requireActivity().onBackPressedDispatcher.onBackPressed() }
}
}

override fun onCreateWebViewClient(savedInstanceState: Bundle?): PageWebViewClient {
val kind = arguments?.getString(ARG_KEY_KIND) ?: throw Exception("missing kind")
val id = arguments?.getLong(ARG_KEY_ID) ?: throw Exception("missing ID")
Expand Down
37 changes: 37 additions & 0 deletions AnkiDroid/src/main/res/layout/image_occlusion.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/webview">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:navigationContentDescription="@string/abc_action_bar_up_description"
app:navigationIcon="?attr/homeAsUpIndicator"
app:menu="@menu/image_occlusion"/>

</com.google.android.material.appbar.AppBarLayout>

<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/app_bar"
app:layout_constraintBottom_toBottomOf="parent"
android:visibility="invisible"
tools:visibility="visible"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
10 changes: 10 additions & 0 deletions AnkiDroid/src/main/res/menu/image_occlusion.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_add"
android:icon="@drawable/ic_add"
android:title="@string/menu_add"
app:showAsAction="always"
/>
</menu>

0 comments on commit 31cd836

Please sign in to comment.