From b65ace709948a1db15316035c54c1cd4016b8047 Mon Sep 17 00:00:00 2001 From: ramabit Date: Thu, 14 Jan 2016 16:28:14 -0300 Subject: [PATCH 1/4] update kotlin version, adapting whole app, fixing errors --- app/build.gradle | 20 ++-- app/src/main/AndroidManifest.xml | 2 +- .../action/SignInUIAction.kt | 2 +- .../restfulandroidkotlin/event/BaseEvent.kt | 2 - .../extension/Activities.kt | 3 +- .../extension/Fragments.kt | 2 +- .../extension/Generics.kt | 10 -- .../restfulandroidkotlin/extension/Realms.kt | 10 +- .../restfulandroidkotlin/extension/Views.kt | 3 +- .../interactor/SignInInteractor.kt | 6 +- .../network/api/TheMovieDBAPI.kt | 68 ++++++------- .../GetListMovieNowplayingSpiceRequest.kt | 4 +- .../GetListMovieTopratedSpiceRequest.kt | 4 +- .../GetListTVAiringtodaySpiceRequest.kt | 4 +- .../request/GetListTVPopularSpiceRequest.kt | 4 +- .../request/GetMovieCreditsSpiceRequest.kt | 4 +- .../request/GetMovieImagesSpiceRequest.kt | 4 +- .../network/request/GetMovieSpiceRequest.kt | 8 +- .../request/GetNewSessionSpiceRequest.kt | 5 +- .../network/request/GetTokenSpiceRequest.kt | 3 +- .../request/ValidateTokenSpiceRequest.kt | 5 +- .../response/EventBusRequestListener.kt | 10 +- .../service/TheMovieAPISpiceService.kt | 10 +- .../presenter/Presenter.kt | 4 +- .../presenter/SignInPresenter.kt | 12 +-- .../resource/client/ResourceClient.kt | 84 ++++++++-------- .../resource/router/ResourceRouter.kt | 11 +-- .../util/CircularTransformation.kt | 11 +-- .../restfulandroidkotlin/util/Preference.kt | 37 ++++--- .../view/activity/BaseActivity.kt | 26 ++--- .../view/activity/BaseSpiceActivity.kt | 2 +- .../view/activity/MainActivity.kt | 35 +++---- .../view/activity/MovieDetailActivity.kt | 88 ++++++++--------- .../view/activity/MovieListActivity.kt | 44 ++++----- .../view/activity/ProductEditActivity.kt | 49 ++++------ .../view/activity/ProductListActivity.kt | 56 +++++------ .../view/activity/SignInActivity.kt | 27 ++--- .../view/fragment/BaseDrawerFragment.kt | 39 +++----- .../view/fragment/BaseFragment.kt | 15 +-- .../view/fragment/BaseSpiceFragment.kt | 2 +- .../fragment/MainNavigationDrawerFragment.kt | 69 +++++++------ .../view/fragment/MovieFragment.kt | 25 +++-- .../view/fragment/MovieGridFragment.kt | 92 ++++++++---------- .../view/fragment/TVFragment.kt | 28 +++--- .../view/fragment/TVGridFragment.kt | 68 ++++++------- .../res/drawable/tool_bar_background.9.png | Bin 257 -> 0 bytes .../main/res/layout/activity_movie_detail.xml | 2 +- app/src/main/res/menu/menu_edit_product.xml | 5 +- app/src/main/res/menu/menu_grid_movie.xml | 2 +- app/src/main/res/menu/menu_list_product.xml | 8 +- app/src/main/res/menu/menu_main.xml | 11 ++- app/src/main/res/values/colors.xml | 4 + build.gradle | 16 ++- circle.yml | 6 ++ gradle/wrapper/gradle-wrapper.properties | 4 +- install-sdk.sh | 29 ++++++ 56 files changed, 517 insertions(+), 587 deletions(-) delete mode 100644 app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Generics.kt delete mode 100755 app/src/main/res/drawable/tool_bar_background.9.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 circle.yml create mode 100644 install-sdk.sh diff --git a/app/build.gradle b/app/build.gradle index 1757d36..4ecfec8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '0.9.66' + ext.kotlin_version = '1.0.0-beta-4584' repositories { mavenCentral() @@ -7,6 +7,7 @@ buildscript { } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" } } @@ -14,13 +15,13 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { - compileSdkVersion 21 - buildToolsVersion "21.1.1" + compileSdkVersion 23 + buildToolsVersion "23.0.2" defaultConfig { applicationId "com.taskworld.android.restfulandroidkotlin" minSdkVersion 16 - targetSdkVersion 21 + targetSdkVersion 23 versionCode 1 versionName "1.0" } @@ -31,7 +32,7 @@ android { buildTypes { release { - runProguard false + minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } @@ -40,14 +41,19 @@ android { exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' } + + lintOptions { + abortOnError false + checkReleaseBuilds false + } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) //android support lib - compile 'com.android.support:appcompat-v7:21.+' - compile 'com.android.support:recyclerview-v7:21.+' + compile ('com.android.support:appcompat-v7:+'){force = true} + compile ('com.android.support:recyclerview-v7:+'){force = true} //kotlin support compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 940c44f..bb287c9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,7 +32,7 @@ - + diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/action/SignInUIAction.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/action/SignInUIAction.kt index 03383ed..e33eb87 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/action/SignInUIAction.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/action/SignInUIAction.kt @@ -4,7 +4,7 @@ package com.taskworld.android.restfulandroidkotlin.action * Created by Kittinun Vantasin on 11/14/14. */ -trait SignInUIAction { +interface SignInUIAction { fun showProgress() fun hideProgress() fun setUnauthorizedError() diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/event/BaseEvent.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/event/BaseEvent.kt index 87c7ed2..d5f2926 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/event/BaseEvent.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/event/BaseEvent.kt @@ -1,7 +1,5 @@ package com.taskworld.android.restfulandroidkotlin.event -import com.taskworld.android.restfulandroidkotlin.extension.tag - /** * Created by Kittinun Vantasin on 10/18/14. */ diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Activities.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Activities.kt index 955c2f0..ded94be 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Activities.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Activities.kt @@ -8,10 +8,9 @@ import android.widget.Toast * Created by Kittinun Vantasin on 10/17/14. */ -fun Activity.bindView(id: Int) : T { +fun Activity.bindView(id: Int): T { val view = findViewById(id) ?: throw IllegalArgumentException("Given ID $id could not be found in $this!") - [suppress("unchecked_cast")] return view as T } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Fragments.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Fragments.kt index 78087ee..4e330ef 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Fragments.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Fragments.kt @@ -9,5 +9,5 @@ import android.widget.Toast fun Fragment.toast(text: String?): Unit { if (text == null) return - Toast.makeText(getActivity(), text, Toast.LENGTH_LONG).show() + Toast.makeText(activity, text, Toast.LENGTH_LONG).show() } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Generics.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Generics.kt deleted file mode 100644 index 8ae6681..0000000 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Generics.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.taskworld.android.restfulandroidkotlin.extension - -/** - * Created by Kittinun Vantasin on 10/18/14. - */ - -fun T.tag(): String { - return javaClass.getSimpleName() -} - diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Realms.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Realms.kt index 6a330e1..5fd25af 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Realms.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Realms.kt @@ -7,7 +7,7 @@ import io.realm.RealmObject * Created by Kittinun Vantasin on 10/20/14. */ -fun Realm.create(clazz: Class, f: (it: T) -> Unit): T { +fun Realm.create(clazz: Class, f: (it: T) -> Unit): T { beginTransaction() var realmObject = createObject(clazz) f(realmObject) @@ -15,7 +15,7 @@ fun Realm.create(clazz: Class, f: (it: T) -> Unit): T { return realmObject } -fun Realm.update(clazz: Class, key: String, value: String, f: (it: T, change: MutableMap) -> Unit): UpdateResult { +fun Realm.update(clazz: Class, key: String, value: String, f: (it: T, change: MutableMap) -> Unit): UpdateResult { beginTransaction() var realmObject = where(clazz).equalTo(key, value).findFirst() var changeMap: MutableMap = hashMapOf() @@ -24,18 +24,18 @@ fun Realm.update(clazz: Class, key: String, value: String, f return UpdateResult(realmObject, changeMap) } -fun Realm.deleteAll(clazz: Class) { +fun Realm.deleteAll(clazz: Class) { beginTransaction() var results = where(clazz).findAll() results.clear() commitTransaction() } -fun Realm.delete(clazz: Class, key: String, value: String) { +fun Realm.delete(clazz: Class, key: String, value: String) { beginTransaction() var results = where(clazz).equalTo(key, value).findAll() results.clear() commitTransaction() } -data class UpdateResult(val result: T, val changeMap: Map) +data class UpdateResult(val result: T, val changeMap: Map) diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Views.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Views.kt index 43fc19b..69f13f5 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Views.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/extension/Views.kt @@ -6,9 +6,8 @@ import android.view.View * Created by Kittinun Vantasin on 10/18/14. */ -fun View.bindView(id: Int): T { +fun View.bindView(id: Int): T { val view = findViewById(id) ?: throw IllegalArgumentException("Given ID $id could not be found in $this!") - [suppress("unchecked_cast")] return view as T } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/interactor/SignInInteractor.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/interactor/SignInInteractor.kt index c3216f5..c329156 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/interactor/SignInInteractor.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/interactor/SignInInteractor.kt @@ -1,17 +1,17 @@ package com.taskworld.android.restfulandroidkotlin.interactor import com.octo.android.robospice.SpiceManager +import com.taskworld.android.restfulandroidkotlin.network.request.GetNewSessionSpiceRequest import com.taskworld.android.restfulandroidkotlin.network.request.GetTokenSpiceRequest -import com.taskworld.android.restfulandroidkotlin.network.response.EventBusRequestListener import com.taskworld.android.restfulandroidkotlin.network.request.ValidateTokenSpiceRequest -import com.taskworld.android.restfulandroidkotlin.network.request.GetNewSessionSpiceRequest +import com.taskworld.android.restfulandroidkotlin.network.response.EventBusRequestListener import de.greenrobot.event.EventBus /** * Created by Kittinun Vantasin on 11/14/14. */ -trait SignInInteractor { +interface SignInInteractor { fun requestNewToken() fun requestNewSession(requestToken: String) fun validateCredentials(username: String, password: String, requestToken: String) diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/api/TheMovieDBAPI.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/api/TheMovieDBAPI.kt index 2114c36..1e0db17 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/api/TheMovieDBAPI.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/api/TheMovieDBAPI.kt @@ -1,64 +1,60 @@ package com.taskworld.android.restfulandroidkotlin.network.api -import retrofit.http.GET -import retrofit.http.Query -import com.taskworld.android.restfulandroidkotlin.model.Movie -import retrofit.http.POST -import retrofit.http.Body -import retrofit.http.EncodedPath -import com.taskworld.android.restfulandroidkotlin.model.TV import com.taskworld.android.restfulandroidkotlin.model.Cast import com.taskworld.android.restfulandroidkotlin.model.Image +import com.taskworld.android.restfulandroidkotlin.model.Movie +import com.taskworld.android.restfulandroidkotlin.model.TV +import retrofit.http.* /** * Created by Kittinun Vantasin on 10/24/14. */ -trait TheMovieDBAPI { +interface TheMovieDBAPI { - trait MovieAPI { - GET("/{path}") - fun get(EncodedPath("path") path: String): Movie + interface MovieAPI { + @GET("/{path}") + fun get(@EncodedPath("path") path: String): Movie - GET("/{path}/now_playing") - fun getNowPlayingList(EncodedPath("path") path: String): Movie.ResultList + @GET("/{path}/now_playing") + fun getNowPlayingList(@EncodedPath("path") path: String): Movie.ResultList - GET("/{path}/top_rated") - fun getTopRatedList(EncodedPath("path") path: String): Movie.ResultList + @GET("/{path}/top_rated") + fun getTopRatedList(@EncodedPath("path") path: String): Movie.ResultList - GET("/{path}/credits") - fun getCastList(EncodedPath("path") path: String): Cast.CastList + @GET("/{path}/credits") + fun getCastList(@EncodedPath("path") path: String): Cast.CastList - GET("/{path}/images") - fun getPosterImageList(EncodedPath("path") path: String): Image.PosterList + @GET("/{path}/images") + fun getPosterImageList(@EncodedPath("path") path: String): Image.PosterList - POST("/{path}") - fun post(EncodedPath("path") path: String, Body movie: Movie) + @POST("/{path}") + fun post(@EncodedPath("path") path: String, @Body movie: Movie) } - trait Authentication { - GET("/authentication/token/new") + interface Authentication { + @GET("/authentication/token/new") fun getRequestToken(): Map - GET("/authentication/token/validate_with_login") - fun validateToken(Query("username") username: String, Query("password") password: String, Query("request_token") token: String): Map + @GET("/authentication/token/validate_with_login") + fun validateToken(@Query("username") username: String, @Query("password") password: String, @Query("request_token") token: String): Map - GET("/authentication/session/new") - fun getNewSession(Query("request_token") token: String): Map + @GET("/authentication/session/new") + fun getNewSession(@Query("request_token") token: String): Map } - trait TVAPI { - GET("/{path}") - fun get(EncodedPath("path") path: String): TV + interface TVAPI { + @GET("/{path}") + fun get(@EncodedPath("path") path: String): TV - GET("/{path}/airing_today") - fun getAiringTodayList(EncodedPath("path") path: String): TV.ResultList + @GET("/{path}/airing_today") + fun getAiringTodayList(@EncodedPath("path") path: String): TV.ResultList - GET("/{path}/popular") - fun getPopularList(EncodedPath("path") path: String): TV.ResultList + @GET("/{path}/popular") + fun getPopularList(@EncodedPath("path") path: String): TV.ResultList - POST("/{path}") - fun post(EncodedPath("path") path: String, Body TV: TV) + @POST("/{path}") + fun post(@EncodedPath("path") path: String, @Body TV: TV) } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListMovieNowplayingSpiceRequest.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListMovieNowplayingSpiceRequest.kt index 1646193..8d8f9c5 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListMovieNowplayingSpiceRequest.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListMovieNowplayingSpiceRequest.kt @@ -9,9 +9,9 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI */ class GetListMovieNowplayingSpiceRequest(val path: String) : - RetrofitSpiceRequest(javaClass(), javaClass()) { + RetrofitSpiceRequest(Movie.ResultList::class.java, TheMovieDBAPI.MovieAPI::class.java) { override fun loadDataFromNetwork(): Movie.ResultList? { - return getService().getNowPlayingList(path) + return service.getNowPlayingList(path) } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListMovieTopratedSpiceRequest.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListMovieTopratedSpiceRequest.kt index 2987724..d24d2f4 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListMovieTopratedSpiceRequest.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListMovieTopratedSpiceRequest.kt @@ -9,9 +9,9 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI */ class GetListMovieTopratedSpiceRequest(val path: String) : - RetrofitSpiceRequest(javaClass(), javaClass()) { + RetrofitSpiceRequest(Movie.ResultList::class.java, TheMovieDBAPI.MovieAPI::class.java) { override fun loadDataFromNetwork(): Movie.ResultList? { - return getService().getTopRatedList(path) + return service.getTopRatedList(path) } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListTVAiringtodaySpiceRequest.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListTVAiringtodaySpiceRequest.kt index ee1b62d..88d102f 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListTVAiringtodaySpiceRequest.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListTVAiringtodaySpiceRequest.kt @@ -9,10 +9,10 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI */ class GetListTVAiringtodaySpiceRequest(val path: String) : - RetrofitSpiceRequest(javaClass(), javaClass()) { + RetrofitSpiceRequest(TV.ResultList::class.java, TheMovieDBAPI.TVAPI::class.java) { override fun loadDataFromNetwork(): TV.ResultList? { - return getService().getAiringTodayList(path) + return service.getAiringTodayList(path) } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListTVPopularSpiceRequest.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListTVPopularSpiceRequest.kt index 2f5b5f5..1ee748e 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListTVPopularSpiceRequest.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetListTVPopularSpiceRequest.kt @@ -9,10 +9,10 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI */ class GetListTVPopularSpiceRequest(val path: String) : - RetrofitSpiceRequest(javaClass(), javaClass()) { + RetrofitSpiceRequest(TV.ResultList::class.java, TheMovieDBAPI.TVAPI::class.java) { override fun loadDataFromNetwork(): TV.ResultList? { - return getService().getPopularList(path) + return service.getPopularList(path) } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieCreditsSpiceRequest.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieCreditsSpiceRequest.kt index 9b33046..a3ff739 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieCreditsSpiceRequest.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieCreditsSpiceRequest.kt @@ -9,9 +9,9 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI */ class GetMovieCreditsSpiceRequest(val path: String) : - RetrofitSpiceRequest(javaClass(), javaClass()) { + RetrofitSpiceRequest(Cast.CastList::class.java, TheMovieDBAPI.MovieAPI::class.java) { override fun loadDataFromNetwork(): Cast.CastList? { - return getService().getCastList(path) + return service.getCastList(path) } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieImagesSpiceRequest.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieImagesSpiceRequest.kt index 9077067..5b3a19f 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieImagesSpiceRequest.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieImagesSpiceRequest.kt @@ -9,10 +9,10 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI */ class GetMovieImagesSpiceRequest(val path: String) : - RetrofitSpiceRequest(javaClass(), javaClass()) { + RetrofitSpiceRequest(Image.PosterList::class.java, TheMovieDBAPI.MovieAPI::class.java) { override fun loadDataFromNetwork(): Image.PosterList? { - return getService().getPosterImageList(path) + return service.getPosterImageList(path) } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieSpiceRequest.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieSpiceRequest.kt index b7691bf..a0265da 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieSpiceRequest.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetMovieSpiceRequest.kt @@ -1,18 +1,18 @@ package com.taskworld.android.restfulandroidkotlin.network.request -import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI -import com.taskworld.android.restfulandroidkotlin.model.Movie import com.octo.android.robospice.request.retrofit.RetrofitSpiceRequest +import com.taskworld.android.restfulandroidkotlin.model.Movie +import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI /** * Created by Kittinun Vantasin on 10/29/14. */ class GetMovieSpiceRequest(val path: String) : - RetrofitSpiceRequest(javaClass(), javaClass()) { + RetrofitSpiceRequest(Movie::class.java, TheMovieDBAPI.MovieAPI::class.java) { override fun loadDataFromNetwork(): Movie? { - return getService().get(path) + return service.get(path) } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetNewSessionSpiceRequest.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetNewSessionSpiceRequest.kt index b392db1..c3c65a8 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetNewSessionSpiceRequest.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetNewSessionSpiceRequest.kt @@ -1,6 +1,5 @@ package com.taskworld.android.restfulandroidkotlin.network.request -import com.octo.android.robospice.retrofit.RetrofitGsonSpiceService import com.octo.android.robospice.request.retrofit.RetrofitSpiceRequest import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI @@ -8,10 +7,10 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI * Created by VerachadW on 11/4/14. */ class GetNewSessionSpiceRequest(val token: String) : - RetrofitSpiceRequest, TheMovieDBAPI.Authentication>(javaClass>(), javaClass()) { + RetrofitSpiceRequest, TheMovieDBAPI.Authentication>(Map::class.java, TheMovieDBAPI.Authentication::class.java) { override fun loadDataFromNetwork(): Map? { - return getService().getNewSession(token) + return service.getNewSession(token) } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetTokenSpiceRequest.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetTokenSpiceRequest.kt index 6675e78..f30c04a 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetTokenSpiceRequest.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/GetTokenSpiceRequest.kt @@ -1,6 +1,5 @@ package com.taskworld.android.restfulandroidkotlin.network.request -import com.octo.android.robospice.retrofit.RetrofitGsonSpiceService import com.octo.android.robospice.request.retrofit.RetrofitSpiceRequest import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI @@ -11,7 +10,7 @@ class GetTokenSpiceRequest : RetrofitSpiceRequest, TheMovieDBAPI.Authentication>(javaClass>(), javaClass()) { override fun loadDataFromNetwork(): Map? { - return getService().getRequestToken() + return service.getRequestToken() } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/ValidateTokenSpiceRequest.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/ValidateTokenSpiceRequest.kt index b261e40..7b754c5 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/ValidateTokenSpiceRequest.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/request/ValidateTokenSpiceRequest.kt @@ -1,18 +1,17 @@ package com.taskworld.android.restfulandroidkotlin.network.request -import com.octo.android.robospice.retrofit.RetrofitGsonSpiceService import com.octo.android.robospice.request.retrofit.RetrofitSpiceRequest import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI /** * Created by VerachadW on 11/4/14. */ -class ValidateTokenSpiceRequest (val username: String, val password: String, val token: String) : +class ValidateTokenSpiceRequest(val username: String, val password: String, val token: String) : RetrofitSpiceRequest, TheMovieDBAPI.Authentication>(javaClass>(), javaClass()) { override fun loadDataFromNetwork(): Map? { - return getService().validateToken(username, password, token) + return service.validateToken(username, password, token) } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/response/EventBusRequestListener.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/response/EventBusRequestListener.kt index 04bb058..ad2363f 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/response/EventBusRequestListener.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/response/EventBusRequestListener.kt @@ -1,21 +1,21 @@ package com.taskworld.android.restfulandroidkotlin.network.response -import com.octo.android.robospice.request.listener.RequestListener import com.octo.android.robospice.persistence.exception.SpiceException +import com.octo.android.robospice.request.listener.RequestListener import de.greenrobot.event.EventBus /** * Created by Kittinun Vantasin on 10/24/14. */ -class EventBusRequestListener private (val bus: EventBus) : RequestListener { +class EventBusRequestListener(val bus: EventBus) : RequestListener { - class object { - fun newInstance(): EventBusRequestListener { + companion object { + fun newInstance(): EventBusRequestListener { return EventBusRequestListener(EventBus.getDefault()) } - fun newInstance(bus: EventBus): EventBusRequestListener { + fun newInstance(bus: EventBus): EventBusRequestListener { return EventBusRequestListener(bus) } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/service/TheMovieAPISpiceService.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/service/TheMovieAPISpiceService.kt index ef82062..9fbef22 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/service/TheMovieAPISpiceService.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/network/service/TheMovieAPISpiceService.kt @@ -1,15 +1,15 @@ package com.taskworld.android.restfulandroidkotlin.network.service +import com.google.gson.GsonBuilder import com.octo.android.robospice.retrofit.RetrofitGsonSpiceService -import retrofit.RestAdapter import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI +import retrofit.RestAdapter import retrofit.converter.Converter import retrofit.converter.GsonConverter -import com.google.gson.GsonBuilder class TheMovieAPISpiceService : RetrofitGsonSpiceService() { - class object { + companion object { val BASE_URL = "http://api.themoviedb.org/3" @@ -24,13 +24,13 @@ class TheMovieAPISpiceService : RetrofitGsonSpiceService() { override fun createRestAdapterBuilder(): RestAdapter.Builder? { var builder = super.createRestAdapterBuilder() builder.setRequestInterceptor { requestInterceptor -> requestInterceptor.addQueryParam(API_KEY, API_VALUE) } - .setLogLevel(RestAdapter.LogLevel.FULL) + .setLogLevel(RestAdapter.LogLevel.FULL) return builder } override fun onCreate() { super.onCreate() - addRetrofitInterface(javaClass()) + addRetrofitInterface(TheMovieDBAPI::class.java) } override fun createConverter(): Converter? { diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/presenter/Presenter.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/presenter/Presenter.kt index 96e9066..3623ea3 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/presenter/Presenter.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/presenter/Presenter.kt @@ -4,13 +4,11 @@ package com.taskworld.android.restfulandroidkotlin.presenter * Created by Kittinun Vantasin on 11/17/14. */ -trait Presenter { +interface Presenter { fun onResume() { - } fun onPause() { - } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/presenter/SignInPresenter.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/presenter/SignInPresenter.kt index 53e8ddb..b78921e 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/presenter/SignInPresenter.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/presenter/SignInPresenter.kt @@ -1,19 +1,19 @@ package com.taskworld.android.restfulandroidkotlin.presenter -import com.taskworld.android.restfulandroidkotlin.action.SignInUIAction import com.octo.android.robospice.SpiceManager -import com.taskworld.android.restfulandroidkotlin.interactor.SignInInteractorImpl +import com.octo.android.robospice.persistence.exception.SpiceException +import com.taskworld.android.restfulandroidkotlin.action.SignInUIAction import com.taskworld.android.restfulandroidkotlin.interactor.SignInInteractor +import com.taskworld.android.restfulandroidkotlin.interactor.SignInInteractorImpl import de.greenrobot.event.EventBus -import com.octo.android.robospice.persistence.exception.SpiceException -import kotlin.properties.Delegates import retrofit.RetrofitError +import kotlin.properties.Delegates /** * Created by Kittinun Vantasin on 11/14/14. */ -trait SignInPresenter : Presenter { +interface SignInPresenter : Presenter { fun logInWithCredentials(username: String, password: String) } @@ -24,7 +24,7 @@ class SignInPresenterImpl(val mAction: SignInUIAction, val mSpiceManager: SpiceM var mInteractor: SignInInteractor - { + init { mInteractor = SignInInteractorImpl(mSpiceManager, mBus) } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/resource/client/ResourceClient.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/resource/client/ResourceClient.kt index 3a29f5f..73cb83b 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/resource/client/ResourceClient.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/resource/client/ResourceClient.kt @@ -1,16 +1,16 @@ package com.taskworld.android.restfulandroidkotlin.resource.client import com.octo.android.robospice.SpiceManager +import com.octo.android.robospice.request.SpiceRequest +import com.taskworld.android.restfulandroidkotlin.extension.toStartingLetterUppercase +import com.taskworld.android.restfulandroidkotlin.network.response.EventBusRequestListener import com.taskworld.android.restfulandroidkotlin.resource.router.ResourceRouter +import com.taskworld.android.restfulandroidkotlin.resource.router.ResourceRouterImpl +import de.greenrobot.event.EventBus import io.realm.Realm import io.realm.RealmObject -import de.greenrobot.event.EventBus -import com.taskworld.android.restfulandroidkotlin.network.response.EventBusRequestListener -import com.taskworld.android.restfulandroidkotlin.extension.toStartingLetterUppercase -import com.octo.android.robospice.request.SpiceRequest -import io.realm.RealmResults import io.realm.RealmQuery -import com.taskworld.android.restfulandroidkotlin.resource.router.ResourceRouterImpl +import io.realm.RealmResults class ResourceClient(builder: ResourceClient.Builder) { @@ -20,47 +20,47 @@ class ResourceClient(builder: ResourceClient.Builder) { private var mBus: EventBus //initialize - { + init { mSpiceManager = builder.manager mResourceRouter = builder.router ?: ResourceRouterImpl.newInstance() mRealm = builder.realm mBus = builder.bus ?: EventBus.getDefault() } - class object { + companion object { private val REQUEST_PACKAGE = "com.taskworld.android.restfulandroidkotlin.network.request" private val REQUEST_CLASS_SUFFIX = "SpiceRequest" + } - inner class Builder { + class Builder { - var manager: SpiceManager? = null - var router: ResourceRouter? = null - var realm: Realm? = null - var bus: EventBus? = null + var manager: SpiceManager? = null + var router: ResourceRouter? = null + var realm: Realm? = null + var bus: EventBus? = null - fun setSpiceManager(manager: SpiceManager): Builder { - this.manager = manager - return this - } + fun setSpiceManager(manager: SpiceManager): Builder { + this.manager = manager + return this + } - fun setRouter(router: ResourceRouter): Builder { - this.router = router - return this - } + fun setRouter(router: ResourceRouter): Builder { + this.router = router + return this + } - fun setRealm(realm: Realm): Builder { - this.realm = realm - return this - } + fun setRealm(realm: Realm): Builder { + this.realm = realm + return this + } - fun setEventBus(bus: EventBus): Builder { - this.bus = bus - return this - } + fun setEventBus(bus: EventBus): Builder { + this.bus = bus + return this + } - fun build(): ResourceClient { - return ResourceClient(this) - } + fun build(): ResourceClient { + return ResourceClient(this) } } @@ -86,7 +86,7 @@ class ResourceClient(builder: ResourceClient.Builder) { // TODO: Call Update API } - fun delete(clazz: Class, conditionMap: Map?) { + fun delete(clazz: Class, conditionMap: Map?) { mRealm!!.beginTransaction() var results = query(clazz, conditionMap) @@ -100,7 +100,7 @@ class ResourceClient(builder: ResourceClient.Builder) { // TODO: Call Delete API } - private fun query(clazz: Class, conditionMap: Map?): RealmResults{ + private fun query(clazz: Class, conditionMap: Map?): RealmResults { var query: RealmQuery = mRealm!!.where(clazz) if (conditionMap != null) { for ((key, value) in conditionMap) { @@ -114,11 +114,11 @@ class ResourceClient(builder: ResourceClient.Builder) { return results } - fun findAll(clazz: Class) { + fun findAll(clazz: Class) { findAll(clazz, null) } - fun findAll(clazz: Class, args: Map?) { + fun findAll(clazz: Class, args: Map?) { //db call val results = query(clazz, args) EventBus.getDefault().post(results) @@ -163,14 +163,12 @@ class ResourceClient(builder: ResourceClient.Builder) { "list" -> extraPath = mResourceRouter.extraPathForList ?: "" } - val className = listOf(httpVerb.toStartingLetterUppercase(), - action.toStartingLetterUppercase(), - resourceName.toStartingLetterUppercase(), - extraPath.replace("_", "").toStartingLetterUppercase(), - REQUEST_CLASS_SUFFIX).join("") - val constructorOfClassName = Class.forName(REQUEST_PACKAGE + "." + className).getConstructor(javaClass()) + val className = httpVerb.toStartingLetterUppercase() + + action.toStartingLetterUppercase() + + resourceName.toStartingLetterUppercase() + + extraPath.replace("_", "").toStartingLetterUppercase() + REQUEST_CLASS_SUFFIX + val constructorOfClassName = Class.forName(REQUEST_PACKAGE + "." + className).getConstructor(String::class.java) - [suppress("unchecked_cast")] val requestInstance = constructorOfClassName.newInstance(requestPath) as SpiceRequest mSpiceManager?.execute(requestInstance, EventBusRequestListener.newInstance(mBus)) } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/resource/router/ResourceRouter.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/resource/router/ResourceRouter.kt index 21108f3..5971840 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/resource/router/ResourceRouter.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/resource/router/ResourceRouter.kt @@ -1,13 +1,12 @@ package com.taskworld.android.restfulandroidkotlin.resource.router import io.realm.RealmObject -import com.taskworld.android.restfulandroidkotlin.extension.plus /** * Created by Kittinun Vantasin on 10/28/14. */ -trait ResourceRouter { +interface ResourceRouter { val extraPathForList: String? val extraPathForSingle: String? @@ -17,7 +16,7 @@ trait ResourceRouter { } fun getPathForAction(action: String, clazz: Class, args: Map?): String? { - if (action.equalsIgnoreCase("list")) { + if (action.equals("list")) { return getPathForListOnResource(clazz, args) } else if (action.isEmpty()) { return getPathForSingleOnResource(clazz, args) @@ -29,9 +28,9 @@ trait ResourceRouter { fun getPathForSingleOnResource(clazz: Class, args: Map?): String } -class ResourceRouterImpl private (override val extraPathForList: String?, override val extraPathForSingle: String?) : ResourceRouter { +class ResourceRouterImpl(override val extraPathForList: String?, override val extraPathForSingle: String?) : ResourceRouter { - class object { + companion object { fun newInstance() = ResourceRouterImpl(null, null) fun newInstance(extraPath: String?) = ResourceRouterImpl(extraPath, null) fun newInstance(extraPathForList: String?, extraPathForSingle: String?) = ResourceRouterImpl(extraPathForList, extraPathForSingle) @@ -47,6 +46,6 @@ class ResourceRouterImpl private (override val extraPathForList: String?, overri val builder = StringBuilder(clazz.getSimpleName().toLowerCase()) - return (builder + "/" + idValue.toString()).toString() + return (builder.toString() + "/" + idValue.toString()).toString() } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/util/CircularTransformation.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/util/CircularTransformation.kt index fac716d..061a1e3 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/util/CircularTransformation.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/util/CircularTransformation.kt @@ -1,13 +1,8 @@ package com.taskworld.android.restfulandroidkotlin.util -import com.squareup.picasso.Transformation -import android.graphics.Bitmap -import com.taskworld.android.restfulandroidkotlin.extension.tag -import android.graphics.Canvas +import android.graphics.* import android.graphics.Bitmap.Config -import android.graphics.Shader -import android.graphics.BitmapShader -import android.graphics.Paint +import com.squareup.picasso.Transformation /** * Created by Kittinun Vantasin on 11/18/14. @@ -33,6 +28,6 @@ class CircularTransformation : Transformation { } override fun key(): String? { - return tag() + return "" } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/util/Preference.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/util/Preference.kt index bdab166..9fb0cb2 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/util/Preference.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/util/Preference.kt @@ -1,15 +1,15 @@ package com.taskworld.android.restfulandroidkotlin.util -import kotlin.properties.Delegates -import android.content.SharedPreferences import android.content.Context +import android.content.SharedPreferences import kotlin.properties.ReadWriteProperty +import kotlin.reflect.KProperty object Preference { private val NAME = "movie" - private var mSharedPreferences: SharedPreferences? = null + private var mSharedPreferences: SharedPreferences? = null // var username: String? by PreferenceDelegate() @@ -20,36 +20,35 @@ object Preference { return this } - inner class PreferenceDelegate() : ReadWriteProperty { - private var value: T = null + class PreferenceDelegate() : ReadWriteProperty { + private var value = "" as T - override fun get(thisRef: Any?, desc: PropertyMetadata): T { + override fun getValue(thisRef: Any?, property: KProperty<*>): T { if (mSharedPreferences == null) throw NullPointerException("Preference.with() must be called before acessing properties") - [suppress("unchecked_cast")] when (value) { - is String -> value = mSharedPreferences!!.getString(desc.name, null) as T - is Float -> value = mSharedPreferences!!.getFloat(desc.name, 0.0f) as T - is Int -> value = mSharedPreferences!!.getInt(desc.name, 0) as T - is Boolean -> value = mSharedPreferences!!.getBoolean(desc.name, false) as T - is Long -> value = mSharedPreferences!!.getLong(desc.name, 0L) as T - else -> throw IllegalArgumentException("${desc.name} variable type is not supported yet!!") + is String -> value = mSharedPreferences!!.getString(property.name, null) as T + is Float -> value = mSharedPreferences!!.getFloat(property.name, 0.0f) as T + is Int -> value = mSharedPreferences!!.getInt(property.name, 0) as T + is Boolean -> value = mSharedPreferences!!.getBoolean(property.name, false) as T + is Long -> value = mSharedPreferences!!.getLong(property.name, 0L) as T + else -> throw IllegalArgumentException("${property.name} variable type is not supported yet!!") } return value } - override fun set(thisRef: Any?, desc: PropertyMetadata, value: T) { + override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { if (mSharedPreferences == null) throw NullPointerException("Preference.with() must be called before acessing properties") val editor = mSharedPreferences!!.edit() when (value) { - is String -> editor.putString(desc.name, value) - is Float -> editor.putFloat(desc.name, value) - is Int -> editor.putInt(desc.name, value) - is Boolean -> editor.putBoolean(desc.name, value) - is Long -> editor.putLong(desc.name, value) + is String -> editor.putString(property.name, value) + is Float -> editor.putFloat(property.name, value) + is Int -> editor.putInt(property.name, value) + is Boolean -> editor.putBoolean(property.name, value) + is Long -> editor.putLong(property.name, value) else -> throw IllegalArgumentException(" variable type is not supported yet!!") } this.value = value diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/BaseActivity.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/BaseActivity.kt index cf04b73..7e17ff1 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/BaseActivity.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/BaseActivity.kt @@ -1,32 +1,30 @@ package com.taskworld.android.restfulandroidkotlin.view.activity -import android.os.Bundle import android.content.Context import android.content.Intent -import de.greenrobot.event.EventBus -import com.taskworld.android.restfulandroidkotlin.event.BaseEvent -import android.support.v7.app.ActionBarActivity -import android.util.Log -import com.taskworld.android.restfulandroidkotlin.extension.tag +import android.os.Bundle +import android.support.v7.app.AppCompatActivity import android.view.View +import com.taskworld.android.restfulandroidkotlin.event.BaseEvent +import de.greenrobot.event.EventBus /** * Created by Kittinun Vantasin on 10/17/14. */ -abstract class BaseActivity : ActionBarActivity() { +abstract class BaseActivity : AppCompatActivity() { abstract val mContentLayoutResourceId: Int //static instantiate - class object { + companion object { public fun newIntent(context: Context): Intent { return Intent(context, javaClass()) } } override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) + super.onCreate(savedInstanceState) if (mContentLayoutResourceId != 0) { setContentView(mContentLayoutResourceId) @@ -44,7 +42,6 @@ abstract class BaseActivity : ActionBarActivity() { } setUp() - Log.v(tag(), tag() + "::onCreate()") } open fun createContentView(): View { @@ -52,20 +49,17 @@ abstract class BaseActivity : ActionBarActivity() { } override fun onResume() { - super.onResume() + super.onResume() EventBus.getDefault().register(this) - Log.v(tag(), tag() + "::onResume()") } override fun onPause() { - super.onPause() + super.onPause() EventBus.getDefault().unregister(this) - Log.v(tag(), tag() + "::onPause()") } override fun onDestroy() { - Log.v(tag(), tag() + "::onDestory()") - super.onDestroy() + super.onDestroy() } open fun handleSavedInstanceState(savedInstanceState: Bundle) { diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/BaseSpiceActivity.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/BaseSpiceActivity.kt index 97439a8..6abe2e8 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/BaseSpiceActivity.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/BaseSpiceActivity.kt @@ -9,7 +9,7 @@ import com.taskworld.android.restfulandroidkotlin.network.service.TheMovieAPISpi abstract class BaseSpiceActivity : BaseActivity() { - val mSpiceManager: SpiceManager = SpiceManager(javaClass()) + val mSpiceManager: SpiceManager = SpiceManager(TheMovieAPISpiceService::class.java) override fun onStart() { super.onStart() diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MainActivity.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MainActivity.kt index f9c437f..2055965 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MainActivity.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MainActivity.kt @@ -1,41 +1,29 @@ package com.taskworld.android.restfulandroidkotlin.view.activity +import android.content.Context +import android.content.Intent import com.taskworld.android.restfulandroidkotlin.R -import kotlin.properties.Delegates -import com.taskworld.android.restfulandroidkotlin.extension.bindView -import android.support.v4.widget.DrawerLayout -import android.support.v7.widget.Toolbar -import com.taskworld.android.restfulandroidkotlin.view.fragment.BaseDrawerFragment import com.taskworld.android.restfulandroidkotlin.event.OnDrawerToggledEvent -import com.taskworld.android.restfulandroidkotlin.view.fragment.BaseDrawerFragment.Direction -import android.widget.TextView import com.taskworld.android.restfulandroidkotlin.event.OnToolbarTitleChangedEvent +import com.taskworld.android.restfulandroidkotlin.view.fragment.BaseDrawerFragment +import com.taskworld.android.restfulandroidkotlin.view.fragment.BaseDrawerFragment.Direction import com.taskworld.android.restfulandroidkotlin.view.fragment.MovieFragment -import android.content.Context -import android.content.Intent + +import kotlinx.android.synthetic.main.activity_main.* class MainActivity : BaseSpiceActivity() { override val mContentLayoutResourceId = R.layout.activity_main - //widgets - val tvBarTitle by Delegates.lazy { bindView(R.id.tvBarTitle) } - - val fgLeftNavigationDrawer by Delegates.lazy { - getSupportFragmentManager().findFragmentById(R.id.fgLeftNavigationDrawer) as BaseDrawerFragment - } - - val dlMain by Delegates.lazy { bindView(R.id.dlMain) } - val tbMain by Delegates.lazy { bindView(R.id.tbMain) } - - class object { + companion object { fun newIntent(context: Context): Intent { - return Intent(context, javaClass()) + return Intent(context, MainActivity::class.java) } } override fun setUp() { setSupportActionBar(tbMain) + val fgLeftNavigationDrawer = supportFragmentManager.findFragmentById(R.id.fgLeftNavigationDrawer) as BaseDrawerFragment fgLeftNavigationDrawer.setUpAsLeftDrawer(dlMain, tbMain) val popularCategory = "popular" @@ -46,8 +34,9 @@ class MainActivity : BaseSpiceActivity() { } fun onEvent(event: OnDrawerToggledEvent) { - when (event.direction) { - Direction.LEFT -> fgLeftNavigationDrawer.toggleDrawer() + val fgLeftNavigationDrawer = supportFragmentManager.findFragmentById(R.id.fgLeftNavigationDrawer) as BaseDrawerFragment + if (event.direction == Direction.LEFT) { + fgLeftNavigationDrawer.toggleDrawer() } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MovieDetailActivity.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MovieDetailActivity.kt index c83771b..70fc5d8 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MovieDetailActivity.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MovieDetailActivity.kt @@ -1,30 +1,30 @@ package com.taskworld.android.restfulandroidkotlin.view.activity -import kotlin.properties.Delegates -import android.support.v7.widget.RecyclerView -import android.support.v7.widget.LinearLayoutManager import android.content.Context import android.content.Intent -import com.taskworld.android.restfulandroidkotlin.extension.bindView -import com.taskworld.android.restfulandroidkotlin.model.Movie +import android.os.Bundle +import android.support.v4.view.PagerAdapter +import android.support.v4.view.ViewPager +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater import android.view.View +import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams import android.widget.ImageView import android.widget.TextView -import com.taskworld.android.restfulandroidkotlin.model.Cast -import com.taskworld.android.restfulandroidkotlin.adapter.ParallaxRecyclerAdapter -import android.os.Bundle import com.squareup.picasso.Picasso -import android.support.v7.widget.Toolbar import com.taskworld.android.restfulandroidkotlin.R -import android.view.ViewGroup -import android.view.LayoutInflater -import android.support.v4.view.ViewPager -import android.support.v4.view.PagerAdapter +import com.taskworld.android.restfulandroidkotlin.adapter.ParallaxRecyclerAdapter +import com.taskworld.android.restfulandroidkotlin.extension.bindView +import com.taskworld.android.restfulandroidkotlin.model.Cast import com.taskworld.android.restfulandroidkotlin.model.Image -import android.view.ViewGroup.LayoutParams +import com.taskworld.android.restfulandroidkotlin.model.Movie import com.taskworld.android.restfulandroidkotlin.resource.client.ResourceClient import com.taskworld.android.restfulandroidkotlin.resource.router.ResourceRouterImpl import com.taskworld.android.restfulandroidkotlin.util.CircularTransformation +import kotlinx.android.synthetic.main.activity_movie_detail.* +import kotlin.properties.Delegates /** * Created by Kittinun Vantasin on 11/11/14. @@ -34,21 +34,13 @@ class MovieDetailActivity : BaseSpiceActivity() { override val mContentLayoutResourceId: Int = R.layout.activity_movie_detail - //widgets //header var tvMovieOverview: TextView by Delegates.notNull() var vpMovieCover: ViewPager by Delegates.notNull() - //toolbar - val tbMovieDetail by Delegates.lazy { bindView(R.id.tbMovieDetail) } - val tvBarTitle by Delegates.lazy { bindView(R.id.tvBarTitle) } - - //list - val rvMovieCast by Delegates.lazy { bindView(R.id.rvMovieCast) } - //adapter - val mMovieCastAdapter by Delegates.lazy { ParallaxRecyclerAdapter(listOf()) } - val mMovieCoverAdapter by Delegates.lazy { MovieCoverImageAdapter() } + val mMovieCastAdapter = ParallaxRecyclerAdapter(listOf()) + val mMovieCoverAdapter = MovieCoverImageAdapter() //data var mMovieId = 0 @@ -59,11 +51,11 @@ class MovieDetailActivity : BaseSpiceActivity() { mMovieCoverAdapter.data = newCoverImages }) - class object { + companion object { val ARG_MOVIE_ID = "movie_id" public fun newIntent(context: Context, id: Int): Intent { - val intent = Intent(context, javaClass()) + val intent = Intent(context, MovieDetailActivity::class.java) intent.putExtra(ARG_MOVIE_ID, id) return intent } @@ -79,48 +71,48 @@ class MovieDetailActivity : BaseSpiceActivity() { mMovieCastAdapter.implementRecyclerAdapterMethods(MoveCastParallaxRecyclerAdapter()) mMovieCastAdapter.setParallaxHeader(createHeaderView(), rvMovieCast) mMovieCastAdapter.setOnParallaxScroll { percentage, offset, parallaxView -> - val d = tbMovieDetail.getBackground() - d.setAlpha(Math.round((percentage) * 255)) - tbMovieDetail.setBackground(d) + val d = tbMovieDetail.background + d.alpha = Math.round((percentage) * 255) + tbMovieDetail.background = d } - rvMovieCast.setLayoutManager(createLayoutManager()) - rvMovieCast.setAdapter(mMovieCastAdapter) + rvMovieCast.layoutManager = createLayoutManager() + rvMovieCast.adapter = mMovieCastAdapter var client = ResourceClient.Builder() .setRouter(ResourceRouterImpl.newInstance(null, "credits")) .setSpiceManager(getServiceSpiceManager()).build() - client.find(javaClass(), mMovieId.toString()) + client.find(Movie::class.java, mMovieId.toString()) client = ResourceClient.Builder() .setRouter(ResourceRouterImpl.newInstance()) .setSpiceManager(getServiceSpiceManager()).build() - client.find(javaClass(), mMovieId.toString()) + client.find(Movie::class.java, mMovieId.toString()) client = ResourceClient.Builder() .setRouter(ResourceRouterImpl.newInstance(null, "images")) .setSpiceManager(getServiceSpiceManager()).build() - client.find(javaClass(), mMovieId.toString()) + client.find(Movie::class.java, mMovieId.toString()) } fun onEvent(movie: Movie) { - tvBarTitle.setText(movie.getTitle()) - tvMovieOverview.setText(movie.getOverview()) + tvBarTitle.text = movie.title + tvMovieOverview.text = movie.overview } fun onEvent(casts: Cast.CastList) { - mCasts = casts.getCasts() + mCasts = casts.casts } fun onEvent(images: Image.PosterList) { - mCoverImages = images.getResults() + mCoverImages = images.results } fun createHeaderView(): View { - val headerView = getLayoutInflater().inflate(R.layout.list_header_movie_detail, null) + val headerView = layoutInflater.inflate(R.layout.list_header_movie_detail, null) tvMovieOverview = headerView.bindView(R.id.tvMovieOverview) vpMovieCover = headerView.bindView(R.id.vpMovieCover) - vpMovieCover.setAdapter(mMovieCoverAdapter) + vpMovieCover.adapter = mMovieCoverAdapter return headerView } @@ -132,7 +124,7 @@ class MovieDetailActivity : BaseSpiceActivity() { var data = listOf() set (value) { - $data = value + data = value notifyDataSetChanged() } @@ -141,14 +133,14 @@ class MovieDetailActivity : BaseSpiceActivity() { } override fun instantiateItem(container: ViewGroup, position: Int): Any? { - val viewPagerItem = LayoutInflater.from(container.getContext()).inflate(R.layout.view_pager_item_movie_cover, container, false) + val viewPagerItem = LayoutInflater.from(container.context).inflate(R.layout.view_pager_item_movie_cover, container, false) val ivMovieCover = viewPagerItem.bindView(R.id.ivMovieCover) val tvMovieCoverVoteCount = viewPagerItem.bindView(R.id.tvMovieCoverVoteCount) //bind views val image = mCoverImages[position] - Picasso.with(container.getContext()).load("https://image.tmdb.org/t/p/w500/" + image.getFilePath()).into(ivMovieCover) - tvMovieCoverVoteCount.setText(image.getVoteCount().toString()) + Picasso.with(container.context).load("https://image.tmdb.org/t/p/w500/" + image.filePath).into(ivMovieCover) + tvMovieCoverVoteCount.text = image.voteCount.toString() container.addView(viewPagerItem, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT) return viewPagerItem @@ -174,7 +166,7 @@ class MovieDetailActivity : BaseSpiceActivity() { var mContext: Context by Delegates.notNull() override fun onCreateViewHolder(container: ViewGroup?, i: Int): RecyclerView.ViewHolder? { - mContext = container!!.getContext() + mContext = container!!.context val view = LayoutInflater.from(mContext).inflate(R.layout.recycle_view_item_movie_cast, container, false) return MovieCastViewHolder(view) } @@ -183,12 +175,12 @@ class MovieDetailActivity : BaseSpiceActivity() { val cast = mCasts[position] val holder = viewHolder as MovieCastViewHolder - Picasso.with(mContext).load("https://image.tmdb.org/t/p/w150/" + cast.getProfilePath()) + Picasso.with(mContext).load("https://image.tmdb.org/t/p/w150/" + cast.profilePath) .transform(CircularTransformation()) //.placeholder(R.drawable.ic_launcher) .into(holder.ivCast) - holder.tvCastName.setText(cast.getName()) - holder.tvCastCharacter.setText("as " + cast.getCharacter()) + holder.tvCastName.text = cast.name + holder.tvCastCharacter.text = "as " + cast.character } override fun getItemCount(): Int { diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MovieListActivity.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MovieListActivity.kt index 0461e5f..3202c96 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MovieListActivity.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/MovieListActivity.kt @@ -1,22 +1,20 @@ package com.taskworld.android.restfulandroidkotlin.view.activity -import com.taskworld.android.restfulandroidkotlin.R -import kotlin.properties.Delegates import android.content.Context import android.content.Intent -import com.taskworld.android.restfulandroidkotlin.extension.bindView -import android.widget.ListView -import android.widget.ArrayAdapter -import com.taskworld.android.restfulandroidkotlin.model.Movie -import com.taskworld.android.restfulandroidkotlin.extension.tag -import android.util.Log import android.view.View import android.view.ViewGroup +import android.widget.ArrayAdapter import android.widget.TextView +import com.taskworld.android.restfulandroidkotlin.R +import com.taskworld.android.restfulandroidkotlin.extension.bindView +import com.taskworld.android.restfulandroidkotlin.extension.toast +import com.taskworld.android.restfulandroidkotlin.model.Movie import com.taskworld.android.restfulandroidkotlin.resource.client.ResourceClient import com.taskworld.android.restfulandroidkotlin.resource.router.ResourceRouterImpl -import com.taskworld.android.restfulandroidkotlin.extension.toast import io.realm.Realm +import kotlinx.android.synthetic.main.activity_movie_list.* +import kotlin.properties.Delegates /** * Created by Kittinun Vantasin on 10/28/14. @@ -26,62 +24,58 @@ class MovieListActivity : BaseSpiceActivity() { override val mContentLayoutResourceId: Int = R.layout.activity_movie_list; - //widget - val lvMovie by Delegates.lazy { bindView(R.id.lvMovie) } - //adapter - val mMovieAdapter by Delegates.lazy { MovieAdapter() } + val mMovieAdapter = MovieAdapter() //data var mItems by Delegates.observable(arrayListOf(), { meta, oldItems, newItems -> - Log.i(tag(), "${oldItems.size} -> ${newItems.size}") mMovieAdapter.clear() mMovieAdapter.addAll(newItems) mMovieAdapter.notifyDataSetChanged() }) - val mRealm by Delegates.lazy { Realm.getInstance(this) } + val mRealm = Realm.getInstance(this) - class object { + companion object { public fun newIntent(context: Context): Intent { - return Intent(context, javaClass()) + return Intent(context, MovieListActivity::class.java) } } override fun setUp() { mItems.clear() - lvMovie.setAdapter(mMovieAdapter) + lvMovie.adapter = mMovieAdapter val client = ResourceClient.Builder() .setRealm(mRealm) .setRouter(ResourceRouterImpl.newInstance("now_playing")) .setSpiceManager(getServiceSpiceManager()).build() - client.findAll(javaClass()) + client.findAll(Movie::class.java) } fun onEvent(items: Movie.ResultList) { - mItems = items.getResults().toArrayList() + mItems = items.results.toArrayList() val client = ResourceClient.Builder() .setRealm(mRealm) .setRouter(ResourceRouterImpl.newInstance()) .setSpiceManager(getServiceSpiceManager()).build() - client.find(javaClass(), "180299") + client.find(Movie::class.java, "180299") } fun onEvent(item: Movie) { - toast(item.getTitle()) + toast(item.title) } inner class MovieAdapter : ArrayAdapter(this, android.R.layout.simple_expandable_list_item_2, android.R.id.text1, mItems) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? { - val view = super.getView(position, convertView, parent) + val view = super.getView(position, convertView, parent) val tv1 = view.bindView(android.R.id.text1) val tv2 = view.bindView(android.R.id.text2) val movie = getItem(position) - tv1.setText(movie.getTitle()) - tv2.setText(movie.getPopularity().toString()) + tv1.text = movie.title + tv2.text = movie.popularity.toString() return view; } } diff --git a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/ProductEditActivity.kt b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/ProductEditActivity.kt index 1b4221d..d27d3bc 100644 --- a/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/ProductEditActivity.kt +++ b/app/src/main/kotlin/com/taskworld/android/restfulandroidkotlin/view/activity/ProductEditActivity.kt @@ -1,18 +1,15 @@ package com.taskworld.android.restfulandroidkotlin.view.activity -import com.taskworld.android.restfulandroidkotlin.R -import android.view.Menu -import android.view.MenuItem -import android.content.Intent +import android.app.Activity import android.content.Context +import android.content.Intent import android.os.Bundle -import io.realm.Realm -import kotlin.properties.Delegates -import com.taskworld.android.restfulandroidkotlin.extension.bindView -import android.widget.EditText -import android.widget.Button -import android.app.Activity +import android.view.Menu +import android.view.MenuItem +import com.taskworld.android.restfulandroidkotlin.R import com.taskworld.android.restfulandroidkotlin.model.Product +import io.realm.Realm +import kotlinx.android.synthetic.main.activity_product_edit.* /** * Created by Kittinun Vantasin on 10/20/14. @@ -22,24 +19,19 @@ class ProductEditActivity : BaseActivity() { override val mContentLayoutResourceId = R.layout.activity_product_edit - //widgets - val etName by Delegates.lazy { bindView(R.id.etName) } - val etPrice by Delegates.lazy { bindView(R.id.etPrice) } - val btDelete by Delegates.lazy { bindView