mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-02 02:13:33 +00:00
feat: implemented version number control and update dialog for Github flavor
This commit is contained in:
parent
c243fa9edc
commit
0a26f0a7b8
19 changed files with 477 additions and 4 deletions
|
|
@ -0,0 +1,29 @@
|
|||
package com.cappielloantonio.tempo.github;
|
||||
|
||||
import com.cappielloantonio.tempo.github.api.release.ReleaseClient;
|
||||
|
||||
public class Github {
|
||||
private static final String OWNER = "CappielloAntonio";
|
||||
private static final String REPO = "Tempo";
|
||||
private ReleaseClient releaseClient;
|
||||
|
||||
public ReleaseClient getReleaseClient() {
|
||||
if (releaseClient == null) {
|
||||
releaseClient = new ReleaseClient(this);
|
||||
}
|
||||
|
||||
return releaseClient;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return "https://api.github.com/";
|
||||
}
|
||||
|
||||
public static String getOwner() {
|
||||
return OWNER;
|
||||
}
|
||||
|
||||
public static String getRepo() {
|
||||
return REPO;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.cappielloantonio.tempo.github
|
||||
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
class GithubRetrofitClient(github: Github) {
|
||||
var retrofit: Retrofit
|
||||
|
||||
init {
|
||||
retrofit = Retrofit.Builder()
|
||||
.baseUrl(github.url)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.client(getOkHttpClient())
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun getOkHttpClient(): OkHttpClient {
|
||||
return OkHttpClient.Builder()
|
||||
.addInterceptor(getHttpLoggingInterceptor())
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun getHttpLoggingInterceptor(): HttpLoggingInterceptor {
|
||||
val loggingInterceptor = HttpLoggingInterceptor()
|
||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
|
||||
return loggingInterceptor
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.cappielloantonio.tempo.github.api.release;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.cappielloantonio.tempo.github.Github;
|
||||
import com.cappielloantonio.tempo.github.GithubRetrofitClient;
|
||||
import com.cappielloantonio.tempo.github.models.LatestRelease;
|
||||
|
||||
import retrofit2.Call;
|
||||
|
||||
public class ReleaseClient {
|
||||
private static final String TAG = "ReleaseClient";
|
||||
|
||||
private final ReleaseService releaseService;
|
||||
|
||||
public ReleaseClient(Github github) {
|
||||
this.releaseService = new GithubRetrofitClient(github).getRetrofit().create(ReleaseService.class);
|
||||
}
|
||||
|
||||
public Call<LatestRelease> getLatestRelease() {
|
||||
Log.d(TAG, "getLatestRelease()");
|
||||
return releaseService.getLatestRelease(Github.getOwner(), Github.getRepo());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.cappielloantonio.tempo.github.api.release;
|
||||
|
||||
import com.cappielloantonio.tempo.github.models.LatestRelease;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Path;
|
||||
|
||||
public interface ReleaseService {
|
||||
@GET("repos/{owner}/{repo}/releases/latest")
|
||||
Call<LatestRelease> getLatestRelease(@Path("owner") String owner, @Path("repo") String repo);
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.cappielloantonio.tempo.github.models
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class Assets(
|
||||
@SerializedName("url")
|
||||
var url: String? = null,
|
||||
@SerializedName("id")
|
||||
var id: Int? = null,
|
||||
@SerializedName("node_id")
|
||||
var nodeId: String? = null,
|
||||
@SerializedName("name")
|
||||
var name: String? = null,
|
||||
@SerializedName("label")
|
||||
var label: String? = null,
|
||||
@SerializedName("uploader")
|
||||
var uploader: Uploader? = Uploader(),
|
||||
@SerializedName("content_type")
|
||||
var contentType: String? = null,
|
||||
@SerializedName("state")
|
||||
var state: String? = null,
|
||||
@SerializedName("size")
|
||||
var size: Int? = null,
|
||||
@SerializedName("download_count")
|
||||
var downloadCount: Int? = null,
|
||||
@SerializedName("created_at")
|
||||
var createdAt: String? = null,
|
||||
@SerializedName("updated_at")
|
||||
var updatedAt: String? = null,
|
||||
@SerializedName("browser_download_url")
|
||||
var browserDownloadUrl: String? = null
|
||||
)
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.cappielloantonio.tempo.github.models
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class Author(
|
||||
@SerializedName("login")
|
||||
var login: String? = null,
|
||||
@SerializedName("id")
|
||||
var id: Int? = null,
|
||||
@SerializedName("node_id")
|
||||
var nodeId: String? = null,
|
||||
@SerializedName("avatar_url")
|
||||
var avatarUrl: String? = null,
|
||||
@SerializedName("gravatar_id")
|
||||
var gravatarId: String? = null,
|
||||
@SerializedName("url")
|
||||
var url: String? = null,
|
||||
@SerializedName("html_url")
|
||||
var htmlUrl: String? = null,
|
||||
@SerializedName("followers_url")
|
||||
var followersUrl: String? = null,
|
||||
@SerializedName("following_url")
|
||||
var followingUrl: String? = null,
|
||||
@SerializedName("gists_url")
|
||||
var gistsUrl: String? = null,
|
||||
@SerializedName("starred_url")
|
||||
var starredUrl: String? = null,
|
||||
@SerializedName("subscriptions_url")
|
||||
var subscriptionsUrl: String? = null,
|
||||
@SerializedName("organizations_url")
|
||||
var organizationsUrl: String? = null,
|
||||
@SerializedName("repos_url")
|
||||
var reposUrl: String? = null,
|
||||
@SerializedName("events_url")
|
||||
var eventsUrl: String? = null,
|
||||
@SerializedName("received_events_url")
|
||||
var receivedEventsUrl: String? = null,
|
||||
@SerializedName("type")
|
||||
var type: String? = null,
|
||||
@SerializedName("site_admin")
|
||||
var siteAdmin: Boolean? = null
|
||||
)
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.cappielloantonio.tempo.github.models
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class LatestRelease(
|
||||
@SerializedName("url")
|
||||
var url: String? = null,
|
||||
@SerializedName("assets_url")
|
||||
var assetsUrl: String? = null,
|
||||
@SerializedName("upload_url")
|
||||
var uploadUrl: String? = null,
|
||||
@SerializedName("html_url")
|
||||
var htmlUrl: String? = null,
|
||||
@SerializedName("id")
|
||||
var id: Int? = null,
|
||||
@SerializedName("author")
|
||||
var author: Author? = Author(),
|
||||
@SerializedName("node_id")
|
||||
var nodeId: String? = null,
|
||||
@SerializedName("tag_name")
|
||||
var tagName: String? = null,
|
||||
@SerializedName("target_commitish")
|
||||
var targetCommitish: String? = null,
|
||||
@SerializedName("name")
|
||||
var name: String? = null,
|
||||
@SerializedName("draft")
|
||||
var draft: Boolean? = null,
|
||||
@SerializedName("prerelease")
|
||||
var prerelease: Boolean? = null,
|
||||
@SerializedName("created_at")
|
||||
var createdAt: String? = null,
|
||||
@SerializedName("published_at")
|
||||
var publishedAt: String? = null,
|
||||
@SerializedName("assets")
|
||||
var assets: ArrayList<Assets> = arrayListOf(),
|
||||
@SerializedName("tarball_url")
|
||||
var tarballUrl: String? = null,
|
||||
@SerializedName("zipball_url")
|
||||
var zipballUrl: String? = null,
|
||||
@SerializedName("body")
|
||||
var body: String? = null,
|
||||
@SerializedName("reactions")
|
||||
var reactions: Reactions? = Reactions()
|
||||
)
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.cappielloantonio.tempo.github.models
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class Reactions(
|
||||
@SerializedName("url")
|
||||
var url: String? = null,
|
||||
@SerializedName("total_count")
|
||||
var totalCount: Int? = null,
|
||||
@SerializedName("+1")
|
||||
var like: Int? = null,
|
||||
@SerializedName("-1")
|
||||
var dislike: Int? = null,
|
||||
@SerializedName("laugh")
|
||||
var laugh: Int? = null,
|
||||
@SerializedName("hooray")
|
||||
var hooray: Int? = null,
|
||||
@SerializedName("confused")
|
||||
var confused: Int? = null,
|
||||
@SerializedName("heart")
|
||||
var heart: Int? = null,
|
||||
@SerializedName("rocket")
|
||||
var rocket: Int? = null,
|
||||
@SerializedName("eyes")
|
||||
var eyes: Int? = null
|
||||
)
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.cappielloantonio.tempo.github.models
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class Uploader(
|
||||
@SerializedName("login")
|
||||
var login: String? = null,
|
||||
@SerializedName("id")
|
||||
var id: Int? = null,
|
||||
@SerializedName("node_id")
|
||||
var nodeId: String? = null,
|
||||
@SerializedName("avatar_url")
|
||||
var avatarUrl: String? = null,
|
||||
@SerializedName("gravatar_id")
|
||||
var gravatarId: String? = null,
|
||||
@SerializedName("url")
|
||||
var url: String? = null,
|
||||
@SerializedName("html_url")
|
||||
var htmlUrl: String? = null,
|
||||
@SerializedName("followers_url")
|
||||
var followersUrl: String? = null,
|
||||
@SerializedName("following_url")
|
||||
var followingUrl: String? = null,
|
||||
@SerializedName("gists_url")
|
||||
var gistsUrl: String? = null,
|
||||
@SerializedName("starred_url")
|
||||
var starredUrl: String? = null,
|
||||
@SerializedName("subscriptions_url")
|
||||
var subscriptionsUrl: String? = null,
|
||||
@SerializedName("organizations_url")
|
||||
var organizationsUrl: String? = null,
|
||||
@SerializedName("repos_url")
|
||||
var reposUrl: String? = null,
|
||||
@SerializedName("events_url")
|
||||
var eventsUrl: String? = null,
|
||||
@SerializedName("received_events_url")
|
||||
var receivedEventsUrl: String? = null,
|
||||
@SerializedName("type")
|
||||
var type: String? = null,
|
||||
@SerializedName("site_admin")
|
||||
var siteAdmin: Boolean? = null
|
||||
)
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.cappielloantonio.tempo.github.utils;
|
||||
|
||||
import com.cappielloantonio.tempo.BuildConfig;
|
||||
import com.cappielloantonio.tempo.github.models.LatestRelease;
|
||||
|
||||
public class UpdateUtil {
|
||||
|
||||
public static boolean showUpdateDialog(LatestRelease release) {
|
||||
if (release.getTagName() == null) return false;
|
||||
|
||||
try {
|
||||
String[] local = BuildConfig.VERSION_NAME.split("\\.");
|
||||
String[] remote = release.getTagName().split("\\.");
|
||||
|
||||
for (int i = 0; i < local.length; i++) {
|
||||
int localPart = Integer.parseInt(local[i]);
|
||||
int remotePart = Integer.parseInt(remote[i]);
|
||||
|
||||
if (localPart > remotePart) {
|
||||
return false;
|
||||
} else if (localPart < remotePart) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue