@@ -15,6 +15,7 @@ import android.os.Handler
1515import android.os.Looper
1616import android.text.Editable
1717import android.text.TextWatcher
18+ import android.view.LayoutInflater
1819import android.view.inputmethod.EditorInfo
1920import android.widget.EditText
2021import android.widget.Toast
@@ -38,6 +39,7 @@ import com.fox2code.mmm.utils.room.ReposListDatabase
3839import com.google.android.material.dialog.MaterialAlertDialogBuilder
3940import com.google.android.material.snackbar.BaseTransientBottomBar
4041import com.google.android.material.snackbar.Snackbar
42+ import com.google.android.material.textfield.TextInputEditText
4143import com.topjohnwu.superuser.internal.UiThreadHandler
4244import timber.log.Timber
4345import java.io.IOException
@@ -55,91 +57,7 @@ class RepoFragment : PreferenceFragmentCompat() {
5557 // CaptchaWebview.setVisible(false);
5658 val androidacyTestMode =
5759 findPreference<Preference >(" pref_androidacy_test_mode" )!!
58- if (! MainApplication .isDeveloper) {
59- androidacyTestMode.isVisible = false
60- } else {
61- // Show a warning if user tries to enable test mode
62- androidacyTestMode.onPreferenceChangeListener =
63- Preference .OnPreferenceChangeListener { _: Preference ? , newValue: Any ->
64- if (java.lang.Boolean .parseBoolean(newValue.toString())) {
65- // Use MaterialAlertDialogBuilder
66- MaterialAlertDialogBuilder (requireContext()).setTitle(R .string.warning)
67- .setCancelable(false ).setMessage(
68- R .string.androidacy_test_mode_warning
69- )
70- .setPositiveButton(android.R .string.ok) { _: DialogInterface ? , _: Int ->
71- // User clicked OK button
72- MainApplication .getPreferences(" mmm" )!!
73- .edit().putBoolean(" androidacy_test_mode" , true ).apply ()
74- // Check the switch
75- val mStartActivity =
76- Intent (requireContext(), MainActivity ::class .java)
77- mStartActivity.flags =
78- Intent .FLAG_ACTIVITY_CLEAR_TOP or Intent .FLAG_ACTIVITY_NEW_TASK
79- val mPendingIntentId = 123456
80- // If < 23, FLAG_IMMUTABLE is not available
81- val mPendingIntent: PendingIntent = PendingIntent .getActivity(
82- requireContext(),
83- mPendingIntentId,
84- mStartActivity,
85- PendingIntent .FLAG_CANCEL_CURRENT or PendingIntent .FLAG_IMMUTABLE
86- )
87- val mgr =
88- requireContext().getSystemService(ALARM_SERVICE ) as AlarmManager
89- mgr[AlarmManager .RTC , System .currentTimeMillis() + 100 ] =
90- mPendingIntent
91- if (MainApplication .forceDebugLogging) Timber .d(
92- " Restarting app to save staging endpoint preference: %s" ,
93- newValue
94- )
95- exitProcess(0 ) // Exit app process
96- }
97- .setNegativeButton(android.R .string.cancel) { _: DialogInterface ? , _: Int ->
98- // User cancelled the dialog
99- // Uncheck the switch
100- val switchPreferenceCompat =
101- androidacyTestMode as SwitchPreferenceCompat
102- switchPreferenceCompat.isChecked = false
103- // There's probably a better way to do this than duplicate code but I'm too lazy to figure it out
104- MainApplication .getPreferences(" mmm" )!!
105- .edit().putBoolean(" androidacy_test_mode" , false ).apply ()
106- }.show()
107- } else {
108- MainApplication .getPreferences(" mmm" )!!
109- .edit().putBoolean(" androidacy_test_mode" , false ).apply ()
110- // Show dialog to restart app with ok button
111- MaterialAlertDialogBuilder (requireContext()).setTitle(R .string.warning)
112- .setCancelable(false ).setMessage(
113- R .string.androidacy_test_mode_disable_warning
114- )
115- .setNeutralButton(android.R .string.ok) { _: DialogInterface ? , _: Int ->
116- // User clicked OK button
117- val mStartActivity =
118- Intent (requireContext(), MainActivity ::class .java)
119- mStartActivity.flags =
120- Intent .FLAG_ACTIVITY_CLEAR_TOP or Intent .FLAG_ACTIVITY_NEW_TASK
121- val mPendingIntentId = 123456
122- // If < 23, FLAG_IMMUTABLE is not available
123- val mPendingIntent: PendingIntent = PendingIntent .getActivity(
124- requireContext(),
125- mPendingIntentId,
126- mStartActivity,
127- PendingIntent .FLAG_CANCEL_CURRENT or PendingIntent .FLAG_IMMUTABLE
128- )
129- val mgr =
130- requireContext().getSystemService(ALARM_SERVICE ) as AlarmManager
131- mgr[AlarmManager .RTC , System .currentTimeMillis() + 100 ] =
132- mPendingIntent
133- if (MainApplication .forceDebugLogging) Timber .d(
134- " Restarting app to save staging endpoint preference: %s" ,
135- newValue
136- )
137- exitProcess(0 ) // Exit app process
138- }.show()
139- }
140- true
141- }
142- }
60+ androidacyTestMode.isVisible = false
14361 // Get magisk_alt_repo enabled state from room reposlist db
14462 val db = Room .databaseBuilder(
14563 requireContext(),
@@ -218,6 +136,38 @@ class RepoFragment : PreferenceFragmentCompat() {
218136 findPreference<LongClickablePreference >(" pref_androidacy_repo_donate" )!!
219137 prefAndroidacyRepoApiD.isEnabled = false
220138 prefAndroidacyRepoApiD.isVisible = false
139+ } else {
140+ val clipboard =
141+ requireContext().getSystemService(CLIPBOARD_SERVICE ) as ClipboardManager
142+ val prefDonateAndroidacy =
143+ findPreference<LongClickablePreference >(" pref_androidacy_repo_donate" )!!
144+ prefDonateAndroidacy.onPreferenceClickListener =
145+ Preference .OnPreferenceClickListener { _: Preference ? ->
146+ // copy FOX2CODE promo code to clipboard and toast user that they can use it for half off any subscription
147+ val toastText = requireContext().getString(R .string.promo_code_copied)
148+ clipboard.setPrimaryClip(ClipData .newPlainText(toastText, " FOX2CODE" ))
149+ Toast .makeText(requireContext(), toastText, Toast .LENGTH_SHORT ).show()
150+ // open androidacy
151+ IntentHelper .openUrl(
152+ MainApplication .INSTANCE !! .lastActivity!! ,
153+ " https://www.androidacy.com/membership-join/?utm_source=AMMM&utm_medium=app&utm_campaign=donate"
154+ )
155+ true
156+ }
157+ // handle long click on pref_donate_androidacy
158+ prefDonateAndroidacy.onPreferenceLongClickListener =
159+ LongClickablePreference .OnPreferenceLongClickListener { _: Preference ? ->
160+ // copy to clipboard
161+ val toastText = requireContext().getString(R .string.link_copied)
162+ clipboard.setPrimaryClip(
163+ ClipData .newPlainText(
164+ toastText,
165+ " https://www.androidacy.com/membership-join/?utm_source=AMMM&utm_medium=app&utm_campaign=donate"
166+ )
167+ )
168+ Toast .makeText(requireContext(), toastText, Toast .LENGTH_SHORT ).show()
169+ true
170+ }
221171 }
222172 }
223173 val originalApiKeyRef = arrayOf(
@@ -510,15 +460,13 @@ class RepoFragment : PreferenceFragmentCompat() {
510460 Preference .OnPreferenceClickListener {
511461 val context = requireContext()
512462 val builder = MaterialAlertDialogBuilder (context)
513- val input = EditText (context)
514- input.setHint(R .string.custom_url)
515- input.setHorizontallyScrolling(true )
516- input.maxLines = 1
463+ val view = LayoutInflater .from(context).inflate(R .layout.custom_repo_input, null )
517464 builder.setIcon(R .drawable.ic_baseline_add_box_24)
518465 builder.setTitle(R .string.add_repo)
519466 // make link in message clickable
520467 builder.setMessage(R .string.add_repo_message)
521- builder.setView(input)
468+ builder.setView(view)
469+ val input = view.findViewById<TextInputEditText >(R .id.custom_repo_input_edit)
522470 builder.setPositiveButton(" OK" ) { _: DialogInterface ? , _: Int ->
523471 var text = input.text.toString()
524472 text = text.trim { it <= ' ' }
@@ -571,8 +519,7 @@ class RepoFragment : PreferenceFragmentCompat() {
571519 )
572520 startActivity(intent)
573521 }
574- val alertDialog = builder.show()
575- val positiveButton = alertDialog.getButton(DialogInterface .BUTTON_POSITIVE )
522+ val alertDialog = builder.create()
576523 // validate as they type
577524 input.addTextChangedListener(object : TextWatcher {
578525 override fun beforeTextChanged (
@@ -594,42 +541,31 @@ class RepoFragment : PreferenceFragmentCompat() {
594541 if (charSequence.toString().isEmpty()) {
595542 input.error = getString(R .string.empty_field)
596543 if (MainApplication .forceDebugLogging) Timber .d(" No input for repo" )
597- positiveButton.isEnabled = false
544+ return
598545 } else if (! charSequence.toString()
599546 .matches(" ^https://.*" .toRegex())
600547 ) {
601548 input.error = getString(R .string.invalid_repo_url)
602549 if (MainApplication .forceDebugLogging) Timber .d(" Non https link for repo" )
603- positiveButton.isEnabled = false
550+ return
604551 } else if (charSequence.toString().contains(" " )) {
605552 input.error = getString(R .string.invalid_repo_url)
606553 if (MainApplication .forceDebugLogging) Timber .d(" Repo url has space" )
607- positiveButton.isEnabled = false
554+ return
608555 } else if (! customRepoManager.canAddRepo(charSequence.toString())) {
609556 input.error = getString(R .string.repo_already_added)
610557 if (MainApplication .forceDebugLogging) Timber .d(" Could not add repo for misc reason" )
611- positiveButton.isEnabled = false
558+ return
612559 } else {
613560 // enable ok button
614561 if (MainApplication .forceDebugLogging) Timber .d(" Repo URL is ok" )
615- positiveButton.isEnabled = true
562+ return
616563 }
617564 }
618565
619566 override fun afterTextChanged (s : Editable ) {}
620567 })
621- positiveButton.isEnabled = false
622- val dp10 = MainApplication .INSTANCE !! .lastActivity?.resources?.getDimensionPixelSize(
623- R .dimen.dp10
624- ) ? : 0
625- val dp20 = MainApplication .INSTANCE !! .lastActivity?.resources?.getDimensionPixelSize(
626- R .dimen.dp20
627- ) ? : 0
628- alertDialog.window!! .setSoftInputMode(20 )
629- alertDialog.window!! .setLayout(
630- dp20,
631- dp10
632- )
568+ alertDialog.show()
633569 true
634570 }
635571 }
0 commit comments