Skip to content

Instantly share code, notes, and snippets.

@shannah
Created June 26, 2021 14:23
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/9fed8c117be477d513d5729bb6f0377f to your computer and use it in GitHub Desktop.
Save shannah/9fed8c117be477d513d5729bb6f0377f to your computer and use it in GitHub Desktop.
Application controller for TweetApp after adding alternate control flow if user is logged in already
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.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;
/**
* 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 {
@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 -> {});
}
@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