Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
### Changed
### Removed
### Fixed
* ui: fix crash when adding a payment mehtod (APPS-2155)

## [0.80.5]
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.progressindicator.CircularProgressIndicator;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -50,6 +51,8 @@ public class PaymentCredentialsListView extends FrameLayout implements PaymentCr
private List<Type> types;
private Project project;
private View emptyState;
private FloatingActionButton fab;
private CircularProgressIndicator circularIndicator;

public PaymentCredentialsListView(Context context) {
super(context);
Expand All @@ -69,17 +72,19 @@ public PaymentCredentialsListView(Context context, AttributeSet attrs, int defSt
private void inflateView() {
inflate(getContext(), R.layout.snabble_view_payment_credentials_list, this);
if (isInEditMode()) return;
emptyState = findViewById(R.id.empty_state);
recyclerView = findViewById(R.id.recycler_view);
fab = findViewById(R.id.fab);
circularIndicator = findViewById(R.id.circular_indicator);

paymentCredentialsStore = Snabble.getInstance().getPaymentCredentialsStore();

recyclerView = findViewById(R.id.recycler_view);
recyclerView.setAdapter(new PaymentCredentialsListView.Adapter());

LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(null);

FloatingActionButton fab = findViewById(R.id.fab);

final Project currentProject = Snabble.getInstance().getCheckedInProject().getLatestValue();
final int primaryColor = RemoteThemingHelper.primaryColorForProject(getContext(), currentProject);
final int onPrimaryColor = RemoteThemingHelper.onPrimaryColorForProject(getContext(), currentProject);
Expand All @@ -97,17 +102,11 @@ public void click() {
Bundle bundle = new Bundle();

Project p = project;
if (p == null) {
p = Snabble.getInstance().getCheckedInProject().getValue();
}

if (p == null) {
throw new IllegalStateException("Cannot get current project. Did you forget to set the projectId to the PaymentCredentialsListFragment or PaymentCredentialsListView?");
if (p != null) {
bundle.putString(SelectPaymentMethodFragment.ARG_PROJECT_ID, p.getId());
dialogFragment.setArguments(bundle);
dialogFragment.show(((FragmentActivity) activity).getSupportFragmentManager(), null);
}

bundle.putString(SelectPaymentMethodFragment.ARG_PROJECT_ID, p.getId());
dialogFragment.setArguments(bundle);
dialogFragment.show(((FragmentActivity) activity).getSupportFragmentManager(), null);
} else {
throw new RuntimeException("Host activity must be a Fragment Activity");
}
Expand All @@ -124,19 +123,20 @@ public void click() {
}
}
});

emptyState = findViewById(R.id.empty_state);
}

public void setProject(Project project) {
this.project = project;
circularIndicator.setVisibility(View.GONE);
onChanged();
}

public void show(List<Type> types, Project project) {
this.types = types;
this.project = project;

entries.clear();
circularIndicator.setVisibility(View.GONE);
onChanged();
}

Expand Down Expand Up @@ -184,24 +184,27 @@ public void onChanged() {
List<PaymentCredentials> paymentCredentials = paymentCredentialsStore.getAll();

for (PaymentCredentials pm : paymentCredentials) {
boolean sameProjectOrNull = true;
boolean sameProject = false;
if (project != null) {
sameProjectOrNull = project.getId().equals(pm.getProjectId());
sameProject = project.getId().equals(pm.getProjectId());
}

if (pm.getProjectId() == null && (pm.getType() == Type.SEPA || pm.getType() == Type.PAYONE_SEPA)) {
sameProjectOrNull = true;
sameProject = true;
}

boolean sameTypeOrNull = true;
boolean sameType = false;
if (types != null) {
if (project != null) {
sameTypeOrNull = project.getAvailablePaymentMethods().contains(pm.getPaymentMethod());
sameType = project.getAvailablePaymentMethods().contains(pm.getPaymentMethod());
} else {
sameTypeOrNull = types.contains(pm.getType());
sameType = types.contains(pm.getType());
}
}
if (pm.isAvailableInCurrentApp() && sameTypeOrNull && sameProjectOrNull) {

boolean isRetailer = Snabble.getInstance().getProjects().size() == 1;

if ((pm.isAvailableInCurrentApp() && sameType && sameProject) || isRetailer) {
switch (pm.getType()) {
case SEPA:
case PAYONE_SEPA:
Expand Down Expand Up @@ -231,11 +234,15 @@ public void onChanged() {
}

if (entries.size() == 0) {
emptyState.setVisibility(View.VISIBLE);
if (project != null) {
emptyState.setVisibility(View.VISIBLE);
fab.setVisibility(View.VISIBLE);
}
recyclerView.setVisibility(View.GONE);
} else {
emptyState.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
fab.setVisibility(View.VISIBLE);
}

recyclerView.getAdapter().notifyDataSetChanged();
Expand Down
10 changes: 10 additions & 0 deletions ui/src/main/res/layout/snabble_view_payment_credentials_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/circular_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:indicatorSize="48dp"
android:indeterminate="true"/>

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -45,6 +54,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:visibility="gone"
app:tint="?attr/colorOnSecondary"
android:src="@drawable/snabble_ic_add"
android:layout_margin="16dp"/>
Expand Down