Skip to content

Commit 1d7a1cc

Browse files
committed
stay on the "generate seed" view after user swipes there
plus, layout fixes on information layout
1 parent 43a7b78 commit 1d7a1cc

File tree

5 files changed

+92
-18
lines changed

5 files changed

+92
-18
lines changed

app/src/main/java/xyz/gsora/siacold/WelcomeUI/GenerateSeed.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,22 @@ public void onActivityCreated(Bundle bundle) {
7575
importSeed.setOnClickListener(this::showImportSeed);
7676
}
7777

78-
public void importSeed(View v) {
79-
80-
}
81-
8278
public void showImportSeed(View v) {
8379
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
8480
// Get the layout inflater
8581
LayoutInflater inflater = getActivity().getLayoutInflater();
8682
View dia = inflater.inflate(R.layout.import_seed, null);
8783
EditText e = (EditText) dia.findViewById(R.id.importSeedText);
84+
byte[] seedByte = e.getText().toString().getBytes(StandardCharsets.UTF_8);
8885

8986
Fragment thisFragment = this;
9087
builder.setView(dia)
9188
// Add action buttons
9289
.setPositiveButton("Save", (dialog, id) -> {
93-
c = new Crypto(getActivity(), getContext(), thisFragment, e.getText().toString().getBytes(StandardCharsets.UTF_8));
90+
c = new Crypto(getActivity(), getContext(), thisFragment, seedByte);
9491
c.tryEncrypt();
9592
try {
96-
setSeed(new Wallet(), c);
93+
setSeed(c);
9794
} catch (NoDecryptedDataException ee) {
9895
ee.printStackTrace();
9996
}
@@ -130,7 +127,7 @@ public void generateSeed(View v) {
130127
c = new Crypto(getActivity(), getContext(), thisFragment, seed.getBytes(StandardCharsets.UTF_8));
131128
c.tryEncrypt();
132129
try {
133-
setSeed(new Wallet(), c);
130+
setSeed(c);
134131
} catch (NoDecryptedDataException e) {
135132
e.printStackTrace();
136133
}
@@ -148,9 +145,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
148145
// Challenge completed, proceed with using cipher
149146
if (resultCode == RESULT_OK) {
150147
if (c.tryEncrypt()) {
151-
Wallet w = new Wallet();
152148
try {
153-
setSeed(w, c);
149+
setSeed(c);
154150
} catch (NoDecryptedDataException e) {
155151
e.printStackTrace();
156152
}
@@ -168,7 +164,8 @@ private void writeDefaultPreferences(String address) {
168164
spEdit.apply();
169165
}
170166

171-
private void setSeed(Wallet w, Crypto c) throws NoDecryptedDataException {
167+
private void setSeed(Crypto c) throws NoDecryptedDataException {
168+
Wallet w = new Wallet();
172169
c.tryDecrypt();
173170
w.setSeed(c.getDecryptedData());
174171
Realm r = Utils.getRealm();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package xyz.gsora.siacold.WelcomeUI;
2+
3+
import android.content.Context;
4+
import android.support.v4.view.ViewPager;
5+
import android.util.AttributeSet;
6+
import android.view.MotionEvent;
7+
8+
/**
9+
* Created by gsora on 7/7/17.
10+
* <p>
11+
* ViewPager that scrolls or not.
12+
* Credits: https://stackoverflow.com/questions/9650265/how-do-disable-paging-by-swiping-with-finger-in-viewpager-but-still-be-able-to-s
13+
*/
14+
public class NonSwipeableViewPager extends ViewPager {
15+
16+
private boolean swipeable;
17+
18+
public NonSwipeableViewPager(Context context) {
19+
super(context);
20+
}
21+
22+
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
23+
super(context, attrs);
24+
this.swipeable = true;
25+
}
26+
27+
@Override
28+
public boolean onTouchEvent(MotionEvent event) {
29+
if (this.swipeable) {
30+
return super.onTouchEvent(event);
31+
}
32+
33+
return false;
34+
}
35+
36+
@Override
37+
public boolean onInterceptTouchEvent(MotionEvent event) {
38+
if (this.swipeable) {
39+
return super.onInterceptTouchEvent(event);
40+
}
41+
42+
return false;
43+
}
44+
45+
public void setSwipeable(boolean swipeable) {
46+
this.swipeable = swipeable;
47+
}
48+
}

app/src/main/java/xyz/gsora/siacold/WelcomeUI/WelcomeActivity.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class WelcomeActivity extends AppCompatActivity {
1919

2020
@BindView(R.id.tutorialViewPager)
21-
ViewPager tutorialViewPager;
21+
NonSwipeableViewPager tutorialViewPager;
2222

2323
@BindView(R.id.tabDots)
2424
TabLayout tabDots;
@@ -37,9 +37,11 @@ protected void onCreate(Bundle savedInstanceState) {
3737

3838
WelcomeUIAdapter adapter = new WelcomeUIAdapter(getSupportFragmentManager());
3939
tutorialViewPager.setAdapter(adapter);
40+
tutorialViewPager.setSwipeable(true);
4041

4142
tabDots.setupWithViewPager(tutorialViewPager, true);
4243
checkIfSecureAndUsable();
44+
setupViewPagerListener();
4345
}
4446

4547
public void checkIfSecureAndUsable() {
@@ -58,7 +60,34 @@ public void checkIfSecureAndUsable() {
5860
}
5961
}
6062

61-
public void moveToNextPage() {
63+
void setupViewPagerListener() {
64+
// Attach the page change listener inside the activity
65+
tutorialViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
66+
67+
// This method will be invoked when a new page becomes selected.
68+
@Override
69+
public void onPageSelected(int position) {
70+
if (position == 1) {
71+
tutorialViewPager.setSwipeable(false);
72+
}
73+
}
74+
75+
// This method will be invoked when the current page is scrolled
76+
@Override
77+
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
78+
// Code goes here
79+
}
80+
81+
// Called when the scroll state changes:
82+
// SCROLL_STATE_IDLE, SCROLL_STATE_DRAGGING, SCROLL_STATE_SETTLING
83+
@Override
84+
public void onPageScrollStateChanged(int state) {
85+
// Code goes here
86+
}
87+
});
88+
}
89+
90+
void moveToNextPage() {
6291
tutorialViewPager.setCurrentItem(tutorialViewPager.getCurrentItem() + 1);
6392
}
6493

app/src/main/res/layout/content_welcome.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
tools:context="xyz.gsora.siacold.WelcomeUI.WelcomeActivity"
1515
tools:showIn="@layout/activity_welcome">
1616

17-
<android.support.v4.view.ViewPager
17+
<xyz.gsora.siacold.WelcomeUI.NonSwipeableViewPager
1818
android:id="@+id/tutorialViewPager"
1919
android:layout_width="match_parent"
2020
android:layout_height="match_parent"
2121
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
2222
<android.support.design.widget.TabLayout
2323
android:id="@+id/tabDots"
24-
android:layout_alignParentBottom="true"
2524
android:layout_width="match_parent"
2625
android:layout_height="wrap_content"
26+
android:layout_alignParentBottom="true"
2727
app:tabBackground="@drawable/tab_selector"
2828
app:tabGravity="center"
2929
app:tabIndicatorHeight="0dp"/>

app/src/main/res/layout/fragment_information.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<android.support.v4.widget.SwipeRefreshLayout
99
android:id="@+id/refreshInfo"
1010
android:layout_width="match_parent"
11-
android:layout_height="wrap_content">4
11+
android:layout_height="wrap_content">
1212

1313
<Space
1414
android:layout_width="wrap_content"
@@ -21,6 +21,8 @@
2121
android:layout_height="wrap_content"
2222
android:layout_alignParentTop="true"
2323
android:layout_centerHorizontal="true"
24+
android:layout_marginLeft="16dp"
25+
android:layout_marginRight="16dp"
2426
android:layout_marginTop="42dp">
2527

2628
<TextView
@@ -29,10 +31,8 @@
2931
android:layout_height="wrap_content"
3032
android:layout_alignParentTop="true"
3133
android:layout_centerHorizontal="true"
32-
android:layout_marginLeft="16dp"
33-
android:layout_marginRight="16dp"
34-
android:layout_marginTop="30dp"
3534
android:maxLines="1"
35+
android:text="memes"
3636
android:textAlignment="center"
3737
android:textSize="75sp"/>
3838
</me.grantland.widget.AutofitLayout>

0 commit comments

Comments
 (0)