Skip to content

Commit

Permalink
Merge branch 'ankidroid:main' into refactor-DatabaseErrorDialog-to-Al…
Browse files Browse the repository at this point in the history
…ertDialog
  • Loading branch information
neeldoshii authored Feb 26, 2024
2 parents b4848d6 + 0ab90ba commit a32b3e6
Show file tree
Hide file tree
Showing 713 changed files with 15,568 additions and 7,499 deletions.
1 change: 1 addition & 0 deletions .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jobs:
"16-multimedia-editor",
"17-model-manager",
"18-standard-models",
"20-search-preference",
"marketdescription",
"ankidroid-titles",
];
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/milestone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.pull_request.number }},
milestone: 51
milestone: 52
});
// graphql query to get referenced issues to merged pull request
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
milestone: 51
milestone: 52
});
}
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
git remote set-url origin git@github.com:$GITHUB_REPOSITORY
shell: bash

- uses: webfactory/ssh-agent@v0.8.0
- uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/sync_translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ jobs:
if (err.status === 422) {
console.log("A PR containing translations sync already exists!");
} else {
console.log("Unexpected error creating pull request: " + err);
throw err;
}
}
6 changes: 4 additions & 2 deletions .github/workflows/tests_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
steps:
- name: Configure Windows Pagefile
uses: al-cheb/configure-pagefile-action@v1.4
if: matrix.os == 'windows-latest'
if: contains(matrix.os, 'windows')
with:
minimum-size: 8GB
maximum-size: 12GB
Expand All @@ -67,6 +67,8 @@ jobs:
# Comment this and the with: above out for performance testing on a branch
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
gradle-home-cache-cleanup: true
# Windows runner currently having cache pollution issues, disable cache for the platform
cache-disabled: ${{ contains(matrix.os, 'windows') }}

- name: Clear Caches Optionally
if: "${{ github.event.inputs.clearCaches != '' }}"
Expand All @@ -90,7 +92,7 @@ jobs:
arguments: jacocoUnitTestReport --daemon

- name: Stop Gradle
if: matrix.os == 'windows-latest'
if: contains(matrix.os, 'windows')
uses: gradle/gradle-build-action@v3
with:
arguments: --stop
Expand Down
1 change: 1 addition & 0 deletions .idea/dictionaries/davidallison.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<w>uint</w>
<w>unbury</w>
<w>unburying</w>
<w>uncatchable</w>
<w>undeletable</w>
<w>underlaid</w>
<w>unflag</w>
Expand Down
24 changes: 15 additions & 9 deletions AnkiDroid/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
// Gradle plugin portal
id 'com.github.triplet.play' version '3.8.6'
id 'com.github.triplet.play' version '3.9.0'
id 'com.android.application'
id 'app.brant.amazonappstorepublisher'
id 'idea'
Expand Down Expand Up @@ -74,8 +74,8 @@ android {
//
// This ensures the correct ordering between the various types of releases (dev < alpha < beta < release) which is
// needed for upgrades to be offered correctly.
versionCode=21700201
versionName="2.17beta1"
versionCode=21800102
versionName="2.18alpha2"
minSdk 23 // also in testlib/build.gradle.kts
// After #13695: change .tests_emulator.yml
targetSdk 33 // also in [api|testlib]/build.gradle.kts and ../robolectricDownloader.gradle
Expand Down Expand Up @@ -319,16 +319,16 @@ dependencies {
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.webkit:webkit:1.9.0'
implementation 'androidx.webkit:webkit:1.10.0'
implementation 'com.google.android.material:material:1.11.0'
implementation 'com.vanniktech:android-image-cropper:4.5.0'
implementation 'org.nanohttpd:nanohttpd:2.3.1'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3"
implementation 'com.squareup:seismic:1.0.3'

// Backend libraries

implementation 'com.google.protobuf:protobuf-kotlin-lite:3.25.2' // This is required when loading from a file
implementation 'com.google.protobuf:protobuf-kotlin-lite:3.25.3' // This is required when loading from a file

Properties localProperties = new Properties()
if (project.rootProject.file('local.properties').exists()) {
Expand All @@ -350,7 +350,7 @@ dependencies {

implementation 'com.afollestad.material-dialogs:core:3.3.0'
implementation 'com.afollestad.material-dialogs:input:3.3.0'
implementation 'org.apache.commons:commons-compress:1.25.0'
implementation 'org.apache.commons:commons-compress:1.26.0'
implementation 'org.apache.commons:commons-collections4:4.4' // SetUniqueList
implementation 'commons-io:commons-io:2.15.1' // FileUtils.contentEquals
implementation 'net.mikehardy:google-analytics-java7:2.0.13'
Expand All @@ -364,7 +364,7 @@ dependencies {
implementation 'com.github.mrudultora:Colorpicker:1.2.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
implementation 'com.github.ByteHamster:SearchPreference:2.5.0'
implementation 'com.github.ByteHamster:SearchPreference:2.5.1'

// Cannot use debugImplementation since classes need to be imported in AnkiDroidApp
// and there's no no-op version for release build. Usage has been disabled for release
Expand Down Expand Up @@ -393,8 +393,14 @@ dependencies {
testImplementation 'org.apache.commons:commons-exec:1.4.0' // obtaining the OS
testImplementation("androidx.fragment:fragment-testing:$fragments_version")
// in a JvmTest we need org.json.JSONObject to not be mocked
testImplementation 'org.json:json:20231013'
testImplementation 'org.json:json:20240205'
testImplementation 'io.github.ivanshafran:shared-preferences-mock:1.2.4'
testImplementation "androidx.test:runner:$androidx_test_version"
testImplementation "androidx.test:rules:$androidx_test_version"
testImplementation "androidx.test.espresso:espresso-core:$espresso_version"
testImplementation("androidx.test.espresso:espresso-contrib:$espresso_version") {
exclude module: "protobuf-lite"
}

androidTestImplementation project(':testlib')

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2024 David Allison <davidallisongithub@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 androidx.core.content.edit
import androidx.test.core.app.ActivityScenario
import com.ichi2.anki.tests.InstrumentedTest
import com.ichi2.anki.testutil.GrantStoragePermission
import com.ichi2.anki.testutil.grantPermissions
import org.junit.Before
import org.junit.Rule
import org.junit.Test

class FilteredDeckOptionsTest : InstrumentedTest() {
@get:Rule
val runtimePermissionRule = grantPermissions(GrantStoragePermission.storagePermission)

@Before
fun before() {
AnkiDroidApp.sharedPrefs().edit {
putBoolean(IntroductionActivity.INTRODUCTION_SLIDES_SHOWN, true)
}
}

@Test
fun canOpenDeckOptions() {
ActivityScenario.launch(DeckPicker::class.java).onActivity { deckPicker ->
val deckId = col.decks.newDyn("Filtered Testing")
deckPicker.showContextMenuDeckOptions(deckId)
}.close()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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.ComponentName
import android.content.Intent
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.ichi2.anki.NoteEditor.Companion.intentLaunchedWithImage
import com.ichi2.anki.tests.InstrumentedTest
import com.ichi2.anki.testutil.GrantStoragePermission
import junit.framework.TestCase.assertFalse
import org.hamcrest.MatcherAssert
import org.hamcrest.Matchers
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import java.util.concurrent.atomic.AtomicReference

@RunWith(AndroidJUnit4::class)
class NoteEditorIntentTest : InstrumentedTest() {
@get:Rule
var runtimePermissionRule: TestRule? = GrantStoragePermission.instance

@get:Rule
var activityRuleIntent: ActivityScenarioRule<NoteEditor>? = ActivityScenarioRule(
noteEditorTextIntent
)

@Test
fun launchActivityWithIntent() {
col
val scenario = activityRuleIntent!!.scenario
scenario.moveToState(Lifecycle.State.RESUMED)

onActivity(scenario) { editor ->
val currentFieldStrings = editor.currentFieldStrings
MatcherAssert.assertThat(currentFieldStrings[0], Matchers.equalTo("sample text"))
}
}

@Test
fun intentLaunchedWithNonImageIntent() {
val intent = Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
}
assertFalse(intentLaunchedWithImage(intent))
}

private val noteEditorTextIntent: Intent
get() {
return Intent(testContext, NoteEditor::class.java).apply {
component = ComponentName(testContext, NoteEditor::class.java)
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "sample text")
}
}

@Throws(Throwable::class)
private fun onActivity(
scenario: ActivityScenario<NoteEditor>,
noteEditorActivityAction: ActivityScenario.ActivityAction<NoteEditor>
) {
val wrapped = AtomicReference<Throwable?>(null)
scenario.onActivity { a: NoteEditor ->
try {
noteEditorActivityAction.perform(a)
} catch (t: Throwable) {
wrapped.set(t)
}
}
wrapped.get()?.let { throw it }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ import com.ichi2.libanki.exception.ConfirmModSchemaException
import com.ichi2.libanki.sched.Scheduler
import com.ichi2.utils.KotlinCleanup
import com.ichi2.utils.emptyStringArray
import net.ankiweb.rsdroid.exceptions.BackendNotFoundException
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
import org.json.JSONObject
import org.junit.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertThrows
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Assume.*
Expand Down Expand Up @@ -122,8 +124,7 @@ class ContentProviderTest : InstrumentedTest() {
// Delete all notes
val remnantNotes = col.findNotes("tag:$TEST_TAG")
if (remnantNotes.isNotEmpty()) {
val noteIds = remnantNotes.toLongArray()
col.remNotes(noteIds)
col.removeNotes(nids = remnantNotes)

assertEquals(
"Check that remnant notes have been deleted",
Expand Down Expand Up @@ -226,19 +227,15 @@ class ContentProviderTest : InstrumentedTest() {
* Check that inserting a note with an invalid modelId returns a reasonable exception
*/
@Test
@KotlinCleanup("assertThrows")
fun testInsertNoteWithBadModelId() {
val invalidModelId = 12
val values = ContentValues().apply {
put(FlashCardsContract.Note.MID, invalidModelId)
put(FlashCardsContract.Note.FLDS, Utils.joinFields(TEST_NOTE_FIELDS))
put(FlashCardsContract.Note.TAGS, TEST_TAG)
}
try {
assertThrows(BackendNotFoundException::class.java) {
contentResolver.insert(FlashCardsContract.Note.CONTENT_URI, values)
fail()
} catch (e: IllegalArgumentException) {
assertThat(e.message, equalTo("Invalid modelId: 12"))
}
}

Expand Down Expand Up @@ -1300,7 +1297,7 @@ class ContentProviderTest : InstrumentedTest() {
fields: Array<String>,
tag: String
): Uri {
val newNote = Note(col.notetypes.get(mid)!!)
val newNote = Note.fromNotetypeId(col, mid)
for (idx in fields.indices) {
newNote.setField(idx, fields[idx])
}
Expand Down
Loading

0 comments on commit a32b3e6

Please sign in to comment.