-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made module fragment powered by backedn
- Loading branch information
1 parent
e4dc0ce
commit a4e7e9c
Showing
20 changed files
with
217 additions
and
122 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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/deepspace/hab/constants/StratofoxFirebaseConstants.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,7 @@ | ||
package com.deepspace.hab.constants | ||
|
||
object StratofoxFirebaseConstants { | ||
const val MODULE_LIST_COLLECTION = "modules" | ||
const val LESSON_LIST_COLLECTION = "lessons" | ||
const val MODULE_LESSON_LIST_COLLECTION = "moduleSections" | ||
} |
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
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/deepspace/hab/screens/HomeRepository.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,23 @@ | ||
package com.deepspace.hab.screens | ||
|
||
import com.deepspace.hab.constants.StratofoxFirebaseConstants | ||
import com.deepspace.hab.models.Module | ||
import com.deepspace.hab.models.Module.Companion.toModule | ||
import com.google.firebase.firestore.ktx.firestore | ||
import com.google.firebase.ktx.Firebase | ||
import kotlinx.coroutines.tasks.await | ||
|
||
class HomeRepository { | ||
|
||
private val db = Firebase.firestore | ||
|
||
suspend fun fetchModuleList(): MutableList<Module> { | ||
val moduleList = mutableListOf<Module>() | ||
db.collection(StratofoxFirebaseConstants.MODULE_LIST_COLLECTION) | ||
.get().await().mapNotNull { snapshot -> | ||
snapshot.toModule()?.let { moduleList.add(it) } | ||
} | ||
return moduleList | ||
} | ||
|
||
} |
19 changes: 16 additions & 3 deletions
19
app/src/main/java/com/deepspace/hab/screens/HomeViewModel.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 |
---|---|---|
@@ -1,11 +1,24 @@ | ||
package com.deepspace.hab.screens | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.deepspace.hab.models.Module | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.launch | ||
|
||
/** | ||
* Created by abhinav on 26/09/21. | ||
*/ | ||
class HomeViewModel: ViewModel() { | ||
var moduleList: List<Module>? = null | ||
class HomeViewModel(private val repo: HomeRepository): ViewModel() { | ||
|
||
private val _moduleViewState = MutableLiveData<ModuleViewState>() | ||
val moduleViewState: LiveData<ModuleViewState> = _moduleViewState | ||
|
||
fun fetchModuleList() { | ||
viewModelScope.launch { | ||
_moduleViewState.value = ModuleViewState(showLoader = true) | ||
_moduleViewState.value = ModuleViewState(showLoader = false, repo.fetchModuleList()) | ||
} | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/deepspace/hab/screens/HomeViewModelFactory.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,11 @@ | ||
package com.deepspace.hab.screens | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
|
||
class HomeViewModelFactory(private val repo: HomeRepository): ViewModelProvider.Factory { | ||
|
||
override fun <T : ViewModel?> create(modelClass: Class<T>): T { | ||
return HomeViewModel(repo) as T | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/deepspace/hab/screens/ModuleViewState.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,5 @@ | ||
package com.deepspace.hab.screens | ||
|
||
import com.deepspace.hab.models.Module | ||
|
||
data class ModuleViewState(val showLoader: Boolean = false, val moduleList: List<Module>? = null) |
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
11 changes: 2 additions & 9 deletions
11
app/src/main/java/com/deepspace/hab/screens/guidelines/GuidelinesFragment.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
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
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
Oops, something went wrong.