API call fixed
This commit is contained in:
@@ -17,7 +17,7 @@ import retrofit2.http.Part
|
|||||||
interface MolbioApi {
|
interface MolbioApi {
|
||||||
@Headers("Content-Type: application/json")
|
@Headers("Content-Type: application/json")
|
||||||
@POST("devices/login")
|
@POST("devices/login")
|
||||||
fun login(@Body jsonObject: JsonObject): MolbioLogin
|
suspend fun login(@Body jsonObject: JsonObject): MolbioLogin
|
||||||
|
|
||||||
|
|
||||||
@Multipart
|
@Multipart
|
||||||
@@ -26,6 +26,6 @@ interface MolbioApi {
|
|||||||
|
|
||||||
@Multipart
|
@Multipart
|
||||||
@PUT("results/upload")
|
@PUT("results/upload")
|
||||||
fun uploadNewPdf(@Header("Authorization") auth:String,@Part("") count:RequestBody,@Part("") userId:RequestBody,@Part file_csv: MultipartBody.Part,@Part file_log:MultipartBody.Part,@Part("DeviceId") name:RequestBody): UploadResponse
|
suspend fun uploadNewPdf(@Header("Authorization") auth:String,@Part("") count:RequestBody,@Part("") userId:RequestBody,@Part file_csv: MultipartBody.Part,@Part file_log:MultipartBody.Part,@Part("DeviceId") name:RequestBody): UploadResponse
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,8 @@ class HomeFragment : Fragment() {
|
|||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||||
sharedPreference = requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
sharedPreference =
|
||||||
|
requireContext().getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
DataHolder.selectedTest = null
|
DataHolder.selectedTest = null
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
@@ -83,35 +84,45 @@ class HomeFragment : Fragment() {
|
|||||||
// jobScheduler.schedule(jobInfo)
|
// jobScheduler.schedule(jobInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun login()
|
override fun onStart() {
|
||||||
{
|
super.onStart()
|
||||||
val jsonObject= JsonObject();
|
val jsonObject = JsonObject()
|
||||||
jsonObject.addProperty("Username","hposdevice");
|
jsonObject.addProperty("Username", "hposdevice")
|
||||||
jsonObject.addProperty("Password","sickle");
|
jsonObject.addProperty("Password", "sickle")
|
||||||
viewModel.login(jsonObject)
|
viewModel.loginResponse.observe(viewLifecycleOwner) { response ->
|
||||||
viewModel.loginResponse.observe(viewLifecycleOwner) {response ->
|
when (response) {
|
||||||
when(response) {
|
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
val editor = sharedPreference.edit();
|
val editor = sharedPreference.edit()
|
||||||
editor.putString(Constants.TOKEN, response.data.token)
|
editor.putString(Constants.TOKEN, response.data.token)
|
||||||
editor.apply()
|
editor.apply()
|
||||||
Log.d("login_api","called");
|
Log.d("login_api", "called")
|
||||||
// showUploadDialog()
|
// showUploadDialog()
|
||||||
}
|
}
|
||||||
|
|
||||||
is Result.Error -> {
|
is Result.Error -> {
|
||||||
if (loginCount < 3) {
|
if (loginCount < 3) {
|
||||||
viewModel.login(jsonObject)
|
viewModel.login(jsonObject)
|
||||||
loginCount++
|
loginCount++
|
||||||
}
|
}
|
||||||
|
Log.d("API Error", response.exception.message.toString())
|
||||||
}
|
}
|
||||||
is Result.Loading -> {
|
|
||||||
|
|
||||||
|
is Result.Loading -> {
|
||||||
|
Toast.makeText(requireContext(), "Loading", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun login() {
|
||||||
|
val jsonObject = JsonObject()
|
||||||
|
jsonObject.addProperty("Username", "hposdevice")
|
||||||
|
jsonObject.addProperty("Password", "sickle")
|
||||||
|
viewModel.login(jsonObject)
|
||||||
|
}
|
||||||
|
|
||||||
private fun setUserId() {
|
private fun setUserId() {
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
val userId = binding.userId.text.toString()
|
val userId = binding.userId.text.toString()
|
||||||
@@ -143,6 +154,7 @@ class HomeFragment : Fragment() {
|
|||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun logoutUser(context: Context) {
|
private fun logoutUser(context: Context) {
|
||||||
val builder = AlertDialog.Builder(context)
|
val builder = AlertDialog.Builder(context)
|
||||||
builder.setTitle("Log Out")
|
builder.setTitle("Log Out")
|
||||||
@@ -165,7 +177,6 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun getData(search: String?, field: String) {
|
private fun getData(search: String?, field: String) {
|
||||||
val capitalizedSearch = search?.replaceFirstChar {
|
val capitalizedSearch = search?.replaceFirstChar {
|
||||||
if (search.lowercase()
|
if (search.lowercase()
|
||||||
@@ -248,7 +259,7 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun uploadLocalDBData(dialog: DialogInterface) {
|
private fun uploadLocalDBData(dialog: DialogInterface) {
|
||||||
val token = sharedPreference.getString(Constants.TOKEN,"")
|
val token = sharedPreference.getString(Constants.TOKEN, "")
|
||||||
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||||
if (userDataList.isEmpty()) {
|
if (userDataList.isEmpty()) {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
@@ -258,9 +269,7 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
requireContext(),
|
requireContext(), R.string.upload_success_message, Toast.LENGTH_SHORT
|
||||||
R.string.upload_success_message,
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class TestRightResults : Fragment() {
|
|||||||
binding.progressBar.visibility = View.VISIBLE
|
binding.progressBar.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
Toast.makeText(requireContext(), "Test upload failed, please try again", Toast.LENGTH_SHORT).show()
|
Toast.makeText(requireContext(), "Test upload failed, please try again $it", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user