1515import net .coding .program .common .Global ;
1616import net .coding .program .common .network .BaseFragment ;
1717import net .coding .program .maopao .MaopaoDetailActivity ;
18+ import net .coding .program .model .ProjectObject ;
19+ import net .coding .program .project .detail .TopicEditFragment ;
1820
1921import org .androidannotations .annotations .AfterViews ;
2022import org .androidannotations .annotations .EFragment ;
2729@ EFragment (R .layout .fragment_task_descrip_html )
2830public class TaskDescripHtmlFragment extends BaseFragment {
2931
32+ private static final String TAG_HTTP_MD_PREVIEW = "TAG_HTTP_MD_PREVIEW" ;
3033 @ ViewById
3134 WebView descWeb ;
32-
3335 @ ViewById
3436 View loading ;
35-
3637 @ FragmentArg
3738 String contentMd = "" ;
38-
3939 @ FragmentArg
4040 String contentHtml = "" ;
41-
4241 @ FragmentArg
4342 boolean preview = false ;
44-
4543 ActionMode mActionMode ;
46-
47- @ AfterViews
48- void init () {
49- setHasOptionsMenu (true );
50-
51- Global .syncCookie (getActivity ());
52-
53- if (contentHtml .isEmpty ()) {
54- mdToHtml ();
55- mActionMode = getActivity ().startActionMode (mActionModeCallback );
56- } else {
57- displayWebView ();
58- }
59- }
60-
6144 private ActionMode .Callback mActionModeCallback = new ActionMode .Callback () {
6245
6346 int id = 0 ;
@@ -110,6 +93,20 @@ public void onDestroyActionMode(ActionMode mode) {
11093 }
11194 };
11295
96+ @ AfterViews
97+ void init () {
98+ setHasOptionsMenu (true );
99+
100+ Global .syncCookie (getActivity ());
101+
102+ if (contentHtml .isEmpty ()) {
103+ mdToHtml ();
104+ mActionMode = getActivity ().startActionMode (mActionModeCallback );
105+ } else {
106+ displayWebView ();
107+ }
108+ }
109+
113110 private void displayWebView () {
114111 String locateHtml = ((TaskDescrip ) getActivity ()).createLocateHtml (contentHtml );
115112
@@ -122,7 +119,6 @@ private void displayWebView() {
122119 descWeb .loadDataWithBaseURL (Global .HOST , locateHtml , "text/html" , "UTF-8" , null );
123120 }
124121
125- public static final String HOST_PREVIEW = Global .HOST + "/api/markdown/preview" ;
126122
127123 @ Override
128124 public void onCreateOptionsMenu (Menu menu , MenuInflater inflater ) {
@@ -134,7 +130,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
134130
135131 @ Override
136132 public void parseJson (int code , JSONObject respanse , String tag , int pos , Object data ) throws JSONException {
137- if (tag .equals (HOST_PREVIEW )) {
133+ if (tag .equals (TAG_HTTP_MD_PREVIEW )) {
138134 if (code == 0 ) {
139135 contentHtml = respanse .optString ("data" , "" );
140136 displayWebView ();
@@ -151,7 +147,9 @@ private void mdToHtml() {
151147
152148 RequestParams params = new RequestParams ();
153149 params .put ("content" , contentMd );
154- postNetwork (HOST_PREVIEW , params , HOST_PREVIEW );
150+ String projectPath = ((TopicEditFragment .SaveData ) getActivity ()).getProjectPath ();
151+ String uri = ProjectObject .getMdPreview (projectPath );
152+ postNetwork (uri , params , TAG_HTTP_MD_PREVIEW );
155153 }
156154
157155 @ OptionsItem
0 commit comments