public class FormPresenter implements FormConnector.Presenter {
private String tag = "";
private FormConnector.View view;
private FormModel model;
private FileLogger fileLogger;
public FormPresenter(FormModel formModel, FormConnector.View view, String tag, String screenType) {
}
@Override
public void start() {
Logger.i("*************MVP WORKED ****************");
}
@Override
public void fileLogger(String log) {
fileLogger.appendLog(tag, log);
}
@Override
public void flushLogger() {
fileLogger.flush(tag);
}
/* @Override
public void updateRating(int rating, String comments) {
view.showProgress();
if (reasons != null) {
model.updateRating(tId, rating, comments, new CallBack<LogoutResponse>() {
@Override
public void success(LogoutResponse objects) {
view.dismissProgress();
view.showMessage(Constants.NEGATIVE, objects.message);
}
@Override
public void responseFailure(LogoutResponse objects) {
view.dismissProgress();
view.showMessage(Constants.ERROR_RESPONSE, "");
}
@Override
public void connectionFailure(Throwable errorThrowable) {
view.dismissProgress();
view.showMessage(Constants.ERROR_NETWORK, "");
}
});
}
}*/
}
*********
public class FormFragment extends BaseFragment implements FormConnector.View {
private FormConnector.Presenter presenter;
private EditText txtPhone, txtEmail;
private Button butSubmit;
public static FormFragment newInstance() {
return new FormFragment();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.frag_form, container, false);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
txtPhone = view.findViewById(R.id.edt_phone);
txtEmail = view.findViewById(R.id.edt_email);
butSubmit = view.findViewById(R.id.but_done);
butSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phone = txtPhone.getText().toString();
String email = txtEmail.getText().toString();
if (!TextUtils.isEmpty(phone) && !TextUtils.isEmpty(email)) {
Toast.makeText(getActivity(), "Submitted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Fill the mandatory fields", Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// presenter.start();
}
@Override
public void setPresenter(FormConnector.Presenter _presenter) {
presenter = _presenter;
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onDestroy() {
super.onDestroy();
presenter.flushLogger();
}
}
************
public interface FormConnector {
interface Presenter extends BasePresenter {
// void updateRating(int rating, String comments);
}
interface View extends BaseView<Presenter> {
}
}
************
public class FormActivity extends AppCompatActivity {
private final static String TAG = "Form";
private FormFragment fragment;
/**
* Start the splash
*
* @param conActivity instance
*/
public static void startActivity(Activity conActivity) {
Intent in = new Intent(conActivity, FormActivity.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
conActivity.startActivity(in);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FileLogger.getInstance().startLoggerForTag(TAG);
setContentView(R.layout.act_container);
findViewById(R.id.lay_toolbar).setVisibility(View.GONE);
if (fragment == null) {
fragment = FormFragment.newInstance();
/*
FCM
https://firebase.google.com/docs/cloud-messaging/android/receive - Handling messages
https://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase
Called when app is in background
*/
String screenType = null;
Bundle bundle = getIntent().getExtras();
if (bundle != null && bundle.containsKey("type")) {
screenType = bundle.getString("type");
Logger.e("Notification Type", screenType);
}
new FormPresenter(new FormModelImpl(this), fragment, TAG, screenType);
Utils.addFragmentToActivity(getSupportFragmentManager(), fragment, R.id.lay_fr_container);
}
}
}
*************
public class FormModelImpl implements FormModel {
private SessionManger sessionManger;
public FormModelImpl(Context context) {
sessionManger = new SessionManger(context);
}
/*@Override
public void updateRating(String tId, int rating, String comments, final CallBack<LogoutResponse> callBack) {
AppController controller = AppController.getInstance();
RatingRequest request = new RatingRequest();
request.comments = comments;
request.ratings = rating;
request.pass_id = tId;
controller.getApiManager().ratRating(controller.getDomainPathSegments(), request, sessionManger.getStringKey(SessionManger.LANGUAGE_LOCALE)).enqueue(new Callback<LogoutResponse>() {
@Override
public void onResponse(Call<LogoutResponse> call, Response<LogoutResponse> response) {
LogoutResponse res = response.body();
if (res != null && response.isSuccessful()) {
callBack.success(res);
} else {
callBack.responseFailure(null);
}
}
@Override
public void onFailure(Call<LogoutResponse> call, Throwable t) {
callBack.connectionFailure(t);
}
});
}*/
}
********
public interface FormModel {
}
*********
Comments
Post a Comment