mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
* 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
103 lines
3.1 KiB
Java
103 lines
3.1 KiB
Java
package fr.free.nrw.commons;
|
|
|
|
import android.net.Uri;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.v4.view.PagerAdapter;
|
|
import android.text.Html;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.TextView;
|
|
|
|
import butterknife.ButterKnife;
|
|
import butterknife.OnClick;
|
|
import butterknife.Optional;
|
|
|
|
public class WelcomePagerAdapter extends PagerAdapter {
|
|
private static final int[] PAGE_LAYOUTS = new int[]{
|
|
R.layout.welcome_wikipedia,
|
|
R.layout.welcome_do_upload,
|
|
R.layout.welcome_dont_upload,
|
|
R.layout.welcome_image_details,
|
|
R.layout.welcome_final
|
|
};
|
|
private static final int PAGE_FINAL = 4;
|
|
private Callback callback;
|
|
private ViewGroup container;
|
|
|
|
/**
|
|
* Changes callback to provided one
|
|
*
|
|
* @param callback New callback
|
|
* it can be null.
|
|
*/
|
|
public void setCallback(@Nullable Callback callback) {
|
|
this.callback = callback;
|
|
}
|
|
|
|
/**
|
|
* Gets total number of layouts
|
|
* @return Number of layouts
|
|
*/
|
|
@Override
|
|
public int getCount() {
|
|
return PAGE_LAYOUTS.length;
|
|
}
|
|
|
|
/**
|
|
* Compares given view with provided object
|
|
* @param view Adapter view
|
|
* @param object Adapter object
|
|
* @return Equality between view and object
|
|
*/
|
|
@Override
|
|
public boolean isViewFromObject(View view, Object object) {
|
|
return (view == object);
|
|
}
|
|
|
|
@Override
|
|
public Object instantiateItem(ViewGroup container, int position) {
|
|
this.container = container;
|
|
LayoutInflater inflater = LayoutInflater.from(container.getContext());
|
|
ViewGroup layout = (ViewGroup) inflater.inflate(PAGE_LAYOUTS[position], container, false);
|
|
|
|
// If final page
|
|
if (position == PAGE_FINAL) {
|
|
// Add link to more information
|
|
TextView moreInfo = layout.findViewById(R.id.welcomeInfo);
|
|
moreInfo.setText(Html.fromHtml(WelcomeActivity.moreInformation));
|
|
moreInfo.setOnClickListener(view -> {
|
|
try {
|
|
Utils.handleWebUrl(
|
|
container.getContext(),
|
|
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);
|
|
return layout;
|
|
}
|
|
|
|
/**
|
|
* Provides a way to remove an item from container
|
|
* @param container Adapter view group container
|
|
* @param position Index of item
|
|
* @param obj Adapter object
|
|
*/
|
|
@Override
|
|
public void destroyItem(ViewGroup container, int position, Object obj) {
|
|
container.removeView((View) obj);
|
|
}
|
|
|
|
public interface Callback {
|
|
void finishTutorial();
|
|
}
|
|
}
|