code refactor: open url

This commit is contained in:
houxg
2016-12-28 17:11:28 +08:00
parent 3fabb48b15
commit 527bb1e5e4
4 changed files with 8 additions and 4 deletions

View File

@@ -36,6 +36,7 @@ import org.houxg.leamonax.editor.MarkdownEditor;
import org.houxg.leamonax.editor.RichTextEditor;
import org.houxg.leamonax.utils.CollectionUtils;
import org.houxg.leamonax.utils.DialogUtils;
import org.houxg.leamonax.utils.OpenUtils;
import org.houxg.leamonax.widget.ToggleImageButton;
import java.util.List;
@@ -392,7 +393,7 @@ public class EditorFragment extends Fragment implements Editor.EditorListener {
}
});
} else {
//TODO: go to link
OpenUtils.openUrl(getActivity(), url);
}
}
@@ -456,8 +457,7 @@ public class EditorFragment extends Fragment implements Editor.EditorListener {
@Override
public void linkTo(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
OpenUtils.openUrl(getActivity(), url);
}
private void refreshFormatStatus(Map<Editor.Format, Object> formatStatus) {

View File

@@ -5,6 +5,8 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import org.houxg.leamonax.R;
public class OpenUtils {
public static void openUrl(Context context, String url) {
@@ -13,7 +15,7 @@ public class OpenUtils {
try {
context.startActivity(i);
} catch (Exception ex) {
ToastUtils.show(context, "Can't open this url");
ToastUtils.show(context, R.string.cant_open_url);
}
}
}

View File

@@ -97,4 +97,5 @@
<string name="retry">重试</string>
<string name="continue_text">继续</string>
<string name="next_time">下次再说</string>
<string name="cant_open_url">无法打开该链接</string>
</resources>

View File

@@ -96,5 +96,6 @@
<string name="update_time">Update time</string>
<string name="upgrade_now">Upgrade now</string>
<string name="your_are_the_latest_version">You are using latest version</string>
<string name="cant_open_url">Can\'t open this url</string>
</resources>