added github status checking automatically

This commit is contained in:
k0shk0sh 2017-10-18 19:06:15 +02:00
parent dfc2cfb543
commit 0678e09d4c
6 changed files with 81 additions and 0 deletions

View File

@ -0,0 +1,52 @@
package com.fastaccess.data.dao;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.Date;
/**
* Created by Hashemsergani on 18.10.17.
*/
public class GitHubStatusModel implements Parcelable {
private String status;
private String body;
private Date createdOn;
public String getStatus() { return status;}
public void setStatus(String status) { this.status = status;}
public String getBody() { return body;}
public void setBody(String body) { this.body = body;}
public Date getCreatedOn() { return createdOn;}
public void setCreatedOn(Date createdOn) { this.createdOn = createdOn;}
@Override public int describeContents() { return 0; }
@Override public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.status);
dest.writeString(this.body);
dest.writeLong(this.createdOn != null ? this.createdOn.getTime() : -1);
}
public GitHubStatusModel() {}
protected GitHubStatusModel(Parcel in) {
this.status = in.readString();
this.body = in.readString();
long tmpCreatedOn = in.readLong();
this.createdOn = tmpCreatedOn == -1 ? null : new Date(tmpCreatedOn);
}
public static final Parcelable.Creator<GitHubStatusModel> CREATOR = new Parcelable.Creator<GitHubStatusModel>() {
@Override public GitHubStatusModel createFromParcel(Parcel source) {return new GitHubStatusModel(source);}
@Override public GitHubStatusModel[] newArray(int size) {return new GitHubStatusModel[size];}
};
}

View File

@ -2,6 +2,7 @@ package com.fastaccess.data.service
import com.fastaccess.data.dao.CommitRequestModel
import com.fastaccess.data.dao.GitCommitModel
import com.fastaccess.data.dao.GitHubStatusModel
import io.reactivex.Observable
import retrofit2.http.*
@ -23,4 +24,7 @@ interface ContentService {
@Path("path") path: String,
@Query("branch") branch: String,
@Body body: CommitRequestModel): Observable<GitCommitModel>
@GET("api/last-message.json")
fun checkStatus(): Observable<GitHubStatusModel>
}

View File

@ -12,6 +12,7 @@ import com.fastaccess.App;
import com.fastaccess.BuildConfig;
import com.fastaccess.R;
import com.fastaccess.data.dao.GitHubErrorResponse;
import com.fastaccess.data.dao.GitHubStatusModel;
import com.fastaccess.data.dao.NameParser;
import com.fastaccess.data.service.ContentService;
import com.fastaccess.data.service.GistService;
@ -40,6 +41,7 @@ import com.google.gson.GsonBuilder;
import java.io.File;
import java.lang.reflect.Modifier;
import io.reactivex.Observable;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import okhttp3.logging.HttpLoggingInterceptor;
@ -212,6 +214,17 @@ public class RestProvider {
return null;
}
@NonNull public static Observable<GitHubStatusModel> gitHubStatus() {
return new Retrofit.Builder()
.baseUrl("https://status.github.com/")
.client(provideOkHttpClient())
.addConverterFactory(new GithubResponseConverter(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
.create(ContentService.class)
.checkStatus();
}
public static void clearHttpClient() {
okHttpClient = null;
}

View File

@ -112,6 +112,7 @@ public abstract class BaseActivity<V extends BaseMvp.FAView, P extends BasePrese
ButterKnife.bind(this);
}
if (savedInstanceState == null) {
getPresenter().onCheckGitHubStatus();
if (getIntent() != null) {
schemeUrl = getIntent().getStringExtra(BundleConstant.SCHEME_URL);
}

View File

@ -70,6 +70,8 @@ public interface BaseMvp {
<T> void makeRestCall(@NonNull Observable<T> observable, @NonNull Consumer<T> onNext);
<T> void makeRestCall(@NonNull Observable<T> observable, @NonNull Consumer<T> onNext, boolean cancelable);
void onCheckGitHubStatus();
}
interface PaginationListener<P> {

View File

@ -121,6 +121,15 @@ public class BasePresenter<V extends BaseMvp.FAView> extends TiPresenter<V> impl
return resId;
}
public void onCheckGitHubStatus() {
manageObservable(RestProvider.gitHubStatus()
.doOnNext(gitHubStatusModel -> {
if (!"good".equalsIgnoreCase(gitHubStatusModel.getStatus())) {
sendToView(v -> v.showErrorMessage("Github Status:\n" + gitHubStatusModel.getBody()));
}
}));
}
public boolean isEnterprise() {
return enterprise;
}