[android] Added attaching the logs to user feedback letter

This commit is contained in:
Александр Зацепин 2019-10-07 19:18:47 +03:00 committed by yoksnod
parent 702a22a8ac
commit 59f97dfefb
3 changed files with 105 additions and 110 deletions

View file

@ -4,13 +4,13 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.R;
import com.mapswithme.maps.WebContainerDelegate;
import com.mapswithme.util.Constants;
@ -20,6 +20,38 @@ import com.mapswithme.util.statistics.Statistics;
public class HelpFragment extends BaseSettingsFragment
{
@NonNull
private DialogInterface.OnClickListener mDialogClickListener = new DialogInterface.OnClickListener()
{
private void sendGeneralFeedback()
{
Statistics.INSTANCE.trackEvent(Statistics.EventName.Settings.FEEDBACK_GENERAL);
AlohaHelper.logClick(AlohaHelper.Settings.FEEDBACK_GENERAL);
Utils.sendFeedback(requireActivity());
}
private void reportBug()
{
Statistics.INSTANCE.trackEvent(Statistics.EventName.Settings.REPORT_BUG);
AlohaHelper.logClick(AlohaHelper.Settings.REPORT_BUG);
Utils.sendBugReport(requireActivity());
}
@Override
public void onClick(DialogInterface dialog, int which)
{
switch (which)
{
case 0:
sendGeneralFeedback();
break;
case 1:
reportBug();
break;
}
}
};;
@Override
protected int getLayoutRes()
@ -42,48 +74,12 @@ public class HelpFragment extends BaseSettingsFragment
};
TextView feedback = root.findViewById(R.id.feedback);
feedback.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
new AlertDialog.Builder(getActivity())
.setTitle(R.string.feedback)
.setNegativeButton(R.string.cancel, null)
.setItems(new CharSequence[] { getString(R.string.feedback_general), getString(R.string.report_a_bug) }, new DialogInterface.OnClickListener()
{
private void sendGeneralFeedback()
{
Statistics.INSTANCE.trackEvent(Statistics.EventName.Settings.FEEDBACK_GENERAL);
AlohaHelper.logClick(AlohaHelper.Settings.FEEDBACK_GENERAL);
startActivity(new Intent(Intent.ACTION_SENDTO)
.setData(Utils.buildMailUri(Constants.Email.FEEDBACK, "[" + BuildConfig.VERSION_NAME + "] Feedback", "")));
}
private void reportBug()
{
Statistics.INSTANCE.trackEvent(Statistics.EventName.Settings.REPORT_BUG);
AlohaHelper.logClick(AlohaHelper.Settings.REPORT_BUG);
Utils.sendSupportMail(getActivity(), "Bugreport from user");
}
@Override
public void onClick(DialogInterface dialog, int which)
{
switch (which)
{
case 0:
sendGeneralFeedback();
break;
case 1:
reportBug();
break;
}
}
}).show();
}
});
feedback.setOnClickListener(v -> new AlertDialog.Builder(getActivity())
.setTitle(R.string.feedback)
.setNegativeButton(R.string.cancel, null)
.setItems(new CharSequence[] { getString(R.string.feedback_general),
getString(R.string.report_a_bug) },
mDialogClickListener).show());
return root;
}

View file

@ -1,7 +1,6 @@
package com.mapswithme.maps.settings;
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
@ -11,14 +10,14 @@ import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import java.util.List;
import java.util.Locale;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.OnBackPressListener;
import com.mapswithme.util.Constants;
import com.mapswithme.util.Utils;
import java.util.List;
import java.util.Locale;
public class StoragePathFragment extends BaseSettingsFragment
implements StoragePathManager.MoveFilesListener,
OnBackPressListener
@ -109,14 +108,7 @@ public class StoragePathFragment extends BaseSettingsFragment
new AlertDialog.Builder(activity)
.setTitle(message)
.setPositiveButton(R.string.report_a_bug, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Utils.sendSupportMail(activity, message);
}
}).show();
.setPositiveButton(R.string.report_a_bug, (dialog, which) -> Utils.sendBugReport(activity)).show();
}
static String getSizeString(long size)

View file

@ -276,9 +276,16 @@ public class Utils
}
}
public static void sendSupportMail(@NonNull Activity activity, @NonNull String subject)
public static void sendBugReport(@NonNull Activity activity)
{
LoggerFactory.INSTANCE.zipLogs(new OnZipCompletedCallback(activity, subject));
LoggerFactory.INSTANCE.zipLogs(new SupportInfoWithLogsCallback(activity, "Bugreport from user",
Constants.Email.SUPPORT));
}
public static void sendFeedback(@NonNull Activity activity)
{
LoggerFactory.INSTANCE.zipLogs(new SupportInfoWithLogsCallback(activity, "Feedback",
Constants.Email.FEEDBACK));
}
public static void navigateToParent(@Nullable Activity activity)
@ -633,59 +640,6 @@ public class Utils
return isTargetOrLater(Build.VERSION_CODES.JELLY_BEAN_MR1);
}
private static class OnZipCompletedCallback implements LoggerFactory.OnZipCompletedListener
{
@NonNull
private final WeakReference<Activity> mActivityRef;
@NonNull
private final String mSubject;
private OnZipCompletedCallback(@NonNull Activity activity, @NonNull String subject)
{
mActivityRef = new WeakReference<>(activity);
mSubject = subject;
}
@Override
public void onCompleted(final boolean success)
{
UiThread.run(new Runnable()
{
@Override
public void run()
{
Activity activity = mActivityRef.get();
if (activity == null)
return;
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.Email.SUPPORT });
intent.putExtra(Intent.EXTRA_SUBJECT, "[" + BuildConfig.VERSION_NAME + "] " + mSubject);
if (success)
{
String logsZipFile = StorageUtils.getLogsZipPath(activity.getApplication());
if (!TextUtils.isEmpty(logsZipFile))
{
Uri uri = StorageUtils.getUriForFilePath(activity, logsZipFile);
intent.putExtra(Intent.EXTRA_STREAM, uri);
}
}
intent.putExtra(Intent.EXTRA_TEXT, ""); // do this so some email clients don't complain about empty body.
intent.setType("message/rfc822");
try
{
activity.startActivity(intent);
}
catch (ActivityNotFoundException e)
{
AlohaHelper.logException(e);
}
}
});
}
}
@NonNull
public static <T> T[] concatArrays(@Nullable T[] a, T... b)
{
@ -781,4 +735,57 @@ public class Utils
String key = "brand." + brand;
return getLocalizedFeatureByKey(context, key);
}
private static class SupportInfoWithLogsCallback implements LoggerFactory.OnZipCompletedListener
{
@NonNull
private final WeakReference<Activity> mActivityRef;
@NonNull
private final String mSubject;
@NonNull
private final String mEmail;
private SupportInfoWithLogsCallback(@NonNull Activity activity, @NonNull String subject,
@NonNull String email)
{
mActivityRef = new WeakReference<>(activity);
mSubject = subject;
mEmail = email;
}
@Override
public void onCompleted(final boolean success)
{
UiThread.run(() -> {
Activity activity = mActivityRef.get();
if (activity == null)
return;
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { mEmail });
intent.putExtra(Intent.EXTRA_SUBJECT, "[" + BuildConfig.VERSION_NAME + "] " + mSubject);
if (success)
{
String logsZipFile = StorageUtils.getLogsZipPath(activity.getApplication());
if (!TextUtils.isEmpty(logsZipFile))
{
Uri uri = StorageUtils.getUriForFilePath(activity, logsZipFile);
intent.putExtra(Intent.EXTRA_STREAM, uri);
}
}
// Do this so some email clients don't complain about empty body.
intent.putExtra(Intent.EXTRA_TEXT, "");
intent.setType("message/rfc822");
try
{
activity.startActivity(intent);
}
catch (ActivityNotFoundException e)
{
CrashlyticsUtils.logException(e);
}
});
}
}
}