Skip to content

Commit

Permalink
fix req bug on mainfragmentViewmodel
Browse files Browse the repository at this point in the history
  • Loading branch information
root14 committed May 18, 2023
1 parent 1414d3f commit 7d95e42
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 69 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import javax.inject.Inject
class ApiHelperImpl @Inject constructor(
private val apiService: ApiService
) : ApiHelper {
override suspend fun flashlights(): Response<List<AppResponse>> = apiService.login()
override suspend fun colorlights(): Response<List<AppResponse>> = apiService.register()
override suspend fun sosalerts(): Response<List<AppResponse>> = apiService.loadFeed()
override suspend fun flashlights(): Response<List<AppResponse>> = apiService.flashlights()
override suspend fun colorlights(): Response<List<AppResponse>> = apiService.colorlights()
override suspend fun sosalerts(): Response<List<AppResponse>> = apiService.sosalerts()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import retrofit2.http.POST
interface ApiService {
@Headers("JsonStub-User-Key: f5e0861a-b53d-4b80-9c28-2233780c3d5d")
@GET("flashlights")
suspend fun login(): Response<List<AppResponse>>
suspend fun flashlights(): Response<List<AppResponse>>

@Headers("JsonStub-User-Key: f5e0861a-b53d-4b80-9c28-2233780c3d5d")
@GET("colorlights")
suspend fun register(): Response<List<AppResponse>>
suspend fun colorlights(): Response<List<AppResponse>>

@Headers("JsonStub-User-Key: f5e0861a-b53d-4b80-9c28-2233780c3d5d")
@GET("sosalerts")
suspend fun loadFeed(): Response<List<AppResponse>>
suspend fun sosalerts(): Response<List<AppResponse>>
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
package com.root14.flashlightappsmarket.view.ui.applicationFragment

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.View
import android.view.ViewGroup
import android.widget.SearchView
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.LiveData
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import com.root14.flashlightappsmarket.R
import com.root14.flashlightappsmarket.data.DataUtils
import com.root14.flashlightappsmarket.data.entity.ColoredLight
import com.root14.flashlightappsmarket.data.entity.Flashlight
import com.root14.flashlightappsmarket.data.entity.SOSAlert
Expand All @@ -25,7 +16,6 @@ import com.root14.flashlightappsmarket.model.AppItem
import com.root14.flashlightappsmarket.model.CategoryType
import com.root14.flashlightappsmarket.viewmodel.ApplicationFragmentViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Job


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class ApplicationFragmentViewModel @Inject constructor(
}
}


/**
* @return all flashLights from db
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class MainFragmentViewModel @Inject constructor(
val colorLight: LiveData<Resource<List<AppResponse>>> get() = _colorLight
private fun fetchColorLight() = viewModelScope.launch {
_isLoading.postValue(true)
mainRepository.flashlights().let { it ->
mainRepository.colorlights().let { it ->
if (it.isSuccessful) {
_colorLight.postValue(Resource.success(it.body()))
Log.d("fetchColorLight", "request success.")
Expand Down Expand Up @@ -136,7 +136,7 @@ class MainFragmentViewModel @Inject constructor(
val sosAlerts: LiveData<Resource<List<AppResponse>>> get() = _sosAlerts
private fun fetchSosAlert() = viewModelScope.launch {
_isLoading.postValue(true)
mainRepository.flashlights().let {
mainRepository.sosalerts().let {
if (it.isSuccessful) {
_sosAlerts.postValue(Resource.success(it.body()))
Log.d("fetchSosAlert", "request success.")
Expand Down

0 comments on commit 7d95e42

Please sign in to comment.