Skip to content

Commit

Permalink
feat(new reviewer): flag
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed May 27, 2024
1 parent 371908a commit 0e702a7
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.lifecycle.lifecycleScope
import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.button.MaterialButton
import com.ichi2.anki.AbstractFlashcardViewer.Companion.RESULT_NO_MORE_CARDS
import com.ichi2.anki.Flag
import com.ichi2.anki.NoteEditor
import com.ichi2.anki.R
import com.ichi2.anki.cardviewer.CardMediaPlayer
Expand Down Expand Up @@ -121,6 +122,14 @@ class ReviewerFragment :
R.id.action_open_deck_options -> launchDeckOptions()
R.id.action_suspend_card -> viewModel.suspendCard()
R.id.action_suspend_note -> viewModel.suspendNote()
R.id.action_flag_zero -> viewModel.setFlag(Flag.NONE)
R.id.action_flag_one -> viewModel.setFlag(Flag.RED)
R.id.action_flag_two -> viewModel.setFlag(Flag.ORANGE)
R.id.action_flag_three -> viewModel.setFlag(Flag.GREEN)
R.id.action_flag_four -> viewModel.setFlag(Flag.BLUE)
R.id.action_flag_five -> viewModel.setFlag(Flag.PINK)
R.id.action_flag_six -> viewModel.setFlag(Flag.TURQUOISE)
R.id.action_flag_seven -> viewModel.setFlag(Flag.PURPLE)
}
return true
}
Expand Down Expand Up @@ -197,6 +206,21 @@ class ReviewerFragment :
suspendItem.isVisible = true
}
}

menu.findItem(R.id.action_flag_zero).title = Flag.NONE.displayName()
menu.findItem(R.id.action_flag_one).title = Flag.RED.displayName()
menu.findItem(R.id.action_flag_two).title = Flag.ORANGE.displayName()
menu.findItem(R.id.action_flag_three).title = Flag.GREEN.displayName()
menu.findItem(R.id.action_flag_four).title = Flag.BLUE.displayName()
menu.findItem(R.id.action_flag_five).title = Flag.PINK.displayName()
menu.findItem(R.id.action_flag_six).title = Flag.TURQUOISE.displayName()
menu.findItem(R.id.action_flag_seven).title = Flag.PURPLE.displayName()

// TODO show that the card is marked somehow when the menu item is overflowed or not shown
viewModel.flagCodeFlow.flowWithLifecycle(lifecycle)
.collectLatestIn(lifecycleScope) { flagCode ->
menu.findItem(R.id.action_flag).setIcon(Flag.fromCode(flagCode).drawableRes)
}
}

private val noteEditorLauncher =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import anki.frontend.SetSchedulingStatesRequest
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.Ease
import com.ichi2.anki.Flag
import com.ichi2.anki.NoteEditor
import com.ichi2.anki.asyncIO
import com.ichi2.anki.cardviewer.CardMediaPlayer
Expand Down Expand Up @@ -62,6 +63,7 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
}
var isQueueFinishedFlow = MutableSharedFlow<Boolean>()
val isMarkedFlow = MutableStateFlow(false)
val flagCodeFlow = MutableStateFlow(Flag.NONE.code)
val actionFeedbackFlow = MutableSharedFlow<String>()
val canBuryNoteFlow = MutableStateFlow(true)
val canSuspendNoteFlow = MutableStateFlow(true)
Expand Down Expand Up @@ -128,6 +130,16 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
}
}

fun setFlag(flag: Flag) {
launchCatchingIO {
val card = currentCard.await()
undoableOp {
setUserFlagForCards(listOf(card.id), flag.code)
}
flagCodeFlow.emit(flag.code)
}
}

fun onStateMutationCallback() {
statesMutated = true
}
Expand Down Expand Up @@ -310,6 +322,7 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
showQuestion()
loadAndPlaySounds(CardSide.QUESTION)
updateMarkedStatus()
flagCodeFlow.emit(card.userFlag())
canBuryNoteFlow.emit(isBuryNoteAvailable(card))
canSuspendNoteFlow.emit(isSuspendNoteAvailable(card))
}
Expand Down
42 changes: 41 additions & 1 deletion AnkiDroid/src/main/res/menu/reviewer2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,47 @@
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/action_flag"
android:title="@string/menu_flag_card"
android:icon="@drawable/ic_flag_transparent"
app:showAsAction="never" >
<menu>
<item
android:id="@+id/action_flag_zero"
tools:title="No Flag"/>
<item
android:id="@+id/action_flag_one"
tools:title="Red"
android:icon="@drawable/ic_flag_red"/>
<item
android:id="@+id/action_flag_two"
tools:title="Orange"
android:icon="@drawable/ic_flag_orange"/>
<item
android:id="@+id/action_flag_three"
tools:title="Green"
android:icon="@drawable/ic_flag_green"/>
<item
android:id="@+id/action_flag_four"
tools:title="Blue"
android:icon="@drawable/ic_flag_blue"/>
<item
android:id="@+id/action_flag_five"
tools:title="Pink"
android:icon="@drawable/ic_flag_pink"/>
<item
android:id="@+id/action_flag_six"
tools:title="Turquoise"
android:icon="@drawable/ic_flag_turquoise"/>
<item
android:id="@+id/action_flag_seven"
tools:title="Purple"
android:icon="@drawable/ic_flag_purple"/>
</menu>
</item>
<item
android:id="@+id/action_mark"
android:icon="@drawable/ic_star_border_white"
Expand Down

0 comments on commit 0e702a7

Please sign in to comment.