mirror of
https://github.com/k0shk0sh/FastHub.git
synced 2025-12-08 19:05:54 +00:00
parent
cf8238f86b
commit
3dd673f161
@ -29,6 +29,7 @@
|
||||
android:configChanges="keyboard|orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/LoginTheme">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
@ -4,6 +4,7 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
@ -23,8 +24,7 @@ public class AuthModel implements Parcelable {
|
||||
private List<String> scopes;
|
||||
private String state;
|
||||
private String note;
|
||||
@SerializedName("X-GitHub-OTP")
|
||||
private String otpCode;
|
||||
@SerializedName("X-GitHub-OTP") private String otpCode;
|
||||
|
||||
@Override public int describeContents() { return 0; }
|
||||
|
||||
|
||||
@ -83,9 +83,11 @@ public interface RepoService {
|
||||
Observable<Pageable<UserModel>> getContributors(@Path("owner") String owner, @Path("repo") String repo, @Query("page") int page);
|
||||
|
||||
@NonNull @GET("repos/{owner}/{repo}/commits/{sha}")
|
||||
@Headers("Accept: application/vnd.github.VERSION.full+json")
|
||||
Observable<CommitModel> getCommit(@Path("owner") String owner, @Path("repo") String repo, @Path("sha") String sha);
|
||||
|
||||
@NonNull @GET("repos/{owner}/{repo}/commits/{sha}/comments")
|
||||
@Headers("Accept: application/vnd.github.VERSION.full+json")
|
||||
Observable<Pageable<CommentsModel>> getCommitComments(@NonNull @Path("owner") String owner, @NonNull @Path("repo") String repo,
|
||||
@NonNull @Path("sha") String ref, @Query("page") int page);
|
||||
|
||||
|
||||
@ -26,8 +26,6 @@ interface LoginMvp {
|
||||
|
||||
interface Presenter extends BaseMvp.FAPresenter {
|
||||
|
||||
void onGetToken(@NonNull String code);
|
||||
|
||||
void onTokenResponse(@Nullable AccessTokenModel response);
|
||||
|
||||
void onUserResponse(@Nullable LoginModel response);
|
||||
|
||||
@ -12,12 +12,11 @@ import com.fastaccess.helper.InputHelper;
|
||||
import com.fastaccess.helper.PrefGetter;
|
||||
import com.fastaccess.provider.rest.LoginProvider;
|
||||
import com.fastaccess.provider.rest.RestProvider;
|
||||
import com.fastaccess.ui.base.mvp.BaseMvp;
|
||||
import com.fastaccess.ui.base.mvp.presenter.BasePresenter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import okhttp3.Credentials;
|
||||
import retrofit2.adapter.rxjava.HttpException;
|
||||
import rx.Observable;
|
||||
@ -28,13 +27,6 @@ import rx.Observable;
|
||||
|
||||
class LoginPresenter extends BasePresenter<LoginMvp.View> implements LoginMvp.Presenter {
|
||||
|
||||
@Override public void onGetToken(@NonNull String code) {
|
||||
makeRestCall(RestProvider.getLoginRestService().getAccessToken(code,
|
||||
BuildConfig.GITHUB_CLIENT_ID, BuildConfig.GITHUB_SECRET,
|
||||
BuildConfig.APPLICATION_ID, BuildConfig.REDIRECT_URL),
|
||||
this::onTokenResponse);
|
||||
}
|
||||
|
||||
@Override public void onTokenResponse(@Nullable AccessTokenModel modelResponse) {
|
||||
if (modelResponse != null) {
|
||||
String token = modelResponse.getToken();
|
||||
@ -69,22 +61,14 @@ class LoginPresenter extends BasePresenter<LoginMvp.View> implements LoginMvp.Pr
|
||||
authModel.setScopes(Arrays.asList("user", "repo", "gist", "notifications"));
|
||||
authModel.setNote(BuildConfig.APPLICATION_ID + "-" + authToken);//make it unique to FastHub.
|
||||
authModel.setClientSecret(BuildConfig.GITHUB_SECRET);
|
||||
|
||||
UUID uuid = UUID.randomUUID();
|
||||
String fingerprint = BuildConfig.APPLICATION_ID + " - " + uuid;
|
||||
|
||||
Observable<AccessTokenModel> loginCall =
|
||||
LoginProvider.getLoginRestService(authToken).login(BuildConfig.GITHUB_CLIENT_ID,
|
||||
fingerprint,
|
||||
authModel);
|
||||
|
||||
if (twoFactorCode != null && !twoFactorCode.isEmpty()) {
|
||||
loginCall = LoginProvider.getLoginRestService(authToken).login(BuildConfig.GITHUB_CLIENT_ID,
|
||||
fingerprint,
|
||||
authModel,
|
||||
twoFactorCode);
|
||||
Observable<AccessTokenModel> loginCall = LoginProvider.getLoginRestService(authToken)
|
||||
.login(BuildConfig.GITHUB_CLIENT_ID, fingerprint, authModel);
|
||||
if (!InputHelper.isEmpty(twoFactorCode)) {
|
||||
loginCall = LoginProvider.getLoginRestService(authToken)
|
||||
.login(BuildConfig.GITHUB_CLIENT_ID, fingerprint, authModel, twoFactorCode);
|
||||
}
|
||||
|
||||
makeRestCall(loginCall, tokenModel -> {
|
||||
if (InputHelper.isEmpty(tokenModel.getToken())) {
|
||||
makeRestCall(LoginProvider.getLoginRestService(authToken).deleteToken(tokenModel.getId()),
|
||||
@ -96,18 +80,20 @@ class LoginPresenter extends BasePresenter<LoginMvp.View> implements LoginMvp.Pr
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable throwable) {
|
||||
@Override public void onError(@NonNull Throwable throwable) {
|
||||
if (RestProvider.getErrorCode(throwable) == 401) {
|
||||
String twoFaToken = ((HttpException) throwable).response().headers().get("X-GitHub-OTP");
|
||||
if (twoFaToken != null) {
|
||||
sendToView(LoginMvp.View::onRequire2Fa);
|
||||
} else {
|
||||
sendToView(LoginMvp.View::onRequireLogin);
|
||||
retrofit2.Response response = ((HttpException) throwable).response();
|
||||
if (response != null && response.headers() != null) {
|
||||
String twoFaToken = response.headers().get("X-GitHub-OTP");
|
||||
if (twoFaToken != null) {
|
||||
sendToView(LoginMvp.View::onRequire2Fa);
|
||||
return;
|
||||
} else {
|
||||
sendToView(LoginMvp.View::onRequireLogin);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
super.onError(throwable);
|
||||
}
|
||||
super.onError(throwable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,11 @@ public class LoginView extends BaseActivity<LoginMvp.View, LoginPresenter> imple
|
||||
@BindView(R.id.login) FloatingActionButton login;
|
||||
@BindView(R.id.progress) ProgressBar progress;
|
||||
|
||||
@OnClick(R.id.login) public void onClick() {
|
||||
getPresenter().login(InputHelper.toString(username),
|
||||
InputHelper.toString(password), InputHelper.toString(twoFactor));
|
||||
}
|
||||
|
||||
@Override protected int layout() {
|
||||
return R.layout.login_layout;
|
||||
}
|
||||
@ -58,8 +63,8 @@ public class LoginView extends BaseActivity<LoginMvp.View, LoginPresenter> imple
|
||||
username.setError(isEmpty ? getString(R.string.required_field) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequire2Fa() {
|
||||
@Override public void onRequire2Fa() {
|
||||
showMessage(R.string.error, R.string.two_fectors_otp_error);
|
||||
twoFactor.setVisibility(View.VISIBLE);
|
||||
hideProgress();
|
||||
}
|
||||
@ -78,11 +83,6 @@ public class LoginView extends BaseActivity<LoginMvp.View, LoginPresenter> imple
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@OnClick(R.id.login) public void onClick() {
|
||||
String twoFactorCode = InputHelper.isEmpty(twoFactor) ? null : InputHelper.toString(twoFactor);
|
||||
getPresenter().login(InputHelper.toString(username), InputHelper.toString(password), twoFactorCode);
|
||||
}
|
||||
|
||||
@Override public void showErrorMessage(@NonNull String msgRes) {
|
||||
hideProgress();
|
||||
super.showErrorMessage(msgRes);
|
||||
|
||||
@ -101,7 +101,6 @@ public class NotificationsPresenter extends BasePresenter<NotificationsMvp.View>
|
||||
showAll ? RestProvider.getNotificationService().getAllNotifications(page)
|
||||
: RestProvider.getNotificationService().getNotifications(page);
|
||||
makeRestCall(observable, response -> {
|
||||
notifications.clear();
|
||||
if (response.getItems() != null) {
|
||||
lastPage = response.getLast();
|
||||
if (page == 1) {
|
||||
|
||||
@ -30,13 +30,13 @@ public class RepoClosedIssuesView extends BaseFragment<RepoIssuesMvp.View, RepoI
|
||||
@BindView(R.id.stateLayout) StateLayout stateLayout;
|
||||
private OnLoadMore<IssueState> onLoadMore;
|
||||
private IssuesAdapter adapter;
|
||||
private final IssueState issueState = IssueState.closed;
|
||||
|
||||
public static RepoClosedIssuesView newInstance(@NonNull String repoId, @NonNull String login, @NonNull IssueState issueState) {
|
||||
public static RepoClosedIssuesView newInstance(@NonNull String repoId, @NonNull String login) {
|
||||
RepoClosedIssuesView view = new RepoClosedIssuesView();
|
||||
view.setArguments(Bundler.start()
|
||||
.put(BundleConstant.ID, repoId)
|
||||
.put(BundleConstant.EXTRA, login)
|
||||
.put(BundleConstant.EXTRA_TWO, issueState)
|
||||
.end());
|
||||
return view;
|
||||
}
|
||||
@ -64,7 +64,7 @@ public class RepoClosedIssuesView extends BaseFragment<RepoIssuesMvp.View, RepoI
|
||||
recycler.setAdapter(adapter);
|
||||
recycler.addOnScrollListener(getLoadMore());
|
||||
if (savedInstanceState == null) {
|
||||
getPresenter().onFragmentCreated(getArguments());
|
||||
getPresenter().onFragmentCreated(getArguments(), issueState);
|
||||
} else if (getPresenter().getIssues().isEmpty() && !getPresenter().isApiCalled()) {
|
||||
onRefresh();
|
||||
}
|
||||
@ -93,7 +93,7 @@ public class RepoClosedIssuesView extends BaseFragment<RepoIssuesMvp.View, RepoI
|
||||
if (onLoadMore == null) {
|
||||
onLoadMore = new OnLoadMore<>(getPresenter());
|
||||
}
|
||||
onLoadMore.setParameter(((IssueState) getArguments().getSerializable(BundleConstant.EXTRA_TWO)));
|
||||
onLoadMore.setParameter(issueState);
|
||||
return onLoadMore;
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ interface RepoIssuesMvp {
|
||||
BaseViewHolder.OnItemClickListener<IssueModel>,
|
||||
BaseMvp.PaginationListener<IssueState> {
|
||||
|
||||
void onFragmentCreated(@NonNull Bundle bundle);
|
||||
void onFragmentCreated(@NonNull Bundle bundle, IssueState issueState);
|
||||
|
||||
void onWorkOffline();
|
||||
|
||||
|
||||
@ -80,10 +80,10 @@ class RepoIssuesPresenter extends BasePresenter<RepoIssuesMvp.View> implements R
|
||||
});
|
||||
}
|
||||
|
||||
@Override public void onFragmentCreated(@NonNull Bundle bundle) {
|
||||
@Override public void onFragmentCreated(@NonNull Bundle bundle, IssueState issueState) {
|
||||
repoId = bundle.getString(BundleConstant.ID);
|
||||
login = bundle.getString(BundleConstant.EXTRA);
|
||||
issueState = (IssueState) bundle.getSerializable(BundleConstant.EXTRA_TWO);
|
||||
this.issueState = issueState;
|
||||
if (!InputHelper.isEmpty(login) && !InputHelper.isEmpty(repoId)) {
|
||||
onCallApi(1, null);
|
||||
}
|
||||
|
||||
@ -35,15 +35,14 @@ public class RepoOpenedIssuesView extends BaseFragment<RepoIssuesMvp.View, RepoI
|
||||
@BindView(R.id.stateLayout) StateLayout stateLayout;
|
||||
private OnLoadMore<IssueState> onLoadMore;
|
||||
private IssuesAdapter adapter;
|
||||
|
||||
private final IssueState issueState = IssueState.open;
|
||||
private RepoIssuesPagerMvp.View pagerCallback;
|
||||
|
||||
public static RepoOpenedIssuesView newInstance(@NonNull String repoId, @NonNull String login, @NonNull IssueState issueState) {
|
||||
public static RepoOpenedIssuesView newInstance(@NonNull String repoId, @NonNull String login) {
|
||||
RepoOpenedIssuesView view = new RepoOpenedIssuesView();
|
||||
view.setArguments(Bundler.start()
|
||||
.put(BundleConstant.ID, repoId)
|
||||
.put(BundleConstant.EXTRA, login)
|
||||
.put(BundleConstant.EXTRA_TWO, issueState)
|
||||
.end());
|
||||
return view;
|
||||
}
|
||||
@ -85,7 +84,7 @@ public class RepoOpenedIssuesView extends BaseFragment<RepoIssuesMvp.View, RepoI
|
||||
recycler.setAdapter(adapter);
|
||||
recycler.addOnScrollListener(getLoadMore());
|
||||
if (savedInstanceState == null) {
|
||||
getPresenter().onFragmentCreated(getArguments());
|
||||
getPresenter().onFragmentCreated(getArguments(), issueState);
|
||||
} else if (getPresenter().getIssues().isEmpty() && !getPresenter().isApiCalled()) {
|
||||
onRefresh();
|
||||
}
|
||||
@ -123,7 +122,7 @@ public class RepoOpenedIssuesView extends BaseFragment<RepoIssuesMvp.View, RepoI
|
||||
if (onLoadMore == null) {
|
||||
onLoadMore = new OnLoadMore<>(getPresenter());
|
||||
}
|
||||
onLoadMore.setParameter(((IssueState) getArguments().getSerializable(BundleConstant.EXTRA_TWO)));
|
||||
onLoadMore.setParameter(issueState);
|
||||
return onLoadMore;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:background="@color/material_indigo_700"
|
||||
android:orientation="vertical"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/material_indigo_700"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<android.support.v4.widget.NestedScrollView
|
||||
@ -23,10 +23,10 @@
|
||||
app:cardElevation="@dimen/spacing_normal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/loginForm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/loginForm">
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.fastaccess.ui.widgets.FontTextView
|
||||
android:id="@+id/mainCard"
|
||||
@ -89,6 +89,7 @@
|
||||
android:id="@+id/twoFactor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/spacing_xs_large"
|
||||
android:hint="@string/twoFactor"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
@ -256,4 +256,5 @@
|
||||
<string name="about">About</string>
|
||||
<string name="notification_settings">Notification Settings</string>
|
||||
<string name="unauthorized_user">Unauthorized user.</string>
|
||||
<string name="two_fectors_otp_error">Two-Factor authentication OTP is required to login.</string>
|
||||
</resources>
|
||||
Loading…
x
Reference in New Issue
Block a user