Android Code Review

1 Code Conventions

Java Code Conventions
https://www.oracle.com/technetwork/java/codeconvtoc-136057.html

Kotlin Code Conventions
https://kotlinlang.org/docs/reference/coding-conventions.html

2 Code Style

配置通用的Code format
Android Code Review_第1张图片
image.png

Code Format

https://github.com/grandcentrix/AndroidCodeStyle

https://github.com/square/java-code-styles/blob/master/configs/codestyles/SquareAndroid.xml

Code Style plugin


Android Code Review_第2张图片
image.png
Android Code Review_第3张图片
image.png
Android Code Review_第4张图片
image.png
Android Code Review_第5张图片
D928AF9E-F465-4E81-AE20-7AE4166F3109.png

3 Best Practice

Communicate with other fragments

public class HeadlinesFragment extends ListFragment {
    OnHeadlineSelectedListener callback;

    public void setOnHeadlineSelectedListener(OnHeadlineSelectedListener callback) {
        this.callback = callback;
    }

    // This interface can be implemented by the Activity, parent Fragment,
    // or a separate test implementation.
    public interface OnHeadlineSelectedListener {
        public void onArticleSelected(int position);
    }

    // ...
}
public static class MainActivity extends Activity
        implements HeadlinesFragment.OnHeadlineSelectedListener{
    // ...

    @Override
    public void onAttachFragment(Fragment fragment) {
        if (fragment instanceof HeadlinesFragment) {
            HeadlinesFragment headlinesFragment = (HeadlinesFragment) fragment;
            headlinesFragment.setOnHeadlineSelectedListener(this);
        }
    }
}

4 Project Conventions

The activity ends with Activity, DummyActivity
The fragment ends with Fragment, DummyFragment

activity layout
start with activity, DummyActivity ->activity_dummy

fragment layout
start with the fragment, DummyFragment →fragment_dummy

Not use String.format for Number, use Utils.format instead, because of issue KDS-XXX

5 Lint

Android Code Review_第6张图片
15107ABD-E6CE-4FD7-AB28-AC8D04DC86BC.png

使用 Android Studio Lint 去除无用、错误、性能不友好的代码

6 Commit Convention
: 地图改版
--- COMMIT END ---
Type can be
feat 新功能
fix Bug修复
refactor 重构
style 代码格式/风格修改
docs 修改注释
test 修改测试代码
add 新增代码
TB任务ID:App-103
影响范围 :地图MapUI大头针的图标
是否自测 : 是 zoomIn和zoomOut 请求不同的门店

参考
Java 代码规范,你应该知道的一些工具和用法

你可能感兴趣的:(Android Code Review)