Browse Source

REPORT-29722【组件复用插件】@harrison,社区的小红点,不装插件也有,需要处理

修改一下菜单的逻辑。 默认是已读状态,只有加入了非已读的按钮,才会展示成非已读状态
feature/big-screen
Harrison 5 years ago
parent
commit
552e3f4d00
  1. 28
      designer-base/src/main/java/com/fr/design/menu/SnapChatMenuDef.java
  2. 9
      designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java
  3. 7
      designer-base/src/main/java/com/fr/design/notification/SnapChat.java
  4. 8
      designer-base/src/main/java/com/fr/design/notification/SnapChatConfig.java
  5. 76
      designer-base/src/test/java/com/fr/design/menu/SnapChatMenuDefTest.java

28
designer-base/src/main/java/com/fr/design/menu/SnapChatMenuDef.java

@ -42,7 +42,9 @@ public class SnapChatMenuDef extends MenuDef implements SnapChat {
public boolean hasRead() { public boolean hasRead() {
String calcKey = calcKey(); String calcKey = calcKey();
return SnapChatConfig.getInstance().hasRead(calcKey); Boolean val = SnapChatConfig.getInstance().hasRead(calcKey);
// 默认读过了。
return val == null ? defaultStatus() : val;
} }
@Override @Override
@ -52,6 +54,30 @@ public class SnapChatMenuDef extends MenuDef implements SnapChat {
SnapChatConfig.getInstance().markRead(calcKey); SnapChatConfig.getInstance().markRead(calcKey);
} }
@Override
public boolean defaultStatus() {
return true;
}
@Override
public void addShortCut(ShortCut... shortCuts) {
if (shortCuts == null) {
return;
}
for (ShortCut shortCut : shortCuts) {
if (shortCut instanceof SnapChatUpdateAction) {
SnapChatUpdateAction action = (SnapChatUpdateAction) shortCut;
if (!action.hasRead()) {
String calcKey = calcKey();
SnapChatConfig.getInstance().resetRead(calcKey);
}
}
}
super.addShortCut(shortCuts);
}
@Override @Override
public SnapChatKey key() { public SnapChatKey key() {

9
designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java

@ -32,7 +32,8 @@ public abstract class SnapChatUpdateAction extends UpdateAction implements SnapC
public boolean hasRead() { public boolean hasRead() {
String calcKey = calcKey(); String calcKey = calcKey();
return SnapChatConfig.getInstance().hasRead(calcKey); Boolean val = SnapChatConfig.getInstance().hasRead(calcKey);
return val == null ? defaultStatus() : val;
} }
@Override @Override
@ -42,6 +43,12 @@ public abstract class SnapChatUpdateAction extends UpdateAction implements SnapC
SnapChatConfig.getInstance().markRead(calcKey); SnapChatConfig.getInstance().markRead(calcKey);
} }
@Override
public boolean defaultStatus() {
return false;
}
@Override @Override
public SnapChatKey key() { public SnapChatKey key() {

7
designer-base/src/main/java/com/fr/design/notification/SnapChat.java

@ -7,6 +7,13 @@ package com.fr.design.notification;
**/ **/
public interface SnapChat { public interface SnapChat {
/**
* 默认状态
*
* @return 默认状态
*/
boolean defaultStatus();
/** /**
* 已读 * 已读
* *

8
designer-base/src/main/java/com/fr/design/notification/SnapChatConfig.java

@ -31,8 +31,7 @@ public class SnapChatConfig implements XMLable {
public Boolean hasRead(String key) { public Boolean hasRead(String key) {
Map<String, Boolean> map = markReadMap; Map<String, Boolean> map = markReadMap;
Boolean val = map.get(key); return map.get(key);
return val == null ? Boolean.FALSE : val;
} }
public void markRead(String key) { public void markRead(String key) {
@ -40,6 +39,11 @@ public class SnapChatConfig implements XMLable {
markReadMap.put(key, Boolean.TRUE); markReadMap.put(key, Boolean.TRUE);
} }
public void resetRead(String key) {
markReadMap.put(key, Boolean.FALSE);
}
@Override @Override
public void readXML(XMLableReader reader) { public void readXML(XMLableReader reader) {

76
designer-base/src/test/java/com/fr/design/menu/SnapChatMenuDefTest.java

@ -0,0 +1,76 @@
package com.fr.design.menu;
import com.fr.config.dao.DaoContext;
import com.fr.config.dao.impl.LocalClassHelperDao;
import com.fr.config.dao.impl.LocalEntityDao;
import com.fr.config.dao.impl.LocalXmlEntityDao;
import com.fr.design.actions.UpdateAction;
import com.fr.design.notification.SnapChatAllTypes;
import com.fr.design.notification.SnapChatConfig;
import com.fr.stable.xml.XMLableReader;
import com.fr.store.StateHubManager;
import com.fr.store.impl.MemoryLock;
import com.fr.store.impl.MemoryStore;
import com.fr.transaction.Configurations;
import com.fr.transaction.LocalConfigurationHelper;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.api.support.membermodification.MemberMatcher;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import java.awt.event.ActionEvent;
import java.util.HashMap;
@RunWith(PowerMockRunner.class)
@PrepareForTest({SnapChatConfig.class, SnapChatUpdateAction.class})
@PowerMockIgnore({"javax.crypto.*","javax.net.ssl.*","sun.security.ssl.*","com.sun.*"})
public class SnapChatMenuDefTest {
@Before
public void before() throws Exception {
DaoContext.setXmlEntityDao(new LocalXmlEntityDao());
DaoContext.setClassHelperDao(new LocalClassHelperDao());
DaoContext.setEntityDao(new LocalEntityDao());
StateHubManager.setLock(new MemoryLock());
StateHubManager.setStorage(new MemoryStore());
Configurations.setHelper(new LocalConfigurationHelper());
}
@Test
public void testAddShortCut() throws Exception {
PowerMock.suppress(MemberMatcher.constructor(UpdateAction.class));
SnapChatConfig snapChatConfig = EasyMock.partialMockBuilder(SnapChatConfig.class)
.addMockedMethod("readXML")
.createMock();
Whitebox.setInternalState(snapChatConfig, "markReadMap", new HashMap());
snapChatConfig.readXML(EasyMock.anyObject(XMLableReader.class));
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(snapChatConfig);
PowerMock.mockStatic(SnapChatConfig.class);
EasyMock.expect(SnapChatConfig.getInstance()).andReturn(snapChatConfig).anyTimes();
PowerMock.replayAll();
SnapChatMenuDef menuDef = new SnapChatMenuDef("test", SnapChatAllTypes.Menu.BBS);
ShortCut action = new SnapChatUpdateAction(SnapChatAllTypes.Menu.BBS) {
@Override
protected void actionPerformed0(ActionEvent e) {
}
};
Assert.assertTrue(menuDef.hasRead());
menuDef.addShortCut(action);
Assert.assertFalse(menuDef.hasRead());
}
}
Loading…
Cancel
Save