|
|
|
@ -59,13 +59,10 @@ import org.json.JSONException;
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
|
|
import eightbitlab.com.blurview.BlurView;
|
|
|
|
|
import io.sentry.Sentry;
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRefreshListener, SearchView.OnQueryTextListener, SearchView.OnCloseListener, OverScrollManager.OverScrollHelper {
|
|
|
|
|
private static final String TAG = "MainActivity";
|
|
|
|
@ -258,8 +255,10 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
|
|
|
|
|
if (MainApplication.isCrashReportingEnabled()) {
|
|
|
|
|
SharedPreferences preferences = getSharedPreferences("sentry", MODE_PRIVATE);
|
|
|
|
|
String lastExitReason = preferences.getString("lastExitReason", "");
|
|
|
|
|
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Last Exit Reason: " + lastExitReason);
|
|
|
|
|
if (lastExitReason.equals("crash")) {
|
|
|
|
|
String lastEventId = preferences.getString("lastEventId", "");
|
|
|
|
|
if (BuildConfig.DEBUG) Log.d("NoodleDebug", "Last Event ID: " + lastEventId);
|
|
|
|
|
if (!lastEventId.equals("")) {
|
|
|
|
|
// Three edit texts for the user to enter their email, name and a description of the issue
|
|
|
|
|
EditText email = new EditText(this);
|
|
|
|
@ -299,47 +298,31 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
|
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
|
connection.setRequestProperty("Content-Type", "application/json");
|
|
|
|
|
connection.setRequestProperty("Authorization", "Bearer " + BuildConfig.SENTRY_TOKEN);
|
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
|
connection.setDoInput(true);
|
|
|
|
|
connection.setChunkedStreamingMode(0);
|
|
|
|
|
connection.connect();
|
|
|
|
|
// Write the JSON data to the output stream
|
|
|
|
|
OutputStream outputStream = connection.getOutputStream();
|
|
|
|
|
// Name and email are optional, so if they are empty, set them to
|
|
|
|
|
// Anonymous and Anonymous respectively
|
|
|
|
|
// Setups the JSON body
|
|
|
|
|
String nameString = name.getText().toString();
|
|
|
|
|
String emailString = email.getText().toString();
|
|
|
|
|
if (nameString.equals("")) nameString = "Anonymous";
|
|
|
|
|
if (emailString.equals("")) emailString = "Anonymous";
|
|
|
|
|
String finalNameString = nameString;
|
|
|
|
|
String finalEmailString = emailString;
|
|
|
|
|
outputStream.write(new JSONObject() {{
|
|
|
|
|
put("event_id", lastEventId);
|
|
|
|
|
put("name", finalNameString);
|
|
|
|
|
put("email", finalEmailString);
|
|
|
|
|
put("comments", description.getText().toString());
|
|
|
|
|
}}.toString().getBytes());
|
|
|
|
|
outputStream.flush();
|
|
|
|
|
outputStream.close();
|
|
|
|
|
// Read the response
|
|
|
|
|
InputStream inputStream = connection.getInputStream();
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
int length;
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
while ((length = inputStream.read(buffer)) != -1) {
|
|
|
|
|
stringBuilder.append(new String(buffer, 0, length));
|
|
|
|
|
JSONObject body = new JSONObject();
|
|
|
|
|
body.put("event_id", lastEventId);
|
|
|
|
|
body.put("name", nameString);
|
|
|
|
|
body.put("email", emailString);
|
|
|
|
|
body.put("comments", description.getText().toString());
|
|
|
|
|
// Send the request
|
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
|
connection.getOutputStream().write(body.toString().getBytes());
|
|
|
|
|
connection.connect();
|
|
|
|
|
// For debug builds, log the response code and response body
|
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
|
Log.d("NoodleDebug", "Response Code: " + connection.getResponseCode());
|
|
|
|
|
}
|
|
|
|
|
inputStream.close();
|
|
|
|
|
connection.disconnect();
|
|
|
|
|
if (BuildConfig.DEBUG) Log.d("Sentry", stringBuilder.toString());
|
|
|
|
|
// Valid responses will be a json object with a key "id"
|
|
|
|
|
JSONObject jsonObject = new JSONObject(stringBuilder.toString());
|
|
|
|
|
if (jsonObject.has("id")) {
|
|
|
|
|
// Show a toast to the user to confirm that the feedback has been sent
|
|
|
|
|
// Check if the request was successful
|
|
|
|
|
if (connection.getResponseCode() == 200) {
|
|
|
|
|
runOnUiThread(() -> Toast.makeText(this, R.string.sentry_dialogue_success, Toast.LENGTH_LONG).show());
|
|
|
|
|
} else {
|
|
|
|
|
// Show a toast to the user to confirm that the feedback has not been sent
|
|
|
|
|
runOnUiThread(() -> Toast.makeText(this, R.string.sentry_dialogue_failed_toast, Toast.LENGTH_LONG).show());
|
|
|
|
|
runOnUiThread(() -> Toast.makeText(this,
|
|
|
|
|
R.string.sentry_dialogue_failed_toast,
|
|
|
|
|
Toast.LENGTH_LONG).show());
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException | JSONException ignored) {
|
|
|
|
|
// Show a toast if the user feedback could not be submitted
|
|
|
|
@ -348,7 +331,8 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
|
|
|
|
|
}).start();
|
|
|
|
|
}).setNegativeButton(R.string.cancel, (dialog, which) -> {
|
|
|
|
|
preferences.edit().remove("lastEventId").apply();
|
|
|
|
|
Sentry.captureMessage("User has ignored the crash");
|
|
|
|
|
preferences.edit().putString("lastExitReason", "").apply();
|
|
|
|
|
Log.w(TAG, "User cancelled sentry dialog");
|
|
|
|
|
}).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|