Skip to content

Commit 46fc195

Browse files
committed
git 的 tag 不能编辑
1 parent 2022bc9 commit 46fc195

5 files changed

Lines changed: 27 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
114114
MenuItem menuItemEdit = menu.findItem(R.id.action_edit);
115115
MenuItem menuItemDelete = menu.findItem(R.id.actionDelete);
116116

117-
if (TextUtils.isEmpty(mFile.getCommitId())) {
117+
if (TextUtils.isEmpty(mFile.getCommitId()) || !mFile.canEdit) {
118118
menuItemEdit.setVisible(false);
119119
menuItemDelete.setVisible(false);
120120
} else if (mFile.getGitFileObject().mode.equals("image")) {

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public class ProjectGitFragment extends CustomMoreFragment implements LoadMore {
8989
@ViewById
9090
View blankLayout;
9191

92+
boolean canEdit;
93+
9294
private ArrayList<GitFileInfoObject> mData = new ArrayList<>();
9395
BaseAdapter adapter = new BaseAdapter() {
9496
@Override
@@ -189,12 +191,16 @@ protected final void initProjectGitFragment() {
189191
((BaseActivity) getActivity()).setActionBarTitle(mGitFileInfoObject.name);
190192
}
191193

194+
loadGitTree();
195+
196+
setHasOptionsMenu(true);
197+
}
198+
199+
protected void loadGitTree() {
192200
if (!mVersion.isEmpty()) {
193201
host_git_tree_url = UrlCreate.gitTree(mProjectPath, mVersion, pathStack.peek());
194202
getNetwork(host_git_tree_url, HOST_GIT_TREE);
195203
}
196-
197-
setHasOptionsMenu(true);
198204
}
199205

200206
@Override
@@ -215,6 +221,14 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
215221
menu.findItem(R.id.action_exit_code).setVisible(false);
216222
}
217223

224+
if (canEdit) {
225+
menu.findItem(R.id.action_create_file).setVisible(true);
226+
menu.findItem(R.id.action_upload_picture).setVisible(true);
227+
} else {
228+
menu.findItem(R.id.action_create_file).setVisible(false);
229+
menu.findItem(R.id.action_upload_picture).setVisible(false);
230+
}
231+
218232
super.onCreateOptionsMenu(menu, inflater);
219233
}
220234

@@ -343,6 +357,11 @@ public void parseJson(int code, JSONObject respanse, String tag, int pos, Object
343357
return;
344358
}
345359

360+
if (jsonData.has("can_edit")) {
361+
canEdit = jsonData.optBoolean("can_edit", false);
362+
getActivity().invalidateOptionsMenu();
363+
}
364+
346365
host_git_treeinfo_url = UrlCreate.gitTreeinfo(mProjectPath, mVersion, pathStack.peek());
347366
getNetwork(host_git_treeinfo_url, HOST_GIT_TREEINFO);
348367
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private void setBlank(int itemSize, Object fragment, boolean request, View v, Vi
315315
private void switchVersion(String name) {
316316
mVersion = name;
317317
adapter.notifyDataSetChanged();
318-
onRefresh();
318+
loadGitTree();
319319
}
320320

321321
@Override

common-coding/src/main/java/net/coding/program/common/model/GitFileBlobObject.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ public class GitFileBlobObject implements Serializable {
1212
GitFileObject gitFileObject;
1313
HeadCommitObject headCommitObject;
1414
String ref;
15+
public boolean canEdit;
1516

1617
public GitFileBlobObject(JSONObject json) {
1718
ref = json.optString("ref", "");
1819
gitFileObject = new GitFileObject(json.optJSONObject("file"));
1920
headCommitObject = new HeadCommitObject(json.optJSONObject("headCommit"));
21+
canEdit = json.optBoolean("can_edit", false);
2022
}
2123

2224
public GitFileObject getGitFileObject() {

common-coding/src/main/java/net/coding/program/common/model/GitFileInfoObject.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class GitFileInfoObject implements Serializable {
2222
public String mode = "";
2323
public String path = "";
2424
public String name = "";
25+
public boolean canEdit = false;
2526

2627
public HeadCommitObject headCommit;
2728

@@ -36,6 +37,7 @@ public GitFileInfoObject(JSONObject json) throws JSONException {
3637
mode = json.optString("mode");
3738
path = json.optString("path");
3839
name = json.optString("name");
40+
canEdit = json.optBoolean("can_edit", false);
3941

4042
if (json.has("headCommit")) {
4143
headCommit = new HeadCommitObject(json.optJSONObject("headCommit"));

0 commit comments

Comments
 (0)