Skip to content

Commit

Permalink
optimize diff view, add background and line number
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirtyDegreesRay committed Nov 10, 2017
1 parent 6e9e05c commit 562dc13
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 71 deletions.
29 changes: 29 additions & 0 deletions app/src/main/assets/code_prettify/diff_dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

/**
* Created by ThirtyDegreesRay on 2017/11/10 16:00:00
*/

body {
font-size: 12px;
line-height: 1.5;
color:#EEEEEE;
}

.pre {
display: table;
min-width: 100%;
padding-right: 8px;
}

.add {
background:#33601E;
}

.remove {
background:#801C1C;
}

.change {
background:#282A2F;
color:#9E9E9E;
}
29 changes: 29 additions & 0 deletions app/src/main/assets/code_prettify/diff_light.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

/**
* Created by ThirtyDegreesRay on 2017/11/10 16:00:00
*/

body {
font-size: 12px;
line-height: 1.5;
color:#212121;
}

.pre {
display: table;
min-width: 100%;
padding-right: 8px;
}

.add {
background:#ACF2BD;
}

.remove {
background:#FDB8C0;
}

.change {
background:#EAEAEA;
color:#757575;
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void onPrepareOptionsMenu(Menu menu) {
menuItemViewFile.setVisible(false);
menuItemRefresh.setVisible(true);
} else if(ViewerActivity.ViewerType.DiffFile.equals(mPresenter.getViewerType())){
menuItem.setVisible(mPresenter.isCode());
menuItem.setVisible(true);
menuItem.setChecked(wrap);
menuItemDownload.setVisible(false);
menuItemViewFile.setVisible(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void setMdSource(@NonNull String source, @Nullable String baseUrl, boolea
if (StringUtils.isBlank(source)) return;
String page = HtmlHelper.generateMdHtml(source, baseUrl, AppUtils.isNightMode(),
getCodeBackgroundColor(), getAccentColor(), wrapCode);
loadMd(page);
loadPage(page);
}

public void setCodeSource(@NonNull String source, boolean wrap, @Nullable String extension) {
Expand All @@ -139,10 +139,9 @@ public void setCodeSource(@NonNull String source, boolean wrap, @Nullable String
settings.setDisplayZoomControls(false);
String page = HtmlHelper.generateCodeHtml(source, extension, AppUtils.isNightMode(),
getCodeBackgroundColor(), wrap, true);
loadCode(page);
loadPage(page);
}

//TODO better diff view
public void setDiffFileSource(@NonNull String source, boolean wrap) {
if (StringUtils.isBlank(source)) return;
WebSettings settings = getSettings();
Expand All @@ -151,9 +150,9 @@ public void setDiffFileSource(@NonNull String source, boolean wrap) {
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
String page = HtmlHelper.generateCodeHtml(source, null, AppUtils.isNightMode(),
getCodeBackgroundColor(), wrap, false);
loadCode(page);
String page = HtmlHelper.generateDiffHtml(source, AppUtils.isNightMode(),
getCodeBackgroundColor(), wrap);
loadPage(page);
}

private void loadPageWithBaseUrl(final String baseUrl, final String page){
Expand All @@ -165,14 +164,10 @@ public void run() {
});
}

private void loadCode(String page) {
private void loadPage(String page) {
loadPageWithBaseUrl("file:///android_asset/code_prettify/", page);
}

private void loadMd(String page){
loadPageWithBaseUrl("file:///android_asset/code_prettify/md/", page);
}

private boolean hitLinkResult(WebView.HitTestResult result) {
return result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE ||
result.getType() == HitTestResult.IMAGE_TYPE ||
Expand Down
Loading

0 comments on commit 562dc13

Please sign in to comment.