From fd65b22301fda2ba25e9466b89c573a4943982b0 Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Mon, 12 Mar 2018 01:09:07 +0300 Subject: [PATCH] IDEA-186881 Improve Data Sharing options dialog --- .../ide/actions/DataSharingOptionsAction.java | 34 ---- .../ide/gdpr/ConsentConfigurable.java | 28 +++ .../com/intellij/ide/gdpr/ConsentOptions.java | 2 +- .../intellij/ide/gdpr/ConsentSettingsUi.java | 178 ++++++++++++++++++ .../src/com/intellij/ui/AppUIUtil.java | 168 ++++------------- .../src/META-INF/PlatformExtensions.xml | 1 + .../src/idea/PlatformActions.xml | 1 - .../com/intellij/ide/gdpr/ConsentsTest.java | 35 ++-- 8 files changed, 265 insertions(+), 182 deletions(-) delete mode 100644 platform/platform-impl/src/com/intellij/ide/actions/DataSharingOptionsAction.java create mode 100644 platform/platform-impl/src/com/intellij/ide/gdpr/ConsentConfigurable.java create mode 100644 platform/platform-impl/src/com/intellij/ide/gdpr/ConsentSettingsUi.java diff --git a/platform/platform-impl/src/com/intellij/ide/actions/DataSharingOptionsAction.java b/platform/platform-impl/src/com/intellij/ide/actions/DataSharingOptionsAction.java deleted file mode 100644 index 819460a0c29f..000000000000 --- a/platform/platform-impl/src/com/intellij/ide/actions/DataSharingOptionsAction.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ -package com.intellij.ide.actions; - -import com.intellij.ide.gdpr.Consent; -import com.intellij.ide.gdpr.ConsentOptions; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.project.DumbAwareAction; -import com.intellij.openapi.util.Pair; -import com.intellij.ui.AppUIUtil; - -import java.util.Collection; - -public class DataSharingOptionsAction extends DumbAwareAction { - public DataSharingOptionsAction() { - super("Data Sharing Options...", "Data Sharing Options", null); - } - - @Override - public void actionPerformed(AnActionEvent e) { - final Pair, Boolean> consentsToShow = ConsentOptions.getInstance().getConsents(); - try { - final Collection result = AppUIUtil.confirmConsentOptions(consentsToShow.first); - if (result != null) { - ConsentOptions.getInstance().setConsents(result); - } - } - catch (Exception ex) { - Logger.getInstance(DataSharingOptionsAction.class).warn(ex); - } - } -} diff --git a/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentConfigurable.java b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentConfigurable.java new file mode 100644 index 000000000000..dd00333af948 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentConfigurable.java @@ -0,0 +1,28 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.ide.gdpr; + +import com.intellij.openapi.options.ConfigurableBase; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public class ConsentConfigurable extends ConfigurableBase> { + private final List myConsents; + + public ConsentConfigurable() { + super("consents", "Analytics", null); + myConsents = new ArrayList<>(ConsentOptions.getInstance().getConsents().first); + } + + @NotNull + @Override + protected List getSettings() { + return myConsents; + } + + @Override + protected ConsentSettingsUi createUi() { + return new ConsentSettingsUi(true); + } +} diff --git a/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java index 31d5e5fd00b0..5dbf51957a71 100644 --- a/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java +++ b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentOptions.java @@ -151,7 +151,7 @@ public final class ConsentOptions { } } - public Pair, Boolean> getConsents() { + public Pair, Boolean> getConsents() { final Map allDefaults = loadDefaultConsents(); if (allDefaults.isEmpty()) { return Pair.create(Collections.emptyList(), Boolean.FALSE); diff --git a/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentSettingsUi.java b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentSettingsUi.java new file mode 100644 index 000000000000..beda765a1013 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/gdpr/ConsentSettingsUi.java @@ -0,0 +1,178 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.ide.gdpr; + +import com.intellij.ide.BrowserUtil; +import com.intellij.openapi.options.ConfigurableUi; +import com.intellij.openapi.options.ShowSettingsUtil; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.HyperlinkAdapter; +import com.intellij.ui.JBColor; +import com.intellij.ui.components.JBCheckBox; +import com.intellij.ui.components.JBLabel; +import com.intellij.ui.components.JBScrollPane; +import com.intellij.util.ui.JBUI; +import com.intellij.util.ui.SwingHelper; +import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import javax.swing.event.HyperlinkEvent; +import javax.swing.text.DefaultCaret; +import javax.swing.text.html.HTMLDocument; +import javax.swing.text.html.StyleSheet; +import java.awt.*; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; +import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; + +public class ConsentSettingsUi extends JPanel implements ConfigurableUi> { + final Collection> consentMapping = new ArrayList<>(); + private final boolean myPreferencesMode; + + public ConsentSettingsUi(boolean preferencesMode) { + myPreferencesMode = preferencesMode; + setLayout(new GridLayout(1, 1)); + } + + @Override + public void reset(@NotNull List consents) { + consentMapping.clear(); + if (consents.isEmpty()) { + JLabel label = new JLabel("There are no data-sharing options available", SwingConstants.CENTER); + label.setVerticalAlignment(SwingConstants.CENTER); + label.setOpaque(true); + label.setBackground(JBColor.background()); + removeAll(); + add(label); + return; + } + final JPanel body = new JPanel(new GridBagLayout()); + + boolean addCheckBox = myPreferencesMode || consents.size() > 1; + for (Iterator it = consents.iterator(); it.hasNext(); ) { + final Consent consent = it.next(); + final JComponent comp = createConsentElement(consent, addCheckBox); + boolean lastConsent = !it.hasNext(); + if (lastConsent) { + body.setBackground(comp.getBackground()); + } else { + comp.setBorder(JBUI.Borders.emptyBottom(15)); + } + body.add(comp, new GridBagConstraints( + 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, lastConsent && myPreferencesMode ? 1.0 : 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.insets(10, 0, 0, 0), 0, 0) + ); + } + if (!myPreferencesMode) { + JLabel hintLabel = new JBLabel("You can always change this behavior in " + ShowSettingsUtil.getSettingsMenuName() + " | Appearance & Behavior | System Settings | Analytics."); + hintLabel.setEnabled(false); + hintLabel.setVerticalAlignment(SwingConstants.TOP); + hintLabel.setFont(JBUI.Fonts.smallFont()); + //noinspection UseDPIAwareInsets + body.add(hintLabel, new GridBagConstraints( + 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, + new Insets(JBUI.scale(16), addCheckBox ? UIUtil.getCheckBoxTextHorizontalOffset(new JCheckBox()) : JBUI.scale(10), JBUI.scale(10), 0), 0, 0) + ); + } + body.setBorder(JBUI.Borders.empty(10)); + removeAll(); + add(new JBScrollPane(body, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED)); + } + + @NotNull + private JComponent createConsentElement(Consent consent, boolean addCheckBox) { + //TODO: refactor DocumentationComponent to use external link marker here, there and everywhere + final JEditorPane viewer = SwingHelper.createHtmlViewer(true, null, JBColor.WHITE, JBColor.BLACK); + viewer.setFocusable(false); + viewer.setCaret(new DefaultCaret(){ + @Override + protected void adjustVisibility(Rectangle nloc) { + //do nothing to avoid autoscroll + } + }); + viewer.addHyperlinkListener(new HyperlinkAdapter() { + @Override + protected void hyperlinkActivated(HyperlinkEvent e) { + final URL url = e.getURL(); + if (url != null) { + BrowserUtil.browse(url); + } + } + }); + viewer.setText("" + StringUtil.replace(consent.getText(), "\n", "
") + ""); + StyleSheet styleSheet = ((HTMLDocument)viewer.getDocument()).getStyleSheet(); + //styleSheet.addRule("body {font-family: \"Segoe UI\", Tahoma, sans-serif;}"); + styleSheet.addRule("body {margin-top:0;padding-top:0;}"); + //styleSheet.addRule("body {font-size:" + JBUI.scaleFontSize(13) + "pt;}"); + styleSheet.addRule("h2, em {margin-top:" + JBUI.scaleFontSize(20) + "pt;}"); + styleSheet.addRule("h1, h2, h3, p, h4, em {margin-bottom:0;padding-bottom:0;}"); + styleSheet.addRule("p, h1 {margin-top:0;padding-top:"+JBUI.scaleFontSize(6)+"pt;}"); + styleSheet.addRule("li {margin-bottom:" + JBUI.scaleFontSize(6) + "pt;}"); + styleSheet.addRule("h2 {margin-top:0;padding-top:"+JBUI.scaleFontSize(13)+"pt;}"); + viewer.setCaretPosition(0); + + final JPanel pane = new JPanel(new BorderLayout()); + pane.setBackground(viewer.getBackground()); + int leftInset = JBUI.scale(10); + if (addCheckBox) { + final JCheckBox cb = new JBCheckBox(consent.getName(), consent.isAccepted()); + cb.setBackground(viewer.getBackground()); + cb.setFont(cb.getFont().deriveFont(Font.BOLD)); + leftInset = UIUtil.getCheckBoxTextHorizontalOffset(cb); + consentMapping.add(Pair.create(cb, consent)); + pane.add(cb, BorderLayout.NORTH); + } else { + consentMapping.add(Pair.create(null, consent)); + } + //noinspection UseDPIAwareBorders + viewer.setBorder(new EmptyBorder(addCheckBox ? 0 : JBUI.scale(5), leftInset, 0, 0)); + pane.add(viewer, BorderLayout.CENTER); + return pane; + } + + @NotNull + private List getState() { + final List result = new ArrayList<>(); + for (Pair pair : consentMapping) { + JCheckBox checkBox = pair.first; + result.add(pair.second.derive(checkBox == null || checkBox.isSelected())); + } + return result; + } + + + @Override + public boolean isModified(@NotNull List consents) { + List state = getState(); + if (consents.size() != state.size()) return true; + for (int i = 0; i < state.size(); i++) { + Consent consent1 = state.get(i); + Consent consent2 = consents.get(i); + if (!consent1.equals(consent2)) return true; + if (consent1.isAccepted() != consent2.isAccepted()) return true; + } + + return false; + } + + @Override + public void apply(@NotNull List consents) { + consents.clear(); + consents.addAll(getState()); + if (myPreferencesMode) { + ConsentOptions.getInstance().setConsents(consents); + } + } + + @NotNull + @Override + public JComponent getComponent() { + return this; + } +} diff --git a/platform/platform-impl/src/com/intellij/ui/AppUIUtil.java b/platform/platform-impl/src/com/intellij/ui/AppUIUtil.java index 5a136a990067..8c9fb993448b 100644 --- a/platform/platform-impl/src/com/intellij/ui/AppUIUtil.java +++ b/platform/platform-impl/src/com/intellij/ui/AppUIUtil.java @@ -18,6 +18,7 @@ package com.intellij.ui; import com.intellij.ide.BrowserUtil; import com.intellij.ide.gdpr.Consent; import com.intellij.ide.gdpr.ConsentOptions; +import com.intellij.ide.gdpr.ConsentSettingsUi; import com.intellij.ide.gdpr.EndUserAgreement; import com.intellij.idea.Main; import com.intellij.openapi.application.Application; @@ -36,10 +37,9 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.openapi.wm.ex.WindowManagerEx; import com.intellij.ui.AppIcon.MacAppIcon; -import com.intellij.ui.components.JBCheckBox; import com.intellij.ui.components.JBScrollPane; import com.intellij.util.*; import com.intellij.util.containers.ContainerUtil; @@ -54,25 +54,23 @@ import sun.awt.AWTAccessor; import javax.swing.*; import javax.swing.border.Border; -import javax.swing.border.EmptyBorder; import javax.swing.event.HyperlinkEvent; -import javax.swing.plaf.ButtonUI; -import javax.swing.plaf.basic.BasicRadioButtonUI; -import javax.swing.plaf.synth.SynthCheckBoxUI; -import javax.swing.plaf.synth.SynthContext; -import javax.swing.text.DefaultCaret; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.StyleSheet; import java.awt.*; +import java.awt.event.ActionEvent; import java.awt.event.AdjustmentEvent; import java.awt.event.AdjustmentListener; import java.io.File; import java.io.InputStream; import java.net.URL; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.Locale; -import static javax.swing.ScrollPaneConstants.*; +import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER; +import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; /** * @author yole @@ -266,7 +264,7 @@ public class AppUIUtil { Logger.getInstance(AppUIUtil.class).warn(e); } } - final Pair, Boolean> consentsToShow = ConsentOptions.getInstance().getConsents(); + final Pair, Boolean> consentsToShow = ConsentOptions.getInstance().getConsents(); if (consentsToShow.second) { try { final Ref> result = Ref.create(null); @@ -366,11 +364,12 @@ public class AppUIUtil { dialog.show(); } - // todo: need a separate action to view and change state of all consets on demand - - public static Collection confirmConsentOptions(@NotNull Collection consents) { - final Collection> consentMapping = new ArrayList<>(); - final DialogWrapper dialog = new DialogWrapper(true) { + @Nullable + public static List confirmConsentOptions(@NotNull List consents) { + if (consents.isEmpty()) return null; + + ConsentSettingsUi ui = new ConsentSettingsUi(false); + final DialogWrapper dialog = new DialogWrapper(WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow(), true) { @Nullable @Override protected Border createContentPaneBorder() { @@ -389,89 +388,24 @@ public class AppUIUtil { @Override protected JComponent createCenterPanel() { - - if (consents.isEmpty()) { - JLabel label = new JLabel("There are no data-sharing options available", SwingConstants.CENTER); - label.setVerticalAlignment(SwingConstants.CENTER); - label.setOpaque(true); - label.setBackground(JBColor.background()); - return label; - } - final JPanel body = new JPanel(new GridBagLayout()); - - //noinspection UseDPIAwareInsets - body.add(new JLabel("Please review your options regarding sharing your data with " + ApplicationInfoImpl.getShadowInstance().getShortCompanyName() + ":"), - new GridBagConstraints( - 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, - new Insets(JBUI.scale(10), getLeftTextMargin(new JCheckBox()), JBUI.scale(10), 0), 0, 0)); - for (Iterator it = consents.iterator(); it.hasNext(); ) { - final Consent consent = it.next(); - final JComponent comp = createConsentElement(consent); - boolean lastConsent = !it.hasNext(); - if (lastConsent) { - body.setBackground(comp.getBackground()); - } else { - comp.setBorder(JBUI.Borders.emptyBottom(15)); - } - body.add(comp, new GridBagConstraints( - 0, GridBagConstraints.RELATIVE, 1, 1, 1.0, lastConsent ? 1.0 : 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.insets(10, 0, 0, 0), 0, 0) - ); - } - body.setBorder(JBUI.Borders.empty(10)); - return new JBScrollPane(body, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED); + return ui.getComponent(); } @NotNull - private JComponent createConsentElement(Consent consent) { - final JEditorPane viewer = SwingHelper.createHtmlViewer(true, null, JBColor.WHITE, JBColor.BLACK); - viewer.setFocusable(false); - viewer.setCaret(new DefaultCaret(){ + @Override + protected Action[] createActions() { + if (consents.size() > 1) { + return super.createActions(); + } + setOKButtonText(consents.iterator().next().getName()); + return new Action[]{getOKAction(), new DialogWrapperAction("Don't send") { @Override - protected void adjustVisibility(Rectangle nloc) { - //do nothing to avoid autoscroll + protected void doAction(ActionEvent e) { + close(NEXT_USER_EXIT_CODE); } - }); - viewer.addHyperlinkListener(new HyperlinkAdapter() { - @Override - protected void hyperlinkActivated(HyperlinkEvent e) { - final URL url = e.getURL(); - if (url != null) { - BrowserUtil.browse(url); - } - } - }); - viewer.setText(consentTextToHtml(consent.getText())); - StyleSheet styleSheet = ((HTMLDocument)viewer.getDocument()).getStyleSheet(); - //styleSheet.addRule("body {font-family: \"Segoe UI\", Tahoma, sans-serif;}"); - styleSheet.addRule("body {margin-top:0;padding-top:0;}"); - //styleSheet.addRule("body {font-size:" + JBUI.scaleFontSize(13) + "pt;}"); - styleSheet.addRule("h2, em {margin-top:" + JBUI.scaleFontSize(20) + "pt;}"); - styleSheet.addRule("h1, h2, h3, p, h4, em {margin-bottom:0;padding-bottom:0;}"); - styleSheet.addRule("p, h1 {margin-top:0;padding-top:"+JBUI.scaleFontSize(6)+"pt;}"); - styleSheet.addRule("li {margin-bottom:" + JBUI.scaleFontSize(6) + "pt;}"); - styleSheet.addRule("h2 {margin-top:0;padding-top:"+JBUI.scaleFontSize(13)+"pt;}"); - viewer.setCaretPosition(0); - - final JCheckBox cb = new JBCheckBox(consent.getName(), consent.isAccepted()); - cb.setBackground(viewer.getBackground()); - cb.setFont(cb.getFont().deriveFont(Font.BOLD)); - int leftInset = getLeftTextMargin(cb); - //noinspection UseDPIAwareBorders - viewer.setBorder(new EmptyBorder(JBUI.scale(5), leftInset, 0, 0)); - - final JPanel pane = new JPanel(new BorderLayout()); - pane.setBackground(viewer.getBackground()); - pane.add(cb, BorderLayout.NORTH); - pane.add(viewer, BorderLayout.CENTER); - consentMapping.add(Pair.create(cb, consent)); - return pane; + }}; } - @NotNull - private String consentTextToHtml(String text) { - return "" + StringUtil.replace(text, "\n", "
") + ""; - } - @Override protected void createDefaultActions() { super.createDefaultActions(); @@ -480,22 +414,25 @@ public class AppUIUtil { } }; + ui.reset(consents); dialog.setModal(true); - dialog.setTitle("Data Sharing Options"); - dialog.setSize(JBUI.scale(600), JBUI.scale(400)); + dialog.setTitle("Analytics"); + dialog.pack(); + dialog.setSize(JBUI.scale(600), dialog.getWindow().getHeight() * 4 / 3); + //dialog.setSize(JBUI.scale(600), JBUI.scale(400)); dialog.show(); - final Collection result; - if (dialog.isOK()) { - result = new ArrayList<>(); - for (Pair pair : consentMapping) { - result.add(pair.second.derive(pair.first.isSelected())); - } + int exitCode = dialog.getExitCode(); + if (exitCode == DialogWrapper.CANCEL_EXIT_CODE) { + return null; //Don't save any changes in this case: user hasn't made a choice } - else { - // no changes were made, save as-is - result = consents; + if (consents.size() == 1) { + consents.set(0, consents.get(0).derive(exitCode == DialogWrapper.OK_EXIT_CODE)); + return consents; } + + List result = new ArrayList<>(); + ui.apply(result); return result; } @@ -521,29 +458,4 @@ public class AppUIUtil { GraphicsConfiguration gc = target != null ? target.getGraphicsConfiguration() : null; AWTAccessor.getComponentAccessor().setGraphicsConfiguration(comp, gc); } - - /** - * Returns distance (px) from the left edge to actual text position for specified checkbox. - * It may be used as left margin when you need to align text in a label located above or below the checkbox - */ - public static int getLeftTextMargin(@NotNull JCheckBox checkBox) { - int leftMargin = 0; - Insets margin = checkBox.getMargin(); - if (margin != null) leftMargin += margin.left; - Border border = checkBox.getBorder(); - if (border != null) leftMargin += border.getBorderInsets(checkBox).left; - ButtonUI ui = checkBox.getUI(); - Icon icon = null; - if (ui instanceof BasicRadioButtonUI) { - icon = ((BasicRadioButtonUI)ui).getDefaultIcon(); - } else if (ui instanceof SynthCheckBoxUI){ - SynthCheckBoxUI sui = (SynthCheckBoxUI)ui; - SynthContext context = sui.getContext(checkBox); - icon = context.getStyle().getIcon(context, "CheckBox.icon"); - } - if (icon != null) { - leftMargin += icon.getIconWidth() + checkBox.getIconTextGap(); - } - return leftMargin; - } } \ No newline at end of file diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index da4095423a26..6e4127605a12 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -322,6 +322,7 @@ + diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index a3fe763586ce..5e8129dd104e 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -558,7 +558,6 @@ - diff --git a/platform/platform-tests/testSrc/com/intellij/ide/gdpr/ConsentsTest.java b/platform/platform-tests/testSrc/com/intellij/ide/gdpr/ConsentsTest.java index 67f940f09928..89bad5ed880f 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/gdpr/ConsentsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ide/gdpr/ConsentsTest.java @@ -9,7 +9,6 @@ import junit.framework.TestCase; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Collection; import java.util.List; /** @@ -35,7 +34,7 @@ public class ConsentsTest extends TestCase{ final ConsentOptions options = data.first; final MemoryIOBackend storage = data.second; - final Pair, Boolean> beforeConfirm = options.getConsents(); + final Pair, Boolean> beforeConfirm = options.getConsents(); assertTrue("Consents should require confirmation", beforeConfirm.second); assertEquals(2, beforeConfirm.first.size()); checkStorage(storage, JSON_CONSENTS_DATA, "", ""); @@ -50,7 +49,7 @@ public class ConsentsTest extends TestCase{ options.setConsents(beforeConfirm.first); { - final Pair, Boolean> afterConfirm = options.getConsents(); + final Pair, Boolean> afterConfirm = options.getConsents(); assertFalse("Consents should NOT require confirmation", afterConfirm.second); final Consent consentAfterCorfirm = lookupConsent(CONSENT_ID_1, afterConfirm.first); assertNotNull(consentAfterCorfirm); @@ -63,7 +62,7 @@ public class ConsentsTest extends TestCase{ Thread.sleep(1L);// ensure timestamp changes options.applyServerUpdates(createUpgradeJson(CONSENT_ID_1, newAcceptedState)); { - final Pair, Boolean> afterUpgrade = options.getConsents(); + final Pair, Boolean> afterUpgrade = options.getConsents(); assertFalse("Consents should NOT require confirmation", afterUpgrade.second); // no confirmation on minor updates required final Consent consentAfterUpgrade = lookupConsent(CONSENT_ID_1, afterUpgrade.first); assertNotNull(consentAfterUpgrade); @@ -77,7 +76,7 @@ public class ConsentsTest extends TestCase{ final ConsentOptions options = data.first; final MemoryIOBackend storage = data.second; - final Pair, Boolean> beforeConfirm = options.getConsents(); + final Pair, Boolean> beforeConfirm = options.getConsents(); assertTrue("Consents should require confirmation", beforeConfirm.second); assertEquals(2, beforeConfirm.first.size()); checkStorage(storage, JSON_CONSENTS_DATA, "", ""); @@ -86,7 +85,7 @@ public class ConsentsTest extends TestCase{ assertEquals(Version.fromString("1.0"), consentBeforeUpgrade.getVersion()); options.setConsents(beforeConfirm.first); - final Pair, Boolean> afterConfirm = options.getConsents(); + final Pair, Boolean> afterConfirm = options.getConsents(); assertFalse("Consents should NOT require confirmation", afterConfirm.second); assertEquals(2, afterConfirm.first.size()); assertEquals(JSON_CONSENTS_DATA, storage.myBundled); @@ -95,7 +94,7 @@ public class ConsentsTest extends TestCase{ options.applyServerUpdates(JSON_MINOR_UPGRADE_CONSENTS_DATA); - final Pair, Boolean> afterUpdate = options.getConsents(); + final Pair, Boolean> afterUpdate = options.getConsents(); assertFalse("Consents should NOT require confirmation", afterUpdate.second); assertEquals(2, afterUpdate.first.size()); assertEquals(JSON_CONSENTS_DATA, storage.myBundled); @@ -112,7 +111,7 @@ public class ConsentsTest extends TestCase{ final MemoryIOBackend storage = data.second; { - final Pair, Boolean> beforeConfirm = options.getConsents(); + final Pair, Boolean> beforeConfirm = options.getConsents(); assertTrue("Consents should require confirmation", beforeConfirm.second); assertEquals(2, beforeConfirm.first.size()); checkStorage(storage, JSON_CONSENTS_DATA, "", ""); @@ -128,7 +127,7 @@ public class ConsentsTest extends TestCase{ // after-confirmation state { - final Pair, Boolean> afterConfirm = options.getConsents(); + final Pair, Boolean> afterConfirm = options.getConsents(); assertFalse("Consents should NOT require confirmation", afterConfirm.second); assertEquals(2, afterConfirm.first.size()); assertEquals(JSON_CONSENTS_DATA, storage.myBundled); @@ -140,7 +139,7 @@ public class ConsentsTest extends TestCase{ // updates from server { options.applyServerUpdates(JSON_MAJOR_UPGRADE_CONSENTS_DATA); - final Pair, Boolean> afterUpdate = options.getConsents(); + final Pair, Boolean> afterUpdate = options.getConsents(); assertTrue("Consents should require confirmation", afterUpdate.second); assertEquals(2, afterUpdate.first.size()); assertEquals(JSON_CONSENTS_DATA, storage.myBundled); @@ -166,7 +165,7 @@ public class ConsentsTest extends TestCase{ } { - final Pair, Boolean> afterSecondConfirm = options.getConsents(); + final Pair, Boolean> afterSecondConfirm = options.getConsents(); assertFalse("Consents should NOT require confirmation", afterSecondConfirm.second); assertEquals(2, afterSecondConfirm.first.size()); assertEquals(JSON_CONSENTS_DATA, storage.myBundled); @@ -185,7 +184,7 @@ public class ConsentsTest extends TestCase{ final ConsentOptions options = data.first; final MemoryIOBackend storage = data.second; - final Pair, Boolean> beforeConfirm = options.getConsents(); + final Pair, Boolean> beforeConfirm = options.getConsents(); assertTrue("Consents should require confirmation", beforeConfirm.second); assertEquals(2, beforeConfirm.first.size()); assertEquals(JSON_CONSENTS_DATA, storage.myDefaults); @@ -195,7 +194,7 @@ public class ConsentsTest extends TestCase{ assertEquals(ConsentOptions.Permission.UNDEFINED, options.isSendingUsageStatsAllowed()); options.setConsents(beforeConfirm.first); - final Pair, Boolean> afterConfirm = options.getConsents(); + final Pair, Boolean> afterConfirm = options.getConsents(); assertFalse("Consents should NOT require confirmation", afterConfirm.second); assertEquals(2, afterConfirm.first.size()); assertEquals("", storage.myBundled); @@ -209,7 +208,7 @@ public class ConsentsTest extends TestCase{ final ConsentOptions options = data.first; final MemoryIOBackend storage = data.second; - final Pair, Boolean> consents = options.getConsents(); + final Pair, Boolean> consents = options.getConsents(); assertTrue("Consents should require confirmation", consents.second); assertEquals(1, consents.first.size()); assertEquals(JSON_DELETED_CONSENTS_DATA, storage.myDefaults); @@ -224,7 +223,7 @@ public class ConsentsTest extends TestCase{ final ConsentOptions options = data.first; final MemoryIOBackend storage = data.second; - final Pair, Boolean> beforeConfirm = options.getConsents(); + final Pair, Boolean> beforeConfirm = options.getConsents(); assertTrue("Consents should require confirmation", beforeConfirm.second); assertEquals(2, beforeConfirm.first.size()); assertEquals("", storage.myBundled); @@ -237,7 +236,7 @@ public class ConsentsTest extends TestCase{ } options.setConsents(changedByUser); - final Pair, Boolean> afterConfirm = options.getConsents(); + final Pair, Boolean> afterConfirm = options.getConsents(); assertFalse("Consents should NOT require confirmation", afterConfirm.second); assertEquals(2, afterConfirm.first.size()); assertEquals("", storage.myBundled); @@ -251,7 +250,7 @@ public class ConsentsTest extends TestCase{ } } - private static Consent lookupConsent(@NotNull String consentId, @NotNull Collection container) { + private static Consent lookupConsent(@NotNull String consentId, @NotNull List container) { for (Consent c : container) { if (consentId.equals(c.getId())) { return c; @@ -260,7 +259,7 @@ public class ConsentsTest extends TestCase{ return null; } - private static Consent lookupConsent(@NotNull Consent consent, @NotNull Collection container) { + private static Consent lookupConsent(@NotNull Consent consent, @NotNull List container) { for (Consent c : container) { if (c.equals(consent)) { return c;