Skip to content

Commit cd94ddb

Browse files
BrayanDSOmikehardy
authored andcommitted
feat: move IO add button to toolbar
1 parent 00dd397 commit cd94ddb

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/pages/ImageOcclusion.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,34 @@ package com.ichi2.anki.pages
1818
import android.content.Context
1919
import android.content.Intent
2020
import android.os.Bundle
21+
import android.view.View
2122
import android.webkit.WebView
2223
import androidx.core.os.bundleOf
24+
import com.google.android.material.appbar.MaterialToolbar
2325
import com.ichi2.anki.CollectionManager.TR
2426
import com.ichi2.anki.ImageOcclusionActivity
27+
import com.ichi2.anki.R
2528
import org.json.JSONObject
29+
import timber.log.Timber
2630

27-
class ImageOcclusion : PageFragment() {
31+
class ImageOcclusion : PageFragment(R.layout.image_occlusion) {
2832

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

37+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
38+
super.onViewCreated(view, savedInstanceState)
39+
40+
view.findViewById<MaterialToolbar>(R.id.toolbar).setOnMenuItemClickListener {
41+
if (it.itemId == R.id.action_save) {
42+
Timber.i("save item selected")
43+
webView.evaluateJavascript("anki.imageOcclusion.addNote()", null)
44+
}
45+
return@setOnMenuItemClickListener true
46+
}
47+
}
48+
3349
override fun onCreateWebViewClient(savedInstanceState: Bundle?): PageWebViewClient {
3450
val kind = arguments?.getString(ARG_KEY_KIND) ?: throw Exception("missing kind")
3551
val id = arguments?.getLong(ARG_KEY_ID) ?: throw Exception("missing ID")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<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">
2+
3+
<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"/>
4+
5+
</vector>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (c) 2024 Brayan Oliveira <[email protected]>
4+
~
5+
~ This program is free software; you can redistribute it and/or modify it under
6+
~ the terms of the GNU General Public License as published by the Free Software
7+
~ Foundation; either version 3 of the License, or (at your option) any later
8+
~ version.
9+
~
10+
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY
11+
~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12+
~ PARTICULAR PURPOSE. See the GNU General Public License for more details.
13+
~
14+
~ You should have received a copy of the GNU General Public License along with
15+
~ this program. If not, see <http://www.gnu.org/licenses/>.
16+
-->
17+
<androidx.constraintlayout.widget.ConstraintLayout
18+
xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:app="http://schemas.android.com/apk/res-auto"
20+
xmlns:tools="http://schemas.android.com/tools"
21+
android:id="@+id/root_layout"
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent">
24+
25+
<com.google.android.material.appbar.AppBarLayout
26+
android:id="@+id/app_bar"
27+
android:layout_width="match_parent"
28+
android:layout_height="wrap_content"
29+
app:layout_constraintTop_toTopOf="parent"
30+
app:layout_constraintBottom_toTopOf="@id/webview">
31+
32+
<com.google.android.material.appbar.MaterialToolbar
33+
android:id="@+id/toolbar"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
app:navigationContentDescription="@string/abc_action_bar_up_description"
37+
app:navigationIcon="?attr/homeAsUpIndicator"
38+
app:menu="@menu/image_occlusion"/>
39+
40+
</com.google.android.material.appbar.AppBarLayout>
41+
42+
<WebView
43+
android:id="@+id/webview"
44+
android:layout_width="match_parent"
45+
android:layout_height="0dp"
46+
app:layout_constraintTop_toBottomOf="@id/app_bar"
47+
app:layout_constraintBottom_toBottomOf="parent"
48+
android:visibility="invisible"
49+
tools:visibility="visible"
50+
/>
51+
52+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (c) 2024 Brayan Oliveira <[email protected]>
4+
~
5+
~ This program is free software; you can redistribute it and/or modify it under
6+
~ the terms of the GNU General Public License as published by the Free Software
7+
~ Foundation; either version 3 of the License, or (at your option) any later
8+
~ version.
9+
~
10+
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY
11+
~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12+
~ PARTICULAR PURPOSE. See the GNU General Public License for more details.
13+
~
14+
~ You should have received a copy of the GNU General Public License along with
15+
~ this program. If not, see <http://www.gnu.org/licenses/>.
16+
-->
17+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto">
19+
<item
20+
android:id="@+id/action_save"
21+
android:icon="@drawable/ic_done"
22+
android:title="@string/save"
23+
app:showAsAction="always"
24+
/>
25+
</menu>

0 commit comments

Comments
 (0)