mirror of
https://codeberg.org/anoncontributorxmr/mysu.git
synced 2024-12-22 13:07:46 +00:00
Display addresses in list. Still need to do styling and stuff.
This commit is contained in:
parent
afc7bb730b
commit
e90462707c
6 changed files with 236 additions and 98 deletions
|
@ -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<SubaddressAdapter.ViewHolder> {
|
||||
|
||||
private List<Subaddress> localDataSet;
|
||||
|
||||
/**
|
||||
* Initialize the dataset of the Adapter.
|
||||
*/
|
||||
public SubaddressAdapter() {
|
||||
this.localDataSet = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void submitList(List<Subaddress> 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());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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()));
|
||||
|
|
|
@ -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<Subaddress> _address = new MutableLiveData<>();
|
||||
private final MutableLiveData<Subaddress> _address = new MutableLiveData<>();
|
||||
public LiveData<Subaddress> address = _address;
|
||||
private final MutableLiveData<List<Subaddress>> _addresses = new MutableLiveData<>();
|
||||
public LiveData<List<Subaddress>> addresses = _addresses;
|
||||
|
||||
public void init() {
|
||||
_address.setValue(AddressService.getInstance().currentSubaddress());
|
||||
_addresses.setValue(getSubaddresses());
|
||||
}
|
||||
|
||||
private List<Subaddress> getSubaddresses() {
|
||||
ArrayList<Subaddress> 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) {
|
||||
|
|
|
@ -39,6 +39,10 @@ public class AddressService extends ServiceBase {
|
|||
return lastUsedSubaddress;
|
||||
}
|
||||
|
||||
public int getLatestAddressIndex() {
|
||||
return latestAddressIndex;
|
||||
}
|
||||
|
||||
public String getPrimaryAddress() {
|
||||
return WalletManager.getInstance().getWallet().getAddress();
|
||||
}
|
||||
|
|
|
@ -1,101 +1,109 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
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:padding="24dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true"
|
||||
android:fitsSystemWindows="true"
|
||||
android:padding="24dp">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recv_monero_textview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="32dp"
|
||||
android:text="@string/recv_monero"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@id/monero_qr_imageview"
|
||||
app:layout_constraintEnd_toStartOf="@id/fresh_address_imageview"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<ImageView
|
||||
android:id="@+id/fresh_address_imageview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/lb_ic_replay"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/recv_monero_textview"
|
||||
app:layout_constraintBottom_toBottomOf="@id/recv_monero_textview"
|
||||
app:tint="@color/oled_textColorPrimary" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/monero_qr_imageview"
|
||||
android:layout_width="256dp"
|
||||
android:layout_height="256dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:src="@drawable/ic_fingerprint"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/recv_monero_textview" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/monero_logo_imageview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_monero_qr"
|
||||
app:layout_constraintBottom_toBottomOf="@id/monero_qr_imageview"
|
||||
app:layout_constraintEnd_toEndOf="@id/monero_qr_imageview"
|
||||
app:layout_constraintStart_toStartOf="@id/monero_qr_imageview"
|
||||
app:layout_constraintTop_toTopOf="@id/monero_qr_imageview" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/address_textview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:ellipsize="middle"
|
||||
android:singleLine="true"
|
||||
app:layout_constraintEnd_toStartOf="@id/copy_address_imagebutton"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/copy_address_imagebutton"
|
||||
app:layout_constraintBottom_toTopOf="@id/address_label_textview"
|
||||
tools:text="ADDRESS" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/address_label_textview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textSize="14sp"
|
||||
android:ellipsize="middle"
|
||||
android:singleLine="true"
|
||||
app:layout_constraintEnd_toStartOf="@id/copy_address_imagebutton"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/address_textview"
|
||||
app:layout_constraintBottom_toBottomOf="@id/copy_address_imagebutton"
|
||||
tools:text="ADDRESS" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/copy_address_imagebutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:layout_marginTop="16dp"
|
||||
android:minWidth="24dp"
|
||||
android:minHeight="24dp"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_content_copy_24dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/address_list_recyclerview"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/address_textview"
|
||||
app:layout_constraintTop_toBottomOf="@id/monero_qr_imageview" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/address_list_recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recv_monero_textview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="32dp"
|
||||
android:text="@string/recv_monero"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@id/monero_qr_imageview"
|
||||
app:layout_constraintEnd_toStartOf="@id/fresh_address_imageview"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/fresh_address_imageview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/lb_ic_replay"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/recv_monero_textview"
|
||||
app:layout_constraintBottom_toBottomOf="@id/recv_monero_textview"
|
||||
app:tint="@color/oled_textColorPrimary" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/monero_qr_imageview"
|
||||
android:layout_width="256dp"
|
||||
android:layout_height="256dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:src="@drawable/ic_fingerprint"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/recv_monero_textview" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/monero_logo_imageview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_monero_qr"
|
||||
app:layout_constraintBottom_toBottomOf="@id/monero_qr_imageview"
|
||||
app:layout_constraintEnd_toEndOf="@id/monero_qr_imageview"
|
||||
app:layout_constraintStart_toStartOf="@id/monero_qr_imageview"
|
||||
app:layout_constraintTop_toTopOf="@id/monero_qr_imageview" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/address_textview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toStartOf="@id/copy_address_imagebutton"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/monero_qr_imageview"
|
||||
tools:text="ADDRESS" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/copy_address_imagebutton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent"
|
||||
android:minWidth="24dp"
|
||||
android:minHeight="24dp"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_content_copy_24dp"
|
||||
app:layout_constraintBottom_toBottomOf="@id/address_textview"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/address_textview"
|
||||
app:layout_constraintTop_toTopOf="@id/address_textview" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/address_list_recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
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" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</ScrollView>
|
||||
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" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -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" />
|
||||
<fragment
|
||||
android:id="@+id/transaction_fragment"
|
||||
android:name="net.mynero.wallet.fragment.transaction.TransactionFragment"
|
||||
android:label="fragment_onboarding"
|
||||
tools:layout="@layout/fragment_settings" />
|
||||
tools:layout="@layout/fragment_transaction" />
|
||||
</navigation>
|
Loading…
Reference in a new issue