Skip to content

Commit

Permalink
Fixed: Currency symbol not updated in "new transactions" fragment whe…
Browse files Browse the repository at this point in the history
…n account is changed

Print locale-sensitive currency symbols
Added code documentation
  • Loading branch information
codinguser committed Aug 12, 2012
1 parent 529479f commit 9f5c41c
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 20 deletions.
2 changes: 1 addition & 1 deletion GnucashMobile/src/org/gnucash/android/data/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public String formattedString(Locale locale){
formatter.setMinimumFractionDigits(DECIMAL_PLACES);
formatter.setMaximumFractionDigits(DECIMAL_PLACES);

return formatter.format(asDouble()) + " " + mCurrency.getSymbol();
return formatter.format(asDouble()) + " " + mCurrency.getSymbol(locale);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ public long getId(String accountUID){
return id;
}

/**
* Returns currency code of account with database ID <code>id</code>
* @param id Record ID of the account to be removed
* @return Currency code of the account
*/
public String getCurrency(long id){
return mTransactionsAdapter.getCurrencyCode(id);
}

/**
* Deletes all accounts and their transactions from the database
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ public boolean onItemLongClick(AdapterView<?> parent, View view, int position,
return true;
}

/**
* Delete the account with record ID <code>rowId</code>
* It shows the delete confirmation dialog if the account has transactions,
* else deletes the account immediately
* @param rowId The record ID of the account
*/
public void tryDeleteAccount(long rowId){
Account acc = mAccountsDbAdapter.getAccount(rowId);
if (acc.getTransactionCount() > 0){
Expand All @@ -302,6 +308,10 @@ public void tryDeleteAccount(long rowId){
}
}

/**
* Deletes an account and show a {@link Toast} notification on success
* @param rowId Record ID of the account to be deleted
*/
protected void deleteAccount(long rowId){

boolean deleted = mAccountsDbAdapter.destructiveDeleteAccount(rowId);
Expand All @@ -311,19 +321,33 @@ protected void deleteAccount(long rowId){
refreshList();
}

/**
* Shows the delete confirmation dialog
* @param id Record ID of account to be deleted after confirmation
*/
public void showConfirmationDialog(long id){
MyAlertDialogFragment alertFragment = MyAlertDialogFragment.newInstance(R.string.title_confirm_delete, id);
alertFragment.setTargetFragment(this, 0);
alertFragment.show(getSherlockActivity().getSupportFragmentManager(), "dialog");
}

/**
* Finish the edit mode and dismisses the Contextual ActionBar
* Any selected (highlighted) accounts are deselected
*/
public void finishEditMode(){
mInEditMode = false;
deselectPreviousSelectedItem();
mActionMode = null;
mSelectedItemId = -1;
}

/**
* Highlights the item at <code>position</code> in the ListView.
* Android has facilities for managing list selection but the highlighting
* is not reliable when using the ActionBar on pre-Honeycomb devices-
* @param position Position of item to be highlighted
*/
private void selectItem(int position){
deselectPreviousSelectedItem();
ListView lv = getListView();
Expand All @@ -334,6 +358,11 @@ private void selectItem(int position){
mSelectedViewPosition = position;
}

/**
* De-selects the previously selected item in a ListView.
* Only one account entry can be highlighted at a time, so the previously selected
* one is deselected.
*/
private void deselectPreviousSelectedItem(){
if (mSelectedViewPosition >= 0){
getListView().setItemChecked(mSelectedViewPosition, false);
Expand Down Expand Up @@ -373,10 +402,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

/**
* Refreshes the list by restarting the {@link DatabaseCursorLoader} associated
* with the ListView
*/
public void refreshList(){
getLoaderManager().restartLoader(0, null, this);
}

/**
* Closes any open database adapters used by the list
*/
@Override
public void onDestroy() {
super.onDestroy();
Expand Down Expand Up @@ -411,6 +447,9 @@ public void showAddAccountDialog(long accountId) {
mAddAccountFragment.show(ft, AccountsActivity.FRAGMENT_NEW_ACCOUNT);
}

/**
* Displays the dialog for exporting transactions in OFX
*/
public void showExportDialog(){
FragmentManager manager = getSherlockActivity().getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
Expand All @@ -425,6 +464,11 @@ public void showExportDialog(){
exportFragment.show(ft, AccountsActivity.FRAGMENT_EXPORT_OFX);
}

/**
* Overrides the {@link SimpleCursorAdapter} to provide custom binding of the
* information from the database to the views
* @author Ngewi Fet <ngewif@gmail.com>
*/
private class AccountsCursorAdapter extends SimpleCursorAdapter {
TransactionsDbAdapter transactionsDBAdapter;

Expand Down Expand Up @@ -468,6 +512,11 @@ public void onClick(View v) {
}
}

/**
* Extends {@link DatabaseCursorLoader} for loading of {@link Account} from the
* database asynchronously
* @author Ngewi Fet <ngewif@gmail.com>
*/
private static final class AccountsCursorLoader extends DatabaseCursorLoader {

public AccountsCursorLoader(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,49 @@
import android.widget.Spinner;
import android.widget.Toast;

/**
* Dialog fragment for exporting account information as OFX files.
* @author Ngewi Fet <ngewif@gmail.com>
*/
public class ExportDialogFragment extends DialogFragment {

/**
* Spinner for selecting destination for the exported file.
* The destination could either be SD card, or another application which
* accepts files, like Google Drive.
*/
Spinner mDestinationSpinner;

/**
* Checkbox indicating that all transactions should be exported,
* regardless of whether they have been exported previously or not
*/
CheckBox mExportAllCheckBox;

/**
* Checkbox for deleting all transactions after exporting them
*/
CheckBox mDeleteAllCheckBox;

/**
* Save button for saving the exported files
*/
Button mSaveButton;

/**
* Cancels the export dialog
*/
Button mCancelButton;

/**
* File path for saving the OFX files
*/
String mFilePath;

/**
* Click listener for positive button in the dialog.
* @author Ngewi Fet <ngewif@gmail.com>
*/
protected class ExportClickListener implements View.OnClickListener {

@Override
Expand Down Expand Up @@ -149,6 +182,9 @@ public void onActivityCreated(Bundle savedInstanceState) {
bindViews();
}

/**
* Collects references to the UI elements and binds click listeners
*/
private void bindViews(){
View v = getView();
mDestinationSpinner = (Spinner) v.findViewById(R.id.spinner_export_destination);
Expand All @@ -175,6 +211,11 @@ public void onClick(View v) {
mSaveButton.setOnClickListener(new ExportClickListener());
}

/**
* Writes the OFX document <code>doc</code> to external storage
* @param Document containing OFX file data
* @throws IOException if file could not be saved
*/
private void writeToExternalStorage(Document doc) throws IOException{
File file = new File(mFilePath);

Expand All @@ -183,6 +224,9 @@ private void writeToExternalStorage(Document doc) throws IOException{

}

/**
* Callback for when the activity chooser dialog is completed
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//TODO: fix the exception which is thrown on return
Expand All @@ -193,6 +237,11 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

/**
* Starts an intent chooser to allow the user to select an activity to receive
* the exported OFX file
* @param path String path to the file on disk
*/
private void shareFile(String path){
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("multipart/xml");
Expand All @@ -204,6 +253,12 @@ private void shareFile(String path){
startActivity(Intent.createChooser(shareIntent, getString(R.string.title_share_ofx_with)));
}

/**
* Copies a file from <code>src</code> to <code>dst</code>
* @param src Absolute path to the source file
* @param dst Absolute path to the destination file
* @throws IOException if the file could not be copied
*/
public static void copyFile(File src, File dst) throws IOException
{
//TODO: Make this asynchronous at some time, t in the future.
Expand All @@ -222,6 +277,10 @@ public static void copyFile(File src, File dst) throws IOException
}
}

/**
* Builds a file name based on the current time stamp for the exported file
* @return String containing the file name
*/
public static String buildExportFilename(){
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_HHmm");
String filename = formatter.format(
Expand All @@ -230,6 +289,13 @@ public static String buildExportFilename(){
return filename;
}

/**
* Exports transactions in the database to the OFX format.
* The accounts are written to a DOM document and returned
* @param exportAll Flag to export all transactions or only the new ones since last export
* @return DOM {@link Document} containing the OFX file information
* @throws ParserConfigurationException
*/
protected Document exportOfx(boolean exportAll) throws ParserConfigurationException{
DocumentBuilderFactory docFactory = DocumentBuilderFactory
.newInstance();
Expand All @@ -248,6 +314,11 @@ protected Document exportOfx(boolean exportAll) throws ParserConfigurationExcept
return document;
}

/**
* Writes out the file held in <code>document</code> to <code>outputWriter</code>
* @param document {@link Document} containing the OFX document structure
* @param outputWriter {@link Writer} to use in writing the file to stream
*/
public void write(Document document, Writer outputWriter){
try {
TransformerFactory transformerFactory = TransformerFactory
Expand Down
Loading

0 comments on commit 9f5c41c

Please sign in to comment.