Browse Source
Preparation for adding ProfileFragmentViewModel
renovate/org.robolectric-robolectric-4.x
Preparation for adding ProfileFragmentViewModel
renovate/org.robolectric-robolectric-4.x
Ammar Githam
4 years ago
4 changed files with 56 additions and 6 deletions
-
8app/build.gradle
-
15app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java
-
21app/src/main/java/awais/instagrabber/viewmodels/ProfileFragmentViewModel.kt
-
18app/src/test/java/awais/instagrabber/viewmodels/ProfileFragmentViewModelTest.kt
@ -0,0 +1,21 @@ |
|||
package awais.instagrabber.viewmodels |
|||
|
|||
import androidx.lifecycle.* |
|||
import awais.instagrabber.repositories.responses.User |
|||
|
|||
class ProfileFragmentViewModel( |
|||
state: SavedStateHandle, |
|||
) : ViewModel() { |
|||
private val _profile = MutableLiveData<User?>() |
|||
val profile: LiveData<User?> = _profile |
|||
val username: LiveData<String> = Transformations.map(profile) { return@map it?.username ?: "" } |
|||
|
|||
var currentUser: User? = null |
|||
var isLoggedIn = false |
|||
get() = currentUser != null |
|||
private set |
|||
|
|||
init { |
|||
// Log.d(TAG, state.keys().toString()) |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
package awais.instagrabber.viewmodels |
|||
|
|||
import androidx.lifecycle.SavedStateHandle |
|||
import androidx.test.ext.junit.runners.AndroidJUnit4 |
|||
import org.junit.Test |
|||
import org.junit.runner.RunWith |
|||
|
|||
@RunWith(AndroidJUnit4::class) |
|||
internal class ProfileFragmentViewModelTest { |
|||
@Test |
|||
fun testNoUsernameNoCurrentUser() { |
|||
val state = SavedStateHandle(mutableMapOf<String, Any>( |
|||
"username" to "" |
|||
)) |
|||
val viewModel = ProfileFragmentViewModel(state) |
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue