mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +01:00
Simplify welcome layouts (#2741)
* Simplify welcome layouts * Add landscape layouts * Reformat welcome layouts * Rename string resources
This commit is contained in:
parent
fb0d025f33
commit
5d299b1511
24 changed files with 331 additions and 925 deletions
|
|
@ -3,19 +3,14 @@ package fr.free.nrw.commons;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import android.view.View;
|
||||
|
||||
import com.viewpagerindicator.CirclePageIndicator;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.quiz.QuizActivity;
|
||||
import fr.free.nrw.commons.theme.BaseActivity;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
|
|
@ -29,7 +24,6 @@ public class WelcomeActivity extends BaseActivity {
|
|||
|
||||
private WelcomePagerAdapter adapter = new WelcomePagerAdapter();
|
||||
private boolean isQuiz;
|
||||
static String moreInformation;
|
||||
|
||||
/**
|
||||
* Initialises exiting fields and dependencies
|
||||
|
|
@ -41,8 +35,6 @@ public class WelcomeActivity extends BaseActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_welcome);
|
||||
|
||||
moreInformation = this.getString(R.string.welcome_help_button_text);
|
||||
|
||||
if (getIntent() != null) {
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
if (bundle != null) {
|
||||
|
|
@ -61,7 +53,6 @@ public class WelcomeActivity extends BaseActivity {
|
|||
|
||||
pager.setAdapter(adapter);
|
||||
indicator.setViewPager(pager);
|
||||
adapter.setCallback(this::finishTutorial);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -73,7 +64,6 @@ public class WelcomeActivity extends BaseActivity {
|
|||
Intent i = new Intent(WelcomeActivity.this, QuizActivity.class);
|
||||
startActivity(i);
|
||||
}
|
||||
adapter.setCallback(null);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.text.Html;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
import org.wikipedia.util.StringUtil;
|
||||
|
||||
public class WelcomePagerAdapter extends PagerAdapter {
|
||||
|
|
@ -15,22 +16,9 @@ public class WelcomePagerAdapter extends PagerAdapter {
|
|||
R.layout.welcome_wikipedia,
|
||||
R.layout.welcome_do_upload,
|
||||
R.layout.welcome_dont_upload,
|
||||
R.layout.welcome_image_details,
|
||||
R.layout.welcome_image_example,
|
||||
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
|
||||
|
|
@ -54,29 +42,22 @@ public class WelcomePagerAdapter extends PagerAdapter {
|
|||
|
||||
@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) {
|
||||
if (position == PAGE_LAYOUTS.length - 1) {
|
||||
// Add link to more information
|
||||
TextView moreInfo = layout.findViewById(R.id.welcomeInfo);
|
||||
moreInfo.setText(StringUtil.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();
|
||||
}
|
||||
});
|
||||
moreInfo.setText(Html.fromHtml(container.getContext().getString(R.string.welcome_help_button_text)));
|
||||
moreInfo.setOnClickListener(view -> Utils.handleWebUrl(
|
||||
container.getContext(),
|
||||
Uri.parse("https://commons.wikimedia.org/wiki/Help:Contents")
|
||||
));
|
||||
|
||||
// Handle click of finishTutorialButton ("YES!" button) inside layout
|
||||
layout.findViewById(R.id.finishTutorialButton)
|
||||
.setOnClickListener(view -> callback.finishTutorial());
|
||||
.setOnClickListener(view -> ((WelcomeActivity) container.getContext()).finishTutorial());
|
||||
}
|
||||
|
||||
container.addView(layout);
|
||||
|
|
@ -93,8 +74,4 @@ public class WelcomePagerAdapter extends PagerAdapter {
|
|||
public void destroyItem(ViewGroup container, int position, Object obj) {
|
||||
container.removeView((View) obj);
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
void finishTutorial();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue