oppia / oppia-android

A free, online & offline learning platform to make quality education accessible for all.
https://www.oppia.org
Apache License 2.0
309 stars 509 forks source link

Create a generic utility for filtering enums #3146

Open anandwana001 opened 3 years ago

anandwana001 commented 3 years ago

Is your feature request related to a problem? Please describe. Currently, in all our enum files, we usually use similar items filtering.

Some examples of filtering include: https://github.com/oppia/oppia-android/blob/d0c8b81566c956c6edf6a7c19c14f8c8391dd939/app/src/main/java/org/oppia/android/app/survey/surveyitemviewmodel/UserTypeItemsViewModel.kt#L146

https://github.com/oppia/oppia-android/blob/d0c8b81566c956c6edf6a7c19c14f8c8391dd939/domain/src/main/java/org/oppia/android/domain/oppialogger/analytics/PerformanceMetricsController.kt#L132

https://github.com/oppia/oppia-android/blob/d0c8b81566c956c6edf6a7c19c14f8c8391dd939/app/src/main/java/org/oppia/android/app/topic/lessons/TopicLessonsFragmentPresenter.kt#L162

Describe the solution you'd like Generalize filtering which can be used by all the enum.

Describe alternatives you've considered

interface EnumWithKey<T : Enum<T>, K> {
  val T.key: K
}
inline fun <reified T : Enum<T>, K> EnumWithKey<T, K>.getValue(key: K): T {
  return enumValues<T>().find { it.key == key }
    ?: throw IllegalStateException("In the enum ${T::class.java} " +
      "there should be at least one enumeration")
}

Additional context Look here for learning purpose - https://gist.github.com/programmerr47/e1a62f912c735249c89c3f5c44b6b366#file-enum-kt

whyash8 commented 1 month ago

I want to work on this issue.

adhiamboperes commented 1 month ago

@whyash8, Please feel free to put up a draft PR with a solution.

whyash8 commented 1 month ago

Ok sir

whyash8 commented 2 weeks ago

i have found a solution for the issue and i need some guidance. please help!

adhiamboperes commented 2 weeks ago

Hi @whyash8, please let us know how we can help. What challenge are you experiencing?

whyash8 commented 2 weeks ago

i made some changes in the code. Now i need help in testing the changes. Please help

adhiamboperes commented 2 weeks ago

@whyash8, could you please create a PR with the code changes so that we can better help with the required tests?

whyash8 commented 2 weeks ago

Ok

whyash8 commented 1 week ago

I am getting this issues while pushing Error: Invalid or corrupt jarfile ../oppia-android-tools/ktlint


Ktlint issue found. Please help !!

adhiamboperes commented 1 week ago

Hi @whyash8, go to your project folder > oppia-android-tools > delete the ktlint file. Then on you terminal inside the project root, run bash setup.sh again. Should this not resolve your issue, please use the discussions tab to share more details on the issue with a screenshot of the error.

whyash8 commented 1 week ago

Ok! thank you

whyash8 commented 5 days ago

i made a PR . please help me to proceed further.