Skip to content

Commit

Permalink
Show a dialog before landing in NsfwAndSpoilerFragment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Docile-Alligator committed Nov 16, 2024
1 parent d732f7e commit 9cff493
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package ml.docilealligator.infinityforreddit.settings;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
Expand All @@ -17,9 +22,11 @@
import javax.inject.Inject;
import javax.inject.Named;

import me.saket.bettermovementmethod.BetterLinkMovementMethod;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.account.Account;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.SettingsActivity;
import ml.docilealligator.infinityforreddit.databinding.FragmentNsfwAndSpoilerBinding;
import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent;
Expand Down Expand Up @@ -151,6 +158,28 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
.show();
}
});

TextView messageTextView = new TextView(activity);
int padding = (int) Utils.convertDpToPixel(24, activity);
messageTextView.setPaddingRelative(padding, padding, padding, padding);
SpannableString message = new SpannableString(getString(R.string.user_agreement_message_sensitive_content, "https://www.redditinc.com/policies/user-agreement", "https://docile-alligator.github.io"));
Linkify.addLinks(message, Linkify.WEB_URLS);
messageTextView.setMovementMethod(BetterLinkMovementMethod.newInstance().setOnLinkClickListener((textView, url) -> {
Intent intent = new Intent(activity, LinkResolverActivity.class);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}));
messageTextView.setLinkTextColor(getResources().getColor(R.color.colorAccent));
messageTextView.setText(message);
new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
.setTitle(getString(R.string.user_agreement_dialog_title))
.setView(messageTextView)
.setPositiveButton(R.string.agree, (dialogInterface, i) -> dialogInterface.dismiss())
.setNegativeButton(R.string.do_not_agree, (dialogInterface, i) -> activity.onBackPressed())
.setCancelable(false)
.show();

return binding.getRoot();
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,7 @@

<string name="user_agreement_dialog_title">User Agreement</string>
<string name="user_agreement_message">You need to agree to Reddit User Agreement (%1$s) and Infinity for Reddit\'s Privacy Policy (%2$s) before logging in.\n\nFrom now on, you will need a monthly subscription to access the Reddit API within Infinity for Reddit and this is because Reddit has started charging for API access since July 1st, 2023.</string>
<string name="user_agreement_message_sensitive_content">You need to agree to Reddit User Agreement (%1$s) and Infinity for Reddit\'s Privacy Policy (%2$s) before changing these settings.</string>
<string name="agree">Agree</string>
<string name="do_not_agree">Don\'t Agree</string>

Expand Down

0 comments on commit 9cff493

Please sign in to comment.