toast show when e-receipt success and failed
This commit is contained in:
parent
5c036eb954
commit
e2fc293e6b
@ -14,8 +14,8 @@ android {
|
||||
applicationId "com.utsmm.kbz"
|
||||
minSdk 24
|
||||
targetSdk 33
|
||||
versionCode 25
|
||||
versionName "2.5"
|
||||
versionCode 28
|
||||
versionName "2.8"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
|
||||
@ -178,6 +178,7 @@ public class MainActivity extends AppCompatActivity implements
|
||||
|
||||
private void initViewModels() {
|
||||
sharedViewModel = new ViewModelProvider(this).get(SharedViewModel.class);
|
||||
sharedViewModel.getToastMsg().observe(this, this::showToast);
|
||||
}
|
||||
|
||||
private void setupUI() {
|
||||
@ -674,4 +675,4 @@ public class MainActivity extends AppCompatActivity implements
|
||||
private void showToast(String message) {
|
||||
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.utsmm.kbz.ui.core_viewmodel;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
import android.widget.ListView;
|
||||
@ -163,6 +164,7 @@ public class SharedViewModel extends ViewModel {
|
||||
|
||||
public MutableLiveData<Integer> loadingView = new MutableLiveData<>(8);
|
||||
public SingleLiveEvent<String> loadingMsg = new SingleLiveEvent<>();
|
||||
private final SingleLiveEvent<String> toastMsg = new SingleLiveEvent<>();
|
||||
|
||||
private SingleLiveEvent<Boolean> isFallback = new SingleLiveEvent<>();
|
||||
private SingleLiveEvent<Boolean> isSeePhone = new SingleLiveEvent<>();
|
||||
@ -295,6 +297,14 @@ public class SharedViewModel extends ViewModel {
|
||||
loadingMsg.setValue("");
|
||||
}
|
||||
|
||||
public SingleLiveEvent<String> getToastMsg() {
|
||||
return toastMsg;
|
||||
}
|
||||
|
||||
public void postToastMsg(String msg) {
|
||||
toastMsg.postValue(msg);
|
||||
}
|
||||
|
||||
public Observable<SiriusResponse> getParams(SiriusRequest siriusRequest) {
|
||||
return repository.getParams(siriusRequest);
|
||||
}
|
||||
@ -471,13 +481,17 @@ public class SharedViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
public void pushReceipt(Object body){
|
||||
Log.d("push receipt", new Gson().toJson(body));
|
||||
repository.sendReceipt(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
response -> Log.d("E-Receipt", "Success =>"+ response.getMessage()),
|
||||
response -> {
|
||||
Log.d("E-Receipt", "Success =>"+ response.getMessage());
|
||||
postToastMsg("E-Receipt saved successfully");
|
||||
},
|
||||
error -> {
|
||||
if (error instanceof HttpException) {
|
||||
HttpException httpEx = (HttpException) error;
|
||||
@ -489,11 +503,14 @@ public class SharedViewModel extends ViewModel {
|
||||
// Parse JSON to model
|
||||
EReceiptResponse res = new Gson().fromJson(errorJson, EReceiptResponse.class);
|
||||
Log.e("E-Receipt", "Parsed Error => " + res.getMessage());
|
||||
postToastMsg("E-Receipt save failed!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
postToastMsg("E-Receipt save failed!");
|
||||
}
|
||||
} else {
|
||||
Log.e("E-Receipt", "Unexpected error => " + error.getMessage());
|
||||
postToastMsg("E-Receipt save failed!");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user