adjuested feedback model

This commit is contained in:
marcin.jedynski 2018-11-28 18:37:48 +01:00
parent d7bc56f5f9
commit 1e07168725
3 changed files with 169 additions and 27 deletions

View File

@ -1,5 +1,5 @@
package com.uam.wmi.findmytutor.model; package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
@ -8,18 +8,53 @@ public class Feedback {
@SerializedName("isAnonymous") @SerializedName("isAnonymous")
@Expose @Expose
private Boolean isAnonymous; private Boolean isAnonymous;
@SerializedName("header") @SerializedName("type")
@Expose @Expose
private String header; private String type;
@SerializedName("user")
@Expose
private String user;
@SerializedName("deviceOS")
@Expose
private String deviceOS;
@SerializedName("appVersion")
@Expose
private String appVersion;
@SerializedName("deviceModel")
@Expose
private String deviceModel;
@SerializedName("body") @SerializedName("body")
@Expose @Expose
private String body; private String body;
public Feedback(boolean isAnonymous, String header, String body){ /**
* No args constructor for use in serialization
*
*/
public Feedback() {
}
/**
*
* @param body
* @param appVersion
* @param deviceModel
* @param type
* @param isAnonymous
* @param user
* @param deviceOS
*/
public Feedback(Boolean isAnonymous, String type, String user, String deviceOS, String appVersion, String deviceModel, String body) {
super();
this.isAnonymous = isAnonymous; this.isAnonymous = isAnonymous;
this.header = header; this.type = type;
this.user = user;
this.deviceOS = deviceOS;
this.appVersion = appVersion;
this.deviceModel = deviceModel;
this.body = body; this.body = body;
} }
public Boolean getIsAnonymous() { public Boolean getIsAnonymous() {
return isAnonymous; return isAnonymous;
} }
@ -28,12 +63,74 @@ public class Feedback {
this.isAnonymous = isAnonymous; this.isAnonymous = isAnonymous;
} }
public String getHeader() { public Feedback withIsAnonymous(Boolean isAnonymous) {
return header; this.isAnonymous = isAnonymous;
return this;
} }
public void setHeader(String header) { public String getType() {
this.header = header; return type;
}
public void setType(String type) {
this.type = type;
}
public Feedback withType(String type) {
this.type = type;
return this;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public Feedback withUser(String user) {
this.user = user;
return this;
}
public String getDeviceOS() {
return deviceOS;
}
public void setDeviceOS(String deviceOS) {
this.deviceOS = deviceOS;
}
public Feedback withDeviceOS(String deviceOS) {
this.deviceOS = deviceOS;
return this;
}
public String getAppVersion() {
return appVersion;
}
public void setAppVersion(String appVersion) {
this.appVersion = appVersion;
}
public Feedback withAppVersion(String appVersion) {
this.appVersion = appVersion;
return this;
}
public String getDeviceModel() {
return deviceModel;
}
public void setDeviceModel(String deviceModel) {
this.deviceModel = deviceModel;
}
public Feedback withDeviceModel(String deviceModel) {
this.deviceModel = deviceModel;
return this;
} }
public String getBody() { public String getBody() {
@ -44,4 +141,38 @@ public class Feedback {
this.body = body; this.body = body;
} }
public Feedback withBody(String body) {
this.body = body;
return this;
}
@Override
public String toString() {
return Boolean.toString(this.isAnonymous) + this.type + this.user+this.deviceOS+this.appVersion+this.deviceModel+this.body;
}
// @Override
// public String toString() {
// return new ToStringBuilder(this).append("isAnonymous", isAnonymous).append("type", type).append("user", user).append("deviceOS", deviceOS).append("appVersion", appVersion).append("deviceModel", deviceModel).append("body", body).toString();
// }
} }
// private Boolean isAnonymous;
// @SerializedName("type")
// @Expose
// private String type;
// @SerializedName("user")
// @Expose
// private String user;
// @SerializedName("deviceOS")
// @Expose
// private String deviceOS;
// @SerializedName("appVersion")
// @Expose
// private String appVersion;
// @SerializedName("deviceModel")
// @Expose
// private String deviceModel;
// @SerializedName("body")
// @Expose
// private String body;

View File

@ -10,8 +10,8 @@ import retrofit2.http.POST;
public interface FeedbackService { public interface FeedbackService {
@POST("api/Feedback") @POST("api/Feedback")
Observable<Response<Void>> postFeedback(@Body Feedback feedback); Observable<Void> postFeedback(@Body Feedback feedback);
@GET("api/Feedback") @GET("api/Feedback")
Single<Feedback> getFeedback(); Observable<Void> getFeedback();
} }

View File

@ -77,31 +77,42 @@ public class FeedbackUtils {
private void sendFeedback(String header, String body, boolean mode) { private void sendFeedback(String header, String body, boolean mode) {
String appVersion = null; String appVersion = null;
String metadata = null; String metadata = null;
Feedback userFeedback= null;
try { try {
appVersion = activityContext.getPackageManager().getPackageInfo(activityContext.getPackageName(), 0).versionName; appVersion = activityContext.getPackageManager().getPackageInfo(activityContext.getPackageName(), 0).versionName;
if( !mode ){ if( !mode ){
metadata = "\n-----------------------------\n" + body = PrefUtils.getUserFirstName(activityContext) + " " + PrefUtils.getUserLastName(activityContext) + "\n" + body;
"User ID: " + PrefUtils.getUserId(activityContext) + "\n" + userFeedback = new Feedback(mode,
"Device OS: Android\n" + header,
"Device OS version: " + Build.VERSION.RELEASE + "\n" + PrefUtils.getUserId(activityContext),
"App Version: " + appVersion + "\n" + "Android "+ Build.VERSION.RELEASE,
"Device Model: " + Build.MODEL + "\n" + appVersion,
"Device Manufacturer: " + Build.MANUFACTURER + "\n" + Build.MODEL,
"-----------------------------\n"; body);
body = metadata + body; Log.d("FEEDBACK non anon", userFeedback.toString());
header = header + " - " + PrefUtils.getUserFirstName(activityContext) + " " + PrefUtils.getUserLastName(activityContext);
}else{
userFeedback = new Feedback(mode,
header,
"anonymous",
"Android "+ Build.VERSION.RELEASE,
appVersion,
Build.MODEL,
body);
Log.d("FEEDBACK anon",userFeedback.toString());
} }
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
} }
FeedbackService feedbackService = ApiClient.getClient(activityContext).create(FeedbackService.class); FeedbackService feedbackService = ApiClient.getClient(activityContext).create(FeedbackService.class);
Feedback userFeedback = new Feedback(mode,header,body);
CompositeDisposable disposable = new CompositeDisposable(); CompositeDisposable disposable = new CompositeDisposable();
disposable.add(feedbackService.postFeedback(userFeedback) disposable.add(feedbackService.postFeedback(userFeedback)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError)); .subscribe(this::handleResponse, this::handleError));
} }
private void handleResponse(Response<Void> resp) { private void handleResponse( Void resp) {
Toast.makeText(activityContext, activityContext.getString(R.string.modal_feedback_thankyou), Toast.LENGTH_SHORT).show(); Toast.makeText(activityContext, activityContext.getString(R.string.modal_feedback_thankyou), Toast.LENGTH_SHORT).show();
} }
@ -113,9 +124,9 @@ public class FeedbackUtils {
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show(); RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
} else { } else {
Toast.makeText(activityContext, // Toast.makeText(activityContext,
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show(); // "Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("FEEDBACK",error.getMessage()); Log.d("FEEDBACK handerr ",error.getMessage());
} }
} }
} }