Skip to content

Commit

Permalink
Add send feedback button to login/signup error dialog, improve feedba…
Browse files Browse the repository at this point in the history
…ck sharing intent to only query email clients
  • Loading branch information
c99koder committed Dec 11, 2020
1 parent c90b6ea commit 0fd20d2
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 119 deletions.
4 changes: 4 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
</queries>

<uses-sdk tools:overrideLibrary="android.support.customtabs, com.datatheorem.android.trustkit, android.support.text.emoji, android.support.text.emoji.bundled" />
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ android {
testBuildType "mockdata"

defaultConfig {
versionCode 296
versionCode 297
versionName "4.24"
minSdkVersion 17
targetSdkVersion 30
Expand Down Expand Up @@ -356,9 +356,9 @@ dependencies {
implementation "androidx.cardview:cardview:1.0.0"
implementation "com.google.android.material:material:1.2.1"
implementation "androidx.recyclerview:recyclerview:1.1.0"
implementation "androidx.browser:browser:1.2.0"
implementation "androidx.browser:browser:1.3.0"
implementation "androidx.emoji:emoji:1.1.0"
implementation "androidx.exifinterface:exifinterface:1.3.1"
implementation "androidx.exifinterface:exifinterface:1.3.2"
implementation "androidx.room:room-runtime:2.2.5"
annotationProcessor "androidx.room:room-compiler:2.2.5"
implementation "com.google.android.gms:play-services-base:17.5.0"
Expand Down
4 changes: 2 additions & 2 deletions irccloud-android.iml
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
<orderEntry type="library" name="Gradle: androidx.cardview:cardview:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.viewpager2:viewpager2:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.recyclerview:recyclerview:1.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.browser:browser:1.2.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.exifinterface:exifinterface:1.3.1@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.browser:browser:1.3.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.exifinterface:exifinterface:1.3.2@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.sharetarget:sharetarget:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.emoji:emoji:1.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-auth:19.0.0@aar" level="project" />
Expand Down
73 changes: 0 additions & 73 deletions src/com/irccloud/android/IRCCloudApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,79 +119,6 @@ public void onFailed(@Nullable Throwable throwable) {
conn = NetworkConnection.getInstance();
ColorFormatter.init();

if (prefs.contains("notify")) {
SharedPreferences.Editor editor = prefs.edit();
editor.putString("notify_type", prefs.getBoolean("notify", true) ? "1" : "0");
editor.remove("notify");
editor.apply();
}

if (prefs.contains("files-wifionly")) {
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("files-usemobiledata", !prefs.getBoolean("files-wifionly", false));
editor.remove("files-wifionly");
editor.apply();
}

if (prefs.contains("notify_sound")) {
SharedPreferences.Editor editor = prefs.edit();
if (!prefs.getBoolean("notify_sound", true))
editor.putString("notify_ringtone", "");
editor.remove("notify_sound");
editor.apply();
}

if (prefs.contains("notify_lights")) {
SharedPreferences.Editor editor = prefs.edit();
if (!prefs.getBoolean("notify_lights", true))
editor.putString("notify_led_color", "0");
editor.remove("notify_lights");
editor.apply();
}

if (prefs.contains("notify_ringtone") && prefs.getString("notify_ringtone", "").startsWith("android.resource://" + getPackageName() + "/")) {
SharedPreferences.Editor editor = prefs.edit();
editor.putString("notify_ringtone", "android.resource://" + getPackageName() + "/raw/digit");
editor.apply();
}

if (prefs.contains("acra.enable")) {
SharedPreferences.Editor editor = prefs.edit();
editor.remove("acra.enable");
editor.apply();
}

if(prefs.contains("notifications_json")) {
SharedPreferences.Editor editor = prefs.edit();
editor.remove("notifications_json");
editor.remove("networks_json");
editor.remove("lastseeneids_json");
editor.remove("dismissedeids_json");
editor.apply();
}

prefs = getSharedPreferences("prefs", 0);
if (prefs.getString("host", "www.irccloud.com").equals("www.irccloud.com") && !prefs.contains("path") && prefs.contains("session_key")) {
IRCCloudLog.Log(Log.INFO, "IRCCloud", "Migrating path from session key");
SharedPreferences.Editor editor = prefs.edit();
editor.putString("path", "/websocket/" + prefs.getString("session_key", "").charAt(0));
editor.apply();
}
if (prefs.contains("host") && prefs.getString("host", "").equals("www.irccloud.com")) {
IRCCloudLog.Log(Log.INFO, "IRCCloud", "Migrating host");
SharedPreferences.Editor editor = prefs.edit();
editor.putString("host", "api.irccloud.com");
editor.apply();
}
if (prefs.contains("gcm_app_version")) {
SharedPreferences.Editor editor = prefs.edit();
editor.remove("gcm_app_version");
editor.remove("gcm_app_build");
editor.remove("gcm_registered");
editor.remove("gcm_reg_id");
editor.apply();
}

NetworkConnection.IRCCLOUD_HOST = prefs.getString("host", BuildConfig.HOST);
NetworkConnection.IRCCLOUD_PATH = prefs.getString("path", "/");

Expand Down
70 changes: 67 additions & 3 deletions src/com/irccloud/android/NetworkConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
package com.irccloud.android;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.LabeledIntent;
import android.content.pm.ResolveInfo;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
Expand All @@ -37,6 +41,9 @@
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.widget.Toast;

import androidx.core.content.FileProvider;

import com.codebutler.android_websockets.WebSocketClient;
import com.datatheorem.android.trustkit.TrustKit;
Expand Down Expand Up @@ -68,6 +75,8 @@
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -87,6 +96,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
Expand Down Expand Up @@ -660,37 +670,47 @@ public JSONObject impression(String adid, String referrer, String sk) {
}

public JSONObject fetchJSON(String url) throws IOException {
String response = null;
try {
String response = fetch(new URL(url), null, session, null, null);
response = fetch(new URL(url), null, session, null, null);
return new JSONObject(response);
} catch (Exception e) {
if(response != null)
IRCCloudLog.Log("Unable to parse JSON: " + response);
printStackTraceToCrashlytics(e);
}
return null;
}

public JSONObject fetchJSON(String url, String postdata) throws IOException {
String response = null;
try {
String response = fetch(new URL(url), postdata, null, null, null);
response = fetch(new URL(url), postdata, null, null, null);
return new JSONObject(response);
} catch (Exception e) {
if(response != null)
IRCCloudLog.Log("Unable to parse JSON: " + response);
printStackTraceToCrashlytics(e);
}
return null;
}

public JSONObject fetchJSON(String url, HashMap<String, String>headers) throws IOException {
String response = null;
try {
String response = fetch(new URL(url), null, null, null, headers);
response = fetch(new URL(url), null, null, null, headers);
return new JSONObject(response);
} catch (Exception e) {
if(response != null)
IRCCloudLog.Log("Unable to parse JSON: " + response);
printStackTraceToCrashlytics(e);
}
return null;
}

public JSONObject fetchConfig() {
try {
IRCCloudLog.Log(Log.INFO, TAG, "Requesting configuration");
JSONObject o = fetchJSON("https://" + IRCCLOUD_HOST + "/config");
if(o != null) {
config = o;
Expand Down Expand Up @@ -735,6 +755,7 @@ public JSONObject fetchConfig() {
NetworkConnection.IRCCLOUD_HOST = NetworkConnection.IRCCLOUD_HOST.substring(0, NetworkConnection.IRCCLOUD_HOST.length() - 1);
editor.putString("host", NetworkConnection.IRCCLOUD_HOST);
editor.apply();
IRCCloudLog.Log(Log.INFO, TAG, "API host: " + NetworkConnection.IRCCLOUD_HOST);
}

}
Expand Down Expand Up @@ -3660,4 +3681,47 @@ public static void printStackTraceToCrashlytics(Exception e) {
IRCCloudLog.Log(Log.WARN, TAG, s);
}
}

public static void sendFeedbackReport(Activity ctx) {
try {
String bugReport = "Briefly describe the issue below:\n\n\n\n\n" +
"===========\n" +
"UID: " + PreferenceManager.getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()).getString("uid", "") + "\n" +
"App version: " + ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionName + " (" + ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode + ")\n" +
"Device: " + Build.MODEL + "\n" +
"Android version: " + Build.VERSION.RELEASE + "\n" +
"Firmware fingerprint: " + Build.FINGERPRINT + "\n";

File f = new File(ctx.getFilesDir(), "logs");
f.mkdirs();
File output = new File(f, "log.txt");

FileOutputStream out = new FileOutputStream(output);
out.write(IRCCloudLog.lines().getBytes());
out.close();

Intent email = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:[email protected]"));
email.putExtra(Intent.EXTRA_SUBJECT, "IRCCloud for Android");

List<ResolveInfo> resolveInfos = ctx.getPackageManager().queryIntentActivities(email, 0);
List<LabeledIntent> intents = new ArrayList<>();
for (ResolveInfo info : resolveInfos) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"IRCCloud Team <[email protected]>"});
intent.putExtra(Intent.EXTRA_TEXT, bugReport);
intent.putExtra(Intent.EXTRA_SUBJECT, "IRCCloud for Android");
intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(ctx, ctx.getPackageName() + ".fileprovider", output));
intents.add(new LabeledIntent(intent, info.activityInfo.packageName, info.loadLabel(ctx.getPackageManager()), info.icon));
}
Intent chooser = Intent.createChooser(intents.remove(intents.size() - 1), "Send Feedback:");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new LabeledIntent[intents.size()]));
ctx.startActivity(chooser);
} catch (Exception e) {
Toast.makeText(ctx, "Unable to generate email report: " + e.getMessage(), Toast.LENGTH_SHORT).show();
IRCCloudLog.LogException(e);
NetworkConnection.printStackTraceToCrashlytics(e);
}
}
}
41 changes: 3 additions & 38 deletions src/com/irccloud/android/activity/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ public class BaseActivity extends AppCompatActivity implements NetworkConnection
private GoogleApiClient mGoogleApiClient;
private boolean mResolvingError;
private static final int REQUEST_RESOLVE_ERROR = 1001;
private static final int REQUEST_SEND_FEEDBACK = 1002;
private static final String LOG_FILENAME = "log.txt";

private SMultiWindow mMultiWindow = null;
private SMultiWindowActivity mMultiWindowActivity = null;
Expand Down Expand Up @@ -248,18 +246,14 @@ public void onConnectionFailed(ConnectionResult result) {

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
if (!mGoogleApiClient.isConnecting() && !mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
} else if(requestCode == REQUEST_SEND_FEEDBACK) {
if(getFileStreamPath(LOG_FILENAME).exists()) {
android.util.Log.d("IRCCloud", "Removing stale log file");
getFileStreamPath(LOG_FILENAME).delete();
}
}
}

Expand Down Expand Up @@ -292,7 +286,7 @@ public void onResume() {
super.onResume();
IRCCloudApplication.getInstance().onResume(this);
finished = false;
File f = new File(getFilesDir(), LOG_FILENAME);
File f = new File(getFilesDir(), "log.txt");
if(f.exists()) {
android.util.Log.d("IRCCloud", "Removing stale log file");
f.delete();
Expand Down Expand Up @@ -687,36 +681,7 @@ public void onResult(Status status) {
startActivity(i);
break;
case R.id.menu_feedback:
try {
String bugReport = "Briefly describe the issue below:\n\n\n\n\n" +
"===========\n" +
"UID: " + PreferenceManager.getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()).getString("uid", "") + "\n" +
"App version: " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName + " (" + getPackageManager().getPackageInfo(getPackageName(), 0).versionCode + ")\n" +
"Device: " + Build.MODEL + "\n" +
"Android version: " + Build.VERSION.RELEASE + "\n" +
"Firmware fingerprint: " + Build.FINGERPRINT + "\n";

File f = new File(getFilesDir(), "logs");
f.mkdirs();
File output = new File(f, LOG_FILENAME);

FileOutputStream out = new FileOutputStream(output);
out.write(IRCCloudLog.lines().getBytes());
out.close();

Intent email = new Intent(Intent.ACTION_SEND);
email.setData(Uri.parse("mailto:"));
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"IRCCloud Team <[email protected]>"});
email.putExtra(Intent.EXTRA_TEXT, bugReport);
email.putExtra(Intent.EXTRA_SUBJECT, "IRCCloud for Android");
email.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", output));
startActivityForResult(Intent.createChooser(email, "Send Feedback:"), 0);
} catch (Exception e) {
Toast.makeText(this, "Unable to generate email report: " + e.getMessage(), Toast.LENGTH_SHORT).show();
IRCCloudLog.LogException(e);
NetworkConnection.printStackTraceToCrashlytics(e);
}
NetworkConnection.sendFeedbackReport(this);
break;
}
return super.onOptionsItemSelected(item);
Expand Down
9 changes: 9 additions & 0 deletions src/com/irccloud/android/activity/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import com.irccloud.android.BuildConfig;
import com.irccloud.android.IRCCloudApplication;
import com.irccloud.android.IRCCloudLinkMovementMethod;
import com.irccloud.android.IRCCloudLog;
import com.irccloud.android.NetworkConnection;
import com.irccloud.android.R;

Expand Down Expand Up @@ -759,6 +760,7 @@ protected JSONObject doInBackground(Void... arg0) {
NetworkConnection.IRCCLOUD_HOST = config.getString("api_host");
trimHost();
} catch (Exception e) {
NetworkConnection.printStackTraceToCrashlytics(e);
return null;
}
if (name.getVisibility() == View.VISIBLE) {
Expand Down Expand Up @@ -879,6 +881,7 @@ public void onSuccess(InstanceIdResult instanceIdResult) {
if (result != null) {
try {
if (result.has("message")) {
IRCCloudLog.Log(Log.ERROR, "IRCCloud", "Failure: " + result.getString("message"));
if (!BuildConfig.ENTERPRISE) {
if (name.getVisibility() == View.VISIBLE) {
Bundle b = new Bundle();
Expand Down Expand Up @@ -965,6 +968,12 @@ public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNeutralButton("Send Feedback", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
NetworkConnection.sendFeedbackReport(LoginActivity.this);
}
});
AlertDialog dialog = builder.create();
dialog.setOwnerActivity(LoginActivity.this);
if(!isFinishing())
Expand Down

0 comments on commit 0fd20d2

Please sign in to comment.