
public class TweetListView extends EntityListView
A view for displaying a list of tweets. This view in a CodeRAD EntityView instance, so it requires a view model, and a UI descriptor to customize it. Please read What is CodeRAD? for an introduction to CodeRAD and how to use CodeRAD components.
The TweetListView, as a subclass of EntityListView
requires an EntityList
for a view model, and a ListNode
as a UI descriptor. The items/rows of the EntityList are expected to be Entity
subclasses conforming to the TweetSchema
schema. The TweetImpl
class is a reference implementation of such a view model. You may use TweetImpl
instances
as the items of the EntityList
, or you may define your own view model.
The rows of this view are TweetRowView
instances, so you can refer to the TweetRowView
docs for further information
about the view model requirements.
// Method the generates a view model of tweets to display in the TweetListView.
private EntityList createDemoTweetList() {
String georgeThumb = "https://weblite.ca/cn1tests/radchat/george.jpg";
String kramerThumb = "https://weblite.ca/cn1tests/radchat/kramer.jpg";
String jerryThumb = "https://weblite.ca/cn1tests/radchat/jerry.jpg";
String elaineThumb = "https://weblite.ca/cn1tests/radchat/elaine.jpg";
String newmanThumb = "https://weblite.ca/cn1tests/radchat/newman.jpg";
Entity george = getOrCreateAuthor("George", "@kostanza", georgeThumb);
Entity kramer = getOrCreateAuthor("Kramer", "@kramer", kramerThumb);
Entity jerry = getOrCreateAuthor("Jerry", "@jerrys", jerryThumb);
Entity elaine = getOrCreateAuthor("Elaine", "@elaine", elaineThumb);
Entity newman = getOrCreateAuthor("Newman", "@newman", newmanThumb);
long SECOND = 1000l;
long MINUTE = SECOND * 60;
long HOUR = MINUTE * 60;
long DAY = HOUR * 24;
long t = System.currentTimeMillis() - 2 * DAY;
EntityList list = new EntityList();
list.add(createTweet(george, "Just made my first sale", new Date(t), "https://optinmonster.com/wp-content/uploads/2018/05/sales-promotion-examples.jpg"));
list.add(createTweet(kramer, "Check out these cool new features we added today. I think you're going to like them.", new Date(t), "https://www.codenameone.com/img/blog/new-features.jpg"));
list.add(createTweet(newman, "This is how I feel every time Jerry gets what he wants", new Date(t), "https://weblite.ca/cn1tests/radchat/damn-you-seinfeld.jpg"));
list.add(createTweet(elaine, "These urban sombreros are going to be a huge hit. Don't miss out. Get them from the Peterman collection.", new Date(t), "https://weblite.ca/cn1tests/radchat/urban-sombrero.jpg"));
return list;
}
As a subclass of EntityListView
, this class will obey all directives obeyed by the EntityListView
class.
In addition, you should refer to the TweetRowView
docs to see the supported UI descriptor attributes at a row level.
TweetListView view = new TweetListView(createDemoTweetList(), new ListNode(
actions(TweetRowView.TWEET_MENU_ACTIONS, notInterested, unfollow, mute),
actions(TweetRowView.TWEET_ACTIONS, reply, retweet, favorite, share),
actions(ProfileAvatarView.PROFILE_AVATAR_CLICKED_MENU, unfollow),
actions(TweetRowView.TWEET_CLICKED, tweetDetails),
UI.param(EntityListView.SCROLLABLE_Y, true)
));
package com.codename1.demos.twitterui;
import ca.weblite.shared.components.CollapsibleHeaderContainer;
import com.codename1.demos.twitterui.AppNavigationViewModel.NavSection;
import static com.codename1.demos.twitterui.AppNavigationViewModel.currentSection;
import static com.codename1.demos.twitterui.TwitterUIDemo.*;
import com.codename1.demos.twitterui.models.UserProfile;
import com.codename1.rad.controllers.Controller;
import com.codename1.rad.models.Entity;
import com.codename1.rad.models.EntityList;
import com.codename1.rad.nodes.ListNode;
import com.codename1.rad.nodes.ViewNode;
import com.codename1.rad.schemas.Thing;
import com.codename1.rad.ui.UI;
import com.codename1.twitterui.views.TweetListView;
import com.codename1.twitterui.models.TWTAuthor;
import com.codename1.twitterui.models.TweetModel;
import com.codename1.twitterui.models.Tweet;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import static com.codename1.rad.ui.UI.*;
import com.codename1.rad.ui.entityviews.EntityListView;
import com.codename1.rad.ui.entityviews.ProfileAvatarView;
import com.codename1.twitterui.views.TWTSearchButton;
import com.codename1.twitterui.views.TWTTitleComponent;
import com.codename1.twitterui.views.TweetRowView;
public class HomeFormController extends BaseFormController {
private Map<String,Entity> authors = new HashMap<>();
public HomeFormController(Controller parent) {
super(parent);
TweetListView view = new TweetListView(createDemoTweetList(), new ListNode(
actions(TweetRowView.TWEET_MENU_ACTIONS, notInterested, unfollow, mute),
actions(TweetRowView.TWEET_ACTIONS, reply, retweet, favorite, share),
actions(ProfileAvatarView.PROFILE_AVATAR_CLICKED_MENU, unfollow),
actions(TweetRowView.TWEET_CLICKED, tweetDetails),
UI.param(EntityListView.SCROLLABLE_Y, true)
));
ViewNode viewNode = getViewNode();
UserProfile p = lookup(UserProfile.class);
CollapsibleHeaderContainer mainFrame = new CollapsibleHeaderContainer(
new TWTTitleComponent(p, viewNode, new TWTSearchButton(p, viewNode)),
view,
view.getScrollWrapper());
setView(mainFrame);
AppNavigationViewModel navigationModel = lookup(AppNavigationViewModel.class);
addActionListener(tweetDetails, evt->{
//Dialog.show("Tweet Details", "The tweet was clicked", "OK", null);
evt.consume();
new TweetDetailsController(this, evt.getEntity()).getView().show();
});
addActionListener(home, evt -> {
evt.consume();
if (navigationModel.get(currentSection) == NavSection.Home) {
// We are already home... so do nothing.
// TODO: This action should scroll to top, and refresh list
return;
}
// If we are on another form, we should show "back"
getView().showBack();
});
}
private EntityList createDemoTweetList() {
String georgeThumb = "https://weblite.ca/cn1tests/radchat/george.jpg";
String kramerThumb = "https://weblite.ca/cn1tests/radchat/kramer.jpg";
String jerryThumb = "https://weblite.ca/cn1tests/radchat/jerry.jpg";
String elaineThumb = "https://weblite.ca/cn1tests/radchat/elaine.jpg";
String newmanThumb = "https://weblite.ca/cn1tests/radchat/newman.jpg";
Entity george = getOrCreateAuthor("George", "@kostanza", georgeThumb);
Entity kramer = getOrCreateAuthor("Kramer", "@kramer", kramerThumb);
Entity jerry = getOrCreateAuthor("Jerry", "@jerrys", jerryThumb);
Entity elaine = getOrCreateAuthor("Elaine", "@elaine", elaineThumb);
Entity newman = getOrCreateAuthor("Newman", "@newman", newmanThumb);
long SECOND = 1000l;
long MINUTE = SECOND * 60;
long HOUR = MINUTE * 60;
long DAY = HOUR * 24;
long t = System.currentTimeMillis() - 2 * DAY;
EntityList list = new EntityList();
list.add(createTweet(george, "Just made my first sale", new Date(t), "https://optinmonster.com/wp-content/uploads/2018/05/sales-promotion-examples.jpg"));
list.add(createTweet(kramer, "Check out these cool new features we added today. I think you're going to like them.", new Date(t), "https://www.codenameone.com/img/blog/new-features.jpg"));
list.add(createTweet(newman, "This is how I feel every time Jerry gets what he wants", new Date(t), "https://weblite.ca/cn1tests/radchat/damn-you-seinfeld.jpg"));
list.add(createTweet(elaine, "These urban sombreros are going to be a huge hit. Don't miss out. Get them from the Peterman collection.", new Date(t), "https://weblite.ca/cn1tests/radchat/urban-sombrero.jpg"));
return list;
}
private Entity getOrCreateAuthor(String name, String id, String iconUrl) {
if (authors.containsKey(id)) {
return authors.get(id);
}
Entity author = new TWTAuthor();
author.set(Thing.name, name);
author.set(Thing.identifier, id);
author.set(Thing.thumbnailUrl, iconUrl);
authors.put(id, author);
return author;
}
private Entity createTweet(Entity author, String content, Date date, String imageUrl) {
Entity tweet = new TweetModel();
tweet.set(Tweet.author, author);
tweet.setText(Tweet.text, content);
tweet.setDate(Tweet.datePosted, date);
tweet.setText(Tweet.image, imageUrl);
return tweet;
}
@Override
public void initController() {
super.initController();
lookup(AppNavigationViewModel.class).set(currentSection, NavSection.Home);
}
EntityListView.Builder, EntityListView.EntityListViewFactory, EntityListView.RowLayout
ANIMATE_INSERTIONS, ANIMATE_REMOVALS, COLUMNS, LANDSCAPE_COLUMNS, LAYOUT, SCROLLABLE_X, SCROLLABLE_Y
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR
Constructor and Description |
---|
TweetListView(EntityList<Tweet> tweets)
Creates a new tweet list view.
|
TweetListView(EntityList<Tweet> tweets,
ListNode node)
Creates a new tweet list view.
|
Modifier and Type | Method and Description |
---|---|
void |
update() |
bindImpl, commit, getListCellRenderer, getListLayout, getRowViewForEntity, getScrollWrapper, getVerticalScroller, getViewNode, isAnimateInsertions, isAnimateRemovals, loadMore, refresh, setAnimateInsertions, setAnimateRemovals, setListCellRenderer, setListLayout, setScrollableY, unbindImpl
activate, addBindListener, addUnbindListener, addUpdateListener, bind, deinitialize, findProperty, getContext, getEntity, getParam, initComponent, isBindOnPropertyChangeEvents, removeUpdateListener, setBindOnPropertyChangeEvents, setEntity, unbind
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndices
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, parsePreferredSize, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDirtyRegion, setDisabledStyle, setDraggable, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public TweetListView(EntityList<Tweet> tweets)
Creates a new tweet list view.
tweets
- List of tweets. Rows of this list should conform to the TweetSchema
schema.A reference implementation conforming to the {@link TweetSchema} schema.
,
For component used to render each individual row.
public TweetListView(EntityList<Tweet> tweets, ListNode node)
Creates a new tweet list view.
tweets
- List of tweets. Rows of this list should conform to the TweetSchema
schema.node
- UI descriptor. Use this to pass parameters, attributes, actions, etc.. to the component.A reference implementation conforming to the {@link TweetSchema} schema.
,
For component used to render each individual row.
public void update()
update
in interface EntityView
update
in class EntityListView
Copyright © 2021. All Rights Reserved.