Comments (10)
Yes. It works as intended. Maybe this is not entirely the right way but first of all, I wanted to display the new decks at the top of the list so that they can be easily discovered. So new decks are always at the top and are sorted by date of creation.
You can learn the sorting logic from this file: https://github.com/tema6120/ForgetMeNot/blob/master/app/src/main/kotlin/com/odnovolov/forgetmenot/presentation/screen/home/DeckPreviewComparator.kt
from forgetmenot.
@tema6120 thanks. will look on it.
from forgetmenot.
@tema5120 what to do if I want to display the decks what user has selected on sort by menu. I tried like this:
return when {
deck1.lastTestedAt == null && deck2.lastTestedAt == null ->
deck1.createdAt.compareTo(deck2.createdAt)
deck1.lastTestedAt == null -> deck1.deckName.compareTo(deck2.deckName)
deck2.lastTestedAt == null -> deck1.deckName.compareTo(deck2.deckName)
deck1.isPinned && deck2.isPinned -> compareRegularly(deck1, deck2)
deck1.isPinned -> -1
deck2.isPinned -> 1
else -> compareRegularly(deck1, deck2)
}
But it only does initial sorting and doesn't obey what user has used in Sort By popup.
from forgetmenot.
If you want to ignore 'new decks' logic:
override fun compare(deck1: RawDeckPreview, deck2: RawDeckPreview): Int {
return when {
deck1.isPinned && deck2.isPinned -> compareRegularly(deck1, deck2)
deck1.isPinned -> -1
deck2.isPinned -> 1
else -> compareRegularly(deck1, deck2)
}
}
If you also want to ignore whether the deck is pinned, do as follows:
override fun compare(deck1: RawDeckPreview, deck2: RawDeckPreview): Int {
return compareRegularly(deck1, deck2)
}
from forgetmenot.
@tema6120 actually i tried that but it was crashing
2021-08-30 10:28:48.425 20484-20484/com.shirshak.grevocabs.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.shirshak.grevocabs.debug, PID: 20484
java.lang.NullPointerException
at com.shirshak.grevocabs.presentation.screen.home.DeckPreviewComparator.compareRegularly(DeckPreviewComparator.kt:25)
at com.shirshak.grevocabs.presentation.screen.home.DeckPreviewComparator.compare(DeckPreviewComparator.kt:15)
at com.shirshak.grevocabs.presentation.screen.home.DeckPreviewComparator.compare(DeckPreviewComparator.kt:7)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.util.TimSort.sort(TimSort.java:234)
at java.util.Arrays.sort(Arrays.java:1424)
at kotlin.collections.ArraysKt___ArraysJvmKt.sortWith(_ArraysJvm.kt:2557)
at kotlin.collections.CollectionsKt___CollectionsKt.sortedWith(_Collections.kt:1043)
at com.shirshak.grevocabs.presentation.screen.home.HomeViewModel$sortedDecksPreview$1.invokeSuspend(HomeViewModel.kt:124)
at com.shirshak.grevocabs.presentation.screen.home.HomeViewModel$sortedDecksPreview$1.invoke(Unknown Source:14)
at kotlinx.coroutines.flow.FlowKt__ZipKt$combine$$inlined$unsafeFlow$1$lambda$1.invokeSuspend(Zip.kt:33)
at kotlinx.coroutines.flow.FlowKt__ZipKt$combine$$inlined$unsafeFlow$1$lambda$1.invoke(Unknown Source:14)
at kotlinx.coroutines.flow.internal.CombineKt$combineInternal$2.invokeSuspend(Combine.kt:79)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
I guess this line is creating the issue.
LastTestedAt -> leftDeck.lastTestedAt!!.compareTo(rightDeck.lastTestedAt!!)
from forgetmenot.
You are right. I should have checked the code.
private fun compareRegularly(deck1: RawDeckPreview, deck2: RawDeckPreview): Int {
val leftDeck = if (deckSorting.direction == Asc) deck1 else deck2
val rightDeck = if (deckSorting.direction == Asc) deck2 else deck1
return when (deckSorting.criterion) {
Name -> leftDeck.deckName.compareTo(rightDeck.deckName)
CreatedAt -> leftDeck.createdAt.compareTo(rightDeck.createdAt)
LastTestedAt -> {
when {
leftDeck.lastTestedAt == null -> -1
rightDeck.lastTestedAt == null -> 1
else -> leftDeck.lastTestedAt.compareTo(rightDeck.lastTestedAt)
}
}
FrequencyOfUse -> leftDeck.averageLaps.compareTo(rightDeck.averageLaps)
Task -> {
when {
leftDeck.numberOfCardsReadyForExercise == null -> -1
rightDeck.numberOfCardsReadyForExercise == null -> 1
else -> {
leftDeck.numberOfCardsReadyForExercise
.compareTo(rightDeck.numberOfCardsReadyForExercise)
}
}
}
}
}
from forgetmenot.
@tema6120 Hi, I created gre vocab flashcard and modified some fonts etc. I have released it in github https://github.com/shirshak55/gre-vocabs.
I would like to release it in playstore. If you don't have any issue let me know. Just wanted to make sure I credit you enough for this app before I publish it in playstores etc..
Thanks.
from forgetmenot.
No, I'm against it. Use my code for personal purposes.
By the way if you fork my project, you should link with my project like this https://github.com/androiddevnotesforks/ForgetMeNot
from forgetmenot.
@tema6120 hmm ok I will not publish it in play store.
from forgetmenot.
Just click on the 'Fork' button at the top-right corner on the project site.
from forgetmenot.
Related Issues (20)
- Just wanted to say Thank You! HOT 2
- Feature Request: Images in cards HOT 2
- More than one Answers for "Spell Check" Mode
- QOL: Generic Sync Option
- QOL: Merge with existing cards instead of duplicating HOT 3
- Curly brackets change case of character to capital
- Feature request: archive HOT 1
- math formula HOT 1
- Multiple choice
- How to update a deck by importing a file? HOT 4
- multiple choice question example import file
- Feature request : subdecks HOT 1
- Feature Request: Image/Audio flashcards
- [Feature request] Mass import
- Add monochrome icon HOT 3
- Export and import progress along with deck
- Kotlin codes are old. HOT 2
- Idea: Support chess training
- Feature Request: Statistics
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from forgetmenot.