From e90462707c358b411f3ee06e87eaba4304673883 Mon Sep 17 00:00:00 2001 From: pokkst Date: Tue, 22 Nov 2022 11:18:57 -0600 Subject: [PATCH] Display addresses in list. Still need to do styling and stuff. --- .../wallet/adapter/SubaddressAdapter.java | 98 +++++++++ .../fragment/receive/ReceiveFragment.java | 13 +- .../fragment/receive/ReceiveViewModel.java | 19 +- .../mynero/wallet/service/AddressService.java | 4 + app/src/main/res/layout/fragment_receive.xml | 196 +++++++++--------- app/src/main/res/navigation/main_nav.xml | 4 +- 6 files changed, 236 insertions(+), 98 deletions(-) create mode 100644 app/src/main/java/net/mynero/wallet/adapter/SubaddressAdapter.java diff --git a/app/src/main/java/net/mynero/wallet/adapter/SubaddressAdapter.java b/app/src/main/java/net/mynero/wallet/adapter/SubaddressAdapter.java new file mode 100644 index 0000000..8f3bd21 --- /dev/null +++ b/app/src/main/java/net/mynero/wallet/adapter/SubaddressAdapter.java @@ -0,0 +1,98 @@ +/* + * 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 net.mynero.wallet.adapter; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; + +import net.mynero.wallet.R; +import net.mynero.wallet.data.Subaddress; +import net.mynero.wallet.model.CoinsInfo; +import net.mynero.wallet.model.Wallet; +import net.mynero.wallet.service.PrefService; +import net.mynero.wallet.util.Constants; + +import java.util.ArrayList; +import java.util.List; + +public class SubaddressAdapter extends RecyclerView.Adapter { + + private List localDataSet; + + /** + * Initialize the dataset of the Adapter. + */ + public SubaddressAdapter() { + this.localDataSet = new ArrayList<>(); + } + + public void submitList(List dataSet) { + System.out.println("ADDRESSES: " + dataSet); + this.localDataSet = dataSet; + notifyDataSetChanged(); + } + + // 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.utxo_selection_item, viewGroup, false); + + return new ViewHolder(view); + } + + // Replace the contents of a view (invoked by the layout manager) + @Override + public void onBindViewHolder(ViewHolder viewHolder, final int position) { + Subaddress subaddress = localDataSet.get(position); + viewHolder.bind(subaddress); + } + + // Return the size of your dataset (invoked by the layout manager) + @Override + public int getItemCount() { + return localDataSet.size(); + } + + public interface SubaddressAdapterListener { + void onSubaddressSelected(Subaddress subaddress); + } + + /** + * Provide a reference to the type of views that you are using + * (custom ViewHolder). + */ + public static class ViewHolder extends RecyclerView.ViewHolder { + + public ViewHolder(View view) { + super(view); + } + + public void bind(Subaddress subaddress) { + TextView pubKeyTextView = itemView.findViewById(R.id.utxo_pub_key_textview); + pubKeyTextView.setText(subaddress.getAddress()); + + } + } +} + diff --git a/app/src/main/java/net/mynero/wallet/fragment/receive/ReceiveFragment.java b/app/src/main/java/net/mynero/wallet/fragment/receive/ReceiveFragment.java index 8177b14..faf26f9 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/receive/ReceiveFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/receive/ReceiveFragment.java @@ -13,6 +13,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; @@ -22,6 +24,7 @@ import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import net.mynero.wallet.R; +import net.mynero.wallet.adapter.SubaddressAdapter; import net.mynero.wallet.data.Subaddress; import net.mynero.wallet.util.DayNightMode; import net.mynero.wallet.util.Helper; @@ -35,6 +38,7 @@ import timber.log.Timber; public class ReceiveFragment extends Fragment { private TextView addressTextView = null; + private TextView addressLabelTextView = null; private ImageView addressImageView = null; private ImageButton copyAddressImageButton = null; private ReceiveViewModel mViewModel; @@ -51,10 +55,11 @@ public class ReceiveFragment extends Fragment { mViewModel = new ViewModelProvider(this).get(ReceiveViewModel.class); addressImageView = view.findViewById(R.id.monero_qr_imageview); addressTextView = view.findViewById(R.id.address_textview); + addressLabelTextView = view.findViewById(R.id.address_label_textview); copyAddressImageButton = view.findViewById(R.id.copy_address_imagebutton); - mViewModel.init(); bindListeners(view); bindObservers(view); + mViewModel.init(); } private void bindListeners(View view) { @@ -65,10 +70,16 @@ public class ReceiveFragment extends Fragment { } private void bindObservers(View view) { + SubaddressAdapter adapter = new SubaddressAdapter(); + RecyclerView recyclerView = view.findViewById(R.id.address_list_recyclerview); + recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); + recyclerView.setAdapter(adapter); mViewModel.address.observe(getViewLifecycleOwner(), this::setAddress); + mViewModel.addresses.observe(getViewLifecycleOwner(), adapter::submitList); } private void setAddress(Subaddress subaddress) { + addressLabelTextView.setText(subaddress.getLabel()); addressTextView.setText(subaddress.getAddress()); addressImageView.setImageBitmap(generate(subaddress.getAddress(), 256, 256)); copyAddressImageButton.setOnClickListener(view1 -> Helper.clipBoardCopy(getContext(), "address", subaddress.getAddress())); diff --git a/app/src/main/java/net/mynero/wallet/fragment/receive/ReceiveViewModel.java b/app/src/main/java/net/mynero/wallet/fragment/receive/ReceiveViewModel.java index 06563e4..63d313a 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/receive/ReceiveViewModel.java +++ b/app/src/main/java/net/mynero/wallet/fragment/receive/ReceiveViewModel.java @@ -5,18 +5,35 @@ import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import net.mynero.wallet.data.Subaddress; +import net.mynero.wallet.model.WalletManager; import net.mynero.wallet.service.AddressService; +import java.util.ArrayList; +import java.util.List; + public class ReceiveViewModel extends ViewModel { - private MutableLiveData _address = new MutableLiveData<>(); + private final MutableLiveData _address = new MutableLiveData<>(); public LiveData address = _address; + private final MutableLiveData> _addresses = new MutableLiveData<>(); + public LiveData> addresses = _addresses; public void init() { _address.setValue(AddressService.getInstance().currentSubaddress()); + _addresses.setValue(getSubaddresses()); + } + + private List getSubaddresses() { + ArrayList subaddresses = new ArrayList<>(); + int addressesSize = AddressService.getInstance().getLatestAddressIndex(); + for(int i = 0; i < addressesSize; i++) { + subaddresses.add(WalletManager.getInstance().getWallet().getSubaddressObject(i)); + } + return subaddresses; } public void getFreshSubaddress() { _address.setValue(AddressService.getInstance().freshSubaddress()); + _addresses.setValue(getSubaddresses()); } public void selectAddress(Subaddress subaddress) { diff --git a/app/src/main/java/net/mynero/wallet/service/AddressService.java b/app/src/main/java/net/mynero/wallet/service/AddressService.java index b51301a..96a1a26 100644 --- a/app/src/main/java/net/mynero/wallet/service/AddressService.java +++ b/app/src/main/java/net/mynero/wallet/service/AddressService.java @@ -39,6 +39,10 @@ public class AddressService extends ServiceBase { return lastUsedSubaddress; } + public int getLatestAddressIndex() { + return latestAddressIndex; + } + public String getPrimaryAddress() { return WalletManager.getInstance().getWallet().getAddress(); } diff --git a/app/src/main/res/layout/fragment_receive.xml b/app/src/main/res/layout/fragment_receive.xml index 58f22a6..600ade1 100644 --- a/app/src/main/res/layout/fragment_receive.xml +++ b/app/src/main/res/layout/fragment_receive.xml @@ -1,101 +1,109 @@ - + android:layout_height="match_parent"> + - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - \ No newline at end of file + android:layout_height="0dp" + android:layout_marginTop="16dp" + android:clipToPadding="false" + android:paddingBottom="128dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/copy_address_imagebutton" + app:layout_constraintVertical_bias="0.0" /> + \ No newline at end of file diff --git a/app/src/main/res/navigation/main_nav.xml b/app/src/main/res/navigation/main_nav.xml index f5b10c9..3437f74 100644 --- a/app/src/main/res/navigation/main_nav.xml +++ b/app/src/main/res/navigation/main_nav.xml @@ -55,10 +55,10 @@ android:id="@+id/onboarding_fragment" android:name="net.mynero.wallet.fragment.onboarding.OnboardingFragment" android:label="fragment_onboarding" - tools:layout="@layout/fragment_settings" /> + tools:layout="@layout/fragment_onboarding" /> + tools:layout="@layout/fragment_transaction" /> \ No newline at end of file