Skip to content

Commit e250a8c

Browse files
Merge branch 'ankidroid:main' into main
2 parents f0fbace + 9bac316 commit e250a8c

6 files changed

Lines changed: 110 additions & 9 deletions

File tree

AnkiDroid/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ dependencies {
418418
implementation libs.androidx.exifinterface
419419
implementation libs.androidx.fragment.ktx
420420
implementation libs.androidx.lifecycle.process
421-
implementation libs.androidx.media
422421
implementation libs.androidx.preference.ktx
423422
implementation libs.androidx.recyclerview
424423
implementation libs.androidx.sqlite.framework

AnkiDroid/src/main/java/com/ichi2/anki/cardviewer/SoundTagPlayer.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
package com.ichi2.anki.cardviewer
1818

1919
import android.content.Context
20-
import android.media.AudioAttributes
2120
import android.media.AudioManager
2221
import android.media.MediaPlayer
2322
import android.net.Uri
2423
import androidx.annotation.CheckResult
24+
import androidx.annotation.OptIn
2525
import androidx.annotation.VisibleForTesting
2626
import androidx.core.net.toUri
27-
import androidx.media.AudioFocusRequestCompat
28-
import androidx.media.AudioManagerCompat
27+
import androidx.media3.common.AudioAttributes
28+
import androidx.media3.common.C.AUDIO_CONTENT_TYPE_MUSIC
29+
import androidx.media3.common.audio.AudioFocusRequestCompat
30+
import androidx.media3.common.audio.AudioManagerCompat
31+
import androidx.media3.common.util.UnstableApi
2932
import com.ichi2.anki.AnkiDroidApp
3033
import com.ichi2.anki.CollectionManager.withCol
3134
import com.ichi2.anki.common.annotations.NeedsTest
@@ -39,6 +42,7 @@ import kotlin.coroutines.resume
3942
import kotlin.coroutines.resumeWithException
4043

4144
/** Player for (`[sound:...]`): [SoundOrVideoTag] */
45+
@OptIn(UnstableApi::class)
4246
@NeedsTest("CardSoundConfig.autoplay should mean that video also isn't played automatically")
4347
class SoundTagPlayer(
4448
private val soundUriBase: String,
@@ -49,7 +53,7 @@ class SoundTagPlayer(
4953
private val music =
5054
AudioAttributes
5155
.Builder()
52-
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
56+
.setContentType(AUDIO_CONTENT_TYPE_MUSIC)
5357
.build()
5458

5559
/**
@@ -118,7 +122,7 @@ class SoundTagPlayer(
118122
} else {
119123
(soundUriBase + Uri.encode(tag.filename)).toUri()
120124
}
121-
setAudioAttributes(music)
125+
setAudioAttributes(music.platformAudioAttributes)
122126
setOnErrorListener { mp, what, extra ->
123127
Timber.w("Media error %d", what)
124128
abandonAudioFocus()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
package com.ichi2.anki.previewer
3+
4+
import androidx.test.core.app.ActivityScenario
5+
import androidx.test.ext.junit.runners.AndroidJUnit4
6+
import com.ichi2.anki.ScreenshotTest
7+
import com.ichi2.anki.browser.IdsFile
8+
import com.ichi2.testutils.createTransientDirectory
9+
import org.junit.Test
10+
import org.junit.runner.RunWith
11+
12+
@RunWith(AndroidJUnit4::class)
13+
class PreviewerScreenshotTest : ScreenshotTest() {
14+
@Test
15+
fun baseState() {
16+
val note = addBasicAndReversedNote()
17+
val intent =
18+
PreviewerFragment.getIntent(
19+
targetContext,
20+
idsFile = IdsFile(createTransientDirectory(), note.cardIds(col)),
21+
currentIndex = 0,
22+
)
23+
24+
ActivityScenario.launch<CardViewerActivity>(intent).use { scenario ->
25+
scenario.onActivity {
26+
captureScreen("base")
27+
}
28+
}
29+
}
30+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
package com.ichi2.anki.previewer
3+
4+
import androidx.test.core.app.ActivityScenario
5+
import androidx.test.ext.junit.runners.AndroidJUnit4
6+
import com.ichi2.anki.NotetypeFile
7+
import com.ichi2.anki.ScreenshotTest
8+
import com.ichi2.testutils.createTransientDirectory
9+
import org.junit.Test
10+
import org.junit.runner.RunWith
11+
12+
@RunWith(AndroidJUnit4::class)
13+
class TemplatePreviewerScreenshotTest : ScreenshotTest() {
14+
@Test
15+
fun baseState() {
16+
val notetype = col.notetypes.basic
17+
val notetypeFile = NotetypeFile(createTransientDirectory(), notetype)
18+
val arguments =
19+
TemplatePreviewerArguments(
20+
notetypeFile = notetypeFile,
21+
fields = listOf("Front", "Back"),
22+
tags = emptyList(),
23+
)
24+
25+
val intent = TemplatePreviewerPage.getIntent(targetContext, arguments)
26+
27+
ActivityScenario.launch<CardViewerActivity>(intent).use { scenario ->
28+
scenario.onActivity {
29+
captureScreen("base")
30+
}
31+
}
32+
}
33+
}

gradle/libs.versions.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ androidxExifinterface = "1.4.2"
4343
androidxFragmentKtx = "1.8.9"
4444
# https://developer.android.com/jetpack/androidx/releases/lifecycle
4545
androidxLifecycleProcess = "2.10.0"
46-
# https://developer.android.com/jetpack/androidx/releases/media
47-
androidxMedia = "1.7.1"
4846
# https://developer.android.com/jetpack/androidx/releases/media3
4947
androidxMedia3 = "1.10.0"
5048
# https://developer.android.com/jetpack/androidx/releases/preference
@@ -146,7 +144,6 @@ androidx-media3-ui = { module = "androidx.media3:media3-ui", version.ref = "andr
146144
androidx-media3-exoplayer-dash = { module = "androidx.media3:media3-exoplayer-dash", version.ref = "androidxMedia3" }
147145
androidx-media3-exoplayer = { module = "androidx.media3:media3-exoplayer", version.ref = "androidxMedia3" }
148146
androidx-preference-ktx = { module = "androidx.preference:preference-ktx", version.ref = "androidxPreferenceKtx" }
149-
androidx-media = { module = "androidx.media:media", version.ref = "androidxMedia" }
150147
androidx-uiautomator = { module = "androidx.test.uiautomator:uiautomator", version.ref = "androidxTestUiAutomator" }
151148
androidx-webkit = { module = "androidx.webkit:webkit", version.ref = "androidxWebkit" }
152149
androidx-viewpager2 = { module = "androidx.viewpager2:viewpager2", version.ref = "androidxViewpager2" }

lint-rules/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Lint Rules Module
2+
3+
This module contains custom Android lint checks for AnkiDroid.
4+
5+
## How to add a new lint check
6+
7+
1. Create a new .kt file in com.ichi2.anki.lint/
8+
2. Create a class that extends Detector
9+
3. Define an Issue object with:
10+
- id - unique identifier
11+
- briefDescription - short summary
12+
- explanation - detailed description
13+
- category - use constants from Category class
14+
- priority - use constants from Priority class
15+
- severity - use constants from Severity class
16+
4. Add the issue to IssueRegistry.kt
17+
18+
See DirectDateFormatDetector.kt for a small example.
19+
Link: https://github.com/ankidroid/Anki-Android/blob/main/lint-rules/src/main/java/com/ichi2/anki/lint/DirectDateFormatDetector.kt
20+
21+
## How to run checks locally
22+
23+
### Terminal
24+
25+
./gradlew :lint-rules:assemble
26+
27+
This refreshes the checks in the IDE. Alternatively, run ./gradlew lint to check the whole codebase.
28+
29+
### Android Studio
30+
31+
1. Make changes in lint-rules/
32+
2. Build -> Rebuild Project
33+
3. Restart Android Studio
34+
4. Analyze -> Run Inspection by Name -> Type "Lint"
35+
36+
## Documentation
37+
38+
Custom Lint Rules Documentation: https://github.com/googlesamples/android-custom-lint-rules

0 commit comments

Comments
 (0)