diff --git a/app/src/main/java/com/hippo/ehviewer/StartActivity.java b/app/src/main/java/com/hippo/ehviewer/StartActivity.java index 1633095ff..b65545ac5 100644 --- a/app/src/main/java/com/hippo/ehviewer/StartActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/StartActivity.java @@ -19,7 +19,6 @@ package com.hippo.ehviewer; import android.app.AlertDialog; import android.content.Intent; import android.graphics.Typeface; -import android.net.Uri; import android.os.Bundle; import android.text.util.Linkify; import android.view.View; @@ -31,6 +30,7 @@ import com.hippo.ehviewer.app.MaterialAlertDialog; import com.hippo.ehviewer.network.Network; import com.hippo.ehviewer.ui.AbsActivity; import com.hippo.ehviewer.ui.GalleryListActivity; +import com.hippo.ehviewer.util.AppUtils; import com.hippo.ehviewer.util.Config; import com.hippo.ehviewer.util.Crash; import com.hippo.ehviewer.util.Secret; @@ -160,11 +160,9 @@ public class StartActivity extends AbsActivity { return true; } }).show(); - Intent i = new Intent(Intent.ACTION_SENDTO); - i.setData(Uri.parse("mailto:ehviewersu@gmail.com")); - i.putExtra(Intent.EXTRA_SUBJECT, "I found a bug in EhViewer !"); - i.putExtra(Intent.EXTRA_TEXT, lastCrash + "======== Description ========\n" + et.getText().toString()); - startActivity(i); + AppUtils.sendEmail(StartActivity.this, "ehviewersu@gmail.com", + "I found a bug in EhViewer !", + lastCrash + "======== Description ========\n" + et.getText().toString()); lastCrash = null; break; case MaterialAlertDialog.NEGATIVE: diff --git a/app/src/main/java/com/hippo/ehviewer/ui/SettingsActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/SettingsActivity.java index 3cff5379f..ec19a61f7 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/SettingsActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/SettingsActivity.java @@ -16,15 +16,6 @@ package com.hippo.ehviewer.ui; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; @@ -67,6 +58,7 @@ import com.hippo.ehviewer.ehclient.EhClient; import com.hippo.ehviewer.ehclient.EhInfo; import com.hippo.ehviewer.network.HttpHelper; import com.hippo.ehviewer.preference.ListPreference; +import com.hippo.ehviewer.util.AppUtils; import com.hippo.ehviewer.util.BgThread; import com.hippo.ehviewer.util.Config; import com.hippo.ehviewer.util.DialogUtils; @@ -80,6 +72,15 @@ import com.hippo.ehviewer.widget.CategoryTable; import com.hippo.ehviewer.widget.MaterialToast; import com.hippo.ehviewer.widget.SuggestionHelper; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public class SettingsActivity extends AbsPreferenceActivity { @SuppressWarnings("unused") private static String TAG = SettingsActivity.class.getSimpleName(); @@ -805,10 +806,8 @@ public class SettingsActivity extends AbsPreferenceActivity { } } else if (KEY_AUTHOR.equals(key)) { - Intent i = new Intent(Intent.ACTION_SENDTO); - i.setData(Uri.parse("mailto:ehviewersu@gmail.com")); - i.putExtra(Intent.EXTRA_SUBJECT, "About EhViewer"); - startActivity(i); + AppUtils.sendEmail(getActivity(), "ehviewersu@gmail.com", + "About EhViewer", null); } else if (KEY_TWITTER.equals(key)) { new MaterialAlertDialog.Builder(getActivity()) diff --git a/app/src/main/java/com/hippo/ehviewer/util/AppUtils.java b/app/src/main/java/com/hippo/ehviewer/util/AppUtils.java new file mode 100644 index 000000000..2c9d7a989 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/util/AppUtils.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer.util; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +public final class AppUtils { + + // TODO add common error tip + public static void sendEmail(@NonNull Activity from, @NonNull String email, + @Nullable String subject, @Nullable String text) { + Intent i = new Intent(Intent.ACTION_SENDTO); + i.setData(Uri.parse("mailto:" + email)); + if (subject != null) { + i.putExtra(Intent.EXTRA_SUBJECT, subject); + } + if (text != null) { + i.putExtra(Intent.EXTRA_TEXT, text); + } + + try { + from.startActivity(i); + } catch (Exception e) { + e.printStackTrace(); + } + } +}