ShihoChan I/O

しほちゃんのブログ

Plaidでのリソースファイルの分割Tips

しほちゃんです。

前のブログ続きです。
リソースファイルを各Featureモジュールに分割する際のTipsについてまとめます。

prefixでの対応

  • リソースにはパッケージがないのでprefixを利用する
    • 例)dribbbleでのみ使用されるリソース => dribbble_xxx
  • styles.xmlなど複数のモジュール用のリソースを含むファイル
<style name="SearchViewTheme" parent="PlaidDarkOverlay">
    <item name="colorControlActivated">?android:colorAccent</item>
    <item name="android:searchViewStyle">@style/Widget.Plaid.SearchView</item>
</style>

<style name="Widget.Plaid.SearchView" parent="android:style/Widget.Material.SearchView">
    <item name="android:searchIcon">@android:color/transparent</item>
    <item name="android:searchHintIcon">@android:color/transparent</item>
    <item name="android:queryBackground">@android:color/transparent</item>
    <item name="android:submitBackground">@android:color/transparent</item>
</style>

リソース分割の例

  • string.xml
    • 分割後は各Featureモジュール毎ににそれぞれのstring.xmlを管理
    • モジュール化前に機能毎にグループ化されていればファイル分割が円滑に進む
search/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
core/src/main/res/values/strings.xml
about/src/main/res/values/strings.xml
dribbble/src/main/res/values/strings.xml
designernews/src/main/res/values/strings.xml
  • search/src/main/res/values/strings.xml
resources>
    <!-- about screen -->
    <string name="about_plaid_0">Plaid is a source of design news &amp; inspiration that serves as a concrete example of [material design principles](https://www.google.com/design/spec/material-design/introduction.html#introduction-principles). Plaid pulls data from [Designer News](https://www.designernews.co/), [Dribbble](https://dribbble.com/) &amp; [Product Hunt](https://www.producthunt.com/); it is in no way an official client for these services nor endorsed by them. It is rather good&#160;though.</string>
    <string name="about_plaid_1">Plaid is written by [Nick&#160;Butcher](http://twitter.com/crafty), [Florina&#160;Muntenescu](http://twitter.com/fmuntenescu), [Ben&#160;Weiss](http://twitter.com/keyboardsurfer), [Tiem&#160;Song](http://twitter.com/tiembo) and the Android community.</string>
    <string name="about_plaid_2">The source code is available on [GitHub](http://github.com/nickbutcher/plaid)</string>
    <string name="about_icon_0">"Plaid\'s icon is lovingly crafted by the inimitable Roman&#160;Nurik"</string>
    <string name="about_icon_1">[Twitter](http://twitter.com/romannurik) | [Google+](http://google.com/+RomanNurik)</string>
    <string name="about_libs_intro">Plaid is built with the help of these awesome&#160;libraries</string>
    <string name="about_lib_link">website</string>
</resources>