From c1d2db3d7d4d03aa60c51bf4fb55fe6b3e6c27fe Mon Sep 17 00:00:00 2001 From: m2049r Date: Mon, 14 Sep 2020 00:24:57 +0200 Subject: [PATCH] onboarding tweaks & version bump (#676) --- app/build.gradle | 4 +- .../onboarding/OnBoardingActivity.java | 39 +++++---- .../onboarding/OnBoardingAdapter.java | 4 +- .../onboarding/OnBoardingScreen.java | 2 +- .../onboarding/OnBoardingViewPager.java | 85 +++++++++++++++++++ .../main/res/layout/activity_on_boarding.xml | 2 +- app/src/main/res/values/strings.xml | 7 +- 7 files changed, 116 insertions(+), 27 deletions(-) create mode 100644 app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingViewPager.java diff --git a/app/build.gradle b/app/build.gradle index 36a0ce90..caed6b45 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "com.m2049r.xmrwallet" minSdkVersion 21 targetSdkVersion 28 - versionCode 400 - versionName "1.14.0 'On Board'" + versionCode 401 + versionName "1.14.1 'On Board'" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { diff --git a/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingActivity.java b/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingActivity.java index 92cebbdc..9b82eba8 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingActivity.java +++ b/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingActivity.java @@ -23,22 +23,24 @@ import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.util.TypedValue; import android.view.View; +import android.widget.Button; +import android.widget.LinearLayout; import com.m2049r.xmrwallet.LoginActivity; import com.m2049r.xmrwallet.R; public class OnBoardingActivity extends AppCompatActivity implements OnBoardingAdapter.Listener { - private ViewPager pager; + private OnBoardingViewPager pager; private OnBoardingAdapter pagerAdapter; - private int mustAgreePages = 0; + private Button nextButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_on_boarding); - final View nextButton = findViewById(R.id.buttonNext); + nextButton = findViewById(R.id.buttonNext); pager = findViewById(R.id.pager); pagerAdapter = new OnBoardingAdapter(getApplicationContext(), this); @@ -48,14 +50,18 @@ public class OnBoardingActivity extends AppCompatActivity implements OnBoardingA pager.setPageMargin(pixels); pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override - public void onPageSelected(int i) { - setButtonState(); + public void onPageSelected(int position) { + setButtonState(position); } }); final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout); if (pagerAdapter.getCount() > 1) { tabLayout.setupWithViewPager(pager, true); + LinearLayout tabStrip = ((LinearLayout) tabLayout.getChildAt(0)); + for (int i = 0; i < tabStrip.getChildCount(); i++) { + tabStrip.getChildAt(i).setClickable(false); + } } else { tabLayout.setVisibility(View.GONE); } @@ -70,8 +76,10 @@ public class OnBoardingActivity extends AppCompatActivity implements OnBoardingA }); 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() { @@ -80,18 +88,12 @@ public class OnBoardingActivity extends AppCompatActivity implements OnBoardingA finish(); } - int agreeCounter = 0; boolean[] agreed = new boolean[OnBoardingScreen.values().length]; @Override public void setAgreeClicked(int position, boolean isChecked) { - if (isChecked) { - agreeCounter++; - } else { - agreeCounter--; - } agreed[position] = isChecked; - setButtonState(); + setButtonState(position); } @Override @@ -100,11 +102,16 @@ public class OnBoardingActivity extends AppCompatActivity implements OnBoardingA } @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 - findViewById(R.id.buttonNext).setEnabled(mustAgreePages == agreeCounter); + nextButton.setText(R.string.onboarding_button_ready); } else { - findViewById(R.id.buttonNext).setEnabled(true); + nextButton.setText(R.string.onboarding_button_next); } } } diff --git a/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingAdapter.java b/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingAdapter.java index 5ec1936f..e4c5f246 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingAdapter.java +++ b/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingAdapter.java @@ -39,7 +39,7 @@ public class OnBoardingAdapter extends PagerAdapter { boolean isAgreeClicked(int position); - void setButtonState(); + void setButtonState(int position); } private final Context context; @@ -68,10 +68,8 @@ public class OnBoardingAdapter extends PagerAdapter { agree.setOnClickListener(v -> { listener.setAgreeClicked(position, ((CheckBox) v).isChecked()); }); - listener.setButtonState(); } collection.addView(view); - Timber.d("add " + position); return view; } diff --git a/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingScreen.java b/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingScreen.java index bbef7add..d731d621 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingScreen.java +++ b/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingScreen.java @@ -21,7 +21,7 @@ import com.m2049r.xmrwallet.R; enum OnBoardingScreen { 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), - 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), NODES(R.string.onboarding_nodes_title, R.string.onboarding_nodes_information, R.drawable.ic_onboarding_nodes, false); diff --git a/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingViewPager.java b/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingViewPager.java new file mode 100644 index 00000000..c1f2e049 --- /dev/null +++ b/app/src/main/java/com/m2049r/xmrwallet/onboarding/OnBoardingViewPager.java @@ -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; + } +} diff --git a/app/src/main/res/layout/activity_on_boarding.xml b/app/src/main/res/layout/activity_on_boarding.xml index 4f945885..3f513ad3 100644 --- a/app/src/main/res/layout/activity_on_boarding.xml +++ b/app/src/main/res/layout/activity_on_boarding.xml @@ -22,7 +22,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> - I get it! Next + I\'m ready! Welcome to Monerujo! This app allows you to create and use Monero wallets. You can store your sweet Monero (XMR) in them. - Write down your seed + Write down your seeds 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. Send Bitcoin Monerujo has XMR.to support builtin. You can send BTC by spending XMR. Just paste or scan a BTC address when sending. Nodes, your way Nodes connect you to the Monero network. Choose between searching for public nodes or go full cypherpunk using your own. Send with fingerprint - You\'ll be able to authorize sending XMR with just your fingerprint. - If you prefer to secure sending by password, please disable fingerprint access for that wallet. - + 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.