├── .gitignore ├── README.md ├── art └── header_image.jpg ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mobile ├── .gitignore ├── build.gradle ├── fabric.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── jp │ │ └── satorufujiwara │ │ └── kotlin │ │ └── ApplicationTest.kt │ ├── debug │ └── kotlin │ │ └── jp │ │ └── satorufujiwara │ │ └── kotlin │ │ ├── AppComponent.kt │ │ ├── DebugAppLifecycleCallbacks.kt │ │ ├── DebugAppModule.kt │ │ └── data │ │ └── DebugDataModule.kt │ ├── local │ └── kotlin │ │ └── jp │ │ └── satorufujiwara │ │ └── kotlin │ │ └── data │ │ └── api │ │ ├── ApiModule.kt │ │ └── mock │ │ ├── MockGitHub.kt │ │ └── MockGitHubService.kt │ ├── main │ ├── AndroidManifest.xml │ ├── kotlin │ │ └── jp │ │ │ └── satorufujiwara │ │ │ └── kotlin │ │ │ ├── AbstractActivity.kt │ │ │ ├── AbstractFragment.kt │ │ │ ├── AppGlideModule.kt │ │ │ ├── AppLifecycleCallbacks.kt │ │ │ ├── AppScope.kt │ │ │ ├── KotlinApp.kt │ │ │ ├── MainAppComponent.kt │ │ │ ├── data │ │ │ ├── api │ │ │ │ ├── GitHubService.kt │ │ │ │ └── dto │ │ │ │ │ └── Repo.kt │ │ │ └── repository │ │ │ │ ├── GitHubRepository.kt │ │ │ │ └── RepositoryModule.kt │ │ │ ├── ui │ │ │ ├── DispatcherDbOpenHelper.kt │ │ │ ├── FluxAction.kt │ │ │ ├── FluxModule.kt │ │ │ └── main │ │ │ │ ├── MainAction.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ ├── MainComponent.kt │ │ │ │ ├── MainDispatcher.kt │ │ │ │ ├── MainFragment.kt │ │ │ │ ├── MainModule.kt │ │ │ │ ├── MainRepoBinder.kt │ │ │ │ ├── MainScope.kt │ │ │ │ ├── MainStore.kt │ │ │ │ ├── MainViewType.kt │ │ │ │ └── drawer │ │ │ │ ├── MainDrawerFragment.kt │ │ │ │ ├── MainDrawerNavigationBinder.kt │ │ │ │ ├── MainDrawerTransparentBinder.kt │ │ │ │ └── MainDrawerViewType.kt │ │ │ └── util │ │ │ ├── CrashlyticsTree.kt │ │ │ └── ext │ │ │ ├── BriteDatabaseExt.kt │ │ │ ├── FragmentActivityExt.kt │ │ │ └── FragmentExt.kt │ └── res │ │ ├── drawable-v21 │ │ └── app_white.xml │ │ ├── drawable │ │ └── app_white.xml │ │ ├── layout │ │ ├── main_activity.xml │ │ ├── main_drawer_fragment.xml │ │ ├── main_drawer_navigation_binder.xml │ │ ├── main_drawer_transparent_binder.xml │ │ ├── main_fragment.xml │ │ └── main_repo_binder.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── product │ └── kotlin │ │ └── jp │ │ └── satorufujiwara │ │ └── kotlin │ │ └── data │ │ └── api │ │ └── ApiModule.kt │ └── release │ └── kotlin │ └── jp │ └── satorufujiwara │ └── kotlin │ ├── AppComponent.kt │ ├── AppModule.kt │ ├── ReleaseAppLifecycleCallbacks.kt │ └── data │ └── DataModule.kt └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Thumbs.db 3 | 4 | .gradle 5 | /local.properties 6 | 7 | .idea 8 | !.idea/codeStyleSettings.xml 9 | *.iml 10 | 11 | /build 12 | /captures -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | kotlin-android-flux 2 | ==== 3 | 4 | This project is example of Android app with Flux and Kotlin and Dagger2 and famous libraries. 5 | 6 | Kotlin 7 | ---- 8 | Kotlin version is [1.0.3](https://blog.jetbrains.com/kotlin/2016/06/kotlin-1-0-3-is-here/). 9 | 10 | [Kotlin Android Roadmap](https://blog.jetbrains.com/kotlin/2016/03/kotlins-android-roadmap/) 11 | 12 | Flux 13 | ---- 14 | http://facebook.github.io/flux/docs/overview.html#content 15 | 16 | Libraries 17 | --------- 18 | 19 | * Kotlin - http://kotlinlang.org 20 | * KotterKnife - https://github.com/JakeWharton/kotterknife 21 | * Dagger2 - http://google.github.io/dagger 22 | * OkHttp - http://square.github.io/okhttp 23 | * Retrofit - http://square.github.io/retrofit 24 | * Gson - https://github.com/google/gson 25 | * Glide - https://github.com/bumptech/glide 26 | * RxJava - https://github.com/ReactiveX/RxJava 27 | * RxAndroid - https://github.com/ReactiveX/RxAndroid 28 | * RxLifecycle - https://github.com/trello/RxLifecycle 29 | * RxBinding - https://github.com/JakeWharton/RxBinding 30 | * SQLBrite - https://github.com/square/sqlbrite 31 | * rx-preferences - https://github.com/f2prateek/rx-preferences 32 | * Timber - http://github.com/JakeWharton/timber 33 | * LeakCanary - http://github.com/square/leakcanary 34 | * Stetho - http://facebook.github.io/stetho 35 | * Fabric - https://get.fabric.io 36 | * RecyclerviewBinder - https://github.com/satorufujiwara/recyclerview-binder 37 | 38 | Tips 39 | ---- 40 | 41 | ### Dagger2 injection 42 | 43 | ```kotlin 44 | @Inject lateinit var mainAction: MainAction 45 | ``` 46 | 47 | ### kapt 48 | 49 | http://blog.jetbrains.com/kotlin/2015/05/kapt-annotation-processing-for-kotlin/ 50 | http://blog.jetbrains.com/kotlin/2015/06/better-annotation-processing-supporting-stubs-in-kapt/ 51 | 52 | If use with Dagger2, must enable 'generateStub' option. 53 | 54 | ```Groovy 55 | kapt { 56 | generateStubs = true 57 | } 58 | ``` 59 | 60 | ### Parcerable 61 | 62 | Use `@JvmField` as `CREATOR`'s annotation instead of `@JvmStatic` 63 | 64 | ```kotlin 65 | companion object { 66 | @JvmField val CREATOR: Parcelable.Creator = object : Parcelable.Creator { 67 | override fun createFromParcel(source: Parcel): Repo? { 68 | return Repo(source) 69 | } 70 | override fun newArray(size: Int): Array? { 71 | return arrayOfNulls(size) 72 | } 73 | } 74 | } 75 | ``` 76 | http://blog.jetbrains.com/kotlin/2015/10/kotlin-1-0-beta-candidate-is-out 77 | 78 | Note 79 | ---- 80 | Fabric [Api Key](./mobile/src/main/AndroidManifest.xml#L22) and [Api Secret](./mobile/fabric.properties#L3) are empty. 81 | If you would build, should use your valid Api Key and Api Secret. 82 | 83 | 84 | ToDo 85 | ---- 86 | At [issues](https://github.com/satorufujiwara/kotlin-android-example/issues). 87 | 88 | If you want to suggest better implementation or you have found some mistakes in this projects, 89 | 90 | Please tell me at [issue](https://github.com/satorufujiwara/kotlin-android-example/issues). 91 | 92 | Thanks 93 | ------ 94 | * u2020 - https://github.com/JakeWharton/u2020 95 | * u2020-mvp - https://github.com/LiveTyping/u2020-mvp 96 | * kotlin-dagger-example - https://github.com/damianpetla/kotlin-dagger-example 97 | 98 | License 99 | ------- 100 | Copyright 2016 Satoru Fujiwara 101 | 102 | Licensed under the Apache License, Version 2.0 (the "License"); 103 | you may not use this file except in compliance with the License. 104 | You may obtain a copy of the License at 105 | 106 | http://www.apache.org/licenses/LICENSE-2.0 107 | 108 | Unless required by applicable law or agreed to in writing, software 109 | distributed under the License is distributed on an "AS IS" BASIS, 110 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 111 | See the License for the specific language governing permissions and 112 | limitations under the License. 113 | -------------------------------------------------------------------------------- /art/header_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-android-flux/46166abf26f8213f74c8f5c805d2d1c25a3f9b63/art/header_image.jpg -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | //fabric 7 | maven { url 'https://maven.fabric.io/public' } 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:2.1.3' 11 | //kotlin required plugin 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" 13 | //fabric 14 | classpath 'io.fabric.tools:gradle:1.+' 15 | 16 | // NOTE: Do not place your application dependencies here; they belong 17 | // in the individual module build.gradle files 18 | } 19 | } 20 | 21 | allprojects { 22 | repositories { 23 | jcenter() 24 | //kotterknife snapshots 25 | maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } 26 | //fabric 27 | maven { url 'https://maven.fabric.io/public' } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | kotlinVersion=1.0.3 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-android-flux/46166abf26f8213f74c8f5c805d2d1c25a3f9b63/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Aug 26 11:04:47 JST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /mobile/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /mobile/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'io.fabric' 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | android { 10 | compileSdkVersion 24 11 | buildToolsVersion "24.0.0" 12 | 13 | defaultConfig { 14 | minSdkVersion 16 15 | targetSdkVersion 24 16 | versionCode 1 17 | versionName "1.0" 18 | multiDexEnabled true 19 | } 20 | buildTypes { 21 | debug { 22 | applicationIdSuffix '.debug' 23 | } 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | 30 | productFlavors { 31 | local { 32 | applicationId 'jp.satorufujiwara.kotlin.local' 33 | } 34 | product { 35 | applicationId 'jp.satorufujiwara.kotlin' 36 | } 37 | } 38 | 39 | sourceSets { 40 | main.java.srcDirs += 'src/main/kotlin' 41 | debug.java.srcDirs += 'src/debug/kotlin' 42 | release.java.srcDirs += 'src/release/kotlin' 43 | local.java.srcDirs += 'src/local/kotlin' 44 | product.java.srcDirs += 'src/product/kotlin' 45 | } 46 | } 47 | 48 | def appcompatVersion = "24.0.0" 49 | def rxBindingVersion = "0.4.0" 50 | def rxLifecycleVersion = "0.5.0" 51 | dependencies { 52 | compile fileTree(dir: 'libs', include: ['*.jar']) 53 | 54 | compile "com.android.support:support-v4:$appcompatVersion" 55 | compile "com.android.support:appcompat-v7:$appcompatVersion" 56 | compile "com.android.support:recyclerview-v7:$appcompatVersion" 57 | compile "com.android.support:design:$appcompatVersion" 58 | 59 | //kotlin 60 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" 61 | compile('com.jakewharton:kotterknife:0.1.0-SNAPSHOT') 62 | 63 | //Dagger 2 64 | compile 'com.google.dagger:dagger:2.5' 65 | kapt 'com.google.dagger:dagger-compiler:2.5' 66 | provided 'org.glassfish:javax.annotation:10.0-b28' 67 | 68 | //data 69 | compile 'com.google.code.gson:gson:2.7' 70 | compile 'com.squareup.okhttp:okhttp:2.7.1' 71 | compile 'com.squareup.retrofit:retrofit:1.9.0' 72 | localCompile 'com.squareup.retrofit:retrofit-mock:1.9.0' 73 | 74 | //image 75 | compile 'com.github.bumptech.glide:glide:3.6.1' 76 | compile 'com.github.bumptech.glide:okhttp-integration:1.3.1' 77 | 78 | // reactive 79 | compile 'io.reactivex:rxjava:1.1.6' 80 | compile 'io.reactivex:rxandroid:1.2.1' 81 | compile "com.trello:rxlifecycle:$rxLifecycleVersion" 82 | compile "com.trello:rxlifecycle-components:$rxLifecycleVersion" 83 | compile "com.trello:rxlifecycle-kotlin:$rxLifecycleVersion" 84 | compile "com.jakewharton.rxbinding:rxbinding-kotlin:$rxBindingVersion" 85 | compile "com.jakewharton.rxbinding:rxbinding-support-v4-kotlin:$rxBindingVersion" 86 | compile "com.jakewharton.rxbinding:rxbinding-appcompat-v7-kotlin:$rxBindingVersion" 87 | compile "com.jakewharton.rxbinding:rxbinding-recyclerview-v7-kotlin:$rxBindingVersion" 88 | compile 'com.f2prateek.rx.preferences:rx-preferences:1.0.2' 89 | compile 'com.squareup.sqlbrite:sqlbrite:0.6.2' 90 | 91 | //debug 92 | compile 'com.jakewharton.timber:timber:4.0.1' 93 | debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3' 94 | releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3' 95 | debugCompile 'com.facebook.stetho:stetho:1.2.0' 96 | debugCompile 'com.facebook.stetho:stetho-okhttp:1.2.0' 97 | compile('com.crashlytics.sdk.android:crashlytics:2.3.2@aar') { 98 | transitive = true; 99 | } 100 | 101 | //ui 102 | compile 'jp.satorufujiwara:recyclerview-binder:1.3.2' 103 | } 104 | 105 | kapt { 106 | generateStubs = true 107 | } 108 | -------------------------------------------------------------------------------- /mobile/fabric.properties: -------------------------------------------------------------------------------- 1 | #Contains API Secret used to validate your application. Commit to internal source control; avoid making secret public. 2 | #Mon Jun 08 18:42:02 JST 2015 3 | apiSecret= 4 | -------------------------------------------------------------------------------- /mobile/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /adt-bundle-mac/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /mobile/src/androidTest/java/jp/satorufujiwara/kotlin/ApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import android.app.Application 4 | import android.test.ApplicationTestCase 5 | 6 | /** 7 | * [Testing Fundamentals](http://d.android.com/tools/testing/testing_android.html) 8 | */ 9 | public class ApplicationTest : ApplicationTestCase(Application::class.java) -------------------------------------------------------------------------------- /mobile/src/debug/kotlin/jp/satorufujiwara/kotlin/AppComponent.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import dagger.Component 4 | import jp.satorufujiwara.kotlin.data.DebugDataModule 5 | import jp.satorufujiwara.kotlin.ui.FluxModule 6 | 7 | @AppScope 8 | @Component(modules = arrayOf(DebugAppModule::class, DebugDataModule::class, FluxModule::class)) 9 | interface AppComponent : MainAppComponent { 10 | 11 | fun inject(app: KotlinApp) 12 | 13 | object Initializer { 14 | fun init(app: KotlinApp): AppComponent = 15 | DaggerAppComponent.builder() 16 | .debugAppModule(DebugAppModule(app)) 17 | .debugDataModule(DebugDataModule()) 18 | .build() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mobile/src/debug/kotlin/jp/satorufujiwara/kotlin/DebugAppLifecycleCallbacks.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import android.app.Application 4 | import com.facebook.stetho.Stetho 5 | import com.squareup.leakcanary.LeakCanary 6 | import timber.log.Timber 7 | 8 | class DebugAppLifecycleCallbacks : AppLifecycleCallbacks { 9 | 10 | override fun onCreate(application: Application) { 11 | Timber.plant(Timber.DebugTree()) 12 | LeakCanary.install(application) 13 | Stetho.initialize(Stetho.newInitializerBuilder(application) 14 | .enableDumpapp(Stetho.defaultDumperPluginsProvider(application)) 15 | .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(application)) 16 | .build()) 17 | } 18 | 19 | override fun onTerminate(application: Application) { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mobile/src/debug/kotlin/jp/satorufujiwara/kotlin/DebugAppModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import android.app.Application 4 | import com.squareup.leakcanary.LeakCanary 5 | import com.squareup.leakcanary.RefWatcher 6 | import dagger.Module 7 | import dagger.Provides 8 | 9 | @Module 10 | class DebugAppModule(private val app: Application) { 11 | 12 | @Provides 13 | @AppScope 14 | fun provideApplication(): Application = app 15 | 16 | @Provides 17 | @AppScope 18 | fun provideAppLifecycleCallbacks(): AppLifecycleCallbacks = DebugAppLifecycleCallbacks() 19 | 20 | @Provides 21 | @AppScope 22 | fun provideRefWatcher(application: Application): RefWatcher = 23 | LeakCanary.install(application) 24 | } 25 | -------------------------------------------------------------------------------- /mobile/src/debug/kotlin/jp/satorufujiwara/kotlin/data/DebugDataModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data 2 | 3 | import android.app.Application 4 | import android.content.Context 5 | import android.content.SharedPreferences 6 | import com.facebook.stetho.okhttp.StethoInterceptor 7 | import com.google.gson.Gson 8 | import com.google.gson.GsonBuilder 9 | import com.squareup.okhttp.OkHttpClient 10 | import dagger.Module 11 | import dagger.Provides 12 | import jp.satorufujiwara.kotlin.AppScope 13 | import jp.satorufujiwara.kotlin.data.api.ApiModule 14 | import jp.satorufujiwara.kotlin.data.repository.RepositoryModule 15 | import retrofit.Endpoint 16 | import retrofit.RestAdapter 17 | import retrofit.client.OkClient 18 | import retrofit.converter.GsonConverter 19 | import javax.inject.Named 20 | 21 | @Module(includes = arrayOf(ApiModule::class, RepositoryModule::class)) 22 | class DebugDataModule { 23 | 24 | @Provides 25 | @AppScope 26 | fun provideSharedPreferences(app: Application): SharedPreferences = 27 | app.getSharedPreferences("kotlin", Context.MODE_PRIVATE) 28 | 29 | @Provides 30 | @AppScope 31 | fun provideGson(): Gson = GsonBuilder().create() 32 | 33 | @Provides 34 | @AppScope 35 | fun provideOkHttpClient(app: Application): OkHttpClient { 36 | val client = OkHttpClient() 37 | client.networkInterceptors().add(StethoInterceptor()) 38 | return client 39 | } 40 | 41 | @Provides 42 | @AppScope 43 | @Named("Api") 44 | fun provideApiClient(client: OkHttpClient): OkHttpClient = client.clone() 45 | 46 | @Provides 47 | @AppScope 48 | fun provideRestAdapter(endpoint: Endpoint, @Named("Api") client: OkHttpClient, 49 | gson: Gson): RestAdapter = 50 | RestAdapter.Builder() 51 | .setLogLevel(RestAdapter.LogLevel.FULL) 52 | .setClient(OkClient(client)) 53 | .setEndpoint(endpoint) 54 | .setConverter(GsonConverter(gson)) 55 | .build() 56 | } 57 | -------------------------------------------------------------------------------- /mobile/src/local/kotlin/jp/satorufujiwara/kotlin/data/api/ApiModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.api 2 | 3 | import android.content.SharedPreferences 4 | 5 | import dagger.Module 6 | import dagger.Provides 7 | import jp.satorufujiwara.kotlin.AppScope 8 | import jp.satorufujiwara.kotlin.data.api.mock.MockGitHubService 9 | import retrofit.Endpoint 10 | import retrofit.Endpoints 11 | import retrofit.MockRestAdapter 12 | import retrofit.RestAdapter 13 | import retrofit.android.AndroidMockValuePersistence 14 | 15 | @Module 16 | public class ApiModule { 17 | 18 | companion object { 19 | @JvmStatic val PRODUCTION_API_URL: String = "https://api.github.com" 20 | } 21 | 22 | @Provides 23 | @AppScope 24 | fun provideEndpoint(): Endpoint = Endpoints.newFixedEndpoint(PRODUCTION_API_URL) 25 | 26 | @Provides 27 | @AppScope 28 | fun provideMockRestAdapter(restAdapter: RestAdapter, 29 | preferences: SharedPreferences): MockRestAdapter { 30 | val mockRestAdapter = MockRestAdapter.from(restAdapter) 31 | AndroidMockValuePersistence.install(mockRestAdapter, preferences) 32 | return mockRestAdapter 33 | } 34 | 35 | @Provides 36 | @AppScope 37 | fun provideGitHubService(restAdapter: MockRestAdapter): GitHubService = 38 | restAdapter.create(GitHubService::class.java, MockGitHubService()) 39 | 40 | } 41 | -------------------------------------------------------------------------------- /mobile/src/local/kotlin/jp/satorufujiwara/kotlin/data/api/mock/MockGitHub.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.api.mock 2 | 3 | import jp.satorufujiwara.kotlin.data.api.dto.Repo 4 | 5 | object MockGitHub { 6 | 7 | val MOCK_REPO_LIST: List = arrayListOf( 8 | Repo(id = "1000", name = "mock-repo0"), 9 | Repo(id = "1001", name = "mock-repo1"), 10 | Repo(id = "1002", name = "mock-repo2"), 11 | Repo(id = "1003", name = "mock-repo3"), 12 | Repo(id = "1004", name = "mock-repo4") 13 | ) 14 | } 15 | -------------------------------------------------------------------------------- /mobile/src/local/kotlin/jp/satorufujiwara/kotlin/data/api/mock/MockGitHubService.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.api.mock 2 | 3 | import jp.satorufujiwara.kotlin.data.api.GitHubService 4 | import jp.satorufujiwara.kotlin.data.api.dto.Repo 5 | import rx.Observable 6 | 7 | class MockGitHubService : GitHubService { 8 | 9 | override fun listRepos(user: String): Observable> = 10 | Observable.just(MockGitHub.MOCK_REPO_LIST) 11 | } 12 | -------------------------------------------------------------------------------- /mobile/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 14 | 15 | 18 | 19 | 20 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/AbstractActivity.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import android.support.v7.app.AppCompatActivity 4 | 5 | abstract class AbstractActivity : AppCompatActivity() { 6 | 7 | } -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/AbstractFragment.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import com.trello.rxlifecycle.components.support.RxFragment 4 | 5 | abstract class AbstractFragment : RxFragment() { 6 | 7 | override fun onDestroy() { 8 | super.onDestroy() 9 | KotlinApp.refWatcher(activity).watch(this) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/AppGlideModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import android.content.Context 4 | import com.bumptech.glide.Glide 5 | import com.bumptech.glide.GlideBuilder 6 | import com.bumptech.glide.integration.okhttp.OkHttpUrlLoader 7 | import com.bumptech.glide.load.DecodeFormat 8 | import com.bumptech.glide.load.engine.cache.LruResourceCache 9 | import com.bumptech.glide.load.model.GlideUrl 10 | import com.bumptech.glide.module.GlideModule 11 | import com.squareup.okhttp.OkHttpClient 12 | import java.io.InputStream 13 | 14 | class AppGlideModule : GlideModule { 15 | 16 | override fun applyOptions(context: Context, builder: GlideBuilder) { 17 | builder.setMemoryCache(LruResourceCache(30 * 1024 * 1024)).setDecodeFormat( 18 | DecodeFormat.PREFER_ARGB_8888) 19 | } 20 | 21 | override fun registerComponents(context: Context, glide: Glide) { 22 | //no op 23 | } 24 | 25 | companion object { 26 | 27 | fun registerComponents(context: Context, okHttpClient: OkHttpClient) { 28 | Glide.get(context).register(GlideUrl::class.java, InputStream::class.java, 29 | OkHttpUrlLoader.Factory(okHttpClient)) 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/AppLifecycleCallbacks.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import android.app.Application 4 | 5 | interface AppLifecycleCallbacks { 6 | 7 | fun onCreate(application: Application) 8 | 9 | fun onTerminate(application: Application) 10 | } 11 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/AppScope.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import javax.inject.Scope 4 | 5 | @Scope 6 | @Retention(AnnotationRetention.RUNTIME) 7 | annotation class AppScope -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/KotlinApp.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import android.app.Application 4 | import android.content.Context 5 | import com.squareup.leakcanary.RefWatcher 6 | import com.squareup.okhttp.OkHttpClient 7 | import jp.satorufujiwara.kotlin.ui.FluxAction 8 | import javax.inject.Inject 9 | 10 | class KotlinApp : Application() { 11 | 12 | companion object { 13 | @JvmStatic fun refWatcher(context: Context): RefWatcher = 14 | (context.applicationContext as KotlinApp).refWatcher 15 | 16 | @JvmStatic fun appComponent(context: Context): AppComponent = 17 | (context.applicationContext as KotlinApp).appComponent 18 | 19 | } 20 | 21 | val appComponent: AppComponent by lazy { AppComponent.Initializer.init(this) } 22 | @Inject lateinit var appLifecycleCallbacks: AppLifecycleCallbacks 23 | @Inject lateinit var refWatcher: RefWatcher 24 | @Inject lateinit var okHttpClient: OkHttpClient 25 | @Inject lateinit var fluxAction: FluxAction 26 | 27 | 28 | override fun onCreate() { 29 | super.onCreate() 30 | appComponent.inject(this) 31 | AppGlideModule.registerComponents(this, okHttpClient) 32 | fluxAction.deleteDispatcherDb() 33 | appLifecycleCallbacks.onCreate(this) 34 | } 35 | 36 | override fun onTerminate() { 37 | appLifecycleCallbacks.onTerminate(this) 38 | super.onTerminate() 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/MainAppComponent.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import android.app.Application 4 | import com.squareup.sqlbrite.BriteDatabase 5 | 6 | import jp.satorufujiwara.kotlin.data.repository.GitHubRepository 7 | import jp.satorufujiwara.kotlin.ui.FluxAction 8 | 9 | interface MainAppComponent { 10 | 11 | fun application(): Application 12 | 13 | fun gitHubRepository(): GitHubRepository 14 | 15 | fun briteDatabase(): BriteDatabase 16 | 17 | fun fluxAction(): FluxAction 18 | 19 | } 20 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/data/api/GitHubService.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.api 2 | 3 | import jp.satorufujiwara.kotlin.data.api.dto.Repo 4 | import retrofit.http.GET 5 | import retrofit.http.Path 6 | import rx.Observable 7 | 8 | public interface GitHubService { 9 | 10 | @GET("/users/{user}/repos") 11 | fun listRepos(@Path("user") user: String): Observable> 12 | 13 | } 14 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/data/api/dto/Repo.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.api.dto 2 | 3 | import android.os.Parcel 4 | import android.os.Parcelable 5 | 6 | data class Repo(var id: String, val name: String) : Parcelable { 7 | 8 | constructor(src: Parcel) : this( 9 | id = src.readString(), 10 | name = src.readString() 11 | ) 12 | 13 | 14 | override fun describeContents(): Int { 15 | return 0 16 | } 17 | 18 | override fun writeToParcel(dest: Parcel?, flags: Int) { 19 | dest?.writeString(id) 20 | dest?.writeString(name) 21 | } 22 | 23 | companion object { 24 | @JvmField val CREATOR: Parcelable.Creator = object : Parcelable.Creator { 25 | override fun createFromParcel(source: Parcel): Repo? { 26 | return Repo(source) 27 | } 28 | 29 | override fun newArray(size: Int): Array? { 30 | return arrayOfNulls(size) 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/data/repository/GitHubRepository.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.repository 2 | 3 | import jp.satorufujiwara.kotlin.data.api.GitHubService 4 | 5 | class GitHubRepository(val gitHubService: GitHubService) { 6 | 7 | fun getRepos(user: String) = gitHubService.listRepos(user) 8 | 9 | } 10 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/data/repository/RepositoryModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.repository 2 | 3 | import dagger.Module 4 | import dagger.Provides 5 | import jp.satorufujiwara.kotlin.AppScope 6 | import jp.satorufujiwara.kotlin.data.api.GitHubService 7 | 8 | @Module 9 | class RepositoryModule { 10 | 11 | @Provides 12 | @AppScope 13 | fun provideGitHubRepository(gitHubService: GitHubService): GitHubRepository = 14 | GitHubRepository(gitHubService) 15 | } 16 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/DispatcherDbOpenHelper.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui 2 | 3 | import android.content.Context 4 | import android.database.sqlite.SQLiteDatabase 5 | import android.database.sqlite.SQLiteOpenHelper 6 | import jp.satorufujiwara.kotlin.BuildConfig 7 | import jp.satorufujiwara.kotlin.ui.main.MainDispatcher 8 | 9 | 10 | class DispatcherDbOpenHelper(context: Context) : SQLiteOpenHelper(context, BuildConfig.APPLICATION_ID + ".dispatcher.db", null, 1) { 11 | 12 | override fun onCreate(db: SQLiteDatabase) { 13 | db.execSQL(MainDispatcher.createTable()) 14 | } 15 | 16 | override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/FluxAction.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui 2 | 3 | import com.squareup.sqlbrite.BriteDatabase 4 | import jp.satorufujiwara.kotlin.ui.main.MainDispatcher 5 | import rx.Observable 6 | import rx.schedulers.Schedulers 7 | 8 | 9 | class FluxAction(val db: BriteDatabase) { 10 | 11 | fun deleteDispatcherDb() = Observable.fromCallable { 12 | db.newTransaction().run { 13 | try { 14 | db.delete(MainDispatcher.TABLE_NAME, "") 15 | markSuccessful() 16 | } finally { 17 | end() 18 | } 19 | } 20 | }.subscribeOn(Schedulers.io()) 21 | } -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/FluxModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui 2 | 3 | import android.app.Application 4 | import com.squareup.sqlbrite.BriteDatabase 5 | import com.squareup.sqlbrite.SqlBrite 6 | import dagger.Module 7 | import dagger.Provides 8 | import jp.satorufujiwara.kotlin.AppScope 9 | import jp.satorufujiwara.kotlin.ui.DispatcherDbOpenHelper 10 | import rx.schedulers.Schedulers 11 | import javax.inject.Named 12 | 13 | @Module 14 | class FluxModule { 15 | 16 | @Provides 17 | @AppScope 18 | @Named("Dispatcher") 19 | fun provideSqlBrite() = SqlBrite.create() 20 | 21 | @Provides 22 | @AppScope 23 | @Named("Dispatcher") 24 | fun provideDispatcherDbOpenHelper(app: Application) = DispatcherDbOpenHelper(app) 25 | 26 | @Provides 27 | @AppScope 28 | fun provideDatabase(@Named("Dispatcher") sqlBrite: SqlBrite, 29 | @Named("Dispatcher") helper: DispatcherDbOpenHelper) = 30 | sqlBrite.wrapDatabaseHelper(helper, Schedulers.io()) 31 | 32 | @Provides 33 | @AppScope 34 | fun provideFluxAction(db: BriteDatabase) = FluxAction(db) 35 | 36 | } -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/MainAction.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import jp.satorufujiwara.kotlin.data.repository.GitHubRepository 4 | import rx.schedulers.Schedulers 5 | 6 | class MainAction(val dispatcher: MainDispatcher, val repository: GitHubRepository) { 7 | 8 | fun refreshList(screenId: String) = repository.getRepos("satorufujiwara") 9 | .subscribeOn(Schedulers.io()) 10 | .subscribe({ 11 | dispatcher.dispatch(screenId, it) 12 | }, { 13 | dispatcher.dispatchError("Couldn't get items... ") 14 | }) 15 | } -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import android.app.Activity 4 | import android.content.Intent 5 | import android.content.res.Configuration 6 | import android.os.Bundle 7 | import android.support.v4.widget.DrawerLayout 8 | import android.support.v7.app.ActionBarDrawerToggle 9 | import android.support.v7.widget.Toolbar 10 | import android.view.Gravity 11 | import android.view.MenuItem 12 | import butterknife.bindView 13 | import com.jakewharton.rxbinding.support.v4.widget.drawerOpen 14 | import jp.satorufujiwara.kotlin.AbstractActivity 15 | import jp.satorufujiwara.kotlin.R 16 | import jp.satorufujiwara.kotlin.util.ext.setContentFragment 17 | import rx.Observable 18 | 19 | class MainActivity : AbstractActivity() { 20 | 21 | companion object { 22 | fun createIntent(activity: Activity) = Intent(activity, MainActivity::class.java) 23 | } 24 | 25 | val toolBar: Toolbar by bindView(R.id.toolBar) 26 | val drawerLayout: DrawerLayout by bindView(R.id.drawerLayout) 27 | val drawerToggle: ActionBarDrawerToggle by lazy { 28 | ActionBarDrawerToggle(this, drawerLayout, 29 | R.string.main_activity_toolbar, R.string.main_activity_toolbar) 30 | } 31 | val drawerObservable: Observable by lazy { drawerLayout.drawerOpen(Gravity.LEFT) } 32 | val component: MainComponent by lazy { MainComponent.Initializer.init(this) } 33 | 34 | override fun onCreate(savedInstanceState: Bundle?) { 35 | super.onCreate(savedInstanceState) 36 | component.inject(this) 37 | setContentView(R.layout.main_activity) 38 | setContentFragment(R.id.containerLayout, MainFragment.newInstance()) 39 | setSupportActionBar(toolBar) 40 | supportActionBar?.setDisplayHomeAsUpEnabled(true) 41 | drawerToggle.isDrawerIndicatorEnabled = true 42 | } 43 | 44 | override fun onPostCreate(savedInstanceState: Bundle?) { 45 | super.onPostCreate(savedInstanceState) 46 | drawerToggle.syncState() 47 | } 48 | 49 | override fun onConfigurationChanged(newConfig: Configuration?) { 50 | super.onConfigurationChanged(newConfig) 51 | drawerToggle.onConfigurationChanged(newConfig) 52 | } 53 | 54 | override fun onOptionsItemSelected(item: MenuItem?): Boolean = 55 | if (drawerToggle.onOptionsItemSelected(item)) true 56 | else super.onOptionsItemSelected(item) 57 | 58 | } 59 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/MainComponent.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import dagger.Component 4 | import jp.satorufujiwara.kotlin.AppComponent 5 | import jp.satorufujiwara.kotlin.KotlinApp 6 | 7 | @MainScope 8 | @Component(dependencies = arrayOf(AppComponent::class), modules = arrayOf(MainModule::class)) 9 | public interface MainComponent { 10 | 11 | public fun inject(activity: MainActivity) 12 | 13 | public fun inject(fragment: MainFragment) 14 | 15 | public object Initializer { 16 | 17 | public fun init(activity: MainActivity): MainComponent { 18 | return DaggerMainComponent.builder() 19 | .appComponent(KotlinApp.appComponent(activity)) 20 | .mainModule(MainModule()) 21 | .build() 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/MainDispatcher.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import android.content.ContentValues 4 | import com.squareup.sqlbrite.BriteDatabase 5 | import jp.satorufujiwara.kotlin.data.api.dto.Repo 6 | import jp.satorufujiwara.kotlin.util.ext.getStringByName 7 | import rx.subjects.PublishSubject 8 | import rx.subjects.SerializedSubject 9 | 10 | class MainDispatcher(val db: BriteDatabase) { 11 | 12 | companion object { 13 | const val TABLE_NAME = "repo" 14 | private const val DB_ID = "_id" 15 | private const val SCREEN_ID = "screen_id" 16 | private const val REPO_ID = "repo_id" 17 | private const val REPO_NAME = "repo_name" 18 | fun createTable() = "CREATE TABLE $TABLE_NAME ($DB_ID INTEGER NOT NULL PRIMARY KEY,$SCREEN_ID TEXT,$REPO_ID TEXT,$REPO_NAME TEXT)" 19 | } 20 | 21 | private val emptyObservable = SerializedSubject(PublishSubject.create()) 22 | val errorEventObservable = SerializedSubject(PublishSubject.create()) 23 | 24 | fun deleteAll() = db.delete(TABLE_NAME, "") 25 | 26 | fun repos(screenId: String) = 27 | db.createQuery(TABLE_NAME, "SELECT * FROM $TABLE_NAME WHERE $SCREEN_ID=?", screenId) 28 | .mapToList { Repo(it.getStringByName(REPO_ID), it.getStringByName(REPO_NAME)) } 29 | .mergeWith(emptyObservable.filter { it == screenId }.map { emptyList() }) 30 | 31 | fun dispatch(screenId: String, list: List) = db.newTransaction().run { 32 | var rows = 0 33 | try { 34 | db.delete(TABLE_NAME, "$SCREEN_ID=?", screenId) 35 | list.filterNotNull().map { repo -> 36 | ContentValues().apply { 37 | put(SCREEN_ID, screenId) 38 | put(REPO_ID, repo.id) 39 | put(REPO_NAME, repo.name) 40 | } 41 | }.forEach { 42 | db.insert(TABLE_NAME, it) 43 | rows++ 44 | } 45 | markSuccessful() 46 | } finally { 47 | end() 48 | } 49 | if (list.size == 0 && rows == 0) emptyObservable.onNext(screenId) 50 | rows 51 | } 52 | 53 | fun dispatchError(message: String) = errorEventObservable.onNext(message) 54 | 55 | } -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/MainFragment.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import android.app.Activity 4 | import android.os.Bundle 5 | import android.support.v7.widget.LinearLayoutManager 6 | import android.support.v7.widget.RecyclerView 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | import butterknife.bindView 11 | import com.trello.rxlifecycle.kotlin.bindToLifecycle 12 | import jp.satorufujiwara.binder.Section 13 | import jp.satorufujiwara.binder.recycler.RecyclerBinderAdapter 14 | import jp.satorufujiwara.kotlin.AbstractFragment 15 | import jp.satorufujiwara.kotlin.R 16 | import jp.satorufujiwara.kotlin.util.ext.inflate 17 | import jp.satorufujiwara.kotlin.util.ext.showToast 18 | import rx.android.schedulers.AndroidSchedulers 19 | import javax.inject.Inject 20 | import kotlin.properties.Delegates 21 | 22 | class MainFragment : AbstractFragment() { 23 | 24 | companion object { 25 | private const val KEY_SCREEN_ID = "screenId" 26 | @JvmStatic fun newInstance() = MainFragment() 27 | } 28 | 29 | private var screenId: String by Delegates.notNull() 30 | val recyclerView: RecyclerView by bindView(R.id.recyclerView) 31 | val adapter: RecyclerBinderAdapter = RecyclerBinderAdapter() 32 | @Inject lateinit var mainAction: MainAction 33 | @Inject lateinit var mainStore: MainStore 34 | 35 | override fun onAttach(activity: Activity?) { 36 | super.onAttach(activity) 37 | (activity as MainActivity).component.inject(this) 38 | } 39 | 40 | override fun onSaveInstanceState(outState: Bundle?) { 41 | super.onSaveInstanceState(outState) 42 | outState?.putString(KEY_SCREEN_ID, screenId) 43 | } 44 | 45 | override fun onCreate(savedInstanceState: Bundle?) { 46 | super.onCreate(savedInstanceState) 47 | screenId = savedInstanceState?.getString(KEY_SCREEN_ID) ?: hashCode().toString() 48 | } 49 | 50 | override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, 51 | savedInstanceState: Bundle?): View? = 52 | inflate(R.layout.main_fragment, inflater, container) 53 | 54 | override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { 55 | super.onViewCreated(view, savedInstanceState) 56 | recyclerView.adapter = adapter 57 | recyclerView.layoutManager = LinearLayoutManager(activity) 58 | mainStore.repos(screenId) 59 | .observeOn(AndroidSchedulers.mainThread()) 60 | .bindToLifecycle(this) 61 | .subscribe { 62 | adapter.replaceAll(MainSection.CONTENTS, it.map { MainRepoBinder(activity, it) }) 63 | adapter.notifyDataSetChanged() 64 | } 65 | savedInstanceState ?: mainAction.refreshList(screenId) 66 | } 67 | 68 | override fun onResume() { 69 | super.onResume() 70 | mainStore.errorEvents() 71 | .observeOn(AndroidSchedulers.mainThread()) 72 | .bindToLifecycle(this) 73 | .subscribe { activity.showToast(it) } 74 | } 75 | 76 | override fun onDestroyView() { 77 | adapter.clear() 78 | super.onDestroyView() 79 | } 80 | 81 | enum class MainSection : Section { 82 | CONTENTS; 83 | 84 | override fun position(): Int = ordinal 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/MainModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import com.squareup.sqlbrite.BriteDatabase 4 | import dagger.Module 5 | import dagger.Provides 6 | import jp.satorufujiwara.kotlin.data.repository.GitHubRepository 7 | 8 | @Module 9 | class MainModule { 10 | 11 | @Provides 12 | @MainScope 13 | fun provideMainDispatcher(db: BriteDatabase) = MainDispatcher(db) 14 | 15 | @Provides 16 | @MainScope 17 | fun provideMainAction(dispatcher: MainDispatcher, repository: GitHubRepository) = 18 | MainAction(dispatcher, repository) 19 | 20 | @Provides 21 | @MainScope 22 | fun provideMainStore(dispatcher: MainDispatcher) = MainStore(dispatcher) 23 | } 24 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/MainRepoBinder.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import android.app.Activity 4 | import android.support.v7.widget.RecyclerView 5 | import android.view.View 6 | import android.widget.RelativeLayout 7 | import android.widget.TextView 8 | import butterknife.bindView 9 | import jp.satorufujiwara.binder.recycler.RecyclerBinder 10 | import jp.satorufujiwara.kotlin.R 11 | import jp.satorufujiwara.kotlin.data.api.dto.Repo 12 | 13 | class MainRepoBinder(activity: Activity, val repo: Repo, val onClick: (() -> Unit)? = null) 14 | : RecyclerBinder(activity, MainViewType.REPO) { 15 | 16 | override fun layoutResId(): Int = R.layout.main_repo_binder 17 | 18 | override fun onCreateViewHolder(view: View?): RecyclerView.ViewHolder? = ViewHolder(view) 19 | 20 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { 21 | holder as ViewHolder 22 | holder.textView.text = repo.name 23 | holder.rootLayout.setOnClickListener { onClick?.invoke() } 24 | } 25 | 26 | class ViewHolder(view: View?) : RecyclerView.ViewHolder(view) { 27 | val rootLayout: RelativeLayout = itemView as RelativeLayout 28 | val textView: TextView by bindView(R.id.textView) 29 | } 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/MainScope.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | 4 | import javax.inject.Scope 5 | 6 | @Scope 7 | @Retention(AnnotationRetention.RUNTIME) 8 | annotation public class MainScope -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/MainStore.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | 4 | class MainStore(val dispatcher: MainDispatcher) { 5 | 6 | fun errorEvents() = dispatcher.errorEventObservable 7 | 8 | fun repos(screenId: String) = dispatcher.repos(screenId) 9 | } -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/MainViewType.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import jp.satorufujiwara.binder.ViewType 4 | 5 | enum class MainViewType : ViewType { 6 | 7 | REPO; 8 | 9 | override fun viewType(): Int = ordinal 10 | } 11 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/drawer/MainDrawerFragment.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main.drawer 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.support.v7.widget.LinearLayoutManager 6 | import android.support.v7.widget.RecyclerView 7 | import android.view.LayoutInflater 8 | import android.view.View 9 | import android.view.ViewGroup 10 | import android.widget.ImageView 11 | import butterknife.bindView 12 | import com.bumptech.glide.Glide 13 | import com.trello.rxlifecycle.kotlin.bindToLifecycle 14 | import jp.satorufujiwara.binder.Section 15 | import jp.satorufujiwara.binder.recycler.RecyclerBinderAdapter 16 | import jp.satorufujiwara.kotlin.AbstractFragment 17 | import jp.satorufujiwara.kotlin.R 18 | import jp.satorufujiwara.kotlin.ui.main.MainActivity 19 | import jp.satorufujiwara.kotlin.util.ext.inflate 20 | import rx.android.schedulers.AndroidSchedulers 21 | import rx.subjects.PublishSubject 22 | 23 | class MainDrawerFragment : AbstractFragment() { 24 | 25 | companion object { 26 | private const val IMAGE_URL = "https://raw.githubusercontent.com/satorufujiwara/kotlin-android-example/master/art/header_image.jpg" 27 | } 28 | 29 | val recyclerView: RecyclerView by bindView(R.id.recyclerView) 30 | val headerImage: ImageView by bindView(R.id.headerImage) 31 | val headerLayout: View by bindView(R.id.headerLayout) 32 | val adapter: RecyclerBinderAdapter = RecyclerBinderAdapter() 33 | val scrollListener: OnScrollListener by lazy { OnScrollListener(headerLayout) } 34 | val itemClickObservable = PublishSubject.create() 35 | 36 | override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, 37 | savedInstanceState: Bundle?): View? = 38 | inflate(R.layout.main_drawer_fragment, inflater, container) 39 | 40 | override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { 41 | super.onViewCreated(view, savedInstanceState) 42 | val activity = activity 43 | recyclerView.adapter = adapter 44 | recyclerView.layoutManager = LinearLayoutManager(activity) 45 | recyclerView.addOnScrollListener(scrollListener) 46 | 47 | adapter.add(MainDrawerSection.HEADER, MainDrawerTransparentBinder(activity)) 48 | adapter.add(MainDrawerSection.NAVIGATION, MainDrawerNavigationBinder(activity, 49 | getString(R.string.main_drawer_navigation_home))) 50 | adapter.addAll(MainDrawerSection.NAVIGATION, 51 | (0..10).map { 52 | MainDrawerNavigationBinder(activity, "Menu : $it") { 53 | itemClickObservable.onNext(MainActivity.createIntent(activity)) 54 | } 55 | }) 56 | Glide.with(this).load(IMAGE_URL).into(headerImage) 57 | } 58 | 59 | override fun onActivityCreated(savedInstanceState: Bundle?) { 60 | super.onActivityCreated(savedInstanceState) 61 | val activity = (activity as MainActivity) 62 | itemClickObservable.observeOn(AndroidSchedulers.mainThread()) 63 | .doOnNext { activity.drawerLayout.closeDrawers() } 64 | .zipWith(activity.drawerObservable.skip(1).filter { !it }) { intent, drawer -> intent } 65 | .bindToLifecycle(this) 66 | .subscribe { startActivity(it) } 67 | } 68 | 69 | override fun onDestroyView() { 70 | recyclerView.removeOnScrollListener(scrollListener) 71 | super.onDestroyView() 72 | } 73 | 74 | enum class MainDrawerSection : Section { 75 | HEADER, 76 | NAVIGATION; 77 | 78 | override fun position(): Int = ordinal 79 | } 80 | 81 | class OnScrollListener(val headerLayout: View) : RecyclerView.OnScrollListener() { 82 | var y: Int = 0 83 | override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { 84 | super.onScrolled(recyclerView, dx, dy) 85 | y += dy 86 | if (y > headerLayout.height) { 87 | return 88 | } 89 | headerLayout.translationY = (-y / 2).toFloat() 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/drawer/MainDrawerNavigationBinder.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main.drawer 2 | 3 | import android.app.Activity 4 | import android.support.v7.widget.RecyclerView 5 | import android.view.View 6 | import android.widget.RelativeLayout 7 | import android.widget.TextView 8 | import butterknife.bindView 9 | import jp.satorufujiwara.binder.recycler.RecyclerBinder 10 | import jp.satorufujiwara.kotlin.R 11 | 12 | class MainDrawerNavigationBinder(activity: Activity, val text: String, val onClick: (() -> Unit)? = null) 13 | : RecyclerBinder(activity, MainDrawerViewType.NAVIGATION) { 14 | 15 | override fun layoutResId(): Int = R.layout.main_drawer_navigation_binder 16 | 17 | override fun onCreateViewHolder(view: View?): RecyclerView.ViewHolder? = ViewHolder(view) 18 | 19 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { 20 | holder as ViewHolder 21 | holder.textView.text = text 22 | holder.rootLayout.setOnClickListener { onClick?.invoke() } 23 | } 24 | 25 | class ViewHolder(view: View?) : RecyclerView.ViewHolder(view) { 26 | val rootLayout: RelativeLayout = itemView as RelativeLayout 27 | val textView: TextView by bindView(R.id.textView) 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/drawer/MainDrawerTransparentBinder.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main.drawer 2 | 3 | import android.app.Activity 4 | import android.support.v7.widget.RecyclerView 5 | import android.view.View 6 | import jp.satorufujiwara.binder.recycler.RecyclerBinder 7 | import jp.satorufujiwara.kotlin.R 8 | 9 | public class MainDrawerTransparentBinder(activity: Activity) 10 | : RecyclerBinder(activity, MainDrawerViewType.TRANSPARENT) { 11 | 12 | override fun layoutResId(): Int = R.layout.main_drawer_transparent_binder 13 | 14 | override fun onCreateViewHolder(view: View?): RecyclerView.ViewHolder? = ViewHolder(view) 15 | 16 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { 17 | } 18 | 19 | class ViewHolder(view: View?) : RecyclerView.ViewHolder(view) { 20 | } 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/ui/main/drawer/MainDrawerViewType.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main.drawer 2 | 3 | import jp.satorufujiwara.binder.ViewType 4 | 5 | enum class MainDrawerViewType : ViewType { 6 | 7 | TRANSPARENT, 8 | NAVIGATION, 9 | TITLE, 10 | CHANNEL; 11 | 12 | override fun viewType(): Int = ordinal 13 | } -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/util/CrashlyticsTree.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.util 2 | 3 | import com.crashlytics.android.Crashlytics 4 | 5 | import android.util.Log 6 | 7 | import timber.log.Timber 8 | 9 | public class CrashlyticsTree : Timber.Tree() { 10 | 11 | override fun log(priority: Int, tag: String, message: String, t: Throwable?) { 12 | if (priority != Log.ERROR) { 13 | return 14 | } 15 | Crashlytics.getInstance().core.log(priority, tag, message) 16 | if (t != null) { 17 | Crashlytics.getInstance().core.logException(t) 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/util/ext/BriteDatabaseExt.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.util.ext 2 | 3 | import android.database.Cursor 4 | 5 | fun Cursor.getStringByName(columnName: String) = getString(getColumnIndexOrThrow(columnName)) -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/util/ext/FragmentActivityExt.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.util.ext 2 | 3 | import android.content.Context 4 | import android.support.annotation.IntDef 5 | import android.support.v4.app.Fragment 6 | import android.support.v4.app.FragmentActivity 7 | import android.widget.Toast 8 | 9 | fun FragmentActivity.setContentFragment(containerViewId: Int, fragment: Fragment?): Fragment? { 10 | val f: Fragment? = supportFragmentManager?.findFragmentById(containerViewId) 11 | f?.let { return@setContentFragment f } 12 | supportFragmentManager?.beginTransaction()?.add(containerViewId, fragment)?.commit() 13 | return fragment 14 | } 15 | 16 | @IntDef(Toast.LENGTH_SHORT.toLong(), Toast.LENGTH_LONG.toLong()) 17 | annotation class Duration 18 | 19 | fun Context.showToast(text: String, @Duration length: Int = Toast.LENGTH_SHORT) { 20 | Toast.makeText(this, text, length).show() 21 | } 22 | -------------------------------------------------------------------------------- /mobile/src/main/kotlin/jp/satorufujiwara/kotlin/util/ext/FragmentExt.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.util.ext 2 | 3 | import android.app.Fragment 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.support.v4.app.Fragment as SupportFragment 8 | 9 | fun SupportFragment.inflate(layoutResId: Int, inflater: LayoutInflater?, 10 | container: ViewGroup?): View? = 11 | inflater?.inflate(layoutResId, container, false) 12 | 13 | fun Fragment.inflate(layoutResId: Int, inflater: LayoutInflater?, 14 | container: ViewGroup?): View? = 15 | inflater?.inflate(layoutResId, container, false) 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /mobile/src/main/res/drawable-v21/app_white.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mobile/src/main/res/drawable/app_white.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /mobile/src/main/res/layout/main_activity.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 17 | 18 | 26 | 27 | 32 | 33 | 34 | 35 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /mobile/src/main/res/layout/main_drawer_fragment.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 19 | 20 | 21 | 22 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /mobile/src/main/res/layout/main_drawer_navigation_binder.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /mobile/src/main/res/layout/main_drawer_transparent_binder.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /mobile/src/main/res/layout/main_fragment.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /mobile/src/main/res/layout/main_repo_binder.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /mobile/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-android-flux/46166abf26f8213f74c8f5c805d2d1c25a3f9b63/mobile/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /mobile/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-android-flux/46166abf26f8213f74c8f5c805d2d1c25a3f9b63/mobile/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /mobile/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-android-flux/46166abf26f8213f74c8f5c805d2d1c25a3f9b63/mobile/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /mobile/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-android-flux/46166abf26f8213f74c8f5c805d2d1c25a3f9b63/mobile/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /mobile/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #212121 4 | 5 | 6 | #ffffffff 7 | #fff4f4f4 8 | #ffd6d6d6 9 | 10 | #1e000000 11 | 12 | #fffafafa 13 | 14 | -------------------------------------------------------------------------------- /mobile/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 280dp 5 | 152dp 6 | 7 | -------------------------------------------------------------------------------- /mobile/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | kotlin 3 | 4 | 5 | Home 6 | 7 | 8 | -------------------------------------------------------------------------------- /mobile/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /mobile/src/product/kotlin/jp/satorufujiwara/kotlin/data/api/ApiModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.api 2 | 3 | import dagger.Module 4 | import dagger.Provides 5 | import jp.satorufujiwara.kotlin.AppScope 6 | import retrofit.Endpoint 7 | import retrofit.Endpoints 8 | import retrofit.RestAdapter 9 | 10 | @Module 11 | public class ApiModule { 12 | 13 | companion object { 14 | @JvmStatic val PRODUCTION_API_URL: String = "https://api.github.com" 15 | } 16 | 17 | @Provides 18 | @AppScope 19 | fun provideEndpoint(): Endpoint = Endpoints.newFixedEndpoint(PRODUCTION_API_URL) 20 | 21 | @Provides 22 | @AppScope 23 | fun provideGitHubService(restAdapter: RestAdapter): GitHubService = 24 | restAdapter.create(GitHubService::class.java) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /mobile/src/release/kotlin/jp/satorufujiwara/kotlin/AppComponent.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import dagger.Component 4 | import jp.satorufujiwara.kotlin.data.DataModule 5 | import jp.satorufujiwara.kotlin.ui.FluxModule 6 | 7 | @AppScope 8 | @Component(modules = arrayOf(AppModule::class, DataModule::class, FluxModule::class)) 9 | public interface AppComponent : MainAppComponent { 10 | 11 | fun inject(app: KotlinApp) 12 | 13 | object Initializer { 14 | 15 | fun init(app: KotlinApp): AppComponent = 16 | DaggerAppComponent.builder() 17 | .appModule(AppModule(app)) 18 | .dataModule(DataModule()) 19 | .build() 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /mobile/src/release/kotlin/jp/satorufujiwara/kotlin/AppModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import android.app.Application 4 | import com.squareup.leakcanary.RefWatcher 5 | import dagger.Module 6 | import dagger.Provides 7 | 8 | @Module 9 | class AppModule(private val app: Application) { 10 | 11 | @Provides 12 | @AppScope 13 | fun provideApplication(): Application = app 14 | 15 | @Provides 16 | @AppScope 17 | public fun provideAppLifecycleCallbacks(): AppLifecycleCallbacks = ReleaseAppLifecycleCallbacks() 18 | 19 | @Provides 20 | @AppScope 21 | public fun provideRefWatcher(): RefWatcher = RefWatcher.DISABLED 22 | 23 | } 24 | -------------------------------------------------------------------------------- /mobile/src/release/kotlin/jp/satorufujiwara/kotlin/ReleaseAppLifecycleCallbacks.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import com.crashlytics.android.Crashlytics 4 | 5 | import android.app.Application 6 | 7 | import io.fabric.sdk.android.Fabric 8 | import jp.satorufujiwara.kotlin.util.CrashlyticsTree 9 | import timber.log.Timber 10 | 11 | class ReleaseAppLifecycleCallbacks : AppLifecycleCallbacks { 12 | 13 | override fun onCreate(application: Application) { 14 | Fabric.with(application, Crashlytics()) 15 | Timber.plant(CrashlyticsTree()) 16 | } 17 | 18 | override fun onTerminate(application: Application) { 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mobile/src/release/kotlin/jp/satorufujiwara/kotlin/data/DataModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data 2 | 3 | import android.app.Application 4 | import android.content.Context 5 | import android.content.SharedPreferences 6 | import com.google.gson.Gson 7 | import com.google.gson.GsonBuilder 8 | import com.squareup.okhttp.OkHttpClient 9 | import dagger.Module 10 | import dagger.Provides 11 | import jp.satorufujiwara.kotlin.AppScope 12 | import jp.satorufujiwara.kotlin.data.api.ApiModule 13 | import jp.satorufujiwara.kotlin.data.repository.RepositoryModule 14 | import retrofit.Endpoint 15 | import retrofit.RestAdapter 16 | import retrofit.client.OkClient 17 | import retrofit.converter.GsonConverter 18 | import javax.inject.Named 19 | 20 | @Module(includes = arrayOf(ApiModule::class, RepositoryModule::class)) 21 | public class DataModule { 22 | 23 | @Provides 24 | @AppScope 25 | fun provideSharedPreferences(app: Application): SharedPreferences = 26 | app.getSharedPreferences("valencia", Context.MODE_PRIVATE) 27 | 28 | @Provides 29 | @AppScope 30 | fun provideGson(): Gson = GsonBuilder().create() 31 | 32 | @Provides 33 | @AppScope 34 | public fun provideOkHttpClient(app: Application): OkHttpClient { 35 | val client = OkHttpClient() 36 | // File cacheDir = new File(app.getCacheDir(), "http"); 37 | // Cache cache = new Cache(cacheDir, size); 38 | // client.setCache(cache); 39 | return client 40 | } 41 | 42 | @Provides 43 | @AppScope 44 | @Named("Api") 45 | fun provideApiClient(client: OkHttpClient): OkHttpClient = client.clone() 46 | 47 | @Provides 48 | @AppScope 49 | fun provideRestAdapter(endpoint: Endpoint, @Named("Api") client: OkHttpClient, 50 | gson: Gson): RestAdapter = 51 | RestAdapter.Builder() 52 | .setClient(OkClient(client)) 53 | .setEndpoint(endpoint) 54 | .setConverter(GsonConverter(gson)) 55 | .build() 56 | 57 | } 58 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':mobile' --------------------------------------------------------------------------------