use of com.ichi2.utils.FunctionalInterfaces.Function in project AnkiChinaAndroid by ankichinateam.
the class BasicTextFieldController method createCloneButton.
/**
* @param layoutTools This creates a button, which will call a dialog, allowing to pick from another note's fields
* one, and use it's value in the current one.
* @param p layout params
*/
private void createCloneButton(LinearLayout layoutTools, LayoutParams p) {
// Makes sense only for two and more fields
if (mNote.getNumberOfFields() > 1) {
// Should be more than one text not empty fields for clone to make
// sense
mPossibleClones = new ArrayList<>();
int numTextFields = 0;
for (int i = 0; i < mNote.getNumberOfFields(); ++i) {
// Sort out non text and empty fields
IField curField = mNote.getField(i);
if (curField == null) {
continue;
}
if (curField.getType() != EFieldType.TEXT) {
continue;
}
if (curField.getText() == null) {
continue;
}
if (curField.getText().length() == 0) {
continue;
}
// as well as the same field
if (curField.getText().contentEquals(mField.getText())) {
continue;
}
// collect clone sources
mPossibleClones.add(curField.getText());
++numTextFields;
}
// Nothing to clone from
if (numTextFields < 1) {
return;
}
Button btnOtherField = new Button(mActivity);
btnOtherField.setText(gtxt(R.string.multimedia_editor_text_field_editing_clone));
layoutTools.addView(btnOtherField, p);
final BasicTextFieldController controller = this;
btnOtherField.setOnClickListener(v -> {
PickStringDialogFragment fragment = new PickStringDialogFragment();
fragment.setChoices(mPossibleClones);
fragment.setOnclickListener(controller);
fragment.setTitle(gtxt(R.string.multimedia_editor_text_field_editing_clone_source));
fragment.show(mActivity.getSupportFragmentManager(), "pick.clone");
// flow continues in the onClick function
});
}
}
use of com.ichi2.utils.FunctionalInterfaces.Function in project AnkiChinaAndroid by ankichinateam.
the class CollectionTask method doInBackgroundRenderBrowserQA.
private TaskData doInBackgroundRenderBrowserQA(TaskData param) {
// TODO: Convert this to accept the following to make thread-safe:
// (Range<Position>, Function<Position, BrowserCard>)
Timber.d("doInBackgroundRenderBrowserQA");
Collection col = getCol();
List<CardBrowser.CardCache> cards = (List<CardBrowser.CardCache>) param.getObjArray()[0];
Integer startPos = (Integer) param.getObjArray()[1];
Integer n = (Integer) param.getObjArray()[2];
int column1Index = (Integer) param.getObjArray()[3];
int column2Index = (Integer) param.getObjArray()[4];
List<Long> invalidCardIds = new ArrayList<>();
// for each specified card in the browser list
for (int i = startPos; i < startPos + n; i++) {
// Stop if cancelled
if (isCancelled()) {
Timber.d("doInBackgroundRenderBrowserQA was aborted");
return null;
}
if (i < 0 || i >= cards.size()) {
continue;
}
CardBrowser.CardCache card;
try {
card = cards.get(i);
} catch (IndexOutOfBoundsException e) {
// we won't reach any more cards.
continue;
}
if (card.isLoaded()) {
// We've already rendered the answer, we don't need to do it again.
continue;
}
// Extract card item
try {
// Ensure that card still exists.
card.getCard();
} catch (WrongId e) {
// #5891 - card can be inconsistent between the deck browser screen and the collection.
// Realistically, we can skip any exception as it's a rendering task which should not kill the
// process
long cardId = card.getId();
Timber.e(e, "Could not process card '%d' - skipping and removing from sight", cardId);
invalidCardIds.add(cardId);
continue;
}
// Update item
card.load(false, column1Index, column2Index);
float progress = (float) i / n * 100;
publishProgress(new TaskData((int) progress));
}
return new TaskData(new Object[] { cards, invalidCardIds });
}
use of com.ichi2.utils.FunctionalInterfaces.Function in project AnkiChinaAndroid by ankichinateam.
the class Sched method _updateCutoff.
/**
* Daily cutoff ************************************************************* **********************************
* This function uses GregorianCalendar so as to be sensitive to leap years, daylight savings, etc.
*/
@Override
public void _updateCutoff() {
Integer oldToday = mToday;
// days since col created
mToday = (int) ((getTime().intTime() - mCol.getCrt()) / SECONDS_PER_DAY);
// end of day cutoff
mDayCutoff = mCol.getCrt() + ((mToday + 1) * SECONDS_PER_DAY);
if (oldToday != mToday) {
mCol.log(mToday, mDayCutoff);
}
// instead
for (Deck deck : mCol.getDecks().all()) {
update(deck);
}
// unbury if the day has rolled over
int unburied = mCol.getConf().optInt("lastUnburied", 0);
if (unburied < mToday) {
SyncStatus.ignoreDatabaseModification(this::unburyCards);
}
}
use of com.ichi2.utils.FunctionalInterfaces.Function in project AnkiChinaAndroid by ankichinateam.
the class SchedV2 method _updateCutoff.
/**
* Daily cutoff ************************************************************* **********************************
* This function uses GregorianCalendar so as to be sensitive to leap years, daylight savings, etc.
*/
/* Overriden: other way to count time*/
public void _updateCutoff() {
Integer oldToday = mToday == null ? 0 : mToday;
// days since col created
mToday = _daysSinceCreation();
// end of day cutoff
mDayCutoff = _dayCutoff();
if (oldToday != mToday) {
mCol.log(mToday, mDayCutoff);
}
// instead
for (Deck deck : mCol.getDecks().all()) {
update(deck);
}
// unbury if the day has rolled over
int unburied = mCol.getConf().optInt("lastUnburied", 0);
if (unburied < mToday) {
SyncStatus.ignoreDatabaseModification(this::unburyCards);
mCol.getConf().put("lastUnburied", mToday);
}
}
use of com.ichi2.utils.FunctionalInterfaces.Function in project Anki-Android by ankidroid.
the class Sched method _updateCutoff.
/**
* Daily cutoff ************************************************************* **********************************
* This function uses GregorianCalendar so as to be sensitive to leap years, daylight savings, etc.
*/
@Override
public void _updateCutoff() {
Integer oldToday = mToday;
// days since col created
mToday = (int) ((getTime().intTime() - mCol.getCrt()) / SECONDS_PER_DAY);
// end of day cutoff
mDayCutoff = mCol.getCrt() + ((mToday + 1) * SECONDS_PER_DAY);
if (!mToday.equals(oldToday)) {
mCol.log(mToday, mDayCutoff);
}
// instead
for (Deck deck : mCol.getDecks().all()) {
update(deck);
}
// unbury if the day has rolled over
int unburied = mCol.get_config("lastUnburied", 0);
if (unburied < mToday) {
SyncStatus.ignoreDatabaseModification(this::unburyCards);
}
}
Aggregations