-
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.
Issue #95: add parsers for dates and translators for weekdays/categor…
…ies; add jsonhome request in top bar (success untested); code properly formatted
- Loading branch information
1 parent
6c3f3d6
commit 04960f6
Showing
36 changed files
with
411 additions
and
253 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
Project/app/src/main/java/org/ionproject/android/common/FetchResult.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,16 @@ | ||
package org.ionproject.android.common | ||
|
||
/** | ||
getJsonHome() returns null when the API is unavailable. This makes the default null status of | ||
rootLiveData ambiguous, so this class envelops the results of the getJsonHome() method in order to | ||
properly evaluate the state of the API and to launch the Remote Config strat | ||
Fetch Failure with null value: request was made to API and there was no response | ||
Fetch Failure with throwable: request threw an Exception, if not caught triggers the global Exception Handler | ||
from ExceptionHandlingActivity() | ||
Fetch Success : valid response | ||
*/ | ||
sealed class FetchResult<out T> | ||
data class FetchFailure<T>(val throwable: Throwable? = null) : FetchResult<T>() | ||
data class FetchSuccess<T>(val value: T) : FetchResult<T>() |
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
39 changes: 39 additions & 0 deletions
39
Project/app/src/main/java/org/ionproject/android/offline/CatalogMainActivityViewModel.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,39 @@ | ||
package org.ionproject.android.offline | ||
|
||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.Observer | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.launch | ||
import org.ionproject.android.common.FetchFailure | ||
import org.ionproject.android.common.FetchResult | ||
import org.ionproject.android.common.FetchSuccess | ||
import org.ionproject.android.common.model.Root | ||
import org.ionproject.android.common.repositories.RootRepository | ||
import java.net.URI | ||
|
||
class CatalogMainActivityViewModel(private val rootRepository: RootRepository): ViewModel(){ | ||
|
||
private val rootLiveData = MutableLiveData<FetchResult<Root>>() | ||
|
||
/** | ||
* Same function from [LoadingViewModel] that requests the JSONHome | ||
*/ | ||
fun getJsonHome(uri: URI) { | ||
viewModelScope.launch { | ||
val result = try { | ||
val root = rootRepository.getJsonHome(uri) | ||
if (root != null) FetchSuccess(root) else FetchFailure<Root>() | ||
} catch (e: Exception) { | ||
FetchFailure<Root>(e) | ||
} | ||
|
||
rootLiveData.postValue(result) | ||
} | ||
} | ||
|
||
fun observeRootLiveData(lifecycleOwner: LifecycleOwner, onUpdate: (FetchResult<Root>) -> Unit) { | ||
rootLiveData.observe(lifecycleOwner, Observer { onUpdate(it) }) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../app/src/main/java/org/ionproject/android/offline/CatalogMainActivityViewModelProvider.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,17 @@ | ||
package org.ionproject.android.offline | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import org.ionproject.android.common.IonApplication | ||
|
||
class CatalogMainActivityViewModelProvider : ViewModelProvider.Factory { | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override fun <T : ViewModel?> create(modelClass: Class<T>): T { | ||
return when (modelClass) { | ||
CatalogMainActivityViewModel::class.java -> CatalogMainActivityViewModel(IonApplication.rootRepository) | ||
else -> throw IllegalArgumentException("Class $modelClass is not valid for this provider") | ||
} as T | ||
} | ||
|
||
} |
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.