-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add send feedback button to login/signup error dialog, improve feedba…
…ck sharing intent to only query email clients
- Loading branch information
Showing
7 changed files
with
88 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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); | ||
} | ||
|
||
} | ||
|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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(); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -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(); | ||
|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters