forked from bitcoin-wallet/bitcoin-wallet
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
11 changed files
with
353 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
wallet/src/de/schildbach/wallet/ui/EditTransactionNoteFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.