diff --git a/kotlin.md b/kotlin.md index f78f2b8..8a17ab2 100644 --- a/kotlin.md +++ b/kotlin.md @@ -1,14 +1,14 @@ -# Makimo Kotlin Style Guide +# Makimo Android Style Guide This section presents coding convention used at Makimo for applications written -in Kotlin. +in Kotlin/Android. The convention is based on [the official Kotlin style guide](https://kotlinlang.org/docs/reference/coding-conventions.html). In case of omitted aspects of code style or some differences between the company policy and Kotlin style guide, the following document gives a preferred coding rules. -## Content +## Kotlin ### 1. Line length @@ -156,3 +156,82 @@ fun foo(x: Int, y: String) = Bar().apply{ this.y = y } ``` + +## XML + +### 1. Naming `layouts` + +Good naming is an absolute must for an Android project. In order to make +searching for Android layout files easier, we use prefixes corresponding +to their function. Accordingly: + +* `layout_` - Raw layouts; imported via ``; + +* `view_` - View layout files, used by widgets and small self-contained widgets; + +* `activity_` - Activity layout files; + +* `fragment_` - Fragment layout files; + + +### 2. Naming `drawables` + +* `btn_` - Custom button layout; + +* `ic_` - Icon layout; + +* `bkg_` - Background layout for a view; + +* `view_` - Generic view layout (when other type does not fit); + + +### 3. Naming colors + +Color names should correspond to color they represent, *not* functionality +it is related to, such as `appBarColor` or `navBarBackgroundColor`. +Those are too hard to remember. An example of good naming: + +```xml +#7bd3f7 +#019fd9 +#007bb2 +#f31f32 +``` + +### 4. Naming strings + +Strings in most applications are divided into one-time specific strings +and generic informational strings, such as error-messages, confirmation +buttons, retry labels and son on. Accordingly, `strings` should reflect +this divide. Examples of generic strings used throughout the application: + +```xml +Dalej +Anuluj +Dane zostały pobrane +Wystąpił błąd podczas pobiernia danych +``` + +Examples of specific strings: + +```xml +Termin ważności: %1$s +Numer polisy +Rodzaj płynu chłodniczego +Nazwa ubezpieczyciela +``` + +### 5. Naming dimens + +* All dimensions should be divisible by 2; +* When possible, dimensions should be multiples of 8, e.g.: 8, 16, 24, 32, 40, 48. +* Most projects should be two keylines - `keyline1`, `keyline2`. +* Most projects should use a finite set of standard paddings; e.g.: + +```xml +4dp +8dp +16dp +24dp +32dp +```