mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +00:00
Add reddit post to rate limit dialog
This commit is contained in:
parent
78b806569e
commit
09306049d5
@ -3,6 +3,8 @@ package awais.instagrabber.dialogs;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -24,17 +26,40 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
@NonNull
|
||||
public static ConfirmDialogFragment newInstance(final int requestCode,
|
||||
@StringRes final int title,
|
||||
@StringRes final int message,
|
||||
@NonNull final CharSequence message,
|
||||
@StringRes final int positiveText,
|
||||
@StringRes final int negativeText,
|
||||
@StringRes final int neutralText) {
|
||||
return newInstance(requestCode, title, 0, message, positiveText, negativeText, neutralText);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ConfirmDialogFragment newInstance(final int requestCode,
|
||||
@StringRes final int title,
|
||||
@StringRes final int messageResId,
|
||||
@StringRes final int positiveText,
|
||||
@StringRes final int negativeText,
|
||||
@StringRes final int neutralText) {
|
||||
return newInstance(requestCode, title, messageResId, null, positiveText, negativeText, neutralText);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static ConfirmDialogFragment newInstance(final int requestCode,
|
||||
@StringRes final int title,
|
||||
@StringRes final int messageResId,
|
||||
@Nullable final CharSequence message,
|
||||
@StringRes final int positiveText,
|
||||
@StringRes final int negativeText,
|
||||
@StringRes final int neutralText) {
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("requestCode", requestCode);
|
||||
if (title != 0) {
|
||||
args.putInt("title", title);
|
||||
}
|
||||
if (message != 0) {
|
||||
args.putInt("message", message);
|
||||
if (messageResId != 0) {
|
||||
args.putInt("messageResId", messageResId);
|
||||
} else if (message != null) {
|
||||
args.putCharSequence("message", message);
|
||||
}
|
||||
if (positiveText != 0) {
|
||||
args.putInt("positive", positiveText);
|
||||
@ -67,7 +92,8 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
|
||||
final Bundle arguments = getArguments();
|
||||
int title = 0;
|
||||
int message = 0;
|
||||
int messageResId = 0;
|
||||
CharSequence message = null;
|
||||
int neutralButtonText = 0;
|
||||
int negativeButtonText = 0;
|
||||
|
||||
@ -75,7 +101,8 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
final int requestCode;
|
||||
if (arguments != null) {
|
||||
title = arguments.getInt("title", 0);
|
||||
message = arguments.getInt("message", 0);
|
||||
messageResId = arguments.getInt("messageResId", 0);
|
||||
message = arguments.getCharSequence("message", null);
|
||||
positiveButtonText = arguments.getInt("positive", defaultPositiveButtonText);
|
||||
negativeButtonText = arguments.getInt("negative", 0);
|
||||
neutralButtonText = arguments.getInt("neutral", 0);
|
||||
@ -92,7 +119,9 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
if (title != 0) {
|
||||
builder.setTitle(title);
|
||||
}
|
||||
if (message != 0) {
|
||||
if (messageResId != 0) {
|
||||
builder.setMessage(messageResId);
|
||||
} else if (message != null) {
|
||||
builder.setMessage(message);
|
||||
}
|
||||
if (negativeButtonText != 0) {
|
||||
@ -110,6 +139,15 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
final Dialog dialog = getDialog();
|
||||
if (dialog == null) return;
|
||||
final TextView view = dialog.findViewById(android.R.id.message);
|
||||
view.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
public interface ConfirmDialogFragmentCallback {
|
||||
void onPositiveButtonClicked(int requestCode);
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package awais.instagrabber.webservices.interceptors;
|
||||
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -57,7 +59,9 @@ public class IgErrorsInterceptor implements Interceptor {
|
||||
final String location = response.header("location");
|
||||
if (location != null && location.equals("https://www.instagram.com/accounts/login/")) {
|
||||
// rate limited
|
||||
showErrorDialog(R.string.rate_limit);
|
||||
final String message = MainActivity.getInstance().getString(R.string.rate_limit);
|
||||
final Spanned spanned = Html.fromHtml(message);
|
||||
showErrorDialog(spanned);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -121,16 +125,15 @@ public class IgErrorsInterceptor implements Interceptor {
|
||||
return String.format("code: %s, internalMessage: %s", errorCode, message);
|
||||
}
|
||||
|
||||
private void showErrorDialog(@StringRes final int messageResId) {
|
||||
private void showErrorDialog(@NonNull final CharSequence message) {
|
||||
final MainActivity mainActivity = MainActivity.getInstance();
|
||||
if (mainActivity == null) return;
|
||||
final FragmentManager fragmentManager = mainActivity.getSupportFragmentManager();
|
||||
if (fragmentManager.isStateSaved()) return;
|
||||
if (messageResId == 0) return;
|
||||
final ConfirmDialogFragment dialogFragment = ConfirmDialogFragment.newInstance(
|
||||
Constants.GLOBAL_NETWORK_ERROR_DIALOG_REQUEST_CODE,
|
||||
R.string.error,
|
||||
messageResId,
|
||||
message,
|
||||
R.string.ok,
|
||||
0,
|
||||
0
|
||||
@ -138,6 +141,10 @@ public class IgErrorsInterceptor implements Interceptor {
|
||||
dialogFragment.show(fragmentManager, "network_error_dialog");
|
||||
}
|
||||
|
||||
private void showErrorDialog(@StringRes final int messageResId) {
|
||||
showErrorDialog(MainActivity.getInstance().getString(messageResId));
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
// mainActivity = null;
|
||||
}
|
||||
|
@ -492,7 +492,7 @@
|
||||
<string name="crash_report_subject">Barinsta Crash Report</string>
|
||||
<string name="crash_report_title">Select an email app to send crash logs</string>
|
||||
<string name="not_found">Not found!</string>
|
||||
<string name="rate_limit">Your IP has been rate limited by Instagram. Wait for an hour and try again.</string>
|
||||
<string name="rate_limit">Your IP has been rate limited by Instagram. Wait for an hour and try again. <a href=\"https://redd.it/msxlko\">Learn more.</a></string>
|
||||
<string name="skip_update">Skip this update</string>
|
||||
<string name="on_latest_version">You\'re already on the latest version</string>
|
||||
<string name="tab_order">Screen order</string>
|
||||
|
Loading…
Reference in New Issue
Block a user