Giter Club home page Giter Club logo

Comments (10)

tema6120 avatar tema6120 commented on June 1, 2024

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.

shirshak55 avatar shirshak55 commented on June 1, 2024

@tema6120 thanks. will look on it.

from forgetmenot.

shirshak55 avatar shirshak55 commented on June 1, 2024

@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.

tema6120 avatar tema6120 commented on June 1, 2024

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.

shirshak55 avatar shirshak55 commented on June 1, 2024

@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.

tema6120 avatar tema6120 commented on June 1, 2024

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.

shirshak55 avatar shirshak55 commented on June 1, 2024

@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.

tema6120 avatar tema6120 commented on June 1, 2024

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.

shirshak55 avatar shirshak55 commented on June 1, 2024

@tema6120 hmm ok I will not publish it in play store.

from forgetmenot.

tema6120 avatar tema6120 commented on June 1, 2024

Just click on the 'Fork' button at the top-right corner on the project site.

from forgetmenot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.