Skip to content

4664: Moved WelcomeActivity to ViewBinding #5063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 24 additions & 32 deletions app/src/main/java/fr/free/nrw/commons/WelcomeActivity.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
package fr.free.nrw.commons;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.viewpager.widget.ViewPager;

import com.viewpagerindicator.CirclePageIndicator;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import fr.free.nrw.commons.databinding.ActivityWelcomeBinding;
import fr.free.nrw.commons.databinding.PopupForCopyrightBinding;
import fr.free.nrw.commons.quiz.QuizActivity;
import fr.free.nrw.commons.theme.BaseActivity;
import fr.free.nrw.commons.utils.ConfigUtils;
import android.app.AlertDialog;
import android.widget.Button;

public class WelcomeActivity extends BaseActivity {

@BindView(R.id.welcomePager)
ViewPager pager;
@BindView(R.id.welcomePagerIndicator)
CirclePageIndicator indicator;
private ActivityWelcomeBinding binding;
private PopupForCopyrightBinding copyrightBinding;

private WelcomePagerAdapter adapter = new WelcomePagerAdapter();
private final WelcomePagerAdapter adapter = new WelcomePagerAdapter();
private boolean isQuiz;
private AlertDialog.Builder dialogBuilder;
private AlertDialog dialog;
Button okButton;

/**
* Initialises exiting fields and dependencies
*
* @param savedInstanceState WelcomeActivity bundled data
*/
@Override
public void onCreate(Bundle savedInstanceState) {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
binding = ActivityWelcomeBinding.inflate(getLayoutInflater());
final View view = binding.getRoot();
setContentView(view);

if (getIntent() != null) {
Bundle bundle = getIntent().getExtras();
final Bundle bundle = getIntent().getExtras();
if (bundle != null) {
isQuiz = bundle.getBoolean("isQuiz");
}
Expand All @@ -52,22 +44,23 @@ public void onCreate(Bundle savedInstanceState) {

// Enable skip button if beta flavor
if (ConfigUtils.isBetaFlavour()) {
findViewById(R.id.finishTutorialButton).setVisibility(View.VISIBLE);
binding.finishTutorialButton.setVisibility(View.VISIBLE);

dialogBuilder = new AlertDialog.Builder(this);
final View contactPopupView = getLayoutInflater().inflate(R.layout.popup_for_copyright,null);
copyrightBinding = PopupForCopyrightBinding.inflate(getLayoutInflater());
final View contactPopupView = copyrightBinding.getRoot();
dialogBuilder.setView(contactPopupView);
dialog = dialogBuilder.create();
dialog.show();

okButton = dialog.findViewById(R.id.button_ok);
okButton.setOnClickListener(view -> dialog.dismiss());
copyrightBinding.buttonOk.setOnClickListener(v -> dialog.dismiss());
}

ButterKnife.bind(this);
binding.welcomePager.setAdapter(adapter);
binding.welcomePagerIndicator.setViewPager(binding.welcomePager);

binding.finishTutorialButton.setOnClickListener(v -> finishTutorial());

pager.setAdapter(adapter);
indicator.setViewPager(pager);
}

/**
Expand All @@ -76,7 +69,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onDestroy() {
if (isQuiz) {
Intent i = new Intent(WelcomeActivity.this, QuizActivity.class);
final Intent i = new Intent(this, QuizActivity.class);
startActivity(i);
}
super.onDestroy();
Expand All @@ -87,8 +80,8 @@ public void onDestroy() {
*
* @param context Activity context
*/
public static void startYourself(Context context) {
Intent welcomeIntent = new Intent(context, WelcomeActivity.class);
public static void startYourself(final Context context) {
final Intent welcomeIntent = new Intent(context, WelcomeActivity.class);
context.startActivity(welcomeIntent);
}

Expand All @@ -97,8 +90,8 @@ public static void startYourself(Context context) {
*/
@Override
public void onBackPressed() {
if (pager.getCurrentItem() != 0) {
pager.setCurrentItem(pager.getCurrentItem() - 1, true);
if (binding.welcomePager.getCurrentItem() != 0) {
binding.welcomePager.setCurrentItem(binding.welcomePager.getCurrentItem() - 1, true);
} else {
if (defaultKvStore.getBoolean("firstrun", true)) {
finishAffinity();
Expand All @@ -108,7 +101,6 @@ public void onBackPressed() {
}
}

@OnClick(R.id.finishTutorialButton)
public void finishTutorial() {
defaultKvStore.putBoolean("firstrun", false);
finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ class WelcomeActivityUnitTest {
}

/**
* Checks if the activity is not null and member variables are not null
* Checks if the activity is not null
*/
@Test
@Throws(Exception::class)
fun checkActivityNotNull() {
assertNotNull(activity)
assertNotNull(activity.pager)
assertNotNull(activity.indicator)
}

/**
Expand Down