mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-22 06:30:32 -04:00
Details : Handle Malformed requests with UI
This commit is contained in:
@@ -24,5 +24,6 @@ public enum ErrorType {
|
||||
NO_NETWORK,
|
||||
NO_APPS,
|
||||
NO_SEARCH,
|
||||
UNKNOWN
|
||||
UNKNOWN,
|
||||
MALFORMED
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.aurora.store.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.aurora.store.exception.MalformedRequestException;
|
||||
import com.aurora.store.utility.Util;
|
||||
import com.dragons.aurora.playstoreapiv2.AuthException;
|
||||
import com.dragons.aurora.playstoreapiv2.GooglePlayAPI;
|
||||
@@ -134,7 +135,7 @@ public class OkHttpClientAdapter extends HttpClientAdapter {
|
||||
} else if (code >= 500) {
|
||||
throw new GooglePlayException("Server error", code);
|
||||
} else if (code >= 400) {
|
||||
throw new GooglePlayException("Malformed request", code);
|
||||
throw new MalformedRequestException("Malformed Request", code);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2019, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Yalp Store
|
||||
* Copyright (C) 2018 Sergey Yeriomin <yeriomin@gmail.com>
|
||||
*
|
||||
* Aurora Store is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MalformedRequestException extends IOException {
|
||||
|
||||
protected int code;
|
||||
|
||||
public MalformedRequestException() {
|
||||
super("MalformedRequestException");
|
||||
}
|
||||
|
||||
public MalformedRequestException(String message, int code) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public MalformedRequestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public MalformedRequestException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import androidx.core.widget.NestedScrollView;
|
||||
|
||||
import com.aurora.store.ErrorType;
|
||||
import com.aurora.store.R;
|
||||
import com.aurora.store.exception.MalformedRequestException;
|
||||
import com.aurora.store.fragment.details.ActionButton;
|
||||
import com.aurora.store.fragment.details.BackToPlayStore;
|
||||
import com.aurora.store.fragment.details.Beta;
|
||||
@@ -53,8 +54,6 @@ import com.aurora.store.receiver.DetailsInstallReceiver;
|
||||
import com.aurora.store.task.DetailsApp;
|
||||
import com.aurora.store.utility.Log;
|
||||
import com.aurora.store.view.ErrorView;
|
||||
import com.dragons.aurora.playstoreapiv2.GooglePlayException;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -187,11 +186,11 @@ public class DetailsFragment extends BaseFragment implements BaseFragment.EventL
|
||||
@Override
|
||||
public void processException(Throwable e) {
|
||||
mDisposable.clear();
|
||||
if (e.getCause() instanceof GooglePlayException && ((GooglePlayException) e).getCode() == 404) {
|
||||
Snackbar.make(mContainer, "App Not Purchased", Snackbar.LENGTH_LONG).show();
|
||||
if (e instanceof MalformedRequestException) {
|
||||
setErrorView(ErrorType.MALFORMED);
|
||||
switchViews(true);
|
||||
} else
|
||||
super.processException(e);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -214,9 +214,8 @@ public class ActionButton extends AbstractHelper {
|
||||
.subscribe(deliveryData -> {
|
||||
initiateDownload(deliveryData);
|
||||
}, err -> {
|
||||
Log.e(err.getMessage());
|
||||
runOnUiThread(() -> {
|
||||
Toast.makeText(context, "App not available", Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(context, "App Not purchased", Toast.LENGTH_LONG).show();
|
||||
draw();
|
||||
switchViews(false);
|
||||
});
|
||||
@@ -284,7 +283,7 @@ public class ActionButton extends AbstractHelper {
|
||||
request = RequestBuilder.buildRequest(context, app, deliveryData.getDownloadUrl());
|
||||
fetchListener = getFetchListener();
|
||||
fetch.addListener(fetchListener);
|
||||
|
||||
|
||||
if (isPaused)
|
||||
fetch.resume(requestId);
|
||||
else
|
||||
|
||||
@@ -76,6 +76,11 @@ public class ErrorView extends RelativeLayout {
|
||||
imgError.setImageDrawable(context.getDrawable(R.drawable.ic_unknown));
|
||||
txtError.setText(R.string.error_unknown);
|
||||
break;
|
||||
case MALFORMED:
|
||||
imgError.setImageDrawable(context.getDrawable(R.drawable.ic_unknown));
|
||||
txtError.setText(R.string.error_app_not_found);
|
||||
btnError.setText(R.string.action_close);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
<string name="action_cancel">Cancel</string>
|
||||
<string name="action_clear">Clear</string>
|
||||
<string name="action_clear_all">Clear All</string>
|
||||
<string name="action_close">Close</string>
|
||||
<string name="action_convert_local">Convert Local</string>
|
||||
<string name="action_convert_system">Convert System</string>
|
||||
<string name="action_copied">Link copied to clipboard</string>
|
||||
|
||||
Reference in New Issue
Block a user