Skip to content

Instantly share code, notes, and snippets.

@shannah
Created June 27, 2021 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shannah/be58c81314a32d87f1de5c54216a71b4 to your computer and use it in GitHub Desktop.
Save shannah/be58c81314a32d87f1de5c54216a71b4 to your computer and use it in GitHub Desktop.
Twitter clone example after adding global navigation tabs
<?xml version="1.0"?>
<border view-controller="com.example.tweetapp.controllers.HomePageViewController"
xsi:noNamespaceSchemaLocation="HomePage.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<title hidden="true"/>
<use-taglib class="com.codename1.twitterui.TagLibrary"/>
<import>
import com.example.tweetapp.providers.NewsFeedProvider;
</import>
<collapsibleHeader scrollableComponent="#tweetList">
<twtTitle>
<twtsearchButton rad-href="#SearchForm" rad-href-trigger="TWTSearchButton.SEARCH_ACTION"/>
</twtTitle>
</collapsibleHeader>
<sidebar>
<twtSideBarView/>
</sidebar>
<tweetListView
name="tweetList"
layout-constraint="center"
provider="NewsFeedProvider.class"
/>
<globalTabs layout-constraint="south" selectedTab="com.example.tweetapp.Tweetapp.HOME_TAB"/>
</border>
<?xml version="1.0"?>
<border xsi:noNamespaceSchemaLocation="InboxPage.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<title>InBox</title>
<use-taglib class="com.codename1.twitterui.TagLibrary"/>
<globalTabs layout-constraint="south" selectedTab="com.example.tweetapp.Tweetapp.INBOX_TAB"/>
</border>
package com.example.tweetapp;
import static com.codename1.rad.util.NonNull.with;
import static com.codename1.ui.CN.*;
import com.codename1.rad.controllers.ControllerEvent;
import com.codename1.rad.nodes.ActionNode;
import com.codename1.rad.ui.ActionStyle;
import com.codename1.twitterui.models.TWTUserProfile;
import com.codename1.twitterui.models.TWTUserProfileImpl;
import com.codename1.twitterui.views.TWTGlobalTabs;
import com.codename1.twitterui.views.TWTSideBarView;
import com.codename1.ui.*;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.layouts.*;
import com.codename1.io.*;
import com.codename1.ui.plaf.*;
import com.codename1.ui.util.Resources;
import com.codename1.rad.controllers.ApplicationController;
import com.example.tweetapp.providers.NewsFeedProvider;
import com.example.tweetapp.services.TweetAppClient;
import com.example.tweetapp.views.HomePageController;
import com.example.tweetapp.views.WelcomePageController;
import com.example.tweetapp.views.InboxPageController;
/**
* This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose
* of building native mobile applications using Java.
*/
public class Tweetapp extends ApplicationController {
public static final ActionNode HOME_TAB = ActionNode.builder().
icon(FontImage.MATERIAL_HOME).
addActionListener(evt->{
evt.consume();
TWTGlobalTabs.showTab(
evt,
new HomePageController(ApplicationController.getApplicationController(evt))
);
}).
build();
public static final ActionNode INBOX_TAB = ActionNode.builder().
icon(FontImage.MATERIAL_INBOX).
badge("2").
addActionListener(evt->{
evt.consume();
TWTGlobalTabs.showTab(
evt,
new InboxPageController(ApplicationController.getApplicationController(evt))
);
}).
build();
@Override
protected void initControllerActions() {
super.initControllerActions();
// Sidebar Actions which will be injected into the TWTSideBarView
ActionNode.builder()
.label("Profile")
.icon(FontImage.MATERIAL_ACCOUNT_CIRCLE)
.addToController(this, TWTSideBarView.SIDEBAR_ACTIONS, evt -> {});
ActionNode.builder()
.label("Lists")
.icon(FontImage.MATERIAL_LIST)
.addToController(this, TWTSideBarView.SIDEBAR_ACTIONS, evt -> {});
ActionNode.builder()
.label("Topics")
.icon(FontImage.MATERIAL_CATEGORY)
.addToController(this, TWTSideBarView.SIDEBAR_ACTIONS, evt -> {});
ActionNode.builder()
.label("Bookmarks")
.icon(FontImage.MATERIAL_BOOKMARKS)
.addToController(this, TWTSideBarView.SIDEBAR_ACTIONS, evt -> {});
ActionNode.builder()
.label("Moments")
.icon(FontImage.MATERIAL_BOLT)
.addToController(this, TWTSideBarView.SIDEBAR_ACTIONS, evt -> {});
ActionNode.builder()
.label("Create new account")
.addToController(this, TWTSideBarView.SIDEBAR_TOP_OVERFLOW_MENU, evt -> {});
ActionNode.builder()
.label("Add Existing Account")
.addToController(this, TWTSideBarView.SIDEBAR_TOP_OVERFLOW_MENU, evt -> {});
ActionNode.builder()
.label("Settings and privacy")
.addToController(this, TWTSideBarView.SIDEBAR_SETTINGS_ACTIONS, evt -> {});
ActionNode.builder()
.label("Help Center")
.addToController(this, TWTSideBarView.SIDEBAR_SETTINGS_ACTIONS, evt -> {});
ActionNode.builder()
.icon(FontImage.MATERIAL_LIGHTBULB_OUTLINE)
.addToController(this, TWTSideBarView.SIDEBAR_BOTTOM_LEFT_ACTIONS, evt -> {});
ActionNode.builder()
.icon(FontImage.MATERIAL_SCANNER)
.addToController(this, TWTSideBarView.SIDEBAR_BOTTOM_RIGHT_ACTIONS, evt -> {});
ActionNode.builder()
.icon(FontImage.MATERIAL_ACCOUNT_CIRCLE)
.addToController(this, TWTSideBarView.SIDEBAR_TOP_ACTIONS, evt -> {});
ActionNode.builder()
.icon(FontImage.MATERIAL_ACCOUNT_BALANCE_WALLET)
.addToController(this, TWTSideBarView.SIDEBAR_TOP_ACTIONS, evt -> {});
ActionNode.builder()
.icon("Following")
.label("311")
.addToController(this, TWTSideBarView.SIDEBAR_STATS, evt -> {});
ActionNode.builder()
.icon("Followers")
.label("344")
.addToController(this, TWTSideBarView.SIDEBAR_STATS, evt -> {});
addActions(TWTGlobalTabs.GLOBAL_TABS,
HOME_TAB, INBOX_TAB
);
}
@Override
protected void onStartController() {
super.onStartController();
/**
* Add a TweetAppClient as a lookup so that it will be available throughout
* the app via {@link #lookup(Class)}
*/
TweetAppClient client = new TweetAppClient();
addLookup(client);
if (client.isLoggedIn()) {
// The client is logged in. We hardcode the userprofile here as me
// but in real app you would have the profile created based on who is logged in.
TWTUserProfile userProfile = new TWTUserProfileImpl();
userProfile.setName("Steve Hannah");
userProfile.setIdentifier("@shannah78");
userProfile.setThumbnailUrl("https://www.codenameone.com/img/steve.jpg");
addLookup(TWTUserProfile.class, userProfile);
}
addLookup(new NewsFeedProvider());
}
public void actionPerformed(ControllerEvent evt) {
with(evt, StartEvent.class, startEvent -> {
if (!startEvent.isShowingForm()) {
startEvent.setShowingForm(true);
if (lookup(TweetAppClient.class).isLoggedIn()) {
new HomePageController(this).show();
} else {
new WelcomePageController(this).show();
}
}
});
super.actionPerformed(evt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment