@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); walletsController = WalletsController.getInstance(); walletRelationsController = WalletRelationsController.getInstance(); usersController = UsersController.getInstance(); friendsController = FriendsController.getInstance(); httpRequest = DBhttpRequest.getInstance(); profile = Profile.getInstance(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* Dialog dialog = new Dialog(this, android.R.style.Theme_NoTitleBar_Fullscreen); dialog.addContentView(new View(this), (new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))); dialog.show(); */ setContentView(R.layout.activity_main); setupUI(findViewById(R.id.drawer_layout), this); fragmentStack = new FragmentStack(); application = (GWApplication) this.getApplication(); demoIntent = new Intent(this, TutorialActivity.class); final TransactionsController transactionsController = TransactionsController.getInstance(); final WalletsController walletsController = WalletsController.getInstance(); final UsersController usersController = UsersController.getInstance(); final WalletRelationsController walletRelationsController = WalletRelationsController.getInstance(); final FriendsController friendsController = FriendsController.getInstance(); final DBhttpRequest httpRequest = DBhttpRequest.getInstance(); profileL = Profile.getInstance(); logOut = new LogOutCurrent(httpRequest, profileL, application); picCache = application.drawableCache; logOutFlag = false; logOutGetData = false; ((RecordsFragment) records).setCache(picCache); ((RecordDetailedFragment) recordDetailedFrag).setCache(picCache); getData = new GetData( httpRequest, profileL, transactionsController, walletRelationsController, walletsController, usersController, friendsController); getData.setGetDataListener( new getDataListener() { @Override public void getWalletComplete(Integer result) { // TODO Auto-generated method stub if (result == -1) { // logOutNow(); getData.cancel(); logOutGetData = true; } else if (result >= 0) { ((WalletsFragment) walletFrag).walletsUpdated(); } } @Override public void getRecordsComplete(Integer result) { if (result == -1) { // logOutNow(); getData.cancel(); logOutGetData = true; } else if (result == 1) { ((QuickPayFragment) quickPay).walletsUpdated(); ((WalletsFragment) walletFrag).walletsUpdated(); } ((RecordsFragment) records).transactionsUpdated(); ((RelationshipsFragment) relationshipFrag).walletRelationshipsUpdated(); } @Override public void inviteWalletComplete(Integer result, ArrayList<Wallet> wallets) { if (wallets != null) { numWalletInvites = getData.getNumInvites(); invalidateOptionsMenu(); } } @Override public void getRelationsComplete( ArrayList<Integer> result, ArrayList<WalletRelation> newRelations) { if (result.contains(-1)) { // logOutNow(); getData.cancel(); logOutGetData = true; } if (newRelations != null) { if (current == quickPay) { ((QuickPayFragment) quickPay).walletRelationsUpdated(newRelations); } } } @Override public void getUsersComplete(Integer result, ArrayList<Integer> results) { ((RelationshipsFragment) relationshipFrag).walletRelationshipsUpdated(); } @Override public void getFriendsComplete(Integer result, ArrayList<Friend> friends) { if (friends != null && current == quickPay) { ((QuickPayFragment) quickPay).friendsUpdated(friends); } numWalletInvites = getData.getNumInvites(); invalidateOptionsMenu(); } @Override public void getDataComplete( Boolean walletFailFlag, Boolean relationFailFlag, Boolean transactionFailFlag, Boolean walletInviteFailFlag, Boolean usersFailFlag, Boolean friendsFailFlag) { if (logOutGetData) { logOutGetData = false; logOutNow(); } } }); ((WalletsFragment) walletFrag) .setWalletFragmentListener( new WalletFragmentListener() { @Override public void walletClicked(Wallet wallet) { showRelations(wallet, wallet.getID(), true); } @Override public void addWallet() { showAdd(AddFragment.Type.WALLET, null, true); } @Override public void load() { getData.getWallets(profileL.getUserID()); } }); ((RelationshipsFragment) relationshipFrag) .setRelationshipListener( new RelationshipListener() { @Override public void walletNameClicked() { showWallets(true); } @Override public void relationClicked(User user, Wallet wallet) { showTransactions(user, wallet, true); } @Override public void addUserClicked(Wallet wallet) { showAdd(AddFragment.Type.USER, wallet.getID(), true); } @Override public void load(Wallet wallet) { if (wallet != null) { ArrayList<Integer> tempWallet = new ArrayList<Integer>(); tempWallet.add(wallet.getID()); getData.getRelationsAndUsers(tempWallet); } } }); ((QuickPayFragment) quickPay) .setQuickPayListener( new QuickPayListener() { @Override public void insertedRecord(Integer result) { if (result == -1) { logOutNow(); } else { showTransactions(null, null, true); } } }); ((RecordsFragment) records) .setRecordFragmentListener( new RecordFragmentListener() { @Override public void oweUserClicked(User user) { showProfile(user, true); } @Override public void owedUserClicked(User user) { showProfile(user, true); } @Override public void recordClicked(Record record) { showDetailedTransaction(record, true); } @Override public void update() { getData.getTransactions(); } }); ((ProfileFragment) profileFrag) .setProfileListener( new ProfileListener() { @Override public void walletsClicked() { showWallets(true); } }); ((AddFragment) addFrag) .setAddListener( new AddListener() { @Override public void newWalletInserted() { showWallets(true); } @Override public void newUserInserted(final Integer walletID) { runOnUiThread( new Runnable() { @Override public void run() { showRelations(null, walletID, true); } }); } }); ((WalletInviteFragment) walletInviteFrag) .setWalletInviteFragmentListener( new WalletInviteFragmentListener() { @Override public void walletClicked(Wallet wallet, Friend friend) {} @Override public void accpeted(Wallet wallet, Friend friend) { if (wallet == null) { showRelations(null, 0, true); } else { showRelations(wallet, wallet.getID(), true); } numWalletInvites -= 1; invalidateOptionsMenu(); } @Override public void failure(Integer result) { if (result == -1) { logOutNow(); } } }); mTitle = mDrawerTitle = getTitle(); mPlanetTitles = getResources().getStringArray(R.array.options_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens // mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter( new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); // getActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }