Skip to content

Commit

Permalink
Adding transaction note feature
Browse files Browse the repository at this point in the history
Closes #25.  This feature lets you take notes on transactions
in your wallet.  I partially implemented backup and restoration
of these in the wallet backups, but it's incomplete.  In the future,
we can add the ability to write these transaction notes to the backup
file, and they should be imported properly
  • Loading branch information
hank committed Feb 3, 2014
1 parent 008308a commit 25c23f3
Show file tree
Hide file tree
Showing 11 changed files with 353 additions and 49 deletions.
58 changes: 58 additions & 0 deletions wallet/res/layout/edit_transaction_note_dialog.xml
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="vertical" >

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="8dp"
android:text="@string/edit_transaction_note_dialog_txid_label"
android:textSize="@dimen/font_size_small"
android:textStyle="bold" />

<EditText
android:id="@+id/edit_transaction_note_txid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:enabled="false"
android:focusable="false"
android:imeOptions="flagNoExtractUi"
android:inputType="none"
android:textColor="@color/fg_less_significant"
android:textSize="@dimen/font_size_normal" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="8dp"
android:text="@string/edit_transaction_note_dialog_note_label"
android:textSize="@dimen/font_size_small"
android:textStyle="bold" />

<EditText
android:id="@+id/edit_transaction_note_note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:imeOptions="flagNoExtractUi"
android:inputType="textPersonName"
android:singleLine="true"
android:textSize="@dimen/font_size_normal" >

<requestFocus />
</EditText>
</LinearLayout>

</ScrollView>
13 changes: 12 additions & 1 deletion wallet/res/layout/transaction_row_extended.xml
Expand Up @@ -72,9 +72,20 @@
android:layout_marginLeft="8dp"
android:textSize="@dimen/font_size_normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/transaction_row_extend_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/txNote"/>
</LinearLayout>
<LinearLayout
android:id="@+id/transaction_row_extend"
android:id="@+id/transaction_row_extend_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
Expand Down
104 changes: 59 additions & 45 deletions wallet/res/layout/transaction_row_oneline.xml
Expand Up @@ -4,57 +4,71 @@
android:layout_height="wrap_content"
android:background="@color/bg_list"
android:baselineAligned="true"
android:orientation="horizontal"
android:orientation="vertical"
android:paddingBottom="2dp"
android:paddingTop="2dp" >

<de.schildbach.wallet.util.CircularProgressView
android:id="@+id/transaction_row_confidence_circular"
android:layout_width="@dimen/symbol_size_normal"
android:layout_height="@dimen/symbol_size_normal"
android:layout_marginRight="8dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<de.schildbach.wallet.util.CircularProgressView
android:id="@+id/transaction_row_confidence_circular"
android:layout_width="@dimen/symbol_size_normal"
android:layout_height="@dimen/symbol_size_normal"
android:layout_marginRight="8dp" />

<TextView
android:id="@+id/transaction_row_confidence_textual"
android:layout_width="@dimen/symbol_size_normal"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:gravity="center_horizontal"
android:textSize="@dimen/font_size_normal"
android:textStyle="bold" />
<TextView
android:id="@+id/transaction_row_confidence_textual"
android:layout_width="@dimen/symbol_size_normal"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:gravity="center_horizontal"
android:textSize="@dimen/font_size_normal"
android:textStyle="bold" />

<TextView
android:id="@+id/transaction_row_fromto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:textSize="@dimen/font_size_normal" />
<TextView
android:id="@+id/transaction_row_fromto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:textSize="@dimen/font_size_normal" />

<ImageView
android:id="@+id/transaction_row_coinbase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="6dp"
android:baselineAlignBottom="true"
android:src="@drawable/coinbase"
android:visibility="gone" />
<ImageView
android:id="@+id/transaction_row_coinbase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="6dp"
android:baselineAlignBottom="true"
android:src="@drawable/coinbase"
android:visibility="gone" />

<TextView
android:id="@+id/transaction_row_address"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:singleLine="true"
android:textSize="@dimen/font_size_normal" />

<de.schildbach.wallet.ui.CurrencyTextView
android:id="@+id/transaction_row_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="8dp"
android:textSize="@dimen/font_size_normal" />
<TextView
android:id="@+id/transaction_row_address"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:singleLine="true"
android:textSize="@dimen/font_size_normal" />

<de.schildbach.wallet.ui.CurrencyTextView
android:id="@+id/transaction_row_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="8dp"
android:textSize="@dimen/font_size_normal" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/txNote"/>
</LinearLayout>
</LinearLayout>
6 changes: 6 additions & 0 deletions wallet/res/menu/wallet_transactions_context.xml
Expand Up @@ -7,6 +7,12 @@
android:showAsAction="ifRoom|withText"
android:title="@string/button_edit_address"
android:titleCondensed="@string/button_edit"/>
<item
android:id="@+id/wallet_transactions_context_edit_note"
android:icon="@drawable/ic_action_edit"
android:showAsAction="ifRoom|withText"
android:title="@string/button_edit_note"
android:titleCondensed="@string/button_edit_note"/>
<item
android:id="@+id/wallet_transactions_context_show_qr"
android:icon="@drawable/ic_action_qr"
Expand Down
4 changes: 4 additions & 0 deletions wallet/res/values/strings.xml
Expand Up @@ -246,5 +246,9 @@
<string name="disclaimer">Have you really read the safety notes? Did you already back up your private keys to a safe
place?
</string>
<string name="edit_transaction_note_dialog_title_edit">Transaction Note</string>
<string name="edit_transaction_note_dialog_txid_label">TX</string>
<string name="edit_transaction_note_dialog_note_label">Note</string>
<string name="button_edit_note">Edit Note</string>

</resources>
1 change: 1 addition & 0 deletions wallet/src/de/schildbach/wallet/WalletApplication.java
Expand Up @@ -435,6 +435,7 @@ private void backupKeys()
final String filename = String.format(Locale.US, "%s.%02d", Constants.WALLET_KEY_BACKUP_BASE58,
(System.currentTimeMillis() / DateUtils.DAY_IN_MILLIS) % 100l);
writeKeys(openFileOutput(filename, Context.MODE_PRIVATE));
// If we
}
catch (final IOException x)
{
Expand Down
146 changes: 146 additions & 0 deletions wallet/src/de/schildbach/wallet/ui/EditTransactionNoteFragment.java
@@ -0,0 +1,146 @@
/*
* Copyright 2011-2014 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.schildbach.wallet.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import de.schildbach.wallet.AddressBookProvider;
import de.schildbach.wallet.Constants;
import de.schildbach.wallet.util.WalletUtils;
import de.schildbach.wallet_ltc.R;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* @author Andreas Schildbach, Litecoin Dev Team
*/
public final class EditTransactionNoteFragment extends DialogFragment
{
private static final String FRAGMENT_TAG = EditTransactionNoteFragment.class.getName();
private static final String KEY_TRANSACTION = "transaction";
private SharedPreferences prefs;
private TransactionsListAdapter adapter;

public static void edit(final FragmentManager fm, @Nonnull final String address, TransactionsListAdapter adapter)
{
final EditTransactionNoteFragment newFragment = EditTransactionNoteFragment.instance(address);
newFragment.setAdapter(adapter);
newFragment.show(fm, FRAGMENT_TAG);
}

private static EditTransactionNoteFragment instance(@Nonnull final String txid)
{
final EditTransactionNoteFragment fragment = new EditTransactionNoteFragment();

final Bundle args = new Bundle();
args.putString(KEY_TRANSACTION, txid);
fragment.setArguments(args);

return fragment;
}

private Activity activity;
private ContentResolver contentResolver;

@Override
public void onAttach(final Activity activity)
{
super.onAttach(activity);

this.activity = activity;
this.contentResolver = activity.getContentResolver();
this.prefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplication());
}

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState)
{
final Bundle args = getArguments();
final String txid = args.getString(KEY_TRANSACTION);

final LayoutInflater inflater = LayoutInflater.from(activity);

final String note = prefs.getString("tx:"+txid, "");
final boolean isAdd = note.isEmpty();

final AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
dialog.setInverseBackgroundForced(true);
dialog.setTitle(R.string.edit_transaction_note_dialog_title_edit);

final View view = inflater.inflate(R.layout.edit_transaction_note_dialog, null);

final TextView viewTxid = (TextView) view.findViewById(R.id.edit_transaction_note_txid);
viewTxid.setText(txid);

final TextView viewNote = (TextView) view.findViewById(R.id.edit_transaction_note_note);
viewNote.setText(note);

dialog.setView(view);

final DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener()
{
@Override
public void onClick(final DialogInterface dialog, final int which)
{
if (which == DialogInterface.BUTTON_POSITIVE)
{
final String newNote = viewNote.getText().toString().trim();

if (!newNote.isEmpty())
{
prefs.edit().putString("tx:"+txid, newNote).commit();
}
}
if (which == DialogInterface.BUTTON_NEUTRAL)
{
prefs.edit().remove("tx:"+txid).commit();
}
// Notify list of update
if(adapter != null)
adapter.notifyDataSetChanged();

dismiss();
}
};

dialog.setPositiveButton(isAdd ? R.string.button_add : R.string.edit_address_book_entry_dialog_button_edit, onClickListener);
if (!isAdd)
dialog.setNeutralButton(R.string.button_delete, onClickListener);
dialog.setNegativeButton(R.string.button_cancel, onClickListener);

return dialog.create();
}

public void setAdapter(TransactionsListAdapter adapter) {
this.adapter = adapter;
}
}

0 comments on commit 25c23f3

Please sign in to comment.