Search in sources :

Example 51 with START

use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.

the class SchedTest method test_reorderV1.

@Test
public void test_reorderV1() throws Exception {
    Collection col = getColV1();
    // add a note with default deck
    Note note = col.newNote();
    note.setItem("Front", "one");
    col.addNote(note);
    Note note2 = col.newNote();
    note2.setItem("Front", "two");
    col.addNote(note2);
    assertEquals(2, note2.cards().get(0).getDue());
    boolean found = false;
    // 50/50 chance of being reordered
    for (int i = 0; i < 20; i++) {
        col.getSched().randomizeCards(1);
        if (note.cards().get(0).getDue() != note.getId()) {
            found = true;
            break;
        }
    }
    assertTrue(found);
    col.getSched().orderCards(1);
    assertEquals(1, note.cards().get(0).getDue());
    // shifting
    Note note3 = col.newNote();
    note3.setItem("Front", "three");
    col.addNote(note3);
    Note note4 = col.newNote();
    note4.setItem("Front", "four");
    col.addNote(note4);
    assertEquals(1, note.cards().get(0).getDue());
    assertEquals(2, note2.cards().get(0).getDue());
    assertEquals(3, note3.cards().get(0).getDue());
    assertEquals(4, note4.cards().get(0).getDue());
/* todo sortCard
           col.getSched().sortCards(new long [] {note3.cards().get(0).getId(), note4.cards().get(0).getId()}, start=1, shift=true);
           assertEquals(3, note.cards().get(0).getDue());
           assertEquals(4, note2.cards().get(0).getDue());
           assertEquals(1, note3.cards().get(0).getDue());
           assertEquals(2, note4.cards().get(0).getDue());
        */
}
Also used : Note(com.ichi2.libanki.Note) Collection(com.ichi2.libanki.Collection) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 52 with START

use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.

the class TemplateTest method missingExclamation.

@Test
@Config(qualifiers = "en")
public void missingExclamation() {
    // Ankidroid used not to display fields whose name start with !
    HashMap<String, String> context = new HashMap<>();
    String rendered = render("{{!Front}}", context);
    assertThat(rendered, is(notNullValue()));
    assertThat(rendered, containsString("there is no field called '!Front'"));
}
Also used : HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 53 with START

use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.

the class SchedV2 method _moveToDyn.

protected void _moveToDyn(long did, @NonNull List<Long> ids, int start) {
    Deck deck = mCol.getDecks().get(did);
    ArrayList<Object[]> data = new ArrayList<>(ids.size());
    int u = mCol.usn();
    int due = start;
    for (Long id : ids) {
        data.add(new Object[] { did, due, u, id });
        due += 1;
    }
    String queue = "";
    if (!deck.getBoolean("resched")) {
        queue = ", queue = " + Consts.QUEUE_TYPE_REV + "";
    }
    mCol.getDb().executeMany("UPDATE cards SET odid = did, " + "odue = due, did = ?, due = (case when due <= 0 then due else ? end), usn = ? " + queue + " WHERE id = ?", data);
}
Also used : ArrayList(java.util.ArrayList) Deck(com.ichi2.libanki.Deck)

Example 54 with START

use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.

the class SchedV2 method _fillDyn.

/**
 * Whether the filtered deck is empty
 * Overriden
 */
private int _fillDyn(Deck deck) {
    int start = -100000;
    int total = 0;
    List<Long> ids;
    JSONArray terms = deck.getJSONArray("terms");
    for (JSONArray term : terms.jsonArrayIterable()) {
        String search = term.getString(0);
        int limit = term.getInt(1);
        int order = term.getInt(2);
        String orderlimit = _dynOrder(order, limit);
        if (!TextUtils.isEmpty(search.trim())) {
            search = String.format(Locale.US, "(%s)", search);
        }
        search = String.format(Locale.US, "%s -is:suspended -is:buried -deck:filtered", search);
        ids = mCol.findCards(search, new SortOrder.AfterSqlOrderBy(orderlimit));
        if (ids.isEmpty()) {
            return total;
        }
        // move the cards over
        mCol.log(deck.getLong("id"), ids);
        _moveToDyn(deck.getLong("id"), ids, start + total);
        total += ids.size();
    }
    return total;
}
Also used : JSONArray(com.ichi2.utils.JSONArray)

Example 55 with START

use of com.ichi2.anim.ActivityTransitionAnimation.Direction.START in project Anki-Android by ankidroid.

the class IntentHandler method handleFileImport.

private void handleFileImport(Intent intent, Intent reloadIntent, String action) {
    Timber.i("Handling file import");
    ImportResult importResult = ImportUtils.handleFileImport(this, intent);
    // Start DeckPicker if we correctly processed ACTION_VIEW
    if (importResult.isSuccess()) {
        Timber.d("onCreate() import successful");
        reloadIntent.setAction(action);
        reloadIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(reloadIntent);
        AnkiActivity.finishActivityWithFade(this);
    } else {
        Timber.i("File import failed");
        // Don't import the file if it didn't load properly or doesn't have apkg extension
        ImportUtils.showImportUnsuccessfulDialog(this, importResult.getHumanReadableMessage(), true);
    }
}
Also used : ImportResult(com.ichi2.utils.ImportUtils.ImportResult)

Aggregations

Test (org.junit.Test)23 Intent (android.content.Intent)21 JSONObject (com.ichi2.utils.JSONObject)17 Model (com.ichi2.libanki.Model)14 View (android.view.View)13 ArrayList (java.util.ArrayList)13 Bundle (android.os.Bundle)12 Collection (com.ichi2.libanki.Collection)11 Note (com.ichi2.libanki.Note)9 File (java.io.File)9 JSONArray (com.ichi2.utils.JSONArray)8 SharedPreferences (android.content.SharedPreferences)7 TextView (android.widget.TextView)7 EditText (android.widget.EditText)6 Deck (com.ichi2.libanki.Deck)6 Dialog (android.app.Dialog)5 NonNull (androidx.annotation.NonNull)5 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)5 RobolectricTest (com.ichi2.anki.RobolectricTest)5 TaskData (com.ichi2.async.TaskData)5