Add reddit post to rate limit dialog

This commit is contained in:
Ammar Githam 2021-05-23 10:35:42 +09:00
parent 78b806569e
commit 09306049d5
3 changed files with 56 additions and 11 deletions

View File

@ -3,6 +3,8 @@ package awais.instagrabber.dialogs;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -24,7 +26,28 @@ public class ConfirmDialogFragment extends DialogFragment {
@NonNull @NonNull
public static ConfirmDialogFragment newInstance(final int requestCode, public static ConfirmDialogFragment newInstance(final int requestCode,
@StringRes final int title, @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 positiveText,
@StringRes final int negativeText, @StringRes final int negativeText,
@StringRes final int neutralText) { @StringRes final int neutralText) {
@ -33,8 +56,10 @@ public class ConfirmDialogFragment extends DialogFragment {
if (title != 0) { if (title != 0) {
args.putInt("title", title); args.putInt("title", title);
} }
if (message != 0) { if (messageResId != 0) {
args.putInt("message", message); args.putInt("messageResId", messageResId);
} else if (message != null) {
args.putCharSequence("message", message);
} }
if (positiveText != 0) { if (positiveText != 0) {
args.putInt("positive", positiveText); args.putInt("positive", positiveText);
@ -67,7 +92,8 @@ public class ConfirmDialogFragment extends DialogFragment {
public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable final Bundle savedInstanceState) {
final Bundle arguments = getArguments(); final Bundle arguments = getArguments();
int title = 0; int title = 0;
int message = 0; int messageResId = 0;
CharSequence message = null;
int neutralButtonText = 0; int neutralButtonText = 0;
int negativeButtonText = 0; int negativeButtonText = 0;
@ -75,7 +101,8 @@ public class ConfirmDialogFragment extends DialogFragment {
final int requestCode; final int requestCode;
if (arguments != null) { if (arguments != null) {
title = arguments.getInt("title", 0); 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); positiveButtonText = arguments.getInt("positive", defaultPositiveButtonText);
negativeButtonText = arguments.getInt("negative", 0); negativeButtonText = arguments.getInt("negative", 0);
neutralButtonText = arguments.getInt("neutral", 0); neutralButtonText = arguments.getInt("neutral", 0);
@ -92,7 +119,9 @@ public class ConfirmDialogFragment extends DialogFragment {
if (title != 0) { if (title != 0) {
builder.setTitle(title); builder.setTitle(title);
} }
if (message != 0) { if (messageResId != 0) {
builder.setMessage(messageResId);
} else if (message != null) {
builder.setMessage(message); builder.setMessage(message);
} }
if (negativeButtonText != 0) { if (negativeButtonText != 0) {
@ -110,6 +139,15 @@ public class ConfirmDialogFragment extends DialogFragment {
return builder.create(); 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 { public interface ConfirmDialogFragmentCallback {
void onPositiveButtonClicked(int requestCode); void onPositiveButtonClicked(int requestCode);

View File

@ -1,5 +1,7 @@
package awais.instagrabber.webservices.interceptors; package awais.instagrabber.webservices.interceptors;
import android.text.Html;
import android.text.Spanned;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
@ -57,7 +59,9 @@ public class IgErrorsInterceptor implements Interceptor {
final String location = response.header("location"); final String location = response.header("location");
if (location != null && location.equals("https://www.instagram.com/accounts/login/")) { if (location != null && location.equals("https://www.instagram.com/accounts/login/")) {
// rate limited // 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; return;
} }
@ -121,16 +125,15 @@ public class IgErrorsInterceptor implements Interceptor {
return String.format("code: %s, internalMessage: %s", errorCode, message); 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(); final MainActivity mainActivity = MainActivity.getInstance();
if (mainActivity == null) return; if (mainActivity == null) return;
final FragmentManager fragmentManager = mainActivity.getSupportFragmentManager(); final FragmentManager fragmentManager = mainActivity.getSupportFragmentManager();
if (fragmentManager.isStateSaved()) return; if (fragmentManager.isStateSaved()) return;
if (messageResId == 0) return;
final ConfirmDialogFragment dialogFragment = ConfirmDialogFragment.newInstance( final ConfirmDialogFragment dialogFragment = ConfirmDialogFragment.newInstance(
Constants.GLOBAL_NETWORK_ERROR_DIALOG_REQUEST_CODE, Constants.GLOBAL_NETWORK_ERROR_DIALOG_REQUEST_CODE,
R.string.error, R.string.error,
messageResId, message,
R.string.ok, R.string.ok,
0, 0,
0 0
@ -138,6 +141,10 @@ public class IgErrorsInterceptor implements Interceptor {
dialogFragment.show(fragmentManager, "network_error_dialog"); dialogFragment.show(fragmentManager, "network_error_dialog");
} }
private void showErrorDialog(@StringRes final int messageResId) {
showErrorDialog(MainActivity.getInstance().getString(messageResId));
}
public void destroy() { public void destroy() {
// mainActivity = null; // mainActivity = null;
} }

View File

@ -492,7 +492,7 @@
<string name="crash_report_subject">Barinsta Crash Report</string> <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="crash_report_title">Select an email app to send crash logs</string>
<string name="not_found">Not found!</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. &lt;a href=\"https://redd.it/msxlko\">Learn more.&lt;/a></string>
<string name="skip_update">Skip this update</string> <string name="skip_update">Skip this update</string>
<string name="on_latest_version">You\'re already on the latest version</string> <string name="on_latest_version">You\'re already on the latest version</string>
<string name="tab_order">Screen order</string> <string name="tab_order">Screen order</string>