Skip to content

Commit 8431d57

Browse files
committed
添加了html和text不存在时的界面
1 parent 409d923 commit 8431d57

6 files changed

Lines changed: 90 additions & 3 deletions

File tree

app/src/main/java/net/coding/program/common/BlankViewDisplay.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import net.coding.program.message.UsersListFragment;
1111
import net.coding.program.project.ProjectListFragment;
1212
import net.coding.program.project.detail.AttachmentsActivity;
13-
import net.coding.program.project.detail.AttachmentsDetailBaseActivity;
13+
import net.coding.program.project.detail.AttachmentsDownloadDetailActivity;
14+
import net.coding.program.project.detail.AttachmentsHtmlDetailActivity;
15+
import net.coding.program.project.detail.AttachmentsTextDetailActivity;
1416
import net.coding.program.project.detail.ProjectDynamicFragment;
1517
import net.coding.program.project.detail.ProjectGitFragment;
1618
import net.coding.program.project.detail.TaskListFragment;
@@ -97,8 +99,10 @@ private static void setBlank(int itemSize, Object fragment, boolean request, Vie
9799
} else if (fragment instanceof MergeListFragment) {
98100
iconId = R.drawable.ic_exception_blank_task;
99101
text = "这里还什么都没有\n赶快起来弄出一点动静吧";
100-
} else if (fragment instanceof ImagePagerFragment &&
101-
fragment instanceof AttachmentsDetailBaseActivity) {
102+
} else if (fragment instanceof ImagePagerFragment
103+
|| fragment instanceof AttachmentsDownloadDetailActivity
104+
|| fragment instanceof AttachmentsHtmlDetailActivity
105+
|| fragment instanceof AttachmentsTextDetailActivity) {
102106
iconId = R.drawable.ic_exception_no_network;
103107
text = "晚了一步\n文件已经被人删除了";
104108
}

app/src/main/java/net/coding/program/project/detail/AttachmentsHtmlDetailActivity.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package net.coding.program.project.detail;
22

3+
import android.view.Menu;
4+
import android.view.View;
35
import android.webkit.WebView;
46

57
import com.loopj.android.http.RequestParams;
68

9+
import net.coding.program.ImagePagerFragment;
710
import net.coding.program.R;
11+
import net.coding.program.common.BlankViewDisplay;
812
import net.coding.program.common.Global;
913
import 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

app/src/main/java/net/coding/program/project/detail/AttachmentsTextDetailActivity.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package net.coding.program.project.detail;
22

3+
import android.view.Menu;
4+
import android.view.View;
35
import android.widget.TextView;
46

7+
import net.coding.program.ImagePagerFragment;
58
import net.coding.program.R;
9+
import net.coding.program.common.BlankViewDisplay;
610
import net.coding.program.common.Global;
711
import net.coding.program.model.AttachmentFileObject;
812

@@ -23,6 +27,11 @@ public class AttachmentsTextDetailActivity extends AttachmentsDetailBaseActivity
2327
@ViewById
2428
TextView textView;
2529

30+
@ViewById
31+
View blankLayout;
32+
33+
boolean downloadFileSuccess = false;
34+
2635
String urlFiles = Global.HOST + "/api/project/%s/files/%s/view";
2736

2837
AttachmentFileObject mFiles = new AttachmentFileObject();
@@ -37,9 +46,22 @@ void init1() {
3746
urlFiles = String.format(urlFiles, mProjectObjectId, mAttachmentFileObject.file_id);
3847

3948
showDialogLoading();
49+
getFileUrlFromNetwork();
50+
}
51+
52+
private void getFileUrlFromNetwork() {
4053
getNetwork(urlFiles, urlFiles);
4154
}
4255

56+
@Override
57+
public boolean onCreateOptionsMenu(Menu menu) {
58+
if (downloadFileSuccess) {
59+
return super.onCreateOptionsMenu(menu);
60+
} else {
61+
return true;
62+
}
63+
}
64+
4365
@Override
4466
public void parseJson(int code, JSONObject respanse, String tag, int pos, Object data) throws JSONException {
4567
super.parseJson(code, respanse, tag, pos, data);
@@ -50,8 +72,20 @@ public void parseJson(int code, JSONObject respanse, String tag, int pos, Object
5072
mFiles = new AttachmentFileObject(file);
5173
String content = respanse.getJSONObject("data").optString("content");
5274
textView.setText(content);
75+
invalidateOptionsMenu();
5376

5477
} else {
78+
if (code == ImagePagerFragment.HTTP_CODE_FILE_NOT_EXIST) {
79+
BlankViewDisplay.setBlank(0, this, true, blankLayout, null);
80+
} else {
81+
BlankViewDisplay.setBlank(0, this, false, blankLayout, new View.OnClickListener() {
82+
@Override
83+
public void onClick(View v) {
84+
getFileUrlFromNetwork();
85+
}
86+
});
87+
}
88+
5589
hideProgressDialog();
5690
showErrorMsg(code, respanse);
5791
}
11.2 KB
Loading

app/src/main/res/layout/activity_attachments_html.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@
1515
android:layout_height="fill_parent"
1616
android:visibility="gone" />
1717

18+
<include
19+
android:id="@+id/blankLayout"
20+
layout="@layout/view_exception"
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent" />
23+
24+
1825
</FrameLayout>

app/src/main/res/layout/activity_attachments_text.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@
1111
android:padding="10dp"
1212
android:textAppearance="?android:attr/textAppearanceMedium" />
1313

14+
<include
15+
android:id="@+id/blankLayout"
16+
layout="@layout/view_exception"
17+
android:layout_width="match_parent"
18+
android:layout_height="match_parent" />
19+
1420
</FrameLayout>

0 commit comments

Comments
 (0)