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 2, 2024
1 parent b803955 commit ee4f6c9
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
18 changes: 17 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,34 @@ 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
import timber.log.Timber

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).setOnMenuItemClickListener {
if (it.itemId == R.id.action_save) {
Timber.i("save item selected")
webView.evaluateJavascript("anki.imageOcclusion.addNote()", null)
}
return@setOnMenuItemClickListener true
}
}

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
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/res/drawable/ic_done.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?attr/colorControlNormal" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>

</vector>
52 changes: 52 additions & 0 deletions AnkiDroid/src/main/res/layout/image_occlusion.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2024 Brayan Oliveira <[email protected]>
~
~ This program is free software; you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by the Free Software
~ Foundation; either version 3 of the License, or (at your option) any later
~ version.
~
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY
~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
~ PARTICULAR PURPOSE. See the GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->
<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>
25 changes: 25 additions & 0 deletions AnkiDroid/src/main/res/menu/image_occlusion.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2024 Brayan Oliveira <[email protected]>
~
~ This program is free software; you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by the Free Software
~ Foundation; either version 3 of the License, or (at your option) any later
~ version.
~
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY
~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
~ PARTICULAR PURPOSE. See the GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_save"
android:icon="@drawable/ic_done"
android:title="@string/save"
app:showAsAction="always"
/>
</menu>

0 comments on commit ee4f6c9

Please sign in to comment.