-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrated help fragment to mvvm
- Loading branch information
1 parent
c2e3ed4
commit c77c614
Showing
3 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.mifos.mobile.utils | ||
|
||
import org.mifos.mobile.models.FAQ | ||
|
||
sealed class HelpUiState { | ||
data class ShowFaq(val faqArrayList: ArrayList<FAQ?>) : HelpUiState() | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/org/mifos/mobile/viewModels/HelpViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.mifos.mobile.viewModels | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import org.mifos.mobile.models.FAQ | ||
import org.mifos.mobile.utils.HelpUiState | ||
import java.util.* | ||
import javax.inject.Inject | ||
import kotlin.collections.ArrayList | ||
|
||
@HiltViewModel | ||
class HelpViewModel @Inject constructor() : ViewModel() { | ||
|
||
private val _helpUiState = MutableLiveData<HelpUiState>() | ||
val helpUiState: LiveData<HelpUiState> get() = _helpUiState | ||
|
||
fun loadFaq(qs: Array<String>?, ans: Array<String>?) { | ||
val faqArrayList = ArrayList<FAQ?>() | ||
if (qs != null) { | ||
for (i in qs.indices) { | ||
faqArrayList.add(FAQ(qs[i], ans?.get(i))) | ||
} | ||
} | ||
_helpUiState.value = HelpUiState.ShowFaq(faqArrayList) | ||
} | ||
|
||
fun filterList(faqArrayList: ArrayList<FAQ?>?, query: String): ArrayList<FAQ?> { | ||
val filteredList = ArrayList<FAQ?>() | ||
if (faqArrayList != null) { | ||
for (faq in faqArrayList) { | ||
if (faq?.question?.lowercase(Locale.ROOT) | ||
?.contains(query.lowercase(Locale.ROOT)) == true | ||
) { | ||
filteredList.add(faq) | ||
} | ||
} | ||
} | ||
return filteredList | ||
} | ||
} |