onboarding tweaks & version bump (#676)

This commit is contained in:
m2049r 2020-09-14 00:24:57 +02:00 committed by GitHub
parent 0c9a2f5e01
commit c1d2db3d7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 116 additions and 27 deletions

View File

@ -7,8 +7,8 @@ android {
applicationId "com.m2049r.xmrwallet" applicationId "com.m2049r.xmrwallet"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 28 targetSdkVersion 28
versionCode 400 versionCode 401
versionName "1.14.0 'On Board'" versionName "1.14.1 'On Board'"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild { externalNativeBuild {
cmake { cmake {

View File

@ -23,22 +23,24 @@ import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import com.m2049r.xmrwallet.LoginActivity; import com.m2049r.xmrwallet.LoginActivity;
import com.m2049r.xmrwallet.R; import com.m2049r.xmrwallet.R;
public class OnBoardingActivity extends AppCompatActivity implements OnBoardingAdapter.Listener { public class OnBoardingActivity extends AppCompatActivity implements OnBoardingAdapter.Listener {
private ViewPager pager; private OnBoardingViewPager pager;
private OnBoardingAdapter pagerAdapter; private OnBoardingAdapter pagerAdapter;
private int mustAgreePages = 0; private Button nextButton;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_on_boarding); setContentView(R.layout.activity_on_boarding);
final View nextButton = findViewById(R.id.buttonNext); nextButton = findViewById(R.id.buttonNext);
pager = findViewById(R.id.pager); pager = findViewById(R.id.pager);
pagerAdapter = new OnBoardingAdapter(getApplicationContext(), this); pagerAdapter = new OnBoardingAdapter(getApplicationContext(), this);
@ -48,14 +50,18 @@ public class OnBoardingActivity extends AppCompatActivity implements OnBoardingA
pager.setPageMargin(pixels); pager.setPageMargin(pixels);
pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override @Override
public void onPageSelected(int i) { public void onPageSelected(int position) {
setButtonState(); setButtonState(position);
} }
}); });
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout); final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout);
if (pagerAdapter.getCount() > 1) { if (pagerAdapter.getCount() > 1) {
tabLayout.setupWithViewPager(pager, true); tabLayout.setupWithViewPager(pager, true);
LinearLayout tabStrip = ((LinearLayout) tabLayout.getChildAt(0));
for (int i = 0; i < tabStrip.getChildCount(); i++) {
tabStrip.getChildAt(i).setClickable(false);
}
} else { } else {
tabLayout.setVisibility(View.GONE); tabLayout.setVisibility(View.GONE);
} }
@ -70,8 +76,10 @@ public class OnBoardingActivity extends AppCompatActivity implements OnBoardingA
}); });
for (int i = 0; i < OnBoardingScreen.values().length; i++) { for (int i = 0; i < OnBoardingScreen.values().length; i++) {
if (OnBoardingScreen.values()[i].isMustAgree()) mustAgreePages++; agreed[i] = !OnBoardingScreen.values()[i].isMustAgree();
} }
setButtonState(0);
} }
private void finishOnboarding() { private void finishOnboarding() {
@ -80,18 +88,12 @@ public class OnBoardingActivity extends AppCompatActivity implements OnBoardingA
finish(); finish();
} }
int agreeCounter = 0;
boolean[] agreed = new boolean[OnBoardingScreen.values().length]; boolean[] agreed = new boolean[OnBoardingScreen.values().length];
@Override @Override
public void setAgreeClicked(int position, boolean isChecked) { public void setAgreeClicked(int position, boolean isChecked) {
if (isChecked) {
agreeCounter++;
} else {
agreeCounter--;
}
agreed[position] = isChecked; agreed[position] = isChecked;
setButtonState(); setButtonState(position);
} }
@Override @Override
@ -100,11 +102,16 @@ public class OnBoardingActivity extends AppCompatActivity implements OnBoardingA
} }
@Override @Override
public void setButtonState() { public void setButtonState(int position) {
nextButton.setEnabled(agreed[position]);
if (nextButton.isEnabled())
pager.setAllowedSwipeDirection(OnBoardingViewPager.SwipeDirection.ALL);
else
pager.setAllowedSwipeDirection(OnBoardingViewPager.SwipeDirection.LEFT);
if (pager.getCurrentItem() + 1 == pagerAdapter.getCount()) { // last page if (pager.getCurrentItem() + 1 == pagerAdapter.getCount()) { // last page
findViewById(R.id.buttonNext).setEnabled(mustAgreePages == agreeCounter); nextButton.setText(R.string.onboarding_button_ready);
} else { } else {
findViewById(R.id.buttonNext).setEnabled(true); nextButton.setText(R.string.onboarding_button_next);
} }
} }
} }

View File

@ -39,7 +39,7 @@ public class OnBoardingAdapter extends PagerAdapter {
boolean isAgreeClicked(int position); boolean isAgreeClicked(int position);
void setButtonState(); void setButtonState(int position);
} }
private final Context context; private final Context context;
@ -68,10 +68,8 @@ public class OnBoardingAdapter extends PagerAdapter {
agree.setOnClickListener(v -> { agree.setOnClickListener(v -> {
listener.setAgreeClicked(position, ((CheckBox) v).isChecked()); listener.setAgreeClicked(position, ((CheckBox) v).isChecked());
}); });
listener.setButtonState();
} }
collection.addView(view); collection.addView(view);
Timber.d("add " + position);
return view; return view;
} }

View File

@ -21,7 +21,7 @@ import com.m2049r.xmrwallet.R;
enum OnBoardingScreen { enum OnBoardingScreen {
WELCOME(R.string.onboarding_welcome_title, R.string.onboarding_welcome_information, R.drawable.ic_onboarding_welcome, false), WELCOME(R.string.onboarding_welcome_title, R.string.onboarding_welcome_information, R.drawable.ic_onboarding_welcome, false),
SEED(R.string.onboarding_seed_title, R.string.onboarding_seed_information, R.drawable.ic_onboarding_seed, true), SEED(R.string.onboarding_seed_title, R.string.onboarding_seed_information, R.drawable.ic_onboarding_seed, true),
FPSEND(R.string.onboarding_fpsend_title, R.string.onboarding_fpsend_information, R.drawable.ic_onboarding_fingerprint, true), FPSEND(R.string.onboarding_fpsend_title, R.string.onboarding_fpsend_information, R.drawable.ic_onboarding_fingerprint, false),
XMRTO(R.string.onboarding_xmrto_title, R.string.onboarding_xmrto_information, R.drawable.ic_onboarding_xmrto, false), XMRTO(R.string.onboarding_xmrto_title, R.string.onboarding_xmrto_information, R.drawable.ic_onboarding_xmrto, false),
NODES(R.string.onboarding_nodes_title, R.string.onboarding_nodes_information, R.drawable.ic_onboarding_nodes, false); NODES(R.string.onboarding_nodes_title, R.string.onboarding_nodes_information, R.drawable.ic_onboarding_nodes, false);

View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 2020 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.
*/
// based on https://stackoverflow.com/a/34076649
package com.m2049r.xmrwallet.onboarding;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class OnBoardingViewPager extends ViewPager {
public enum SwipeDirection {
ALL, LEFT, RIGHT, NONE;
}
private float initialXValue;
private SwipeDirection direction;
public OnBoardingViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.direction = SwipeDirection.ALL;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.IsSwipeAllowed(event)) {
return super.onTouchEvent(event);
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.IsSwipeAllowed(event)) {
return super.onInterceptTouchEvent(event);
}
return false;
}
private boolean IsSwipeAllowed(MotionEvent event) {
if (this.direction == SwipeDirection.ALL) return true;
if (direction == SwipeDirection.NONE)//disable any swipe
return false;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
initialXValue = event.getX();
return true;
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
float diffX = event.getX() - initialXValue;
if (diffX > 0 && direction == SwipeDirection.RIGHT) {
// swipe from left to right detected
return false;
} else if (diffX < 0 && direction == SwipeDirection.LEFT) {
// swipe from right to left detected
return false;
}
}
return true;
}
public void setAllowedSwipeDirection(SwipeDirection direction) {
this.direction = direction;
}
}

View File

@ -22,7 +22,7 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
<android.support.v4.view.ViewPager <com.m2049r.xmrwallet.onboarding.OnBoardingViewPager
android:id="@+id/pager" android:id="@+id/pager"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"

View File

@ -441,17 +441,16 @@
<string name="onboarding_agree">I get it!</string> <string name="onboarding_agree">I get it!</string>
<string name="onboarding_button_next">Next</string> <string name="onboarding_button_next">Next</string>
<string name="onboarding_button_ready">I\'m ready!</string>
<string name="onboarding_welcome_title">Welcome to Monerujo!</string> <string name="onboarding_welcome_title">Welcome to Monerujo!</string>
<string name="onboarding_welcome_information">This app allows you to create and use Monero wallets. You can store your sweet Monero (XMR) in them.</string> <string name="onboarding_welcome_information">This app allows you to create and use Monero wallets. You can store your sweet Monero (XMR) in them.</string>
<string name="onboarding_seed_title">Write down your seed</string> <string name="onboarding_seed_title">Write down your seeds</string>
<string name="onboarding_seed_information">Your seed is secret and we cannot help you recover it. It unlocks your money to whoever has it. If you lose it, you lose your beloved Monero.</string> <string name="onboarding_seed_information">Your seed is secret and we cannot help you recover it. It unlocks your money to whoever has it. If you lose it, you lose your beloved Monero.</string>
<string name="onboarding_xmrto_title">Send Bitcoin</string> <string name="onboarding_xmrto_title">Send Bitcoin</string>
<string name="onboarding_xmrto_information">Monerujo has XMR.to support builtin. You can send BTC by spending XMR. Just paste or scan a BTC address when sending.</string> <string name="onboarding_xmrto_information">Monerujo has XMR.to support builtin. You can send BTC by spending XMR. Just paste or scan a BTC address when sending.</string>
<string name="onboarding_nodes_title">Nodes, your way</string> <string name="onboarding_nodes_title">Nodes, your way</string>
<string name="onboarding_nodes_information">Nodes connect you to the Monero network. Choose between searching for public nodes or go full cypherpunk using your own.</string> <string name="onboarding_nodes_information">Nodes connect you to the Monero network. Choose between searching for public nodes or go full cypherpunk using your own.</string>
<string name="onboarding_fpsend_title">Send with fingerprint</string> <string name="onboarding_fpsend_title">Send with fingerprint</string>
<string name="onboarding_fpsend_information">You\'ll be able to authorize sending XMR with just your fingerprint. <string name="onboarding_fpsend_information">You\'ll now be able to authorize sending XMR with just your fingerprint if you have it enabled on your wallets. To force the password for sending, please disable fingerprint access.</string>
If you prefer to secure sending by password, please disable fingerprint access for that wallet.</string>
</resources> </resources>