Molbio Data upload error fix
This commit is contained in:
@@ -1,46 +0,0 @@
|
|||||||
package com.example.hpostesting.data
|
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import com.example.hpostesting.data.model.Response
|
|
||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
|
||||||
import com.example.hpostesting.util.MyUtils
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
class FileUploader {
|
|
||||||
|
|
||||||
private val TAG = "FileUploader"
|
|
||||||
val repository = DatabaseRepository()
|
|
||||||
|
|
||||||
suspend fun start() {
|
|
||||||
|
|
||||||
val listOfFiles = repository.getAllFromPendingQueue()
|
|
||||||
|
|
||||||
for (each in listOfFiles){
|
|
||||||
// Checking internet connectivity & mobile as same or not
|
|
||||||
if (MyUtils.isInternetConnected() && each.mobileId == DataHolder.mobileUniqueId) {
|
|
||||||
|
|
||||||
Log.d(TAG, "uploading file ${each.pendingId}")
|
|
||||||
GlobalScope.launch {
|
|
||||||
val response = repository.uploadFileToStorage(each.patientId, each.filePath)
|
|
||||||
|
|
||||||
when (response) {
|
|
||||||
is Response.Success -> {
|
|
||||||
Log.d(TAG, "File Uploaded ${each.pendingId}")
|
|
||||||
repository.removeFromPendingQueue(each.pendingId)
|
|
||||||
}
|
|
||||||
|
|
||||||
is Response.Error -> {
|
|
||||||
Log.d(TAG, response.exception.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.join()
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,8 +2,10 @@ package com.example.hpostesting.domain
|
|||||||
|
|
||||||
import android.app.job.JobParameters
|
import android.app.job.JobParameters
|
||||||
import android.app.job.JobService
|
import android.app.job.JobService
|
||||||
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
import com.example.hpostesting.presentation.testRight.TestRightViewModel
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
@@ -12,12 +14,19 @@ import javax.inject.Inject
|
|||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MyJobScheduler : JobService(){
|
class MyJobScheduler : JobService(){
|
||||||
|
|
||||||
private lateinit var sharedPreference: SharedPreferences
|
|
||||||
@Inject
|
@Inject
|
||||||
|
lateinit var sharedPreference: SharedPreferences
|
||||||
private lateinit var viewModel: TestRightViewModel
|
private lateinit var viewModel: TestRightViewModel
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(application)
|
||||||
|
.create(TestRightViewModel::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStartJob(p0: JobParameters?): Boolean {
|
override fun onStartJob(p0: JobParameters?): Boolean {
|
||||||
Log.d("jober","job started")
|
Log.d("jober","job started")
|
||||||
|
sharedPreference = this.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
viewModel.networkStatusLiveData.observeForever {
|
viewModel.networkStatusLiveData.observeForever {
|
||||||
if (it) {
|
if (it) {
|
||||||
fetchInternalDataAndUpload()
|
fetchInternalDataAndUpload()
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ package com.example.hpostesting.domain.di
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import com.example.hpostesting.data.api.MolbioApi
|
import com.example.hpostesting.data.api.MolbioApi
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.dao.MyDatabase
|
import com.example.hpostesting.data.dao.MyDatabase
|
||||||
import com.example.hpostesting.data.dao.UserDao
|
import com.example.hpostesting.data.dao.UserDao
|
||||||
import com.example.hpostesting.data.datasource.LocalFileDataSource
|
import com.example.hpostesting.data.datasource.LocalFileDataSource
|
||||||
import com.example.hpostesting.data.repository.DatabaseRepository
|
|
||||||
import com.example.hpostesting.data.repository.LocalFileRepository
|
import com.example.hpostesting.data.repository.LocalFileRepository
|
||||||
import com.example.hpostesting.domain.SaveRawData
|
import com.example.hpostesting.domain.SaveRawData
|
||||||
import com.example.hpostesting.domain.SaveRawDataTest
|
import com.example.hpostesting.domain.SaveRawDataTest
|
||||||
@@ -17,10 +18,8 @@ import dagger.Provides
|
|||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import okhttp3.OkHttpClient
|
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
import retrofit2.create
|
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
@@ -63,7 +62,7 @@ object AppModule {
|
|||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideRetrofit(client: OkHttpClient): Retrofit =
|
fun provideRetrofit(): Retrofit =
|
||||||
Retrofit
|
Retrofit
|
||||||
.Builder()
|
.Builder()
|
||||||
.baseUrl(Constants.BASE_URL)
|
.baseUrl(Constants.BASE_URL)
|
||||||
@@ -75,4 +74,16 @@ object AppModule {
|
|||||||
@Singleton
|
@Singleton
|
||||||
fun provideMolbioApi(retrofit: Retrofit): MolbioApi =
|
fun provideMolbioApi(retrofit: Retrofit): MolbioApi =
|
||||||
retrofit.create(MolbioApi::class.java)
|
retrofit.create(MolbioApi::class.java)
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences {
|
||||||
|
return context.getSharedPreferences("my_preferences", Context.MODE_PRIVATE)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideViewModelFactory(application: Application): ViewModelProvider.Factory {
|
||||||
|
return ViewModelProvider.AndroidViewModelFactory.getInstance(application)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user