I am using MVP to decouple my view and model in my android application. I need to know how the model should feedback the result of the business logic to the view.
If for example a button is pressed to login, the activity would be like this, using butterknife #OnClick annotation:
#OnClick(R.id.login_button)
public void login() {
String email = mEmailEditText.getText().toString();
String password = mPasswordEditText.getText().toString();
LoginCredentials loginCredentials = new LoginCredentials(email, password);
mPresenter.loginWithEmail(loginCredentials);
}
The presenter would then validate and make a request to the repository:
public void loginWithEmail(LoginCredentials loginCredentials) {
boolean isEmailValid = AuthValidator.validateEmail(loginCredentials.getUsername());
boolean isPasswordValid = AuthValidator.validatePassword(loginCredentials.getPassword());
if(isEmailValid && isPasswordValid) repository.loginEmailUser(loginCredentials);
if (!isEmailValid) view.handleInvalidEmail();
if (!isPasswordValid) view.handleInvalidPassword();
}
The repository would then execute the business logic:
#Override
public void loginEmailUser(LoginCredentials loginCredentials) {
Call<Token> call = userServiceApi.loginInToken(loginCredentials);
call.enqueue(new Callback<Token>() {
#Override
public void onResponse(#NonNull Call<Token> call, #NonNull Response<Token> response) {
if (response.isSuccessful()) {
// handle successful login
} else {
// Handle unsuccessful login
}
}
#Override
public void onFailure(#NonNull Call<Token> call, #NonNull Throwable t) {
// Handle failed request
}
});
Where the comments say // handle unsuccessful something, how does the model feedback to the view the outcomes of the business logic so that the view can handle these outcomes?
Thank you.
You can use a interface as callback, for example :
public interface RepositoryCallback {
void onLoginEmailUserSuccess(/*paramaters if you need*/);
void onLoginEmailUserError(/*paramaters if you need*/);
void onRequestFailed(/*paramaters if you need*/)
}
In the repository defined the listener
public class MyRepository {
private RepositoryCallback mListener;
#Override
public void loginEmailUser(LoginCredentials loginCredentials) {
Call<Token> call = userServiceApi.loginInToken(loginCredentials);
call.enqueue(new Callback<Token>() {
#Override
public void onResponse(#NonNull Call<Token> call, #NonNull Response<Token> response) {
if (response.isSuccessful()) {
// handle successful login
if (mListener != null) {
mListener.onLoginEmailUserSuccess()
}
} else {
// Handle unsuccessful login
if (mListener != null) {
mListener.onLoginEmailUserError()
}
}
}
#Override
public void onFailure(#NonNull Call<Token> call, #NonNull Throwable t) {
// Handle failed request
if (mListener != null) {
mListener.onRequestFailed()
}
}
});
public void setRepositoryCallback(RepositoryCallback listener) {
mListener = listener;
}
}
Then set the presenter as listener :
public class MyPresenter implements RepositoryCallback {
public void loginWithEmail(LoginCredentials loginCredentials) {
repository.setRepositoryCallback(this) // here or in the presenter constructor
boolean isEmailValid = AuthValidator.validateEmail(loginCredentials.getUsername());
boolean isPasswordValid = AuthValidator.validatePassword(loginCredentials.getPassword());
if(isEmailValid && isPasswordValid) repository.loginEmailUser(loginCredentials);
if (!isEmailValid) view.handleInvalidEmail();
if (!isPasswordValid) view.handleInvalidPassword();
}
#Override
public void onLoginEmailUserSuccess(//paramaters if you need){
// your code
}
#Override
public void onLoginEmailUserError(//paramaters if you need){
// your code
}
#Override
public void onRequestFailed(//paramaters if you need){
// your code
}
}
Hope this helps.
Sorry for my english.
Related
So I have a app where I am displaying the products list from the database using a Recycler View.
There is delete button beside each item which is working fine.
And there is a scan item button which opens a BARCODE SCANNER which on succesfull scanning adds the new product to the database and goes back to the Recycler View display is supposed to refresh the view and display the new Item.
but I am having problem with refreshing the recycler view on adding a new Product.
there is also a delete product function which works perfectly so I tried to do the add item method the same way, but the recycler view doesn't refresh.
UserPage activity
public class UserPage extends AppCompatActivity implements ProductAdaptar.clickedItem {
Toolbar toolbar;
RecyclerView recyclerView;
String rfidNo;
public static String barcode;
Button scanItem;
Button payBill;
TextView total;
ProductAdaptar productAdaptar;
Call<List<UserLoginResp>> productList;
List<UserLoginResp> productListsItems = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_page);
toolbar=findViewById(R.id.toolbar);
recyclerView=findViewById(R.id.recyclerview);
scanItem = findViewById(R.id.scanItem);
payBill = findViewById(R.id.payBill);
total = findViewById(R.id.total);
scanItem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(),ScannerView.class).putExtra("rfid",rfidNo));
}
});
payBill.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
checkout();
}
});
LinearLayoutManager manager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(manager);
recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
productAdaptar = new ProductAdaptar(this::clickedItem, this);
Intent intent =getIntent();
if(intent.getExtras()!=null){
rfidNo= intent.getStringExtra("rfid");
}
getAllProducts(rfidNo);
}
public void getAllProducts(String rfidno){
LinearLayoutManager manager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(manager);
productAdaptar = new ProductAdaptar(this::clickedItem,this);
productList= ApiClient.getUserPageService().getCartItems(rfidno);
productList.enqueue(new Callback<List<UserLoginResp>>() {
#Override
public void onResponse(Call<List<UserLoginResp>> call, Response<List<UserLoginResp>> response) {
if (response.isSuccessful()) {
productListsItems = response.body();
productAdaptar.setData(productListsItems);
RecyclerView recyclerView = findViewById(R.id.recyclerview);
recyclerView.setAdapter(productAdaptar);
getTotal();
}
}
#Override
public void onFailure(Call<List<UserLoginResp>> call, Throwable t) {
Log.e("listfailed",t.getLocalizedMessage());
}
});
}
public void getTotal(){
Call<getBill> bill = ApiClient.getUserPageService().getBill(rfidNo);
bill.enqueue(new Callback<getBill>() {
#Override
public void onResponse(Call<getBill> call, Response<getBill> response) {
if(response.isSuccessful()){
getBill getBill = response.body();
String bill = String.valueOf(getBill.getBill());
total.setText(bill);
}
}
#Override
public void onFailure(Call<getBill> call, Throwable t) {
Log.e("bill error",""+t);
}
});
}
public void checkout(){
Call<String> payment= APIClientString.getUserPageService().checkout(rfidNo);
payment.enqueue(new Callback<String>() {
#Override
public void onResponse(Call<String> call, Response<String> response) {
if(response.isSuccessful()){
getAllProducts(rfidNo);
Toast.makeText(UserPage.this, "Payment Successful", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onFailure(Call<String> call, Throwable t) {
Log.e("paymentfail",""+t);
}
});
}
#Override
public void clickedItem(UserLoginResp userLoginResp) {
Log.e("clicked prodcut", userLoginResp.toString());
}
}
ScannerView Class
enter #Override
public void handleResult(Result rawResult) {
barcode = rawResult.getText();
if(addItem(barcode,rfidNo)) {
userPage.getAllProducts(rfidNo);
}
onBackPressed();
}
public boolean addItem(String barcode,String rfidNo){
final boolean[] res = {false};
Call<String> resp = APIClientString.getUserPageService().addProduct(barcode,rfidNo);
resp.enqueue(new Callback<String>() {
#Override
public void onResponse(Call<String> call, Response<String> response) {
if(response.isSuccessful()){
Toast.makeText(ScannerView.this, response.body().toString(), Toast.LENGTH_SHORT).show();
res[0] =true;
}
}
This is the scanner class which is suppose to call the call the getAllproducts function from the UserPage Activity to refresh the view. It shows no error but the recycler view doesn't get updated.
This is the Adapter Class
public class ProductAdaptar extends RecyclerView.Adapter<ProductAdaptar.ProductAdaptarVH> {
private List<UserLoginResp> productListItems;
private UserPage context;
private clickedItem clickedItem;
public ProductAdaptar(clickedItem clickedItem, UserPage activity) {
this.clickedItem = clickedItem;
this.context= activity;
}
public void setData(List<UserLoginResp> productListItems) {
this.productListItems = productListItems;
notifyDataSetChanged();
}
#NonNull
#Override
public ProductAdaptarVH onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
return new ProductAdaptar.ProductAdaptarVH(LayoutInflater.
from(context).inflate(R.layout.row_products,parent,false));
}
#Override
public void onBindViewHolder(#NonNull ProductAdaptarVH holder, int position) {
UserLoginResp userLoginResp = productListItems.get(position);
String pName = userLoginResp.getProductName();
String pQuan = userLoginResp.getQuantity();
String pPrice = userLoginResp.getProductPrice();
String pBarcode = userLoginResp.getProductID();
String userID = userLoginResp.getUserID();
holder.pName.setText(pName);
holder.pQuan.setText(pQuan);
holder.pPrice.setText(pPrice);
holder.delProdcut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
delProduct(userID,pBarcode);
}
});
holder.moreDetails.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
public interface clickedItem{
public void clickedItem(UserLoginResp userLoginResp);
}
public void delProduct(String userID, String pBarcode){
Call<String> res = APIClientString.getUserPageService().deleteProduct(pBarcode,userID);
res.enqueue(new Callback<String>() {
#Override
public void onResponse(Call<String> call, Response<String> response) {
if(response.isSuccessful()){
Toast.makeText(context, response.body().toString(), Toast.LENGTH_SHORT).show();
context.getAllProducts(userID);
}
}
#Override
public void onFailure(Call<String> call, Throwable t) {
Log.e("deletefailed",""+t);
}
});
}
#Override
public int getItemCount() {
return productListItems.size();
}
public static class ProductAdaptarVH extends RecyclerView.ViewHolder {
TextView pName;
TextView pQuan;
TextView pPrice;
Button delProdcut;
Button moreDetails;
public ProductAdaptarVH(#NonNull View itemView) {
super(itemView);
pName=itemView.findViewById(R.id.pName);
pQuan=itemView.findViewById(R.id.pQuantity);
pPrice=itemView.findViewById(R.id.pPrice);
delProdcut=itemView.findViewById(R.id.delProduct);
moreDetails=itemView.findViewById(R.id.moreDetails);
}
}
}
In this Product Apdapter there is a delete product item function
holder.delProdcut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
delProduct(userID,pBarcode);
}
});
public void delProduct(String userID, String pBarcode){
Call<String> res = APIClientString.getUserPageService().deleteProduct(pBarcode,userID);
res.enqueue(new Callback<String>() {
#Override
public void onResponse(Call<String> call, Response<String> response) {
if(response.isSuccessful()){
Toast.makeText(context, response.body().toString(), Toast.LENGTH_SHORT).show();
context.getAllProducts(userID);
}
}
#Override
public void onFailure(Call<String> call, Throwable t) {
Log.e("deletefailed",""+t);
}
});
}
Which also calls the getProduts function from UserPage activity and it works perfectly fine but the AddItem function doesn't refresh the view.
The Retrofit APIs are working completly fine too, the problem is only with refreshing the recycler view display on Item Add.
I am new to android coding so I can't seem to understand how to do it.
As you are refreshing your adapter using getAllProducts() method but it is being called in onCreate(). Now whenever you start a ScannerView activity, UserPage activity gets paused and then started (not created) when ScannerView activity finishes. So, you should call getAllProducts() in onStart() method like this:
#Override
protected void onStart() {
super.onStart();
Intent intent = getIntent();
if (intent.getExtras() != null) {
rfidNo = intent.getStringExtra("rfid");
}
getAllProducts(rfidNo);
}
I've added some code to make my question more clear.
Retrofit interface:
public interface JsonPlaceHolderAPI {
public static final String BASE_URL = "https://jsonplaceholder.typicode.com/";
#GET("todos/{number}")
Call<ResponseBody> getJsonResponse(#Path("number") String number);
}
The repository: --> fetchResponse() takes Viewmodel's MutableLiveData as parameter and uses it to update its value and then trigger View to change its UI.
public class Repository {
private final JsonPlaceHolderAPI api;
public Repository() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.build();
api = retrofit.create(JsonPlaceHolderAPI.class);
}
public void fetchResponse(String number, final MutableLiveData<CharSequence> mld){
final MutableLiveData<CharSequence> ml = new MutableLiveData<>();
api.getJsonResponse(number).enqueue(new Callback<ResponseBody>() {
#Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
mld.setValue(response.body().string());
} catch (IOException e) {
e.printStackTrace();
}
}
#Override
public void onFailure(Call<ResponseBody> call, Throwable t) {}
});
}
}
The viewModel:
public class MainActivityViewModel extends AndroidViewModel {
MutableLiveData<CharSequence> response = new MutableLiveData<>();
Repository repository;
public MainActivityViewModel(#NonNull Application application) {
super(application);
repository = new Repository();
}
public void fetchData(String number) {
response.setValue("Loading data");
repository.fetchResponse(number, response);
}
public LiveData<? extends CharSequence> getLiveData() {
return response;
}
}
The View:
...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewModel = ViewModelProviders.of(this).get(MainActivityViewModel.class);
initViews();
viewModel.getLiveData().observe(this, new Observer<CharSequence>() {
#Override
public void onChanged(CharSequence charSequence) {
if (charSequence != null) {
txt.setText(charSequence);
}
}
});
}
...
I am not sure if I should pass the MutableLiveData from the viewModel to the Repository.
Is there any recommended way to let viewModel know that data is ready to be published from Repository??
I have read a lot of questions and articles and still I don't get it. I would love if somebody explain to me a nice way to achieve it!
Api
public interface TodoApi {
#GET("todos/")
Call<List<Todo>> getTodos();
#GET("todos/{id}")
Call<Todo> getTodo(#Path("id") long id);
}
Respository
public class TodoRepository {
private static final String TAG = "TodoRepository";
private static final TodoRepository ourInstance = new TodoRepository();
private TodoApi api;
private MutableLiveData<List<Todo>> todoListLiveData = new MutableLiveData<>();
private MutableLiveData<Todo> todoLiveData = new MutableLiveData<>();
public static TodoRepository getInstance() {
return ourInstance;
}
private TodoRepository() {
api = ApiBuilder.create(TodoApi.class);
}
public LiveData<List<Todo>> getTodos() {
api.getTodos().enqueue(new Callback<List<Todo>>() {
#Override
public void onResponse(#NonNull Call<List<Todo>> call, #NonNull Response<List<Todo>> response) {
todoListLiveData.setValue(response.body());
}
#Override
public void onFailure(#NonNull Call<List<Todo>> call, #NonNull Throwable t) {
Log.d(TAG, "onFailure: failed to fetch todo list from server");
}
});
return todoListLiveData;
}
public LiveData<Todo> getTodo(long id) {
api.getTodo(id).enqueue(new Callback<Todo>() {
#Override
public void onResponse(#NonNull Call<Todo> call, #NonNull Response<Todo> response) {
todoLiveData.setValue(response.body());
}
#Override
public void onFailure(#NonNull Call<Todo> call, #NonNull Throwable t) {
Log.d(TAG, "onFailure: failed to get todo");
}
});
return todoLiveData;
}
}
ViewModel
public class MainActivityViewModel extends ViewModel {
private static final String TAG = "MainActivityViewModel";
private TodoRepository repository = TodoRepository.getInstance();
private MutableLiveData<Boolean> isLoading = new MutableLiveData<>();
private LiveData<List<Todo>> todoLiveData;
public MainActivityViewModel() {
super();
isLoading.setValue(true);
todoLiveData = repository.getTodos();
}
#Override
protected void onCleared() {
super.onCleared();
}
public MutableLiveData<Boolean> getIsLoading() {
return isLoading;
}
public LiveData<List<Todo>> getTodoLiveData() {
return todoLiveData;
}
}
View
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
todoListRecyclerView = findViewById(R.id.todo_recycler_view);
loadingIndicator = findViewById(R.id.todo_loading_indicator);
mViewModel = ViewModelProviders.of(this).get(MainActivityViewModel.class);
getSupportActionBar().setTitle("Todos");
mViewModel.getIsLoading().observe(this, new Observer<Boolean>() {
#Override
public void onChanged(Boolean isLoading) {
if (isLoading) loadingIndicator.setVisibility(View.VISIBLE);
else loadingIndicator.setVisibility(View.GONE);
}
});
mViewModel.getTodoLiveData().observe(this, new Observer<List<Todo>>() {
#Override
public void onChanged(List<Todo> todos) {
mViewModel.getIsLoading().postValue(false);
initRecyclerView(todos);
}
});
}
For full sample
https://github.com/AnvarNazar/RetrofitTypicodeApiExample
I am trying to make generic implementation for adding and showing progress bar in fragment / activity when there are multiple calls.
Anyone have any better solution rather than taking two references of progress bar and toggling its visibility? The implementation should be generic which can be applied to any views.
Add this interface in your Project....
public interface RetrofitCallback {
<T> void getSuccessCallBack(Response<T> response, int position);
void getErrorCallBack(String message, int position);
}
add these methods in your Utility or RetrofitUtility.
public static <T> void callRetrofit(final Context context, final Fragment fragment, Call<T> call, final int position, final RetrofitCallback callback) {
final ProgressDialog pDialog = CommonMethod.showProgressDialog(context, context.getResources().getString(R.string.loading));// progress for whole application
call.enqueue(new Callback<T>() {
#Override
public void onResponse(Call<T> call, Response<T> response) {
pDialog.dismiss();
if (response.isSuccessful()) {
ResultBody result = (ResultBody) response.body();
if (result.isSuccess())
callback.getSuccessCallBack(response, position);
else
callback.getErrorCallBack(result.getMessage(), position);
} else
Toast.makeText(context, response.message(), Toast.LENGTH_SHORT).show();
}
#Override
public void onFailure(Call<T> call, Throwable t) {
pDialog.dismiss();
if (CommonMethod.checkconnection(context)) { // checking internet connection
Toast.makeText(context, "Server_error", Toast.LENGTH_SHORT).show();
} else {
CommonMethod.showconnectiondialog(context, fragment);
}
}
});
}
public static Retrofit getClient() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl("XXXXXXXXXXXXX")
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
All Retrofit API
public interface RetrofitApi {
#POST("allData")
Call<UserData> getAllData();
}
Implement RetrofitCallback in your Activity and Fragment
Call Api like this
Call<UserData> call = ApiClient.getClient().create(RetrofitApi.class).getAllData();
ApiClient.callRetrofit(context, this, call, 0, this);
and you will get data from RetrofitCallback override methods below
#Override
public <T> void getSuccessCallBack(Response<T> response, int position) {
UserData userData = ((UserData) response.body());
// do your operation over here
}
#Override
public void getErrorCallBack(String message, int position) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
Here is all models file....
ResultBody.class
public class ResultBody {
private String message;
private boolean success;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
}
UserData.class
public class UserData extends ResultBody {
private User userData;
public User getUserData() {
return userData;
}
public void setUserData(User user) {
this.userData = user;
}
}
Let me know if you stuck anywhere.....
Relative Posts or Questions
Android:dynamically pass model class to retrofit callback
I am using a ProgressDialog to be presented before making a Rest request using Retrofit + RxJava, the response of the request is large and this is freezing the animation of ProgressDialog. How can I fix this? I only found examples saying to use runOnUiThread or the doInBackground with AsyncTask but, I'm using RxJava. I tried the runOnUiThread but it did not work.
//My request
public void getMyData(final MyListener listener) {
AppApi AppApi = getInstanceMyApi();
AppApi.getMyData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ResponseData>() {
#Override
public void onCompleted() {
}
#Override
public void onError(Throwable e) {
//error
}
#Override
public void onNext(ResponseData response) {
//success, send data to presenter to update view
}
});
//Presenter call ws
public void attemptGetDataFromWS() {
showProgress();
getMyData(this);
}
#Override
public void onGetMyDataSuccess(ResponseData response) {
hideProgress();
}
#Override
public void onGetMyDataError(String error) {
hideProgress();
}
public void getMyData(final MyListener listener) {
AppApi AppApi = getInstanceMyApi();
AppApi.getMyData()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new DisposableObserver<ResponseData>() {
#Override
public void onCompleted() {
dispose();
}
#Override
public void onError(Throwable e) {
listener.onGetMyDataError(e.getMessage());
}
#Override
public void onNext(ResponseData response) {
listener.onGetMyDataSuccess(response);
}
});
//Presenter call ws
public void attemptGetDataFromWS() {
showProgress();
getMyData(this);
}
#Override
public void onGetMyDataSuccess(ResponseData response) {
hideProgress();
}
#Override
public void onGetMyDataError(String error) {
hideProgress();
}
Follow this method .this is calling example with REST API + Retrofit
private void callRestAPI() {
Retrofit retrofit = new Retrofit.Builder().baseUrl(BASEURL)
.addConverterFactory(GsonConverterFactory.create())
.build();
newsAPI = retrofit.create(NewsAPI.class);
Call<JSONResponse> call = newsAPI.topNews("soure", "api-key");
// Set up progress before call
final ProgressDialog progressDoalog;
progressDoalog = new ProgressDialog(MainActivity.this);
progressDoalog.setMax(100);
progressDoalog.setMessage("Its loading....");
progressDoalog.setTitle("ProgressDialog bar example");
progressDoalog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// show it
progressDoalog.show();
call.enqueue(new Callback<JSONResponse>() {
#Override
public void onResponse(Call<JSONResponse> call, Response<JSONResponse> response) {
// close it after response
progressDoalog.dismiss();
}
}
#Override public void onFailure (Call < JSONResponse > call, Throwable t){
// close it after response
progressDoalog.dismiss();
}
});
}
I have a fragment where I post request to server. This type of action should be in onResume() method, but I don't want to post request to server every time when I put app on background. Is exist any solution?
request which I want to post
FactoryAPI.getContacts().getContacts(user.getToken()).enqueue(new Callback<ContactsResponse>() {
#Override
public void onResponse(Call<ContactsResponse> call, Response<ContactsResponse> response) {
if(response.isSuccessful()) {
contactList = response.body().getContactsList();
sortList();
progressDialog.dismiss();
setRecyclerView();
}
}
#Override
public void onFailure(Call<ContactsResponse> call, Throwable t) {}
});
In your Fragment class, create a data member of type boolean like,
private boolean isResponseSend;
In your onResume() method,
#Override
public void onResume() {
super.onResume();
if(!isResponseSend)
{
isResponseSend = true;
//your code
FactoryAPI.getContacts().getContacts(user.getToken()).enqueue(new Callback<ContactsResponse>() {
#Override
public void onResponse(Call<ContactsResponse> call, Response<ContactsResponse> response) {
if(response.isSuccessful()) {
contactList = response.body().getContactsList();
sortList();
progressDialog.dismiss();
setRecyclerView();
}
}
#Override
public void onFailure(Call<ContactsResponse> call, Throwable t) {}
});
}
}
According to
https://developer.android.com/guide/components/fragments.html#Creating
you can post the request on
https://developer.android.com/reference/android/app/Fragment.html#onAttach(android.content.Context)
Use some variable like flag, and initialise it in the onCreate. and based on the flag, you can handle the request.