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
private lateinit var repository: UserRepository | |
private lateinit var testApis: TestApis | |
private lateinit var mockWebServer: MockWebServer | |
@Before | |
fun setUp() { | |
mockWebServer = MockWebServer() | |
mockWebServer.start() | |
testApis = RetrofitHelper.testApiInstance(mockWebServer.url("/").toString()) | |
repository = UserRepositoryImpl(testApis) |
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
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
val viewModel: MainViewModel by viewModels() | |
var isEligible by remember { | |
mutableStateOf(false) | |
} | |
LaunchedEffect(true) { |
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
class MainViewModel: ViewModel() { | |
private val _creditScore = MutableStateFlow(0) | |
private val _age = MutableStateFlow(18) | |
val isEligible = combine(_creditScore, _age) { creditScore, age -> | |
creditScore > 400 && age > 18 && age < 70 | |
} | |
fun creditScore(score: Int) { |
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
class MainViewModel: ViewModel() { | |
private var creditScore = mutableStateOf(0) | |
private var age = mutableStateOf(18) | |
val isEligible = derivedStateOf { | |
creditScore > 400 && age > 18 && age < 70 | |
} | |
fun creditScore(score: Int) { |
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
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
val viewModel: MainViewModel by viewModels() | |
val isEligible by remember { | |
viewModel.isEligible | |
} | |
Column( |
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
class MainViewModel: ViewModel() { | |
var creditScore = 0 | |
var age = 18 | |
fun isEligible() = creditScore > 400 && age > 18 && age < 70 | |
} |
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
@OptIn(ExperimentalCoroutinesApi::class) | |
class TestDispatcherRule( | |
private val testDispatcher: TestDispatcher = UnconfinedTestDispatcher() | |
): TestWatcher() { | |
override fun starting(description: Description) { | |
Dispatchers.setMain(testDispatcher) | |
} | |
override fun finished(description: Description) { | |
Dispatchers.resetMain() |
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
class MemberListViewHolder(mContext: Context, itemView:View):RecyclerView.ViewHolder(itemView){ | |
lateinit var userPreference: Preference<LoginResponse> | |
init{ | |
super.itemView | |
ButterKnife.bind(this,itemView) | |
inject(context) | |
} | |
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
@InstallIn(ActivityComponent::class) | |
@EntryPoint | |
interface UserListViewHolderEntryPoint { | |
var loginPref: Preference<LoginResponse> | |
} |
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
class MemberListViewHolder(itemView:View):RecyclerView.ViewHolder(itemView){ | |
@Inject | |
lateinit var userPreference: Preference<LoginResponse> | |
init{ | |
super.itemView | |
ButterKnife.bind(this,itemView) | |
SheroesApplication.getAppComponent(itemView.context).inject(this) | |
if(null!=userPreference&&userPreference.isSet&&null!=userPreference.get().userSummary){ | |
mUserId=userPreference.get().userSummary.userId |