Skip to content

Commit 384ea94

Browse files
committed
add comments and recode utils
1 parent 8bfd6b6 commit 384ea94

39 files changed

+506
-278
lines changed

app/src/main/java/com/yydcdut/markdowndemo/controller/Utils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.yydcdut.markdown.span.MDOrderListSpan;
88
import com.yydcdut.markdown.span.MDUnOrderListSpan;
9+
import com.yydcdut.markdown.utils.TextHelper;
910
import com.yydcdut.rxmarkdown.RxMDEditText;
1011

1112
/**
@@ -91,6 +92,6 @@ public static boolean hasTodoDone(RxMDEditText rxMDEditText, int start) {
9192
}
9293

9394
public static int safePosition(int position, CharSequence s) {
94-
return com.yydcdut.markdown.utils.Utils.safePosition(position, s);
95+
return TextHelper.safePosition(position, s);
9596
}
9697
}

markdown-processor/src/main/java/com/yydcdut/markdown/MarkdownProcessor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown;
217

318
import android.content.Context;

markdown-processor/src/main/java/com/yydcdut/markdown/callback/OnTodoClickCallback.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown.callback;
217

318
import android.view.View;
419

520
/**
621
* the callback of _todo syntax
7-
*
22+
* <p>
823
* Created by yuyidong on 2018/5/17.
924
*/
1025
public interface OnTodoClickCallback {

markdown-processor/src/main/java/com/yydcdut/markdown/callback/OnTodoClickListener.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown.callback;
217

318
import android.text.SpannableStringBuilder;
419
import android.view.View;
520

621
/**
722
* the listener of _todo syntax
8-
*
23+
* <p>
924
* Created by yuyidong on 2018/5/17.
1025
*/
1126
public interface OnTodoClickListener {

markdown-processor/src/main/java/com/yydcdut/markdown/config/BlockQuote.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown.config;
217

318
import android.graphics.Color;

markdown-processor/src/main/java/com/yydcdut/markdown/config/Code.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown.config;
217

318
import android.graphics.Color;

markdown-processor/src/main/java/com/yydcdut/markdown/config/Header.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown.config;
217

318
/**

markdown-processor/src/main/java/com/yydcdut/markdown/config/HorizontalRule.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown.config;
217

318
import android.graphics.Color;

markdown-processor/src/main/java/com/yydcdut/markdown/config/Image.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown.config;
217

318
import android.content.Context;

markdown-processor/src/main/java/com/yydcdut/markdown/config/Link.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown.config;
217

318
import android.graphics.Color;

markdown-processor/src/main/java/com/yydcdut/markdown/config/Todo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown.config;
217

318
import android.graphics.Color;

markdown-processor/src/main/java/com/yydcdut/markdown/config/UnOrderList.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2018 yydcdut (yuyidong2015@gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.yydcdut.markdown.config;
217

318
import android.graphics.Color;

markdown-processor/src/main/java/com/yydcdut/markdown/live/BlockQuotesLive.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.yydcdut.markdown.syntax.SyntaxKey;
2323
import com.yydcdut.markdown.syntax.edit.EditFactory;
2424
import com.yydcdut.markdown.utils.SyntaxUtils;
25-
import com.yydcdut.markdown.utils.Utils;
25+
import com.yydcdut.markdown.utils.TextHelper;
2626

2727
import java.util.List;
2828

@@ -39,17 +39,17 @@ public void beforeTextChanged(CharSequence s, int start, int before, int after)
3939
if (before == 0 || mMarkdownConfiguration == null) {
4040
return;
4141
}
42-
String deleteString = s.subSequence(Utils.safePosition(start, s), Utils.safePosition(start + before, s)).toString();
42+
String deleteString = s.subSequence(TextHelper.safePosition(start, s), TextHelper.safePosition(start + before, s)).toString();
4343
String beforeString = null;
4444
String afterString = null;
4545
if (start > 0) {
46-
beforeString = s.subSequence(Utils.safePosition(start - 1, s), Utils.safePosition(start, s)).toString();
46+
beforeString = s.subSequence(TextHelper.safePosition(start - 1, s), TextHelper.safePosition(start, s)).toString();
4747
}
4848
if (start + before + 1 <= s.length()) {
49-
afterString = s.subSequence(Utils.safePosition(start + before, s), Utils.safePosition(start + before + 1, s)).toString();
49+
afterString = s.subSequence(TextHelper.safePosition(start + before, s), TextHelper.safePosition(start + before + 1, s)).toString();
5050
}
5151
//"> a" --> ">a"
52-
if (SyntaxUtils.isNeedFormat(SyntaxKey.KEY_BLOCK_QUOTES_LEFT_SINGLE, deleteString, beforeString, afterString)) {
52+
if (TextHelper.isNeedFormat(SyntaxKey.KEY_BLOCK_QUOTES_LEFT_SINGLE, deleteString, beforeString, afterString)) {
5353
shouldFormat = true;
5454
}
5555
}
@@ -66,25 +66,25 @@ public void onTextChanged(CharSequence s, int start, int before, int after) {
6666
if (after == 0) {
6767
return;
6868
}
69-
String addString = s.subSequence(Utils.safePosition(start, s), Utils.safePosition(start + after, s)).toString();
69+
String addString = s.subSequence(TextHelper.safePosition(start, s), TextHelper.safePosition(start + after, s)).toString();
7070
String beforeString = null;
7171
String afterString = null;
7272
if (start + 1 <= s.length()) {
73-
afterString = s.subSequence(Utils.safePosition(start, s), Utils.safePosition(start + 1, s)).toString();
73+
afterString = s.subSequence(TextHelper.safePosition(start, s), TextHelper.safePosition(start + 1, s)).toString();
7474
}
7575
if (start > 0) {
76-
beforeString = s.subSequence(Utils.safePosition(start - 1, s), Utils.safePosition(start, s)).toString();
76+
beforeString = s.subSequence(TextHelper.safePosition(start - 1, s), TextHelper.safePosition(start, s)).toString();
7777
}
7878
//">a" --> "> a"
79-
if (SyntaxUtils.isNeedFormat(SyntaxKey.KEY_BLOCK_QUOTES_LEFT_SINGLE, addString, beforeString, afterString)) {
79+
if (TextHelper.isNeedFormat(SyntaxKey.KEY_BLOCK_QUOTES_LEFT_SINGLE, addString, beforeString, afterString)) {
8080
format((Editable) s, start);
8181
}
8282
}
8383

8484
private void format(Editable editable, int start) {
85-
Utils.removeSpans(editable, start, MDQuoteSpan.class);
85+
SyntaxUtils.removeSpans(editable, start, MDQuoteSpan.class);
8686
Syntax syntax = EditFactory.create().getBlockQuotesSyntax(mMarkdownConfiguration);
87-
List<EditToken> editTokenList = Utils.getMatchedEditTokenList(editable, syntax.format(editable), start);
88-
Utils.setSpans(editable, editTokenList);
87+
List<EditToken> editTokenList = SyntaxUtils.getMatchedEditTokenList(editable, syntax.format(editable), start);
88+
SyntaxUtils.setSpans(editable, editTokenList);
8989
}
9090
}

markdown-processor/src/main/java/com/yydcdut/markdown/live/CenterAlignLive.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import com.yydcdut.markdown.syntax.Syntax;
2222
import com.yydcdut.markdown.syntax.SyntaxKey;
2323
import com.yydcdut.markdown.syntax.edit.EditFactory;
24-
import com.yydcdut.markdown.utils.Utils;
24+
import com.yydcdut.markdown.utils.SyntaxUtils;
25+
import com.yydcdut.markdown.utils.TextHelper;
2526

2627
import java.util.List;
2728

@@ -38,7 +39,7 @@ public void beforeTextChanged(CharSequence s, int start, int before, int after)
3839
if (before == 0 || mMarkdownConfiguration == null) {
3940
return;
4041
}
41-
if (isNeedFormat(s.subSequence(Utils.safePosition(start, s), Utils.safePosition(start + before, s)).toString())) {
42+
if (isNeedFormat(s.subSequence(TextHelper.safePosition(start, s), TextHelper.safePosition(start + before, s)).toString())) {
4243
shouldFormat = true;
4344
}
4445
}
@@ -55,16 +56,16 @@ public void onTextChanged(CharSequence s, int start, int before, int after) {
5556
if (after == 0) {
5657
return;
5758
}
58-
if (isNeedFormat(s.subSequence(Utils.safePosition(start, s), Utils.safePosition(start + after, s)).toString())) {
59+
if (isNeedFormat(s.subSequence(TextHelper.safePosition(start, s), TextHelper.safePosition(start + after, s)).toString())) {
5960
format((Editable) s, start);
6061
}
6162
}
6263

6364
private void format(Editable editable, int start) {
64-
Utils.removeSpans(editable, start, AlignmentSpan.Standard.class);
65+
SyntaxUtils.removeSpans(editable, start, AlignmentSpan.Standard.class);
6566
Syntax syntax = EditFactory.create().getCenterAlignSyntax(mMarkdownConfiguration);
66-
List<EditToken> editTokenList = Utils.getMatchedEditTokenList(editable, syntax.format(editable), start);
67-
Utils.setSpans(editable, editTokenList);
67+
List<EditToken> editTokenList = SyntaxUtils.getMatchedEditTokenList(editable, syntax.format(editable), start);
68+
SyntaxUtils.setSpans(editable, editTokenList);
6869
}
6970

7071
private boolean isNeedFormat(String string) {

0 commit comments

Comments
 (0)