move ConfirmReceiveView to pure XML SwapView with logic in Presenter

This commit is contained in:
Hans-Christoph Steiner 2019-05-15 13:34:47 +02:00
parent d5f2e26ea7
commit 1e1ea03bc3
3 changed files with 36 additions and 68 deletions

View File

@ -1,54 +0,0 @@
package org.fdroid.fdroid.views.swap;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.data.NewRepoConfig;
import org.fdroid.fdroid.localrepo.SwapView;
public class ConfirmReceiveView extends SwapView {
private NewRepoConfig config;
public ConfirmReceiveView(Context context) {
super(context);
}
public ConfirmReceiveView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ConfirmReceiveView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public ConfirmReceiveView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
findViewById(R.id.no_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().denySwap();
}
});
findViewById(R.id.yes_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().swapWith(config);
}
});
}
public void setup(NewRepoConfig config) {
this.config = config;
}
}

View File

@ -435,11 +435,9 @@ public class SwapWorkflowActivity extends AppCompatActivity {
return;
}
// This is separate from the switch statement below, because it is usually populated
// during onResume, when there is a high probability of not having a swap service
// available. Thus, we were unable to set the state of the swap service appropriately.
if (confirmSwapConfig != null) {
showConfirmSwap(confirmSwapConfig);
inflateSwapView(R.layout.swap_confirm_receive);
setUpConfirmReceive();
confirmSwapConfig = null;
return;
}
@ -528,12 +526,6 @@ public class SwapWorkflowActivity extends AppCompatActivity {
inflateSwapView(R.layout.swap_start_swap);
}
private void showConfirmSwap(@NonNull NewRepoConfig config) {
((ConfirmReceiveView) inflateSwapView(R.layout.swap_confirm_receive)).setup(config);
TextView descriptionTextView = (TextView) findViewById(R.id.text_description);
descriptionTextView.setText(getResources().getString(R.string.swap_confirm_connect, config.getHost()));
}
public void startQrWorkflow() {
if (!getService().isEnabled()) {
new AlertDialog.Builder(this)
@ -993,4 +985,34 @@ public class SwapWorkflowActivity extends AppCompatActivity {
});
}
}
private void setUpConfirmReceive() {
TextView descriptionTextView = findViewById(R.id.text_description);
if (descriptionTextView != null) {
descriptionTextView.setText(getString(R.string.swap_confirm_connect, confirmSwapConfig.getHost()));
}
Button confirmReceiveYes = container.findViewById(R.id.confirm_receive_yes);
if (confirmReceiveYes != null) {
findViewById(R.id.confirm_receive_yes).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
denySwap();
}
});
}
Button confirmReceiveNo = container.findViewById(R.id.confirm_receive_no);
if (confirmReceiveNo != null) {
findViewById(R.id.confirm_receive_no).setOnClickListener(new View.OnClickListener() {
private final NewRepoConfig config = confirmSwapConfig;
@Override
public void onClick(View v) {
swapWith(config);
}
});
}
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<org.fdroid.fdroid.views.swap.ConfirmReceiveView
<org.fdroid.fdroid.localrepo.SwapView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:swap="http://schemas.android.com/apk/res-auto"
@ -56,7 +56,7 @@
<!-- TODO: Remove associated style files style="@style/SwapTheme.Wizard.ReceiveSwap.Deny"-->
<Button
android:id="@+id/no_button"
android:id="@+id/confirm_receive_yes"
android:text="@string/no"
android:backgroundTint="@color/swap_deny"
android:layout_width="wrap_content"
@ -67,7 +67,7 @@
<!-- TODO: Remove associated style files style="@style/SwapTheme.Wizard.ReceiveSwap.Confirm" -->
<Button
android:id="@+id/yes_button"
android:id="@+id/confirm_receive_no"
android:text="@string/yes"
android:backgroundTint="@color/swap_light_blue"
android:layout_width="wrap_content"
@ -76,4 +76,4 @@
</LinearLayout>
</org.fdroid.fdroid.views.swap.ConfirmReceiveView>
</org.fdroid.fdroid.localrepo.SwapView>