Android Open Source - atb-mobile Balance Fragment






From Project

Back to project page atb-mobile.

License

The source code is released under:

Apache License

If you think the Android project atb-mobile listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2013 Omar BELKHODJA/*ww  w  .  j  av a2s . co  m*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.androidinahurry.tunisiabanking.ui;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.androidinahurry.atb.R;
import com.androidinahurry.network.utils.Response;
import com.androidinahurry.tunisiabanking.bank.atb.AtbService;
import com.androidinahurry.tunisiabanking.model.Account;
import com.androidinahurry.tunisiabanking.service.AccountLoader;
import com.androidinahurry.tunisiabanking.service.ErrorCode;
import com.androidinahurry.utils.EasyFormatter;
import com.androidinahurry.utils.LoadingSupportFragment;
import com.androidinahurry.utils.LoadingViewListener;

public class BalanceFragment extends LoadingSupportFragment<Response<Account, ErrorCode>> {
  
  private static final String ARG_USER = "user";
  private static final String ARG_PASSWORD = "password";
  
  private TextView textViewBalance;
  private LoadingViewListener mListener;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View rootView = inflater.inflate(R.layout.fragment_balance, container, false);
    
    // Get local references on views
    textViewBalance = (TextView) rootView.findViewById(R.id.textViewBalance);
    
    // Init the loader
    getActivity().getSupportLoaderManager().initLoader(getLoaderId(), null, this);
    
    return rootView;
  }
  
  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);
    
    try {
          this.mListener = (LoadingViewListener)activity;
      }
      catch (final ClassCastException e) {
          throw new ClassCastException(activity.toString() + " must implement LoadingViewListener");
      }
  }
  
  private String getUser() {
    return getArguments().getString(ARG_USER);
  }
  
  private String getPassword() {
    return getArguments().getString(ARG_PASSWORD);
  }
  
  public static BalanceFragment newInstance(String user, String password) {
    BalanceFragment fragment = new BalanceFragment();

      Bundle args = new Bundle();
      args.putString(ARG_USER, user);
      args.putString(ARG_PASSWORD, password);

      fragment.setArguments(args);

      return fragment;
  }

  @Override
  public Loader<Response<Account, ErrorCode>> onCreateLoader(int id, Bundle bundle) {
    return new AccountLoader(getActivity(), new AtbService(), getUser(), getPassword());
  }

  @Override
  public void onLoadFinished(Loader<Response<Account, ErrorCode>> loader, Response<Account, ErrorCode> response) {
    switch(response.errorCode) {
    case NO_ERROR:
      String balance = EasyFormatter.formatCurrencyWihtoutSign(response.data.balance, response.data.currency); 
      textViewBalance.setText(balance);
      break;
    default:
      // TODO : add a toast or a messagebox
    }
    
    mListener.onLoadFinished(getLoaderId());
  }

  @Override
  public void onLoaderReset(Loader<Response<Account, ErrorCode>> loader) {
    // TODO Auto-generated method stub
  }

  @Override
  public int getLoaderId() {
    return LoaderId.ACCOUNT;
  }
}




Java Source Code List

com.androidinahurry.network.utils.FakeSSLSocketFactory.java
com.androidinahurry.network.utils.Response.java
com.androidinahurry.network.utils.UnsafeSslSocketFactory.java
com.androidinahurry.network.utils.WebServiceLoader.java
com.androidinahurry.tunisiabanking.bank.atb.AtbHtmlResponseParser.java
com.androidinahurry.tunisiabanking.bank.atb.AtbService.java
com.androidinahurry.tunisiabanking.model.Account.java
com.androidinahurry.tunisiabanking.model.Transaction.java
com.androidinahurry.tunisiabanking.service.AccountLoader.java
com.androidinahurry.tunisiabanking.service.ErrorCode.java
com.androidinahurry.tunisiabanking.service.HistoryLoader.java
com.androidinahurry.tunisiabanking.service.LoginLoader.java
com.androidinahurry.tunisiabanking.ui.AccountActivity.java
com.androidinahurry.tunisiabanking.ui.BalanceFragment.java
com.androidinahurry.tunisiabanking.ui.LoaderId.java
com.androidinahurry.tunisiabanking.ui.LoginActivity.java
com.androidinahurry.tunisiabanking.ui.TransactionAdapter.java
com.androidinahurry.tunisiabanking.ui.TransactionsFragment.java
com.androidinahurry.utils.DialogUtils.java
com.androidinahurry.utils.EasyFormatter.java
com.androidinahurry.utils.LoadingSupportFragment.java
com.androidinahurry.utils.LoadingViewListener.java
com.androidinahurry.utils.ViewHolder.java