Skip to content

Commit f79456e

Browse files
mrahimygkneslihanturan
authored andcommitted
"Skip Tutorial" button moved to parent view so that it does not animate by swipes. (commons-app#1945)
* Update WelcomeActivity.java Now it starts welcome screen after not finishing the pager. Moved "Skip Tutorial" button here so it does not animate by swipe. * Update activity_welcome.xml Putting "Skip Tutorial" button here so that it does not animate by swipes. * Update LoginActivity.java Removing the set of "first run " flag from here. we set it after the buttons press or on WelcomeActivity's finish() * Update welcome_do_upload.xml removing "skip tut" button from here. * Update welcome_dont_upload.xml Removing "Skip Tutorial" button from here so that it does not animate by swipes. * Update welcome_image_details.xml Removing "Skip Tutorial" button from here so that it does not animate by swipes. * Update welcome_wikipedia.xml Removing "Skip Tutorial" button from here so that it does not animate by swipes. * Update WelcomePagerAdapter.java the "welcomyesButton" is removed from the child views in pager, so it is optional now. * Add JavaDoc to WelcomeActivity.onBackPressed() * Fix commons-app#2103: Remove welcomeYesButton from landscape layout * Refactor WelcomePagerAdapter
1 parent 11e5c3c commit f79456e

14 files changed

+89
-182
lines changed

app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,33 @@
22

33
import android.content.Context;
44
import android.content.Intent;
5+
import android.content.SharedPreferences;
56
import android.os.Bundle;
67
import android.support.v4.view.ViewPager;
8+
import android.view.View;
79

810
import com.viewpagerindicator.CirclePageIndicator;
911

12+
import javax.inject.Inject;
13+
import javax.inject.Named;
14+
1015
import butterknife.BindView;
1116
import butterknife.ButterKnife;
17+
import butterknife.OnClick;
18+
import butterknife.Optional;
1219
import fr.free.nrw.commons.quiz.QuizActivity;
1320
import fr.free.nrw.commons.theme.BaseActivity;
1421

1522
public class WelcomeActivity extends BaseActivity {
1623

17-
@BindView(R.id.welcomePager) ViewPager pager;
18-
@BindView(R.id.welcomePagerIndicator) CirclePageIndicator indicator;
24+
@Inject
25+
@Named("application_preferences")
26+
SharedPreferences prefs;
27+
28+
@BindView(R.id.welcomePager)
29+
ViewPager pager;
30+
@BindView(R.id.welcomePagerIndicator)
31+
CirclePageIndicator indicator;
1932

2033
private WelcomePagerAdapter adapter = new WelcomePagerAdapter();
2134
private boolean isQuiz;
@@ -38,23 +51,28 @@ public void onCreate(Bundle savedInstanceState) {
3851
if (bundle != null) {
3952
isQuiz = bundle.getBoolean("isQuiz");
4053
}
41-
} else{
54+
} else {
4255
isQuiz = false;
4356
}
4457

58+
// Enable skip button if beta flavor
59+
if (BuildConfig.FLAVOR == "beta") {
60+
findViewById(R.id.finishTutorialButton).setVisibility(View.VISIBLE);
61+
}
62+
4563
ButterKnife.bind(this);
4664

4765
pager.setAdapter(adapter);
4866
indicator.setViewPager(pager);
49-
adapter.setCallback(this::finish);
67+
adapter.setCallback(this::finishTutorial);
5068
}
5169

5270
/**
5371
* References WelcomePageAdapter to null before the activity is destroyed
5472
*/
5573
@Override
5674
public void onDestroy() {
57-
if (isQuiz){
75+
if (isQuiz) {
5876
Intent i = new Intent(WelcomeActivity.this, QuizActivity.class);
5977
startActivity(i);
6078
}
@@ -71,4 +89,22 @@ public static void startYourself(Context context) {
7189
Intent welcomeIntent = new Intent(context, WelcomeActivity.class);
7290
context.startActivity(welcomeIntent);
7391
}
92+
93+
/**
94+
* Override onBackPressed() to go to previous tutorial 'pages' if not on first page
95+
*/
96+
@Override
97+
public void onBackPressed() {
98+
if (pager.getCurrentItem() != 0) {
99+
pager.setCurrentItem(pager.getCurrentItem() - 1, true);
100+
} else {
101+
finish();
102+
}
103+
}
104+
105+
@OnClick(R.id.finishTutorialButton)
106+
public void finishTutorial() {
107+
prefs.edit().putBoolean("firstrun", false).apply();
108+
finish();
109+
}
74110
}

app/src/main/java/fr/free/nrw/commons/WelcomePagerAdapter.java

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import butterknife.Optional;
1515

1616
public class WelcomePagerAdapter extends PagerAdapter {
17-
static final int[] PAGE_LAYOUTS = new int[]{
17+
private static final int[] PAGE_LAYOUTS = new int[]{
1818
R.layout.welcome_wikipedia,
1919
R.layout.welcome_do_upload,
2020
R.layout.welcome_dont_upload,
@@ -57,29 +57,31 @@ public boolean isViewFromObject(View view, Object object) {
5757

5858
@Override
5959
public Object instantiateItem(ViewGroup container, int position) {
60-
this.container=container;
60+
this.container = container;
6161
LayoutInflater inflater = LayoutInflater.from(container.getContext());
6262
ViewGroup layout = (ViewGroup) inflater.inflate(PAGE_LAYOUTS[position], container, false);
63-
if (BuildConfig.FLAVOR == "beta") {
64-
TextView textView = layout.findViewById(R.id.welcomeYesButton);
65-
if (textView.getVisibility() != View.VISIBLE) {
66-
textView.setVisibility(View.VISIBLE);
67-
}
68-
ViewHolder holder = new ViewHolder(layout);
69-
layout.setTag(holder);
7063

71-
if (position == PAGE_FINAL){
72-
TextView moreInfo = layout.findViewById(R.id.welcomeInfo);
73-
moreInfo.setText(Html.fromHtml(WelcomeActivity.moreInformation));
74-
ViewHolder holder1 = new ViewHolder(layout);
75-
layout.setTag(holder1);
76-
}
77-
} else {
78-
if (position == PAGE_FINAL) {
79-
ViewHolder holder = new ViewHolder(layout);
80-
layout.setTag(holder);
81-
}
64+
// If final page
65+
if (position == PAGE_FINAL) {
66+
// Add link to more information
67+
TextView moreInfo = layout.findViewById(R.id.welcomeInfo);
68+
moreInfo.setText(Html.fromHtml(WelcomeActivity.moreInformation));
69+
moreInfo.setOnClickListener(view -> {
70+
try {
71+
Utils.handleWebUrl(
72+
container.getContext(),
73+
Uri.parse("https://commons.wikimedia.org/wiki/Help:Contents")
74+
);
75+
} catch (Exception e) {
76+
e.printStackTrace();
77+
}
78+
});
79+
80+
// Handle click of finishTutorialButton ("YES!" button) inside layout
81+
layout.findViewById(R.id.finishTutorialButton)
82+
.setOnClickListener(view -> callback.finishTutorial());
8283
}
84+
8385
container.addView(layout);
8486
return layout;
8587
}
@@ -96,33 +98,6 @@ public void destroyItem(ViewGroup container, int position, Object obj) {
9698
}
9799

98100
public interface Callback {
99-
void onYesClicked();
100-
}
101-
102-
class ViewHolder {
103-
ViewHolder(View view) {
104-
ButterKnife.bind(this, view);
105-
}
106-
107-
/**
108-
* Triggers on click callback on button click
109-
*/
110-
@OnClick(R.id.welcomeYesButton)
111-
void onClicked() {
112-
if (callback != null) {
113-
callback.onYesClicked();
114-
}
115-
}
116-
117-
@Optional
118-
@OnClick(R.id.welcomeInfo)
119-
void onHelpClicked () {
120-
try {
121-
Utils.handleWebUrl(container.getContext(),Uri.parse("https://commons.wikimedia.org/wiki/Help:Contents" ));
122-
} catch (Exception e) {
123-
e.printStackTrace();
124-
}
125-
}
126-
101+
void finishTutorial();
127102
}
128103
}

app/src/main/java/fr/free/nrw/commons/auth/LoginActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ protected void onResume() {
177177
super.onResume();
178178
if (prefs.getBoolean("firstrun", true)) {
179179
WelcomeActivity.startYourself(this);
180-
prefs.edit().putBoolean("firstrun", false).apply();
181180
}
182181

183182
if (sessionManager.getCurrentAccount() != null

app/src/main/res/layout-land/welcome_do_upload.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,6 @@
99
android:gravity="center"
1010
android:orientation="horizontal">
1111

12-
<TextView
13-
android:id="@+id/welcomeYesButton"
14-
android:layout_width="wrap_content"
15-
android:layout_height="@dimen/overflow_button_dimen"
16-
android:layout_marginEnd="@dimen/standard_gap"
17-
android:layout_marginRight="@dimen/standard_gap"
18-
android:layout_marginTop="@dimen/standard_gap"
19-
android:text="@string/welcome_skip_button"
20-
android:textColor="#fff"
21-
android:textSize="@dimen/normal_text"
22-
android:textStyle="bold"
23-
android:visibility="gone"
24-
app:layout_constraintEnd_toEndOf="parent"
25-
app:layout_constraintTop_toTopOf="parent" />
26-
2712
<android.support.constraint.Guideline
2813
android:id="@+id/center_guideline"
2914
android:layout_width="wrap_content"

app/src/main/res/layout-land/welcome_dont_upload.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,6 @@
66
xmlns:app="http://schemas.android.com/apk/res-auto"
77
android:background="#0c609c">
88

9-
<TextView
10-
android:id="@+id/welcomeYesButton"
11-
android:layout_width="wrap_content"
12-
android:layout_height="@dimen/overflow_button_dimen"
13-
android:layout_marginEnd="@dimen/standard_gap"
14-
android:layout_marginRight="@dimen/standard_gap"
15-
android:layout_marginTop="@dimen/standard_gap"
16-
android:text="@string/welcome_skip_button"
17-
android:textColor="#fff"
18-
android:textSize="@dimen/normal_text"
19-
android:textStyle="bold"
20-
android:visibility="gone"
21-
app:layout_constraintEnd_toEndOf="parent"
22-
app:layout_constraintTop_toTopOf="parent" />
23-
249
<android.support.constraint.Guideline
2510
android:id="@+id/center_guideline"
2611
android:layout_width="wrap_content"

app/src/main/res/layout-land/welcome_final.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
android:layout_marginBottom="@dimen/large_gap"
1515
android:layout_width="wrap_content"
1616
android:layout_height="wrap_content"
17-
android:text="@string/welcome_help_button_text"
1817
android:id="@+id/welcomeInfo"
1918
android:layout_gravity="end|top"
2019
android:layout_marginTop="@dimen/standard_gap"
@@ -73,7 +72,7 @@
7372
android:layout_height="@dimen/overflow_button_dimen"
7473
android:layout_marginTop="@dimen/standard_gap"
7574
android:text="@string/welcome_final_button_text"
76-
android:id="@+id/welcomeYesButton"
75+
android:id="@+id/finishTutorialButton"
7776
android:layout_gravity="center"
7877
android:background="@android:color/white"
7978
android:textColor="#0c609c"

app/src/main/res/layout-land/welcome_image_details.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@
88
android:gravity="center"
99
android:orientation="horizontal">
1010

11-
<TextView
12-
android:id="@+id/welcomeYesButton"
13-
android:layout_width="wrap_content"
14-
android:layout_height="@dimen/overflow_button_dimen"
15-
android:layout_marginEnd="@dimen/standard_gap"
16-
android:layout_marginRight="@dimen/standard_gap"
17-
android:layout_marginTop="@dimen/standard_gap"
18-
android:text="@string/welcome_skip_button"
19-
android:textColor="#fff"
20-
android:textSize="@dimen/normal_text"
21-
android:textStyle="bold"
22-
android:visibility="gone"
23-
app:layout_constraintEnd_toEndOf="parent"
24-
app:layout_constraintTop_toTopOf="parent" />
25-
2611
<android.support.constraint.Guideline
2712
android:id="@+id/center_guideline"
2813
android:layout_width="wrap_content"

app/src/main/res/layout-land/welcome_wikipedia.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,6 @@
77
android:layout_height="match_parent"
88
android:background="#0c609c">
99

10-
<TextView
11-
android:id="@+id/welcomeYesButton"
12-
android:layout_width="wrap_content"
13-
android:layout_height="@dimen/overflow_button_dimen"
14-
android:layout_marginEnd="@dimen/standard_gap"
15-
android:layout_marginRight="@dimen/standard_gap"
16-
android:layout_marginTop="@dimen/standard_gap"
17-
android:text="@string/welcome_skip_button"
18-
android:textColor="#fff"
19-
android:textSize="@dimen/normal_text"
20-
android:textStyle="bold"
21-
android:visibility="gone"
22-
app:layout_constraintEnd_toEndOf="parent"
23-
app:layout_constraintTop_toTopOf="parent" />
24-
2510
<android.support.constraint.Guideline
2611
android:id="@+id/center_guideline"
2712
android:layout_width="wrap_content"

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@
1010
android:layout_height="match_parent"
1111
android:fadingEdge="none" />
1212

13+
<TextView
14+
android:layout_width="wrap_content"
15+
android:layout_height="@dimen/overflow_button_dimen"
16+
android:layout_marginTop="@dimen/standard_gap"
17+
android:layout_marginRight="@dimen/standard_gap"
18+
android:text="@string/welcome_skip_button"
19+
android:id="@+id/finishTutorialButton"
20+
android:textSize="@dimen/normal_text"
21+
android:layout_gravity="right"
22+
android:layout_alignParentRight="true"
23+
android:textColor="#fff"
24+
android:textStyle="bold"
25+
android:visibility="gone"
26+
/>
27+
1328
<com.viewpagerindicator.CirclePageIndicator
1429
android:id="@+id/welcomePagerIndicator"
1530
android:layout_height="@dimen/half_standard_height"
1631
android:layout_width="match_parent"
1732
android:layout_gravity="bottom"
1833
android:padding="5dp" />
1934

20-
</FrameLayout>
35+
</FrameLayout>

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,5 @@
164164

165165
</LinearLayout>
166166
</LinearLayout>
167-
<TextView
168-
android:layout_width="wrap_content"
169-
android:layout_height="@dimen/overflow_button_dimen"
170-
android:layout_marginTop="@dimen/standard_gap"
171-
android:layout_marginRight="@dimen/standard_gap"
172-
android:text="@string/welcome_skip_button"
173-
android:id="@+id/welcomeYesButton"
174-
android:textSize="@dimen/normal_text"
175-
android:visibility="gone"
176-
android:layout_gravity="right"
177-
android:layout_alignParentRight="true"
178-
android:textColor="#fff"
179-
android:textStyle="bold"
180-
/>
181-
182-
183-
</RelativeLayout>
167+
168+
</RelativeLayout>

0 commit comments

Comments
 (0)