Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Updating app to the last version of Kotlin language + fixing errors #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
buildscript {
ext.kotlin_version = '0.9.66'
ext.kotlin_version = '1.0.0-beta-4584'

repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
}
}

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"
}
Expand All @@ -31,7 +32,7 @@ android {

buildTypes {
release {
runProguard false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<activity android:name=".view.activity.MovieListActivity"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />

<activity android:name=".view.activity.MovieDetailActivity"
android:theme="@style/AppTheme.AppCompat.Translucent"
android:parentActivityName=".view.activity.MainActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ public String getFilePath() {
public int getVoteCount() {
return voteCount;
}

public void setVoteCount(int voteCount) {
this.voteCount = voteCount;
}

public void setFilePath(String filePath) {
this.filePath = filePath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import android.widget.Toast
* Created by Kittinun Vantasin on 10/17/14.
*/

fun <T: View> Activity.bindView(id: Int) : T {
fun <T : View> 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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import io.realm.RealmObject
* Created by Kittinun Vantasin on 10/20/14.
*/

fun <T: RealmObject> Realm.create(clazz: Class<T>, f: (it: T) -> Unit): T {
fun <T : RealmObject> Realm.create(clazz: Class<T>, f: (it: T) -> Unit): T {
beginTransaction()
var realmObject = createObject(clazz)
f(realmObject)
commitTransaction()
return realmObject
}

fun <T: RealmObject> Realm.update(clazz: Class<T>, key: String, value: String, f: (it: T, change: MutableMap<String, String>) -> Unit): UpdateResult<T> {
fun <T : RealmObject> Realm.update(clazz: Class<T>, key: String, value: String, f: (it: T, change: MutableMap<String, String>) -> Unit): UpdateResult<T> {
beginTransaction()
var realmObject = where(clazz).equalTo(key, value).findFirst()
var changeMap: MutableMap<String, String> = hashMapOf()
Expand All @@ -24,18 +24,18 @@ fun <T: RealmObject> Realm.update(clazz: Class<T>, key: String, value: String, f
return UpdateResult(realmObject, changeMap)
}

fun <T: RealmObject> Realm.deleteAll(clazz: Class<T>) {
fun <T : RealmObject> Realm.deleteAll(clazz: Class<T>) {
beginTransaction()
var results = where(clazz).findAll()
results.clear()
commitTransaction()
}

fun <T: RealmObject> Realm.delete(clazz: Class<T>, key: String, value: String) {
fun <T : RealmObject> Realm.delete(clazz: Class<T>, key: String, value: String) {
beginTransaction()
var results = where(clazz).equalTo(key, value).findAll()
results.clear()
commitTransaction()
}

data class UpdateResult<T: RealmObject>(val result: T, val changeMap: Map<String, String>)
data class UpdateResult<T : RealmObject>(val result: T, val changeMap: Map<String, String>)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package com.taskworld.android.restfulandroidkotlin.extension
fun String.toStartingLetterUppercase(): String {
if (this.isEmpty()) return this

var firstChar = this.charAt(0)
var firstChar = this.get(0)
val valueOfFirstChar = firstChar.toInt()

if (valueOfFirstChar in 97..122) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import android.view.View
* Created by Kittinun Vantasin on 10/18/14.
*/

fun <T: View> View.bindView(id: Int): T {
fun <T : View> 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
}
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String>

GET("/authentication/token/validate_with_login")
fun validateToken(Query("username") username: String, Query("password") password: String, Query("request_token") token: String): Map<String, String>
@GET("/authentication/token/validate_with_login")
fun validateToken(@Query("username") username: String, @Query("password") password: String, @Query("request_token") token: String): Map<String, String>

GET("/authentication/session/new")
fun getNewSession(Query("request_token") token: String): Map<String, String>
@GET("/authentication/session/new")
fun getNewSession(@Query("request_token") token: String): Map<String, String>
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI
*/

class GetListMovieNowplayingSpiceRequest(val path: String) :
RetrofitSpiceRequest<Movie.ResultList, TheMovieDBAPI.MovieAPI>(javaClass<Movie.ResultList>(), javaClass<TheMovieDBAPI.MovieAPI>()) {
RetrofitSpiceRequest<Movie.ResultList, TheMovieDBAPI.MovieAPI>(Movie.ResultList::class.java, TheMovieDBAPI.MovieAPI::class.java) {

override fun loadDataFromNetwork(): Movie.ResultList? {
return getService().getNowPlayingList(path)
return service.getNowPlayingList(path)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI
*/

class GetListMovieTopratedSpiceRequest(val path: String) :
RetrofitSpiceRequest<Movie.ResultList, TheMovieDBAPI.MovieAPI>(javaClass<Movie.ResultList>(), javaClass<TheMovieDBAPI.MovieAPI>()) {
RetrofitSpiceRequest<Movie.ResultList, TheMovieDBAPI.MovieAPI>(Movie.ResultList::class.java, TheMovieDBAPI.MovieAPI::class.java) {

override fun loadDataFromNetwork(): Movie.ResultList? {
return getService().getTopRatedList(path)
return service.getTopRatedList(path)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI
*/

class GetListTVAiringtodaySpiceRequest(val path: String) :
RetrofitSpiceRequest<TV.ResultList, TheMovieDBAPI.TVAPI>(javaClass<TV.ResultList>(), javaClass<TheMovieDBAPI.TVAPI>()) {
RetrofitSpiceRequest<TV.ResultList, TheMovieDBAPI.TVAPI>(TV.ResultList::class.java, TheMovieDBAPI.TVAPI::class.java) {

override fun loadDataFromNetwork(): TV.ResultList? {
return getService().getAiringTodayList(path)
return service.getAiringTodayList(path)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI
*/

class GetListTVPopularSpiceRequest(val path: String) :
RetrofitSpiceRequest<TV.ResultList, TheMovieDBAPI.TVAPI>(javaClass<TV.ResultList>(), javaClass<TheMovieDBAPI.TVAPI>()) {
RetrofitSpiceRequest<TV.ResultList, TheMovieDBAPI.TVAPI>(TV.ResultList::class.java, TheMovieDBAPI.TVAPI::class.java) {

override fun loadDataFromNetwork(): TV.ResultList? {
return getService().getPopularList(path)
return service.getPopularList(path)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI
*/

class GetMovieCreditsSpiceRequest(val path: String) :
RetrofitSpiceRequest<Cast.CastList, TheMovieDBAPI.MovieAPI>(javaClass<Cast.CastList>(), javaClass<TheMovieDBAPI.MovieAPI>()) {
RetrofitSpiceRequest<Cast.CastList, TheMovieDBAPI.MovieAPI>(Cast.CastList::class.java, TheMovieDBAPI.MovieAPI::class.java) {

override fun loadDataFromNetwork(): Cast.CastList? {
return getService().getCastList(path)
return service.getCastList(path)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import com.taskworld.android.restfulandroidkotlin.network.api.TheMovieDBAPI
*/

class GetMovieImagesSpiceRequest(val path: String) :
RetrofitSpiceRequest<Image.PosterList, TheMovieDBAPI.MovieAPI>(javaClass<Image.PosterList>(), javaClass<TheMovieDBAPI.MovieAPI>()) {
RetrofitSpiceRequest<Image.PosterList, TheMovieDBAPI.MovieAPI>(Image.PosterList::class.java, TheMovieDBAPI.MovieAPI::class.java) {

override fun loadDataFromNetwork(): Image.PosterList? {
return getService().getPosterImageList(path)
return service.getPosterImageList(path)
}

}
Loading