Merge branch 'sendFeedbackAndBugToDrawer' of s416084/find-my-tutor-android into develop

This commit is contained in:
Marcin Jedyński 2018-11-18 01:10:45 +00:00 committed by Gogs
commit b0e81d474e
9 changed files with 301 additions and 12 deletions

View File

@ -24,16 +24,16 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.Toast;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
import com.uam.wmi.findmytutor.utils.ActiveFragment;
import com.uam.wmi.findmytutor.utils.FeedbackUtils;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
@ -55,7 +55,7 @@ public abstract class BaseActivity
protected DrawerLayout sideDrawer;
protected Toolbar toolbar;
protected boolean isTutor;
protected FeedbackUtils feedbackUtils;
private ActionBarDrawerToggle actionBarDrawerToggle;
private SharingFragment sharingFragment;
@ -68,7 +68,7 @@ public abstract class BaseActivity
setContentView(getContentViewId());
drawerNavigationView = findViewById(R.id.nav_view);
sideDrawer = findViewById(R.id.activity_container);
feedbackUtils = new FeedbackUtils(BaseActivity.this);
drawerNavigationView.setNavigationItemSelectedListener(
item -> {
String itemName = (String) item.getTitle();
@ -76,17 +76,17 @@ public abstract class BaseActivity
if (itemName.equals(getResources().getString(R.string.navigation_item_whitelist))) {
/* launchIntent = new Intent(getApplicationContext(), WhitelistActivity.class);
startActivity(launchIntent);*/
} else if (itemName.equals(getResources().getString(R.string.navigation_item_blacklist))) {
} else if (itemName.equals(getResources().getString(R.string.navigation_item_blacklist))) {
/* launchIntent = new Intent(getApplicationContext(), BlacklistActivity.class);
startActivity(launchIntent);*/
} else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) {
} else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) {
/* launchIntent = new Intent(getApplicationContext(), ProfileActivity.class);
startActivity(launchIntent);*/
} else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) {
} else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) {
launchIntent = new Intent(getApplicationContext(), SettingsActivity.class);
startActivity(launchIntent);
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
stopBackgroundLocalizationTask();
}
@ -101,8 +101,14 @@ public abstract class BaseActivity
}
startActivity(i);
finish();
} else if (itemName.equals(getResources().getString(R.string.navigation_item_feedback))) {
feedbackUtils.showNoteDialog("FEEDBACK");
}
/*showNoteDialog(BaseActivity.this, );*/
} else if (itemName.equals(getResources().getString(R.string.navigation_item_bug))) {
feedbackUtils.showNoteDialog("BUG REPORT");
/*showNoteDialog(BaseActivity.this, "BUG REPORT");*/
}
sideDrawer.closeDrawers();
@ -351,6 +357,8 @@ public abstract class BaseActivity
item.setChecked(true);
}
abstract int getNavigationMenuItemId();
abstract int getContentViewId();

View File

@ -0,0 +1,47 @@
package com.uam.wmi.findmytutor.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Feedback {
@SerializedName("isAnonymous")
@Expose
private Boolean isAnonymous;
@SerializedName("header")
@Expose
private String header;
@SerializedName("body")
@Expose
private String body;
public Feedback(boolean isAnonymous, String header, String body){
this.isAnonymous = isAnonymous;
this.header = header;
this.body = body;
}
public Boolean getIsAnonymous() {
return isAnonymous;
}
public void setIsAnonymous(Boolean isAnonymous) {
this.isAnonymous = isAnonymous;
}
public String getHeader() {
return header;
}
public void setHeader(String header) {
this.header = header;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
}

View File

@ -0,0 +1,17 @@
package com.uam.wmi.findmytutor.service;
import com.uam.wmi.findmytutor.model.Feedback;
import io.reactivex.Observable;
import io.reactivex.Single;
import retrofit2.Response;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
public interface FeedbackService {
@POST("api/Feedback")
Observable<Response<Void>> postFeedback(@Body Feedback feedback);
@GET("api/Feedback")
Single<Feedback> getFeedback();
}

View File

@ -0,0 +1,122 @@
package com.uam.wmi.findmytutor.utils;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.activity.BaseActivity;
import com.uam.wmi.findmytutor.model.Feedback;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.FeedbackService;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.Response;
public class FeedbackUtils {
private Context activityContext;
public FeedbackUtils(Context context){
activityContext = context;
}
public void showNoteDialog(String subject) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(activityContext);
View view = layoutInflaterAndroid.inflate(R.layout.feedback_modal, null);
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(activityContext);
alertDialogBuilderUserInput.setView(view).setPositiveButton("SEND",null);
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
EditText modalUserInput = view.findViewById(R.id.feedback_input);
CheckBox modalIsAnonymous = view.findViewById(R.id.feedback_is_anonymous);
TextView modalTitle = view.findViewById(R.id.feedback_modal_title);
TextView modalSubtitle = view.findViewById(R.id.feedback_modal_subtitle);
modalTitle.setText(subject);
if( subject == "BUG REPORT"){
modalSubtitle.setText("Tell us what you noticed!(max 1000 characters)");
} else if (subject == "FEEDBACK")
{
modalSubtitle.setText("Tell us what you think!(max 1000 characters)");
}
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String body = modalUserInput.getText().toString();
if(TextUtils.isEmpty(body)){
Toast.makeText(activityContext, "Please describe your insights.", Toast.LENGTH_SHORT).show();
modalUserInput.requestFocus();
}else{
boolean mode = modalIsAnonymous.isChecked();
sendFeedback(subject,body,mode);
alertDialog.dismiss();
}
}
});
}
});
alertDialog.show();
}
private void sendFeedback(String header, String body, boolean mode) {
String appVersion = null;
String metadata = null;
try {
appVersion = activityContext.getPackageManager().getPackageInfo(activityContext.getPackageName(), 0).versionName;
if( !mode ){
metadata = "\n-----------------------------\n" +
"User ID: " + PrefUtils.getUserId(activityContext) + "\n" +
"Device OS: Android\n" +
"Device OS version: " + Build.VERSION.RELEASE + "\n" +
"App Version: " + appVersion + "\n" +
"Device Model: " + Build.MODEL + "\n" +
"Device Manufacturer: " + Build.MANUFACTURER + "\n" +
"-----------------------------\n";
body = metadata + body;
header = header + " - " + PrefUtils.getUserFirstName(activityContext) + " " + PrefUtils.getUserLastName(activityContext);
}
} catch (PackageManager.NameNotFoundException e) {
}
FeedbackService feedbackService = ApiClient.getClient(activityContext).create(FeedbackService.class);
Feedback userFeedback = new Feedback(mode,header,body);
CompositeDisposable disposable = new CompositeDisposable();
disposable.add(feedbackService.postFeedback(userFeedback)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError));
}
private void handleResponse(Response<Void> resp) {
Toast.makeText(activityContext, "Thank you for subbmiting your feedback", Toast.LENGTH_SHORT).show();
}
private void handleError(Throwable error) {
if (error instanceof HttpException) {
ResponseBody responseBody = ((HttpException) error).response().errorBody();
Toast.makeText(activityContext,
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(activityContext,
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
Log.d("FEEDBACK",error.getMessage());
}
}
}

View File

@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M511.988,288.9c-0.478,17.43 -15.217,31.1 -32.653,31.1H424v16c0,21.864 -4.882,42.584 -13.6,61.145l60.228,60.228c12.496,12.497 12.496,32.758 0,45.255 -12.498,12.497 -32.759,12.496 -45.256,0l-54.736,-54.736C345.886,467.965 314.351,480 280,480V236c0,-6.627 -5.373,-12 -12,-12h-24c-6.627,0 -12,5.373 -12,12v244c-34.351,0 -65.886,-12.035 -90.636,-32.108l-54.736,54.736c-12.498,12.497 -32.759,12.496 -45.256,0 -12.496,-12.497 -12.496,-32.758 0,-45.255l60.228,-60.228C92.882,378.584 88,357.864 88,336v-16H32.666C15.23,320 0.491,306.33 0.013,288.9 -0.484,270.816 14.028,256 32,256h56v-58.745l-46.628,-46.628c-12.496,-12.497 -12.496,-32.758 0,-45.255 12.498,-12.497 32.758,-12.497 45.256,0L141.255,160h229.489l54.627,-54.627c12.498,-12.497 32.758,-12.497 45.256,0 12.496,12.497 12.496,32.758 0,45.255L424,197.255V256h56c17.972,0 32.484,14.816 31.988,32.9zM257,0c-61.856,0 -112,50.144 -112,112h224C369,50.144 318.856,0 257,0z"/>
</vector>

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/feedback_modal_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/feedback_input"
android:layout_marginBottom="@dimen/dimen_10"
android:fontFamily="sans-serif-medium"
android:lineSpacingExtra="8sp"
android:text="placeholder"
android:textColor="@color/colorAccent"
android:textSize="@dimen/lbl_new_note_title"
android:textStyle="normal" />
<EditText
android:id="@+id/feedback_input"
android:layout_width="315dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:ems="10"
android:hint="@string/modal_feedback_hint"
android:inputType="textMultiLine"
android:maxLength="1000"
android:maxLines="7"
android:requiresFadingEdge="vertical"
android:scrollbars="vertical" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/feedback_input"
android:layout_toStartOf="@+id/feedback_is_anonymous"
android:text="@string/modal_feedback_question"
android:textSize="16sp" />
<CheckBox
android:id="@+id/feedback_is_anonymous"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_below="@+id/feedback_input"
android:layout_alignEnd="@+id/feedback_input"
android:textSize="14sp" />
<TextView
android:id="@+id/feedback_modal_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/feedback_input"
android:layout_alignEnd="@+id/feedback_input"
android:layout_marginEnd="0dp"
android:layout_marginBottom="-50dp"
android:text="Tell us what you think (max 1000 characters)"
android:textSize="14sp" />
</RelativeLayout>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group>
<group android:id="@+id/drawer_group_tutor">
<item
android:id="@+id/nav_item_one"
android:icon="@drawable/ic_people_white"
@ -14,13 +14,23 @@
android:icon="@drawable/outline_person_white_24dp"
android:title="@string/navigation_item_profile" />
</group>
<group android:id="@+id/group_menu">
<group android:id="@+id/drawer_group_feedback">
<item
android:id="@+id/nav_item_four"
android:icon="@android:drawable/ic_dialog_email"
android:title="@string/navigation_item_feedback" />
<item
android:id="@+id/nav_item_five"
android:icon="@drawable/bug_icon"
android:title="@string/navigation_item_bug" />
</group>
<group android:id="@+id/drawer_group_utilities">
<item
android:id="@+id/nav_item_six"
android:icon="@drawable/ic_menu_settings_key"
android:title="@string/navigation_item_settings" />
<item
android:id="@+id/nav_item_five"
android:id="@+id/nav_item_seven"
android:icon="@android:drawable/ic_lock_power_off"
android:title="@string/navigation_item_logout" />
</group>

View File

@ -127,6 +127,8 @@
<string name="user_location_permission_explanation">Ta aplikacja potrzebuje uprawnień do lokalizacji.</string>
<string name="settings_category_status">Ustawienia statusu</string>
<string name="settings_category_manuallocation">Ręczny wybór lokalizacji</string>
<string name="navigation_item_feedback">Wyślij nam feedback</string>
<string name="navigation_item_bug">Zgłoś błąd</string>
<string name="fab_title_bound_area">Bounds OFF</string>
</resources>

View File

@ -12,9 +12,19 @@
<string name="navigation_drawer_close">Drawer Closed</string>
<string name="navigation_item_blacklist">Blacklist</string>
<string name="navigation_item_whitelist">Whitelist</string>
<string name="navigation_item_feedback">Send us feedback</string>
<string name="navigation_item_bug">Report a bug</string>
<string name="navigation_item_settings">Settings</string>
<string name="navigation_item_profile">Profile</string>
<string name="navigation_item_logout">Log out</string>
<!--Feedback/Bug report-->
<string name="email_subject_feedback">Find My Tutor - feedback</string>
<string name="email_subject_bug">Find My Tutor - bug report</string>
<string name="modal_feedback_hint">Please input your feedback.</string>
<string name="modal_feedback_question">Send anonymously</string>
<!-- Tutors list -->
<string name="action_settings">Settings</string>
<string name="activity_title_home">Notes</string>
@ -34,6 +44,7 @@
<string name="action_white_list">White List</string>
<string name="title_activity_settings">Settings</string>
<string name="fmt_email">findmytutorwmi@gmail.com</string>