11package net .coding .program .project .detail ;
22
3+ import android .view .Menu ;
4+ import android .view .View ;
35import android .webkit .WebView ;
46
57import com .loopj .android .http .RequestParams ;
68
9+ import net .coding .program .ImagePagerFragment ;
710import net .coding .program .R ;
11+ import net .coding .program .common .BlankViewDisplay ;
812import net .coding .program .common .Global ;
913import net .coding .program .model .AttachmentFileObject ;
1014
@@ -32,6 +36,9 @@ public class AttachmentsHtmlDetailActivity extends AttachmentsDetailBaseActivity
3236 @ ViewById
3337 WebView webview ;
3438
39+ @ ViewById
40+ View blankLayout ;
41+
3542 String urlFiles = Global .HOST + "/api/project/%d/files/%s/view" ;
3643 String urlPages = Global .HOST + "/api/project/%d/files/image/%s?folderId=%s&orderByDesc=true" ;
3744 String urlMdPreview = Global .HOST + "/api/markdown/preview" ;
@@ -40,6 +47,8 @@ public class AttachmentsHtmlDetailActivity extends AttachmentsDetailBaseActivity
4047
4148 String markdown ;
4249
50+ boolean downloadFileSuccess = false ;
51+
4352 @ AfterViews
4453 void init1 () {
4554
@@ -55,9 +64,22 @@ void init1() {
5564 Global .initWebView (webview );
5665
5766 showDialogLoading ();
67+ getFileUrlFromNetwork ();
68+ }
69+
70+ private void getFileUrlFromNetwork () {
5871 getNetwork (urlFiles , urlFiles );
5972 }
6073
74+ @ Override
75+ public boolean onCreateOptionsMenu (Menu menu ) {
76+ if (downloadFileSuccess ) {
77+ return super .onCreateOptionsMenu (menu );
78+ } else {
79+ return true ;
80+ }
81+ }
82+
6183 @ Override
6284 public void parseJson (int code , JSONObject respanse , String tag , int pos , Object data ) throws JSONException {
6385 super .parseJson (code , respanse , tag , pos , data );
@@ -75,8 +97,20 @@ public void parseJson(int code, JSONObject respanse, String tag, int pos, Object
7597 params .put ("content" , content );
7698 postNetwork (urlMdPreview , params , urlMdPreview );
7799 }
100+ invalidateOptionsMenu ();
78101
79102 } else {
103+ if (code == ImagePagerFragment .HTTP_CODE_FILE_NOT_EXIST ) {
104+ BlankViewDisplay .setBlank (0 , this , true , blankLayout , null );
105+ } else {
106+ BlankViewDisplay .setBlank (0 , this , false , blankLayout , new View .OnClickListener () {
107+ @ Override
108+ public void onClick (View v ) {
109+ getFileUrlFromNetwork ();
110+ }
111+ });
112+ }
113+
80114 hideProgressDialog ();
81115 showErrorMsg (code , respanse );
82116 }
@@ -108,7 +142,9 @@ private String readTextFile(InputStream inputStream) {
108142 inputStream .close ();
109143
110144 } catch (IOException e ) {
145+ Global .errorLog (e );
111146 }
147+
112148 return outputStream .toString ();
113149 }
114150
0 commit comments