Android Open Source - swazam Transaction Store






From Project

Back to project page swazam.

License

The source code is released under:

MIT License

If you think the Android project swazam 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

package at.saws2013.szazam.store.impl;
/*from   w  w w. j  av a 2s  .  c om*/
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.json.JSONArray;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.SharedPreferences;
import android.util.Log;
import at.saws2013.szazam.App;
import at.saws2013.szazam.entities.IListItem;
import at.saws2013.szazam.entities.Request;
import at.saws2013.szazam.entities.Transaction;
import at.saws2013.szazam.store.ITransactionStore;

/**
 * Singleton class which stores and gets transactions
 * from shared preferences
 * 
 * @author Ren?
 *
 */
public class TransactionStore extends ContextWrapper implements ITransactionStore {
  
  private static final String TRANSACTION = "transactions";
  private volatile static TransactionStore instance;
  private SharedPreferences prefs;
  private Gson gson;
  
  private TransactionStore(Context context){
    super(context);
    gson = new Gson();
  }
  
  public static TransactionStore getInstance(Context context){
    if (instance == null){
      synchronized (TransactionStore.class) {
        if (instance == null){
          instance = new TransactionStore(context);
        }
      }
    }
    return instance;
  }

  @Override
  public List<IListItem> getTransactionHistory() {
    prefs = getSharedPreferences(App.PREFS, MODE_MULTI_PROCESS);
    Type collectionType = new TypeToken<List<Transaction>>(){}.getType();
    String transactionsOnDisk = prefs.getString(TRANSACTION, null);
    Log.d(TRANSACTION, "" + transactionsOnDisk);
    List<Transaction> transactions = gson.fromJson(transactionsOnDisk, collectionType);
    List<IListItem> transactionsList;
    if (transactions != null){
      transactionsList = new ArrayList<IListItem>(transactions);
      Collections.reverse(transactionsList);
    } else {
      transactionsList = new ArrayList<IListItem>();
    }
    return transactionsList;
  }

  @Override
  public void storeTransactions(JSONArray transactions) {
    prefs = getSharedPreferences(App.PREFS, MODE_MULTI_PROCESS);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString(TRANSACTION, transactions.toString());
    editor.commit();
  }

  public List<IListItem> transformToList(JSONArray responseJSON) {
    Type collectionType = new TypeToken<List<Transaction>>(){}.getType();
    List<Transaction> transactions = gson.fromJson(responseJSON.toString(), collectionType);
    List<IListItem> transactionsList;
    if (transactions != null){
      transactionsList = new ArrayList<IListItem>(transactions);
      Collections.reverse(transactionsList);
    } else {
      transactionsList = new ArrayList<IListItem>();
    }
    return transactionsList;
  }

}




Java Source Code List

ac.tuwien.sa13.beans.HibernateAwareObjectMapper.java
ac.tuwien.sa13.controller.HomeController.java
ac.tuwien.sa13.controller.LoginController.java
ac.tuwien.sa13.controller.RequestController.java
ac.tuwien.sa13.controller.TransactionController.java
ac.tuwien.sa13.controller.api.UserRestController.java
ac.tuwien.sa13.dao.HibernateDAO.java
ac.tuwien.sa13.dao.IGenericDAO.java
ac.tuwien.sa13.dao.IRequestDAO.java
ac.tuwien.sa13.dao.ITransactionDAO.java
ac.tuwien.sa13.dao.IUserDAO.java
ac.tuwien.sa13.dao.RequestDAO.java
ac.tuwien.sa13.dao.TransactionDAO.java
ac.tuwien.sa13.dao.UserDAO.java
ac.tuwien.sa13.entity.Request.java
ac.tuwien.sa13.entity.Transaction.java
ac.tuwien.sa13.entity.User.java
ac.tuwien.sa13.service.IGenericService.java
ac.tuwien.sa13.service.IRequestService.java
ac.tuwien.sa13.service.ITransactionService.java
ac.tuwien.sa13.service.IUserService.java
ac.tuwien.sa13.service.PeerManager.java
ac.tuwien.sa13.service.RequestService.java
ac.tuwien.sa13.service.TransactionService.java
ac.tuwien.sa13.service.UserService.java
ac.tuwien.sa13.utilities.SessionIdentifierGenerator.java
ac.tuwien.sa13.utilities.Token.java
ac.tuwien.sa13.validator.LoginValidator.java
at.ac.tuwien.swa13.swazam.NetworkConnection.java
at.ac.tuwien.swa13.swazam.Peer.java
at.ac.tuwien.swa13.swazam.fingerprint.IFingerPrintCreator.java
at.ac.tuwien.swa13.swazam.fingerprint.impl.FingerPrintCreator.java
at.ac.tuwien.swa13.swazam.library.ILibraryManager.java
at.ac.tuwien.swa13.swazam.library.ISong.java
at.ac.tuwien.swa13.swazam.library.impl.LibraryManager.java
at.ac.tuwien.swa13.swazam.library.impl.Song.java
at.ac.tuwien.swa13.swazam.p2p.PeerConnector.java
at.saws2013.szazam.App.java
at.saws2013.szazam.BaseActivity.java
at.saws2013.szazam.HistoryActivity.java
at.saws2013.szazam.LoginActivity.java
at.saws2013.szazam.RecognitionActivity.java
at.saws2013.szazam.SettingsActivity.java
at.saws2013.szazam.entities.IListItem.java
at.saws2013.szazam.entities.ListItemTypes.java
at.saws2013.szazam.entities.Request.java
at.saws2013.szazam.entities.Transaction.java
at.saws2013.szazam.fingerprint.IFingerPrintSystem.java
at.saws2013.szazam.fingerprint.impl.FingerPrintCreator.java
at.saws2013.szazam.fragments.SettingsFragment.java
at.saws2013.szazam.media.IAudioFilePicker.java
at.saws2013.szazam.media.IAudioRecorder.java
at.saws2013.szazam.media.impl.AudioFilePicker.java
at.saws2013.szazam.media.impl.AudioRecorder.java
at.saws2013.szazam.store.IAuthStore.java
at.saws2013.szazam.store.IRequestStore.java
at.saws2013.szazam.store.ITransactionStore.java
at.saws2013.szazam.store.impl.AuthStore.java
at.saws2013.szazam.store.impl.RequestStore.java
at.saws2013.szazam.store.impl.TransactionStore.java
at.saws2013.szazam.ui.CustomListAdapter.java
at.saws2013.szazam.ui.ViewTools.java
at.saws2013.szazam.volley.CustomVolleyStringRequest.java
de.passsy.holocircularprogressbar.HoloCircularProgressBar.java