fix github status check

This commit is contained in:
k0shk0sh 2019-12-26 11:23:18 +01:00
parent 666fb6b19c
commit 5fa8ab2f31
5 changed files with 35 additions and 66 deletions

View File

@ -1,52 +0,0 @@
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

@ -0,0 +1,15 @@
package com.fastaccess.data.dao
import com.google.gson.annotations.SerializedName
/**
* Created by Hashemsergani on 18.10.17.
*/
data class GitHubStatusModel(
@SerializedName("status") var status: GithubStatus? = null
)
data class GithubStatus(
@SerializedName("description") var description: String? = null,
@SerializedName("indicator") var indicator: String? = null
)

View File

@ -25,6 +25,6 @@ interface ContentService {
@Query("branch") branch: String,
@Body body: CommitRequestModel): Observable<GitCommitModel>
@GET("api/last-message.json")
@GET("api/v2/status.json")
fun checkStatus(): Observable<GitHubStatusModel>
}

View File

@ -4,15 +4,9 @@ import android.app.DownloadManager;
import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.widget.Toast;
import com.crashlytics.android.Crashlytics;
import com.fastaccess.App;
import com.fastaccess.BuildConfig;
import com.fastaccess.R;
import com.fastaccess.data.dao.GitHubErrorResponse;
@ -44,6 +38,8 @@ import com.google.gson.GsonBuilder;
import java.io.File;
import java.lang.reflect.Modifier;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.reactivex.Observable;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
@ -210,7 +206,7 @@ public class RestProvider {
@NonNull public static Observable<GitHubStatusModel> gitHubStatus() {
return new Retrofit.Builder()
.baseUrl("https://status.github.com/")
.baseUrl("https://kctbh9vrtdwd.statuspage.io/")
.client(provideOkHttpClient())
.addConverterFactory(new GithubResponseConverter(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())

View File

@ -1,6 +1,7 @@
package com.fastaccess.ui.base.mvp.presenter;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
@ -8,6 +9,10 @@ import androidx.annotation.StringRes;
import com.evernote.android.state.StateSaver;
import com.fastaccess.R;
import com.fastaccess.data.dao.GitHubErrorResponse;
import com.fastaccess.data.dao.GithubStatus;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.Logger;
import com.fastaccess.helper.ObjectsCompat;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.ui.base.mvp.BaseMvp;
@ -116,12 +121,17 @@ public class BasePresenter<V extends BaseMvp.FAView> extends TiPresenter<V> impl
}
public void onCheckGitHubStatus() {
// manageObservable(RestProvider.gitHubStatus()
// .doOnNext(gitHubStatusModel -> {
// if (!"good".equalsIgnoreCase(gitHubStatusModel.getStatus())) {
// sendToView(v -> v.showErrorMessage("Github Status:\n" + gitHubStatusModel.getBody()));
// }
// }));
manageObservable(RestProvider.gitHubStatus()
.filter(ObjectsCompat::nonNull)
.doOnNext(gitHubStatusModel -> {
Logger.e(gitHubStatusModel);
GithubStatus status = gitHubStatusModel.getStatus();
String description = status != null ? status.getDescription() : null;
String indicatorStatus = status != null ? status.getIndicator() : null;
if (!InputHelper.isEmpty(description) && !"none".equalsIgnoreCase(indicatorStatus)) {
sendToView(v -> v.showErrorMessage("Github Status:(" + indicatorStatus + ")\n" + description));
}
}));
}
public boolean isEnterprise() {