"Skip Tutorial" button moved to parent view so that it does not animate by swipes. (#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 #2103: Remove welcomeYesButton from landscape layout

* Refactor WelcomePagerAdapter
This commit is contained in:
Mojtaba Rahimy 2018-12-17 14:50:13 +03:30 committed by neslihanturan
parent 11e5c3c01a
commit f79456ec8e
14 changed files with 89 additions and 182 deletions

View file

@ -2,20 +2,33 @@ package fr.free.nrw.commons;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.view.View;
import com.viewpagerindicator.CirclePageIndicator; import com.viewpagerindicator.CirclePageIndicator;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Optional;
import fr.free.nrw.commons.quiz.QuizActivity; import fr.free.nrw.commons.quiz.QuizActivity;
import fr.free.nrw.commons.theme.BaseActivity; import fr.free.nrw.commons.theme.BaseActivity;
public class WelcomeActivity extends BaseActivity { public class WelcomeActivity extends BaseActivity {
@BindView(R.id.welcomePager) ViewPager pager; @Inject
@BindView(R.id.welcomePagerIndicator) CirclePageIndicator indicator; @Named("application_preferences")
SharedPreferences prefs;
@BindView(R.id.welcomePager)
ViewPager pager;
@BindView(R.id.welcomePagerIndicator)
CirclePageIndicator indicator;
private WelcomePagerAdapter adapter = new WelcomePagerAdapter(); private WelcomePagerAdapter adapter = new WelcomePagerAdapter();
private boolean isQuiz; private boolean isQuiz;
@ -38,15 +51,20 @@ public class WelcomeActivity extends BaseActivity {
if (bundle != null) { if (bundle != null) {
isQuiz = bundle.getBoolean("isQuiz"); isQuiz = bundle.getBoolean("isQuiz");
} }
} else{ } else {
isQuiz = false; isQuiz = false;
} }
// Enable skip button if beta flavor
if (BuildConfig.FLAVOR == "beta") {
findViewById(R.id.finishTutorialButton).setVisibility(View.VISIBLE);
}
ButterKnife.bind(this); ButterKnife.bind(this);
pager.setAdapter(adapter); pager.setAdapter(adapter);
indicator.setViewPager(pager); indicator.setViewPager(pager);
adapter.setCallback(this::finish); adapter.setCallback(this::finishTutorial);
} }
/** /**
@ -54,7 +72,7 @@ public class WelcomeActivity extends BaseActivity {
*/ */
@Override @Override
public void onDestroy() { public void onDestroy() {
if (isQuiz){ if (isQuiz) {
Intent i = new Intent(WelcomeActivity.this, QuizActivity.class); Intent i = new Intent(WelcomeActivity.this, QuizActivity.class);
startActivity(i); startActivity(i);
} }
@ -71,4 +89,22 @@ public class WelcomeActivity extends BaseActivity {
Intent welcomeIntent = new Intent(context, WelcomeActivity.class); Intent welcomeIntent = new Intent(context, WelcomeActivity.class);
context.startActivity(welcomeIntent); context.startActivity(welcomeIntent);
} }
/**
* Override onBackPressed() to go to previous tutorial 'pages' if not on first page
*/
@Override
public void onBackPressed() {
if (pager.getCurrentItem() != 0) {
pager.setCurrentItem(pager.getCurrentItem() - 1, true);
} else {
finish();
}
}
@OnClick(R.id.finishTutorialButton)
public void finishTutorial() {
prefs.edit().putBoolean("firstrun", false).apply();
finish();
}
} }

View file

@ -14,7 +14,7 @@ import butterknife.OnClick;
import butterknife.Optional; import butterknife.Optional;
public class WelcomePagerAdapter extends PagerAdapter { public class WelcomePagerAdapter extends PagerAdapter {
static final int[] PAGE_LAYOUTS = new int[]{ private static final int[] PAGE_LAYOUTS = new int[]{
R.layout.welcome_wikipedia, R.layout.welcome_wikipedia,
R.layout.welcome_do_upload, R.layout.welcome_do_upload,
R.layout.welcome_dont_upload, R.layout.welcome_dont_upload,
@ -57,29 +57,31 @@ public class WelcomePagerAdapter extends PagerAdapter {
@Override @Override
public Object instantiateItem(ViewGroup container, int position) { public Object instantiateItem(ViewGroup container, int position) {
this.container=container; this.container = container;
LayoutInflater inflater = LayoutInflater.from(container.getContext()); LayoutInflater inflater = LayoutInflater.from(container.getContext());
ViewGroup layout = (ViewGroup) inflater.inflate(PAGE_LAYOUTS[position], container, false); ViewGroup layout = (ViewGroup) inflater.inflate(PAGE_LAYOUTS[position], container, false);
if (BuildConfig.FLAVOR == "beta") {
TextView textView = layout.findViewById(R.id.welcomeYesButton);
if (textView.getVisibility() != View.VISIBLE) {
textView.setVisibility(View.VISIBLE);
}
ViewHolder holder = new ViewHolder(layout);
layout.setTag(holder);
if (position == PAGE_FINAL){ // If final page
TextView moreInfo = layout.findViewById(R.id.welcomeInfo); if (position == PAGE_FINAL) {
moreInfo.setText(Html.fromHtml(WelcomeActivity.moreInformation)); // Add link to more information
ViewHolder holder1 = new ViewHolder(layout); TextView moreInfo = layout.findViewById(R.id.welcomeInfo);
layout.setTag(holder1); moreInfo.setText(Html.fromHtml(WelcomeActivity.moreInformation));
} moreInfo.setOnClickListener(view -> {
} else { try {
if (position == PAGE_FINAL) { Utils.handleWebUrl(
ViewHolder holder = new ViewHolder(layout); container.getContext(),
layout.setTag(holder); Uri.parse("https://commons.wikimedia.org/wiki/Help:Contents")
} );
} catch (Exception e) {
e.printStackTrace();
}
});
// Handle click of finishTutorialButton ("YES!" button) inside layout
layout.findViewById(R.id.finishTutorialButton)
.setOnClickListener(view -> callback.finishTutorial());
} }
container.addView(layout); container.addView(layout);
return layout; return layout;
} }
@ -96,33 +98,6 @@ public class WelcomePagerAdapter extends PagerAdapter {
} }
public interface Callback { public interface Callback {
void onYesClicked(); void finishTutorial();
}
class ViewHolder {
ViewHolder(View view) {
ButterKnife.bind(this, view);
}
/**
* Triggers on click callback on button click
*/
@OnClick(R.id.welcomeYesButton)
void onClicked() {
if (callback != null) {
callback.onYesClicked();
}
}
@Optional
@OnClick(R.id.welcomeInfo)
void onHelpClicked () {
try {
Utils.handleWebUrl(container.getContext(),Uri.parse("https://commons.wikimedia.org/wiki/Help:Contents" ));
} catch (Exception e) {
e.printStackTrace();
}
}
} }
} }

View file

@ -177,7 +177,6 @@ public class LoginActivity extends AccountAuthenticatorActivity {
super.onResume(); super.onResume();
if (prefs.getBoolean("firstrun", true)) { if (prefs.getBoolean("firstrun", true)) {
WelcomeActivity.startYourself(this); WelcomeActivity.startYourself(this);
prefs.edit().putBoolean("firstrun", false).apply();
} }
if (sessionManager.getCurrentAccount() != null if (sessionManager.getCurrentAccount() != null

View file

@ -9,21 +9,6 @@
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView
android:id="@+id/welcomeYesButton"
android:layout_width="wrap_content"
android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginEnd="@dimen/standard_gap"
android:layout_marginRight="@dimen/standard_gap"
android:layout_marginTop="@dimen/standard_gap"
android:text="@string/welcome_skip_button"
android:textColor="#fff"
android:textSize="@dimen/normal_text"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline <android.support.constraint.Guideline
android:id="@+id/center_guideline" android:id="@+id/center_guideline"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -6,21 +6,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#0c609c"> android:background="#0c609c">
<TextView
android:id="@+id/welcomeYesButton"
android:layout_width="wrap_content"
android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginEnd="@dimen/standard_gap"
android:layout_marginRight="@dimen/standard_gap"
android:layout_marginTop="@dimen/standard_gap"
android:text="@string/welcome_skip_button"
android:textColor="#fff"
android:textSize="@dimen/normal_text"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline <android.support.constraint.Guideline
android:id="@+id/center_guideline" android:id="@+id/center_guideline"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -14,7 +14,6 @@
android:layout_marginBottom="@dimen/large_gap" android:layout_marginBottom="@dimen/large_gap"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/welcome_help_button_text"
android:id="@+id/welcomeInfo" android:id="@+id/welcomeInfo"
android:layout_gravity="end|top" android:layout_gravity="end|top"
android:layout_marginTop="@dimen/standard_gap" android:layout_marginTop="@dimen/standard_gap"
@ -73,7 +72,7 @@
android:layout_height="@dimen/overflow_button_dimen" android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginTop="@dimen/standard_gap" android:layout_marginTop="@dimen/standard_gap"
android:text="@string/welcome_final_button_text" android:text="@string/welcome_final_button_text"
android:id="@+id/welcomeYesButton" android:id="@+id/finishTutorialButton"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@android:color/white" android:background="@android:color/white"
android:textColor="#0c609c" android:textColor="#0c609c"

View file

@ -8,21 +8,6 @@
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView
android:id="@+id/welcomeYesButton"
android:layout_width="wrap_content"
android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginEnd="@dimen/standard_gap"
android:layout_marginRight="@dimen/standard_gap"
android:layout_marginTop="@dimen/standard_gap"
android:text="@string/welcome_skip_button"
android:textColor="#fff"
android:textSize="@dimen/normal_text"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline <android.support.constraint.Guideline
android:id="@+id/center_guideline" android:id="@+id/center_guideline"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -7,21 +7,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#0c609c"> android:background="#0c609c">
<TextView
android:id="@+id/welcomeYesButton"
android:layout_width="wrap_content"
android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginEnd="@dimen/standard_gap"
android:layout_marginRight="@dimen/standard_gap"
android:layout_marginTop="@dimen/standard_gap"
android:text="@string/welcome_skip_button"
android:textColor="#fff"
android:textSize="@dimen/normal_text"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline <android.support.constraint.Guideline
android:id="@+id/center_guideline" android:id="@+id/center_guideline"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -10,6 +10,21 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:fadingEdge="none" /> android:fadingEdge="none" />
<TextView
android:layout_width="wrap_content"
android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginTop="@dimen/standard_gap"
android:layout_marginRight="@dimen/standard_gap"
android:text="@string/welcome_skip_button"
android:id="@+id/finishTutorialButton"
android:textSize="@dimen/normal_text"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:textColor="#fff"
android:textStyle="bold"
android:visibility="gone"
/>
<com.viewpagerindicator.CirclePageIndicator <com.viewpagerindicator.CirclePageIndicator
android:id="@+id/welcomePagerIndicator" android:id="@+id/welcomePagerIndicator"
android:layout_height="@dimen/half_standard_height" android:layout_height="@dimen/half_standard_height"

View file

@ -164,20 +164,5 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginTop="@dimen/standard_gap"
android:layout_marginRight="@dimen/standard_gap"
android:text="@string/welcome_skip_button"
android:id="@+id/welcomeYesButton"
android:textSize="@dimen/normal_text"
android:visibility="gone"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:textColor="#fff"
android:textStyle="bold"
/>
</RelativeLayout> </RelativeLayout>

View file

@ -138,20 +138,4 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginTop="@dimen/standard_gap"
android:layout_marginRight="@dimen/standard_gap"
android:text="@string/welcome_skip_button"
android:id="@+id/welcomeYesButton"
android:textSize="@dimen/normal_text"
android:visibility="gone"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:textColor="#fff"
android:textStyle="bold"
/>
</RelativeLayout> </RelativeLayout>

View file

@ -56,7 +56,7 @@
android:layout_height="@dimen/overflow_button_dimen" android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginTop="@dimen/standard_gap" android:layout_marginTop="@dimen/standard_gap"
android:text="@string/welcome_final_button_text" android:text="@string/welcome_final_button_text"
android:id="@+id/welcomeYesButton" android:id="@+id/finishTutorialButton"
android:textSize="@dimen/normal_text" android:textSize="@dimen/normal_text"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@android:color/white" android:background="@android:color/white"

View file

@ -135,18 +135,5 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginTop="@dimen/standard_gap"
android:layout_marginRight="@dimen/standard_gap"
android:text="@string/welcome_skip_button"
android:id="@+id/welcomeYesButton"
android:textSize="@dimen/normal_text"
android:visibility="gone"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:textColor="#fff"
android:textStyle="bold"
/>
</RelativeLayout> </RelativeLayout>

View file

@ -49,18 +49,5 @@
android:textColor="@android:color/white" android:textColor="@android:color/white"
/> />
</LinearLayout> </LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="@dimen/overflow_button_dimen"
android:layout_marginTop="@dimen/standard_gap"
android:layout_marginRight="@dimen/standard_gap"
android:text="@string/welcome_skip_button"
android:id="@+id/welcomeYesButton"
android:textSize="@dimen/normal_text"
android:visibility="gone"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:textColor="#fff"
android:textStyle="bold"
/>
</RelativeLayout> </RelativeLayout>