Add support for a donation megaphone.

fork-5.53.8
Greyson Parrelli 2020-11-18 10:33:46 -05:00 zatwierdzone przez GitHub
rodzic 6e5abc92a0
commit 5c3baca055
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 76 dodań i 17 usunięć

Wyświetl plik

@ -22,8 +22,9 @@ import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.messagerequests.MessageRequestMegaphoneActivity;
import org.thoughtcrime.securesms.profiles.ProfileName;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.CommunicationActions;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.ResearchMegaphone;
import org.thoughtcrime.securesms.util.PopulationFeatureFlags;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import java.util.LinkedHashMap;
@ -89,6 +90,7 @@ public final class Megaphones {
put(Event.LINK_PREVIEWS, shouldShowLinkPreviewsMegaphone(context) ? ALWAYS : NEVER);
put(Event.CLIENT_DEPRECATED, SignalStore.misc().isClientDeprecated() ? ALWAYS : NEVER);
put(Event.RESEARCH, shouldShowResearchMegaphone() ? ShowForDurationSchedule.showForDays(7) : NEVER);
put(Event.DONATE, shouldShowDonateMegaphone() ? ShowForDurationSchedule.showForDays(7) : NEVER);
}};
}
@ -108,6 +110,8 @@ public final class Megaphones {
return buildClientDeprecatedMegaphone(context);
case RESEARCH:
return buildResearchMegaphone(context);
case DONATE:
return buildDonateMegaphone(context);
default:
throw new IllegalArgumentException("Event not handled!");
}
@ -219,12 +223,31 @@ public final class Megaphones {
.build();
}
private static @NonNull Megaphone buildDonateMegaphone(@NonNull Context context) {
return new Megaphone.Builder(Event.DONATE, Megaphone.Style.BASIC)
.disableSnooze()
.setTitle(R.string.DonateMegaphone_donate_to_signal)
.setBody(R.string.DonateMegaphone_Signal_is_powered_by_people_like_you_show_your_support_today)
.setImage(R.drawable.ic_donate_megaphone)
.setActionButton(R.string.DonateMegaphone_donate, (megaphone, controller) -> {
controller.onMegaphoneCompleted(megaphone.getEvent());
CommunicationActions.openBrowserLink(controller.getMegaphoneActivity(), context.getString(R.string.donate_url));
})
.setSecondaryButton(R.string.DonateMegaphone_not_now, (megaphone, controller) -> controller.onMegaphoneCompleted(megaphone.getEvent()))
.setPriority(Megaphone.Priority.DEFAULT)
.build();
}
private static boolean shouldShowMessageRequestsMegaphone() {
return Recipient.self().getProfileName() == ProfileName.EMPTY;
}
private static boolean shouldShowResearchMegaphone() {
return ResearchMegaphone.isInResearchMegaphone();
return PopulationFeatureFlags.isInResearchMegaphone();
}
private static boolean shouldShowDonateMegaphone() {
return PopulationFeatureFlags.isInDonateMegaphone();
}
private static boolean shouldShowLinkPreviewsMegaphone(@NonNull Context context) {
@ -238,7 +261,8 @@ public final class Megaphones {
MESSAGE_REQUESTS("message_requests"),
LINK_PREVIEWS("link_previews"),
CLIENT_DEPRECATED("client_deprecated"),
RESEARCH("research");
RESEARCH("research"),
DONATE("donate");
private final String key;

Wyświetl plik

@ -60,6 +60,7 @@ public final class FeatureFlags {
private static final String PHONE_NUMBER_PRIVACY_VERSION = "android.phoneNumberPrivacyVersion";
private static final String CLIENT_EXPIRATION = "android.clientExpiration";
public static final String RESEARCH_MEGAPHONE_1 = "research.megaphone.1";
public static final String DONATE_MEGAPHONE = "android.donate";
private static final String VIEWED_RECEIPTS = "android.viewed.receipts";
private static final String MAX_ENVELOPE_SIZE = "android.maxEnvelopeSize";
private static final String GV1_AUTO_MIGRATE_VERSION = "android.groupsv2.autoMigrateVersion";
@ -82,6 +83,7 @@ public final class FeatureFlags {
VERIFY_V2,
CLIENT_EXPIRATION,
RESEARCH_MEGAPHONE_1,
DONATE_MEGAPHONE,
VIEWED_RECEIPTS,
MAX_ENVELOPE_SIZE,
GV1_AUTO_MIGRATE_VERSION,
@ -243,6 +245,11 @@ public final class FeatureFlags {
return getString(RESEARCH_MEGAPHONE_1, "");
}
/** The raw donate megaphone CSV string */
public static String donateMegaphone() {
return getString(DONATE_MEGAPHONE, "");
}
/**
* Whether the user can choose phone number privacy settings, and;
* Whether to fetch and store the secondary certificate

Wyświetl plik

@ -19,9 +19,9 @@ import java.util.Map;
* in the list. For example, "1:20000,*:40000" would mean 2% of the NANPA phone numbers and 4% of the rest of
* the world should see the megaphone.
*/
public final class ResearchMegaphone {
public final class PopulationFeatureFlags {
private static final String TAG = Log.tag(ResearchMegaphone.class);
private static final String TAG = Log.tag(PopulationFeatureFlags.class);
private static final String COUNTRY_WILDCARD = "*";
@ -29,7 +29,18 @@ public final class ResearchMegaphone {
* In research megaphone group for given country code
*/
public static boolean isInResearchMegaphone() {
Map<String, Integer> countryCountEnabled = parseCountryCounts(FeatureFlags.researchMegaphone());
return isEnabled(FeatureFlags.RESEARCH_MEGAPHONE_1, FeatureFlags.researchMegaphone());
}
/**
* In donate megaphone group for given country code
*/
public static boolean isInDonateMegaphone() {
return isEnabled(FeatureFlags.DONATE_MEGAPHONE, FeatureFlags.donateMegaphone());
}
private static boolean isEnabled(@NonNull String flag, @NonNull String serialized) {
Map<String, Integer> countryCountEnabled = parseCountryCounts(serialized);
Recipient self = Recipient.self();
if (countryCountEnabled.isEmpty() || !self.getE164().isPresent() || !self.getUuid().isPresent()) {
@ -37,7 +48,7 @@ public final class ResearchMegaphone {
}
long countEnabled = determineCountEnabled(countryCountEnabled, self.getE164().or(""));
long currentUserBucket = BucketingUtil.bucket(FeatureFlags.RESEARCH_MEGAPHONE_1, self.requireUuid(), 1_000_000);
long currentUserBucket = BucketingUtil.bucket(flag, self.requireUuid(), 1_000_000);
return countEnabled > currentUserBucket;
}

Wyświetl plik

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="64dp"
android:height="64dp"
android:viewportWidth="64"
android:viewportHeight="64">
<path
android:pathData="M32,0L32,0A32,32 0,0 1,64 32L64,32A32,32 0,0 1,32 64L32,64A32,32 0,0 1,0 32L0,32A32,32 0,0 1,32 0z"
android:fillColor="#F9F9F9"/>
<path
android:pathData="M22.1523,45.341C20.9919,44.105 19.8347,42.7715 18.7433,41.3631L20.2926,40.241C21.3746,41.6331 22.4879,42.9211 23.5762,44.0595L23.6263,44.1115L22.1523,45.341ZM28.5502,48.8017C27.4117,47.8259 26.1479,46.655 24.8526,45.3605L23.4852,46.7038C24.7805,48.0048 26.0506,49.1725 27.1953,50.1742L28.5502,48.8017ZM40.5085,46.7363L39.1411,45.393C37.8427,46.694 36.5757,47.8487 35.4404,48.8342L36.7953,50.2035C37.9274,49.205 39.1944,48.0406 40.496,46.7363H40.5085ZM19.2764,38.8652C18.2917,37.5112 17.4078,36.0814 16.6326,34.5881L14.9579,35.4923C15.7412,37.0154 16.6333,38.4755 17.6268,39.8604L19.2764,38.8652ZM12.5556,26.0599L14.4373,26.0827C14.5018,24.337 15.001,22.6383 15.8862,21.1519L14.2961,20.1533C13.2281,21.9306 12.628,23.9671 12.5556,26.0599ZM47.3454,34.6271C46.5727,36.1187 45.692,37.5474 44.711,38.9009L46.345,39.8962C47.339,38.5115 48.2332,37.0526 49.0202,35.5313L47.3454,34.6271ZM15.8956,33.0009C15.1768,31.3724 14.708,29.6373 14.5063,27.8586L12.6246,27.9854C12.8372,29.9852 13.3548,31.9372 14.1582,33.7685L15.8956,33.0009ZM43.6792,40.2735C42.6066,41.6493 41.4839,42.9243 40.4238,44.053L40.3392,44.1408L41.8163,45.367C42.9767,44.1343 44.1371,42.8007 45.2285,41.3924L43.6792,40.2735ZM16.8772,19.7826C17.9591,18.5078 19.324,17.5255 20.8539,16.9203L20.2643,15.0794C18.3752,15.8248 16.6956,17.0479 15.3781,18.6377L16.8772,19.7826ZM22.4377,16.4585C22.9547,16.3564 23.4796,16.3041 24.0058,16.3023C25.1357,16.2823 26.26,16.4695 27.3271,16.8553L28.1111,15.0729C26.7963,14.5715 25.4034,14.3267 24.0027,14.3508C23.3403,14.3531 22.6797,14.4217 22.03,14.5557L22.4377,16.4585ZM49.4906,27.8944C49.2836,29.6767 48.8106,31.4148 48.0887,33.0464L49.8262,33.8075C50.6319,31.9719 51.1526,30.0157 51.3692,28.0115L49.4906,27.8944ZM34.1232,49.9466C33.2764,50.6458 32.5551,51.2183 32.0094,51.6314C31.4606,51.2118 30.7204,50.6296 29.858,49.9173L28.6223,51.3939C30.6295,53.056 32,54.0317 32,54.0317C32,54.0317 33.3548,53.0787 35.3526,51.4297L34.1232,49.9466ZM28.8168,17.6034C29.5097,18.0438 30.1654,18.5443 30.7769,19.0995L32,20.1729L33.2231,19.0865C33.8295,18.5513 34.4898,18.0857 35.1927,17.6977L34.2518,16.0096C33.4498,16.4582 32.6951,16.9924 32,17.6034C31.3032,16.9692 30.5539,16.4 29.7608,15.9023L28.8168,17.6034ZM48.2612,21.0836C49.0835,22.6283 49.5302,24.3576 49.5627,26.1217L51.4445,26.099C51.4084,23.9836 50.8698,21.9102 49.8764,20.0623L48.2612,21.0836ZM36.7043,16.9919C37.7807,16.5599 38.9217,16.3265 40.0757,16.3023C40.5679,16.3018 41.0594,16.3377 41.5466,16.4097L41.9574,14.5004C41.3348,14.4009 40.7057,14.3509 40.0757,14.3508C38.6464,14.3755 37.2331,14.6687 35.9046,15.216L36.7043,16.9919ZM43.1774,16.7935C44.5502,17.2395 45.7998,18.0202 46.8217,19.0703C46.9973,19.2556 47.1604,19.4475 47.3203,19.6427L48.8445,18.4881C47.5141,16.8215 45.7476,15.5892 43.7576,14.9395L43.1774,16.7935ZM39.7621,18.2539C36.7043,18.2539 33.2545,20.7421 32,23.4579C30.7455,20.7421 27.2957,18.2539 24.2379,18.2539C22.129,18.2702 20.112,19.1518 18.6281,20.7061C17.1442,22.2603 16.314,24.3606 16.319,26.5478C16.319,37.5251 32,49.1529 32,49.1529C32,49.1529 47.681,37.5251 47.681,26.5478C47.686,24.3606 46.8558,22.2603 45.3719,20.7061C43.888,19.1518 41.871,18.2702 39.7621,18.2539Z"
android:fillColor="#CC163D"/>
</vector>

Wyświetl plik

@ -473,6 +473,13 @@
<!-- DocumentView -->
<string name="DocumentView_unnamed_file">Unnamed file</string>
<!-- DonateMegaphone -->
<string name="DonateMegaphone_donate_to_signal">Donate to Signal</string>
<string name="DonateMegaphone_Signal_is_powered_by_people_like_you_show_your_support_today">Signal is powered by people like you. Show your support today!</string>
<string name="DonateMegaphone_donate">Donate</string>
<string name="DonateMegaphone_not_now">Not Now</string>
<!-- DozeReminder -->
<string name="DozeReminder_optimize_for_missing_play_services">Optimize for missing Play Services</string>
<string name="DozeReminder_this_device_does_not_support_play_services_tap_to_disable_system_battery">This device does not support Play Services. Tap to disable system battery optimizations that prevent Signal from retrieving messages while inactive.</string>

Wyświetl plik

@ -2,8 +2,6 @@ package org.thoughtcrime.securesms.util;
import androidx.annotation.NonNull;
import com.google.protobuf.Empty;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -19,7 +17,7 @@ import java.util.Map;
import static org.junit.Assert.*;
@RunWith(Parameterized.class)
public class ResearchMegaphoneTest_determineCountEnabled {
public class PopulationFeatureFlagsTest_determineCountEnabled {
private final String phoneNumber;
private final Map<String, Integer> countryCounts;
@ -68,9 +66,9 @@ public class ResearchMegaphoneTest_determineCountEnabled {
Log.initialize(new EmptyLogger());
}
public ResearchMegaphoneTest_determineCountEnabled(@NonNull String phoneNumber,
@NonNull Map<String, Integer> countryCounts,
long output)
public PopulationFeatureFlagsTest_determineCountEnabled(@NonNull String phoneNumber,
@NonNull Map<String, Integer> countryCounts,
long output)
{
this.phoneNumber = phoneNumber;
this.countryCounts = countryCounts;
@ -79,7 +77,7 @@ public class ResearchMegaphoneTest_determineCountEnabled {
@Test
public void determineCountEnabled() {
assertEquals(output, ResearchMegaphone.determineCountEnabled(countryCounts, phoneNumber));
assertEquals(output, PopulationFeatureFlags.determineCountEnabled(countryCounts, phoneNumber));
}
}

Wyświetl plik

@ -12,7 +12,7 @@ import java.util.Map;
import static org.junit.Assert.assertEquals;
@RunWith(Parameterized.class)
public class ResearchMegaphoneTest_parseCountryCounts {
public class PopulationFeatureFlagsTest_parseCountryCounts {
private final String input;
private final Map<String, Integer> output;
@ -46,14 +46,14 @@ public class ResearchMegaphoneTest_parseCountryCounts {
});
}
public ResearchMegaphoneTest_parseCountryCounts(String input, Map<String, Integer> output) {
public PopulationFeatureFlagsTest_parseCountryCounts(String input, Map<String, Integer> output) {
this.input = input;
this.output = output;
}
@Test
public void parseCountryCounts() {
assertEquals(output, ResearchMegaphone.parseCountryCounts(input));
assertEquals(output, PopulationFeatureFlags.parseCountryCounts(input));
}
}