Skip to content

Commit

Permalink
enhancement: allow Image occlusion Editor to survive config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
criticalAY authored and mikehardy committed Feb 5, 2024
1 parent 5378d5e commit be6a8c8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@
android:name="com.ichi2.anki.SingleFragmentActivity"
android:exported="false"
/>
<activity
android:name="com.ichi2.anki.ImageOcclusionActivity"
android:exported="false"
android:configChanges="orientation|screenSize"
/>
<activity
android:name="com.ichi2.anki.CardTemplatePreviewer"
android:label="@string/preview_title"
Expand Down
42 changes: 42 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/ImageOcclusionActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2024 Ashish Yadav <mailtoashish693@gmail.com>
*
* 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/>.
*/
package com.ichi2.anki

import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import kotlin.reflect.KClass
import kotlin.reflect.jvm.jvmName

/**
* Handles adding and editing Image Occlusion cards.
*
* Based in [SingleFragmentActivity], but with `configChanges="orientation|screenSize"`
* to avoid unwanted activity recreations
*/
class ImageOcclusionActivity : SingleFragmentActivity() {

companion object {

fun getIntent(context: Context, fragmentClass: KClass<out Fragment>, arguments: Bundle? = null): Intent {
return Intent(context, ImageOcclusionActivity::class.java).apply {
putExtra(FRAGMENT_NAME_EXTRA, fragmentClass.jvmName)
putExtra(FRAGMENT_ARGS_EXTRA, arguments)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import kotlin.reflect.jvm.jvmName
*
* [getIntent] can be used as an easy way to build a [SingleFragmentActivity]
*/
class SingleFragmentActivity : AnkiActivity() {
open class SingleFragmentActivity : AnkiActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
if (showedActivityFailedScreen(savedInstanceState)) {
return
Expand All @@ -60,8 +60,8 @@ class SingleFragmentActivity : AnkiActivity() {
}
}
companion object {
private const val FRAGMENT_NAME_EXTRA = "fragmentName"
private const val FRAGMENT_ARGS_EXTRA = "fragmentArgs"
const val FRAGMENT_NAME_EXTRA = "fragmentName"
const val FRAGMENT_ARGS_EXTRA = "fragmentArgs"

fun getIntent(context: Context, fragmentClass: KClass<out Fragment>, arguments: Bundle? = null): Intent {
return Intent(context, SingleFragmentActivity::class.java).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import android.os.Bundle
import android.webkit.WebView
import androidx.core.os.bundleOf
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.anki.SingleFragmentActivity
import com.ichi2.anki.ImageOcclusionActivity
import org.json.JSONObject

class ImageOcclusion : PageFragment() {
Expand Down Expand Up @@ -60,7 +60,7 @@ class ImageOcclusion : PageFragment() {

fun getIntent(context: Context, kind: String, noteOrNotetypeId: Long, imagePath: String?): Intent {
val arguments = bundleOf(ARG_KEY_KIND to kind, ARG_KEY_ID to noteOrNotetypeId, ARG_KEY_PATH to imagePath)
return SingleFragmentActivity.getIntent(context, ImageOcclusion::class, arguments)
return ImageOcclusionActivity.getIntent(context, ImageOcclusion::class, arguments)
}
}
}
3 changes: 2 additions & 1 deletion AnkiDroid/src/test/java/com/ichi2/testutils/ActivityList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ object ActivityList {
get(ManageNotetypes::class.java),
get(ManageSpaceActivity::class.java),
get(PermissionsActivity::class.java),
get(SingleFragmentActivity::class.java)
get(SingleFragmentActivity::class.java),
get(ImageOcclusionActivity::class.java)
)
}

Expand Down

0 comments on commit be6a8c8

Please sign in to comment.