Begin work on displaying tx history.

NOTE: This commit still logs seed phrases for development purposes
This commit is contained in:
pokkst 2022-09-07 17:21:47 -05:00
parent cde290d52e
commit c051c2aee9
No known key found for this signature in database
GPG key ID: 90C2ED85E67A50FF
5 changed files with 279 additions and 6 deletions

View file

@ -153,6 +153,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.navigation:navigation-fragment:2.5.1'
implementation 'androidx.navigation:navigation-ui:2.5.1'
implementation 'androidx.leanback:leanback:1.0.0'
//noinspection GradleDependency
testImplementation "junit:junit:4.13.2"

View file

@ -0,0 +1,115 @@
/*
* Copyright (c) 2017 m2049r
*
* 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.m2049r.xmrwallet.adapter;
import android.content.Context;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.leanback.widget.DiffCallback;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.progressindicator.CircularProgressIndicator;
import com.m2049r.xmrwallet.R;
import com.m2049r.xmrwallet.data.Crypto;
import com.m2049r.xmrwallet.data.UserNotes;
import com.m2049r.xmrwallet.model.TransactionInfo;
import com.m2049r.xmrwallet.util.Helper;
import com.m2049r.xmrwallet.util.ThemeHelper;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.TimeZone;
import timber.log.Timber;
public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfoAdapter.ViewHolder> {
private List<TransactionInfo> localDataSet;
private TxInfoAdapterListener listener = null;
/**
* Provide a reference to the type of views that you are using
* (custom ViewHolder).
*/
public static class ViewHolder extends RecyclerView.ViewHolder {
private TxInfoAdapterListener listener = null;
public ViewHolder(TxInfoAdapterListener listener, View view) {
super(view);
this.listener = listener;
}
public void bind(TransactionInfo txInfo) {
itemView.setOnClickListener(view -> {
listener.onClickTransaction(txInfo);
});
}
}
/**
* Initialize the dataset of the Adapter.
*/
public TransactionInfoAdapter(TxInfoAdapterListener listener) {
this.listener = listener;
this.localDataSet = new ArrayList<>();
}
public void submitList(List<TransactionInfo> dataSet) {
this.localDataSet = dataSet;
}
// Create new views (invoked by the layout manager)
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
// Create a new view, which defines the UI of the list item
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.transaction_history_item, viewGroup, false);
return new ViewHolder(listener, view);
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
TransactionInfo tx = localDataSet.get(position);
viewHolder.bind(tx);
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return localDataSet.size();
}
public interface TxInfoAdapterListener {
void onClickTransaction(TransactionInfo txInfo);
}
}

View file

@ -18,18 +18,23 @@ import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.fragment.NavHostFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.m2049r.xmrwallet.MainActivity;
import com.m2049r.xmrwallet.R;
import com.m2049r.xmrwallet.adapter.TransactionInfoAdapter;
import com.m2049r.xmrwallet.fragment.dialog.ReceiveBottomSheetDialog;
import com.m2049r.xmrwallet.fragment.dialog.SendBottomSheetDialog;
import com.m2049r.xmrwallet.model.TransactionInfo;
import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.service.AddressService;
import com.m2049r.xmrwallet.service.BalanceService;
import com.m2049r.xmrwallet.service.HistoryService;
import com.m2049r.xmrwallet.service.TxService;
public class HomeFragment extends Fragment {
public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxInfoAdapterListener {
private HomeViewModel mViewModel;
@ -43,16 +48,15 @@ public class HomeFragment extends Fragment {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mViewModel = new ViewModelProvider(this).get(HomeViewModel.class);
bindObservers(view);
bindListeners(view);
}
private void bindListeners(View view) {
ImageView settingsImageView = view.findViewById(R.id.settings_imageview);
TextView balanceTextView = view.findViewById(R.id.balance_textview);
Button sendButton = view.findViewById(R.id.send_button);
Button receiveButton = view.findViewById(R.id.receive_button);
BalanceService.getInstance().balance.observe(getViewLifecycleOwner(), balance -> {
balanceTextView.setText(getString(R.string.wallet_balance_text, Wallet.getDisplayAmount(balance)));
});
settingsImageView.setOnClickListener(view12 -> {
navigate(R.id.settings_fragment);
});
@ -68,6 +72,32 @@ public class HomeFragment extends Fragment {
});
}
private void bindObservers(View view) {
RecyclerView txHistoryRecyclerView = view.findViewById(R.id.transaction_history_recyclerview);
TextView balanceTextView = view.findViewById(R.id.balance_textview);
BalanceService.getInstance().balance.observe(getViewLifecycleOwner(), balance -> {
balanceTextView.setText(getString(R.string.wallet_balance_text, Wallet.getDisplayAmount(balance)));
});
TransactionInfoAdapter adapter = new TransactionInfoAdapter(this);
txHistoryRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
txHistoryRecyclerView.setAdapter(adapter);
HistoryService.getInstance().history.observe(getViewLifecycleOwner(), history -> {
if(history.isEmpty()) {
txHistoryRecyclerView.setVisibility(View.GONE);
} else {
adapter.submitList(history);
txHistoryRecyclerView.setVisibility(View.VISIBLE);
}
});
}
@Override
public void onClickTransaction(TransactionInfo txInfo) {
System.out.println(txInfo.hash);
}
private void navigate(int destination) {
FragmentActivity activity = getActivity();
if (activity != null) {

View file

@ -29,6 +29,17 @@
app:layout_constraintTop_toTopOf="@id/settings_imageview"
app:layout_constraintBottom_toBottomOf="@id/settings_imageview"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/transaction_history_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/balance_textview"
app:layout_constraintBottom_toTopOf="@id/receive_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintVertical_bias="0.0"/>
<Button
android:id="@+id/receive_button"
android:layout_width="0dp"

View file

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="9"
android:orientation="horizontal">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:id="@+id/ivTxType"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center"
android:src="@drawable/ic_xmrto_btc"
android:visibility="visible" />
<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/pbConfirmations"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="center"
android:indeterminate="false"
android:max="10"
android:progress="8"
android:visibility="visible"
app:indicatorInset="0dp"
app:indicatorSize="30dp"
app:trackThickness="4dp" />
<TextView
android:id="@+id/tvConfirmations"
style="@style/MoneroText.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingBottom="1dp"
android:text="8"
android:visibility="visible" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tx_amount"
style="@style/MoneroText.PosAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
tools:text="+ 999.999999" />
<TextView
android:id="@+id/tx_failed"
style="@style/MoneroText.PosFee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:text="@string/tx_list_failed_text" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/tx_paymentid"
style="@style/MoneroText.PosNote"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_weight="13"
android:gravity="start"
tools:text="0123456789abcdef" />
<TextView
android:id="@+id/tx_datetime"
style="@style/MoneroText.PosDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="6"
android:gravity="center"
tools:text="2017-05-22 21:32" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_navigate_next" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>