Partial migration of data package to Kotlin
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package eu.kanade.tachiyomi.data.updater
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
/**
|
||||
* Release object.
|
||||
* Contains information about the latest release from Github.
|
||||
*
|
||||
* @param version version of latest release.
|
||||
* @param changeLog log of latest release.
|
||||
* @param assets assets of latest release.
|
||||
*/
|
||||
class GithubRelease(@SerializedName("tag_name") val version: String,
|
||||
@SerializedName("body") val changeLog: String,
|
||||
@SerializedName("assets") val assets: List<Assets>) {
|
||||
|
||||
/**
|
||||
* Get download link of latest release from the assets.
|
||||
* @return download link of latest release.
|
||||
*/
|
||||
val downloadLink: String
|
||||
get() = assets[0].downloadLink
|
||||
|
||||
/**
|
||||
* Assets class containing download url.
|
||||
* @param downloadLink download url.
|
||||
*/
|
||||
inner class Assets(@SerializedName("browser_download_url") val downloadLink: String)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package eu.kanade.tachiyomi.data.updater
|
||||
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import retrofit2.http.GET
|
||||
import rx.Observable
|
||||
|
||||
|
||||
/**
|
||||
* Used to connect with the Github API.
|
||||
*/
|
||||
interface GithubService {
|
||||
|
||||
companion object {
|
||||
fun create(): GithubService {
|
||||
val restAdapter = Retrofit.Builder()
|
||||
.baseUrl("https://api.github.com")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
|
||||
.build()
|
||||
|
||||
return restAdapter.create(GithubService::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
@GET("/repos/inorichi/tachiyomi/releases/latest")
|
||||
fun getLatestVersion(): Observable<GithubRelease>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package eu.kanade.tachiyomi.data.updater
|
||||
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.toast
|
||||
import rx.Observable
|
||||
|
||||
|
||||
class GithubUpdateChecker(private val context: Context) {
|
||||
|
||||
val service: GithubService = GithubService.create()
|
||||
|
||||
/**
|
||||
* Returns observable containing release information
|
||||
*/
|
||||
fun checkForApplicationUpdate(): Observable<GithubRelease> {
|
||||
context.toast(R.string.update_check_look_for_updates)
|
||||
return service.getLatestVersion()
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package eu.kanade.tachiyomi.data.updater;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import eu.kanade.tachiyomi.R;
|
||||
import eu.kanade.tachiyomi.data.rest.GithubService;
|
||||
import eu.kanade.tachiyomi.data.rest.Release;
|
||||
import eu.kanade.tachiyomi.data.rest.ServiceFactory;
|
||||
import eu.kanade.tachiyomi.util.ToastUtil;
|
||||
import rx.Observable;
|
||||
|
||||
|
||||
public class UpdateChecker {
|
||||
private final Context context;
|
||||
|
||||
public UpdateChecker(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns observable containing release information
|
||||
*
|
||||
*/
|
||||
public Observable<Release> checkForApplicationUpdate() {
|
||||
ToastUtil.showShort(context, context.getString(R.string.update_check_look_for_updates));
|
||||
//Create Github service to retrieve Github data
|
||||
GithubService service = ServiceFactory.createRetrofitService(GithubService.class, GithubService.SERVICE_ENDPOINT);
|
||||
return service.getLatestVersion();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user