toast show when e-receipt success and failed

This commit is contained in:
moon 2026-04-01 20:52:09 +06:30
parent 5c036eb954
commit e2fc293e6b
3 changed files with 22 additions and 4 deletions

View File

@ -14,8 +14,8 @@ android {
applicationId "com.utsmm.kbz" applicationId "com.utsmm.kbz"
minSdk 24 minSdk 24
targetSdk 33 targetSdk 33
versionCode 25 versionCode 28
versionName "2.5" versionName "2.8"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -178,6 +178,7 @@ public class MainActivity extends AppCompatActivity implements
private void initViewModels() { private void initViewModels() {
sharedViewModel = new ViewModelProvider(this).get(SharedViewModel.class); sharedViewModel = new ViewModelProvider(this).get(SharedViewModel.class);
sharedViewModel.getToastMsg().observe(this, this::showToast);
} }
private void setupUI() { private void setupUI() {

View File

@ -1,5 +1,6 @@
package com.utsmm.kbz.ui.core_viewmodel; package com.utsmm.kbz.ui.core_viewmodel;
import android.annotation.SuppressLint;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.util.Log; import android.util.Log;
import android.widget.ListView; import android.widget.ListView;
@ -163,6 +164,7 @@ public class SharedViewModel extends ViewModel {
public MutableLiveData<Integer> loadingView = new MutableLiveData<>(8); public MutableLiveData<Integer> loadingView = new MutableLiveData<>(8);
public SingleLiveEvent<String> loadingMsg = new SingleLiveEvent<>(); public SingleLiveEvent<String> loadingMsg = new SingleLiveEvent<>();
private final SingleLiveEvent<String> toastMsg = new SingleLiveEvent<>();
private SingleLiveEvent<Boolean> isFallback = new SingleLiveEvent<>(); private SingleLiveEvent<Boolean> isFallback = new SingleLiveEvent<>();
private SingleLiveEvent<Boolean> isSeePhone = new SingleLiveEvent<>(); private SingleLiveEvent<Boolean> isSeePhone = new SingleLiveEvent<>();
@ -295,6 +297,14 @@ public class SharedViewModel extends ViewModel {
loadingMsg.setValue(""); loadingMsg.setValue("");
} }
public SingleLiveEvent<String> getToastMsg() {
return toastMsg;
}
public void postToastMsg(String msg) {
toastMsg.postValue(msg);
}
public Observable<SiriusResponse> getParams(SiriusRequest siriusRequest) { public Observable<SiriusResponse> getParams(SiriusRequest siriusRequest) {
return repository.getParams(siriusRequest); return repository.getParams(siriusRequest);
} }
@ -471,13 +481,17 @@ public class SharedViewModel extends ViewModel {
} }
@SuppressLint("CheckResult")
public void pushReceipt(Object body){ public void pushReceipt(Object body){
Log.d("push receipt", new Gson().toJson(body)); Log.d("push receipt", new Gson().toJson(body));
repository.sendReceipt(body) repository.sendReceipt(body)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
response -> Log.d("E-Receipt", "Success =>"+ response.getMessage()), response -> {
Log.d("E-Receipt", "Success =>"+ response.getMessage());
postToastMsg("E-Receipt saved successfully");
},
error -> { error -> {
if (error instanceof HttpException) { if (error instanceof HttpException) {
HttpException httpEx = (HttpException) error; HttpException httpEx = (HttpException) error;
@ -489,11 +503,14 @@ public class SharedViewModel extends ViewModel {
// Parse JSON to model // Parse JSON to model
EReceiptResponse res = new Gson().fromJson(errorJson, EReceiptResponse.class); EReceiptResponse res = new Gson().fromJson(errorJson, EReceiptResponse.class);
Log.e("E-Receipt", "Parsed Error => " + res.getMessage()); Log.e("E-Receipt", "Parsed Error => " + res.getMessage());
postToastMsg("E-Receipt save failed!");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
postToastMsg("E-Receipt save failed!");
} }
} else { } else {
Log.e("E-Receipt", "Unexpected error => " + error.getMessage()); Log.e("E-Receipt", "Unexpected error => " + error.getMessage());
postToastMsg("E-Receipt save failed!");
} }
} }
); );