/** Retrieves the latest litters for the the user and updates the display */ public void getLastestLitters() { // Show the busy state final LitterActivity glitterActivity = (LitterActivity) getActivity(); glitterActivity.showBusy(true); // Get a reference to the API LitterAPI glitterAPI = new LitterAPI(); // Call the getLitters method with a callback glitterAPI.getLitters( mCurrentUser.getUserId(), new LitterAPI.GetLittersCallback() { @Override public void gotLitters(ArrayList<Litter> litters) { mAdapter = new LitterAdapter(getActivity(), R.layout.litter_item, litters); // Set the adapter mListView = (AbsListView) mView.findViewById(android.R.id.list); ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter); glitterActivity.showBusy(false); } @Override public void callFailed(String message) { // Woops Log.e(LOG_TAG, message); glitterActivity.showBusy(false); } }); }
/** * Implements the login button pressed called by the LoginFragment * * @param usernameOrEmail the username or email entered * @param password the password entered * @param rememberMe true if the user wants to autologin next time */ @Override public void loginPressed(String usernameOrEmail, String password, boolean rememberMe) { Log.d( LOG_TAG, "Login Pressed. Username='******', Password='******', Remember Me=" + rememberMe); showBusy(true); // Disable the fragment so the user can't press or enter text while we are calling the // litter service mLoginFragment.enable(false); mGlitterAPI.login( usernameOrEmail, password, new LitterAPI.LoginCallback() { @Override public void loginSuccessful(User user) { // Success! mCurrentUser = user; showBusy(false); showLittersList(); } @Override public void badCredentials() { showBusy(false); showBadCredentials(); } @Override public void callFailed(String message) { // TODO: Network communictions failure displayed here } }); }
/** * The user pressed the postLitter button, sends the message to the API * * @param message */ public void postLitterPressed(String message) { // Validate the message boolean messageOk = message.length() > 0 && message.length() < 140; if (!messageOk) { // TODO: Display an error popup to the user explaining message is invalid return; } Log.d(LOG_TAG, "About to post litter message: " + message); hideKeyboard(); mLitterFragment.hideLitterLayout(); showBusy(true); mGlitterAPI.postLitter( mCurrentUser.getUserId(), message, new LitterAPI.PostLitterCallback() { @Override public void callFailed(String message) { showBusy(false); // TODO: The API call failed - tell the user } @Override public void litterPosted() { showBusy(false); mLitterFragment.getLastestLitters(); } }); }