Skip to content

Commit

Permalink
Merge branch 'master' into js-api-version
Browse files Browse the repository at this point in the history
  • Loading branch information
krmanik authored Jul 4, 2020
2 parents 870f155 + a16a795 commit d127e55
Show file tree
Hide file tree
Showing 342 changed files with 1,773 additions and 1,370 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
- ANDROID_TOOLS_URL="https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip"
- EMU_FLAVOR=default # use google_apis flavor if no default flavor emulator
- LOCALE="NONE"
- GRAVIS_REPO="https://github.com/mikehardy/Gravis-CI.git"
- GRAVIS_REPO="https://github.com/DanySK/Gravis-CI.git"
- GRAVIS="$HOME/gravis"
- JDK="1.8"
- TOOLS=${ANDROID_HOME}/tools
Expand Down Expand Up @@ -87,7 +87,7 @@ before_install:
# It should not make assumptions about os platform or desired tool installation

# Set up JDK 8 for Android SDK - Java is universally needed: codacy, unit tests, emulators
- travis_retry git clone --single-branch --branch resilience --depth 1 $GRAVIS_REPO $GRAVIS
- travis_retry git clone --depth 1 $GRAVIS_REPO $GRAVIS
- export TARGET_JDK="${JDK}"
- JDK="1.8"
- source $GRAVIS/install-jdk
Expand Down
4 changes: 2 additions & 2 deletions AnkiDroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,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=21200120
versionName="2.12alpha20"
versionCode=21300100
versionName="2.13alpha00"
minSdkVersion 16
//noinspection OldTargetApi - also performed in api/build.fradle
targetSdkVersion 28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testDBCorruption() throws Exception {


// Test fixture that lets us inspect corruption handler status
public class TestDB extends DB {
public static class TestDB extends DB {

private boolean databaseIsCorrupt = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testLogin() {
}


public class TestTaskListener implements Connection.TaskListener {
public static class TestTaskListener implements Connection.TaskListener {

private Connection.Payload mPayload;
private boolean mDisconnectedCalled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
import static com.ichi2.anki.cardviewer.CardAppearance.calculateDynamicFontSize;
import static com.ichi2.anki.cardviewer.ViewerCommand.*;
import static com.ichi2.anki.reviewer.CardMarker.*;
import static com.ichi2.async.CollectionTask.TASK_TYPE.*;

@SuppressWarnings({"PMD.AvoidThrowingRawExceptionTypes","PMD.FieldDeclarationsShouldBeAtStartOfClass"})
public abstract class AbstractFlashcardViewer extends NavigationDrawerActivity implements ReviewerUi, CommandProcessor {
Expand Down Expand Up @@ -1085,23 +1086,23 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
note type could have lead to the card being deleted */
if (data != null && data.hasExtra("reloadRequired")) {
getCol().getSched().deferReset();
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_ANSWER_CARD, mAnswerCardHandler(false),
CollectionTask.launchCollectionTask(ANSWER_CARD, mAnswerCardHandler(false),
new CollectionTask.TaskData(null, 0));
}

if (requestCode == EDIT_CURRENT_CARD) {
if (resultCode == RESULT_OK) {
// content of note was changed so update the note and current card
Timber.i("AbstractFlashcardViewer:: Saving card...");
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_UPDATE_NOTE, mUpdateCardHandler,
CollectionTask.launchCollectionTask(UPDATE_NOTE, mUpdateCardHandler,
new CollectionTask.TaskData(sEditorCard, true));
} else if (resultCode == RESULT_CANCELED && !(data!=null && data.hasExtra("reloadRequired"))) {
// nothing was changed by the note editor so just redraw the card
redrawCard();
}
} else if (requestCode == DECK_OPTIONS && resultCode == RESULT_OK) {
getCol().getSched().deferReset();
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_ANSWER_CARD, mAnswerCardHandler(false),
CollectionTask.launchCollectionTask(ANSWER_CARD, mAnswerCardHandler(false),
new CollectionTask.TaskData(null, 0));
}
if (!mDisableClipboard) {
Expand Down Expand Up @@ -1191,7 +1192,7 @@ private void resumeTimer() {

protected void undo() {
if (isUndoAvailable()) {
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_UNDO, mAnswerCardHandler(false));
CollectionTask.launchCollectionTask(UNDO, mAnswerCardHandler(false));
}
}

Expand Down Expand Up @@ -1344,7 +1345,7 @@ protected void answerCard(int ease) {
mSoundPlayer.stopSounds();
mCurrentEase = ease;

CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_ANSWER_CARD, mAnswerCardHandler(true),
CollectionTask.launchCollectionTask(ANSWER_CARD, mAnswerCardHandler(true),
new CollectionTask.TaskData(mCurrentCard, mCurrentEase));
}

Expand Down Expand Up @@ -2624,7 +2625,7 @@ protected boolean isUndoAvailable() {
/**
* Provides a hook for calling "alert" from javascript. Useful for debugging your javascript.
*/
public final class AnkiDroidWebChromeClient extends WebChromeClient {
public static final class AnkiDroidWebChromeClient extends WebChromeClient {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Timber.i("AbstractFlashcardViewer:: onJsAlert: %s", message);
Expand Down Expand Up @@ -3057,7 +3058,7 @@ protected void onFlag(Card card, @FlagDef int flag) {

protected void dismiss(Collection.DismissType type) {
blockControls(false);
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_DISMISS, mDismissCardHandler,
CollectionTask.launchCollectionTask(DISMISS, mDismissCardHandler,
new CollectionTask.TaskData(new Object[]{mCurrentCard, type}));
}

Expand Down Expand Up @@ -3451,7 +3452,7 @@ void handleUrlFromJavascript(String url) {

@VisibleForTesting
void loadInitialCard() {
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_ANSWER_CARD, mAnswerCardHandler(false),
CollectionTask.launchCollectionTask(ANSWER_CARD, mAnswerCardHandler(false),
new CollectionTask.TaskData(null, 0));
}

Expand Down Expand Up @@ -3551,6 +3552,7 @@ public int ankiGetCardInterval() {
}

@JavascriptInterface
@Consts.CARD_QUEUE
public int ankiGetCardQueue() {
return mCurrentCard.getQueue();
}
Expand Down
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ public void onCreate() {
}
Timber.tag(TAG);

Timber.d("Startup - Application Start");

// analytics after ACRA, they both install UncaughtExceptionHandlers but Analytics chains while ACRA does not
UsageAnalytics.initialize(this);
if (BuildConfig.DEBUG) {
Expand Down
45 changes: 23 additions & 22 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import java.util.regex.Pattern;

import timber.log.Timber;
import static com.ichi2.async.CollectionTask.TASK_TYPE.*;

public class CardBrowser extends NavigationDrawerActivity implements
DeckDropDownAdapter.SubtitleListener {
Expand Down Expand Up @@ -676,8 +677,8 @@ private void openNoteEditorForCurrentlySelectedNote() {
protected void onStop() {
Timber.d("onStop()");
// cancel rendering the question and answer, which has shared access to mCards
CollectionTask.cancelTask(CollectionTask.TASK_TYPE_SEARCH_CARDS);
CollectionTask.cancelTask(CollectionTask.TASK_TYPE_RENDER_BROWSER_QA);
CollectionTask.cancelTask(SEARCH_CARDS);
CollectionTask.cancelTask(RENDER_BROWSER_QA);
super.onStop();
if (!isFinishing()) {
WidgetStatus.update(this);
Expand Down Expand Up @@ -862,7 +863,7 @@ private void updateMultiselectMenu() {
}

if (!mCheckedCardPositions.isEmpty()) {
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_CHECK_CARD_SELECTION,
CollectionTask.launchCollectionTask(CHECK_CARD_SELECTION,
mCheckSelectedCardsHandler,
new CollectionTask.TaskData(new Object[]{mCheckedCardPositions, getCards()}));
}
Expand All @@ -884,7 +885,7 @@ private boolean hasSelectedAllCards() {


private void flagTask (int flag) {
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_DISMISS_MULTI,
CollectionTask.launchCollectionTask(DISMISS_MULTI,
mFlagCardHandler,
new CollectionTask.TaskData(new Object[]{getSelectedCardIds(), Collection.DismissType.FLAG, new Integer (flag)}));
}
Expand Down Expand Up @@ -978,7 +979,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

case R.id.action_delete_card:
if (mInMultiSelectMode) {
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_DISMISS_MULTI,
CollectionTask.launchCollectionTask(DISMISS_MULTI,
mDeleteNoteHandler,
new CollectionTask.TaskData(new Object[]{getSelectedCardIds(), Collection.DismissType.DELETE_NOTE_MULTI}));

Expand All @@ -989,15 +990,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;

case R.id.action_mark_card:
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_DISMISS_MULTI,
CollectionTask.launchCollectionTask(DISMISS_MULTI,
mMarkCardHandler,
new CollectionTask.TaskData(new Object[]{getSelectedCardIds(), Collection.DismissType.MARK_NOTE_MULTI}));

return true;


case R.id.action_suspend_card:
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_DISMISS_MULTI,
CollectionTask.launchCollectionTask(DISMISS_MULTI,
mSuspendCardHandler,
new CollectionTask.TaskData(new Object[]{getSelectedCardIds(), Collection.DismissType.SUSPEND_CARD_MULTI}));

Expand Down Expand Up @@ -1037,7 +1038,7 @@ public void onClick(DialogInterface dialog, int which) {

case R.id.action_undo:
if (getCol().undoAvailable()) {
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_UNDO, mUndoHandler);
CollectionTask.launchCollectionTask(UNDO, mUndoHandler);
}
return true;
case R.id.action_select_none:
Expand Down Expand Up @@ -1073,7 +1074,7 @@ public void onClick(DialogInterface dialog, int which) {
dialog.setArgs(title, message);
Runnable confirm = () -> {
Timber.i("CardBrowser:: ResetProgress button pressed");
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_DISMISS_MULTI, mResetProgressCardHandler,
CollectionTask.launchCollectionTask(DISMISS_MULTI, mResetProgressCardHandler,
new CollectionTask.TaskData(new Object[]{getSelectedCardIds(), Collection.DismissType.RESET_CARDS}));
};
dialog.setConfirm(confirm);
Expand All @@ -1085,7 +1086,7 @@ public void onClick(DialogInterface dialog, int which) {

long[] selectedCardIds = getSelectedCardIds();
FunctionalInterfaces.Consumer<Integer> consumer = newDays ->
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_DISMISS_MULTI,
CollectionTask.launchCollectionTask(DISMISS_MULTI,
mRescheduleCardHandler,
new TaskData(new Object[]{selectedCardIds, Collection.DismissType.RESCHEDULE_CARDS, newDays}));

Expand Down Expand Up @@ -1124,7 +1125,7 @@ public void onClick(DialogInterface dialog, int which) {
getString(R.string.reposition_card_dialog_message),
5);
repositionDialog.setCallbackRunnable(days ->
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_DISMISS_MULTI, mRepositionCardHandler,
CollectionTask.launchCollectionTask(DISMISS_MULTI, mRepositionCardHandler,
new CollectionTask.TaskData(new Object[] {cardIds, Collection.DismissType.REPOSITION_CARDS, days}))
);
showDialogFragment(repositionDialog);
Expand Down Expand Up @@ -1153,7 +1154,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == EDIT_CARD && resultCode != RESULT_CANCELED) {
Timber.i("CardBrowser:: CardBrowser: Saving card...");
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_UPDATE_NOTE, mUpdateCardHandler,
CollectionTask.launchCollectionTask(UPDATE_NOTE, mUpdateCardHandler,
new CollectionTask.TaskData(sCardBrowserCard, false));
} else if (requestCode == ADD_NOTE && resultCode == RESULT_OK) {
if (mSearchView != null) {
Expand Down Expand Up @@ -1239,8 +1240,8 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {

private void searchCards() {
// cancel the previous search & render tasks if still running
CollectionTask.cancelTask(CollectionTask.TASK_TYPE_SEARCH_CARDS);
CollectionTask.cancelTask(CollectionTask.TASK_TYPE_RENDER_BROWSER_QA);
CollectionTask.cancelTask(SEARCH_CARDS);
CollectionTask.cancelTask(RENDER_BROWSER_QA);
String searchText;
if (mSearchTerms == null) {
mSearchTerms = "";
Expand All @@ -1262,7 +1263,7 @@ private void searchCards() {
int numCardsToRender = (int) Math.ceil(mCardsListView.getHeight()/
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics())) + 5;
// Perform database query to get all card ids
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_SEARCH_CARDS, mSearchCardsHandler, new CollectionTask.TaskData(
CollectionTask.launchCollectionTask(SEARCH_CARDS, mSearchCardsHandler, new CollectionTask.TaskData(
new Object[] {searchText, ((mOrder != CARD_ORDER_NONE)), numCardsToRender}));
}
}
Expand Down Expand Up @@ -1465,7 +1466,7 @@ protected void actualPostExecute(CollectionTask.TaskData result) {
mUndoSnackbar = UIUtils.showSnackbar(CardBrowser.this, String.format(getString(R.string.changed_deck_message), deckName), SNACKBAR_DURATION, R.string.undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_UNDO, mUndoHandler);
CollectionTask.launchCollectionTask(UNDO, mUndoHandler);
}
}, mCardsListView, null);
}
Expand Down Expand Up @@ -1647,7 +1648,7 @@ protected void actualPostExecute(CollectionTask.TaskData result) {
mUndoSnackbar = UIUtils.showSnackbar(CardBrowser.this, getString(R.string.deleted_message), SNACKBAR_DURATION, R.string.undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_UNDO, mUndoHandler);
CollectionTask.launchCollectionTask(UNDO, mUndoHandler);
}
}, mCardsListView, null);
}
Expand Down Expand Up @@ -1860,8 +1861,8 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
long currentTime = SystemClock.elapsedRealtime ();
if ((currentTime - mLastRenderStart > 300 || lastVisibleItem >= totalItemCount)) {
mLastRenderStart = currentTime;
CollectionTask.cancelTask(CollectionTask.TASK_TYPE_RENDER_BROWSER_QA);
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_RENDER_BROWSER_QA, mRenderQAHandler,
CollectionTask.cancelTask(RENDER_BROWSER_QA);
CollectionTask.launchCollectionTask(RENDER_BROWSER_QA, mRenderQAHandler,
new CollectionTask.TaskData(new Object[]{getCards(), firstVisibleItem, visibleItemCount}));
}
}
Expand All @@ -1875,7 +1876,7 @@ public void onScrollStateChanged(AbsListView listView, int scrollState) {
if (scrollState == SCROLL_STATE_IDLE) {
int startIdx = listView.getFirstVisiblePosition();
int numVisible = listView.getLastVisiblePosition() - startIdx;
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_RENDER_BROWSER_QA, mRenderQAHandler,
CollectionTask.launchCollectionTask(RENDER_BROWSER_QA, mRenderQAHandler,
new CollectionTask.TaskData(new Object[]{getCards(), startIdx - 5, 2 * numVisible + 5}));
}
}
Expand Down Expand Up @@ -2237,7 +2238,7 @@ void clearCardData(int position) {

@VisibleForTesting(otherwise = VisibleForTesting.NONE)
void rerenderAllCards() {
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_RENDER_BROWSER_QA, mRenderQAHandler,
CollectionTask.launchCollectionTask(RENDER_BROWSER_QA, mRenderQAHandler,
new CollectionTask.TaskData(new Object[]{getCards(), 0, mCards.size()-1}));
}

Expand Down Expand Up @@ -2296,7 +2297,7 @@ public List<Long> getCheckedCardIds() {
@VisibleForTesting(otherwise = VisibleForTesting.NONE) //should only be called from changeDeck()
void executeChangeCollectionTask(long[] ids, long newDid) {
mNewDid = newDid; //line required for unit tests, not necessary, but a noop in regular call.
CollectionTask.launchCollectionTask(CollectionTask.TASK_TYPE_DISMISS_MULTI, mChangeDeckHandler,
CollectionTask.launchCollectionTask(DISMISS_MULTI, mChangeDeckHandler,
new TaskData(new Object[]{ids, Collection.DismissType.CHANGE_DECK_MULTI, newDid}));
}

Expand Down
Loading

0 comments on commit d127e55

Please sign in to comment.