美文网首页
Android Code Review

Android Code Review

作者: 城平京 | 来源:发表于2019-05-21 11:32 被阅读0次

    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 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


    image.png image.png image.png 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

    15107ABD-E6CE-4FD7-AB28-AC8D04DC86BC.png

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

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

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

    相关文章

      网友评论

          本文标题:Android Code Review

          本文链接:https://www.haomeiwen.com/subject/flvdzqtx.html