mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
4664: Moved WelcomeActivity to ViewBinding (#5063)
* 4664: Moved WelcomeActivity to ViewBinding * 4664: Removed non-null test on member variables
This commit is contained in:
parent
1a39c9f8b1
commit
10b025c237
2 changed files with 25 additions and 35 deletions
|
|
@ -1,35 +1,25 @@
|
||||||
package fr.free.nrw.commons;
|
package fr.free.nrw.commons;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import fr.free.nrw.commons.databinding.ActivityWelcomeBinding;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
import fr.free.nrw.commons.databinding.PopupForCopyrightBinding;
|
||||||
|
|
||||||
import com.viewpagerindicator.CirclePageIndicator;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
import butterknife.OnClick;
|
|
||||||
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;
|
||||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
public class WelcomeActivity extends BaseActivity {
|
public class WelcomeActivity extends BaseActivity {
|
||||||
|
|
||||||
@BindView(R.id.welcomePager)
|
private ActivityWelcomeBinding binding;
|
||||||
ViewPager pager;
|
private PopupForCopyrightBinding copyrightBinding;
|
||||||
@BindView(R.id.welcomePagerIndicator)
|
|
||||||
CirclePageIndicator indicator;
|
|
||||||
|
|
||||||
private WelcomePagerAdapter adapter = new WelcomePagerAdapter();
|
private final WelcomePagerAdapter adapter = new WelcomePagerAdapter();
|
||||||
private boolean isQuiz;
|
private boolean isQuiz;
|
||||||
private AlertDialog.Builder dialogBuilder;
|
private AlertDialog.Builder dialogBuilder;
|
||||||
private AlertDialog dialog;
|
private AlertDialog dialog;
|
||||||
Button okButton;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialises exiting fields and dependencies
|
* Initialises exiting fields and dependencies
|
||||||
|
|
@ -37,12 +27,14 @@ public class WelcomeActivity extends BaseActivity {
|
||||||
* @param savedInstanceState WelcomeActivity bundled data
|
* @param savedInstanceState WelcomeActivity bundled data
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_welcome);
|
binding = ActivityWelcomeBinding.inflate(getLayoutInflater());
|
||||||
|
final View view = binding.getRoot();
|
||||||
|
setContentView(view);
|
||||||
|
|
||||||
if (getIntent() != null) {
|
if (getIntent() != null) {
|
||||||
Bundle bundle = getIntent().getExtras();
|
final Bundle bundle = getIntent().getExtras();
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
isQuiz = bundle.getBoolean("isQuiz");
|
isQuiz = bundle.getBoolean("isQuiz");
|
||||||
}
|
}
|
||||||
|
|
@ -52,22 +44,23 @@ public class WelcomeActivity extends BaseActivity {
|
||||||
|
|
||||||
// Enable skip button if beta flavor
|
// Enable skip button if beta flavor
|
||||||
if (ConfigUtils.isBetaFlavour()) {
|
if (ConfigUtils.isBetaFlavour()) {
|
||||||
findViewById(R.id.finishTutorialButton).setVisibility(View.VISIBLE);
|
binding.finishTutorialButton.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
dialogBuilder = new AlertDialog.Builder(this);
|
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);
|
dialogBuilder.setView(contactPopupView);
|
||||||
dialog = dialogBuilder.create();
|
dialog = dialogBuilder.create();
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
okButton = dialog.findViewById(R.id.button_ok);
|
copyrightBinding.buttonOk.setOnClickListener(v -> dialog.dismiss());
|
||||||
okButton.setOnClickListener(view -> 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -76,7 +69,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);
|
final Intent i = new Intent(this, QuizActivity.class);
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
@ -87,8 +80,8 @@ public class WelcomeActivity extends BaseActivity {
|
||||||
*
|
*
|
||||||
* @param context Activity context
|
* @param context Activity context
|
||||||
*/
|
*/
|
||||||
public static void startYourself(Context context) {
|
public static void startYourself(final Context context) {
|
||||||
Intent welcomeIntent = new Intent(context, WelcomeActivity.class);
|
final Intent welcomeIntent = new Intent(context, WelcomeActivity.class);
|
||||||
context.startActivity(welcomeIntent);
|
context.startActivity(welcomeIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,8 +90,8 @@ public class WelcomeActivity extends BaseActivity {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (pager.getCurrentItem() != 0) {
|
if (binding.welcomePager.getCurrentItem() != 0) {
|
||||||
pager.setCurrentItem(pager.getCurrentItem() - 1, true);
|
binding.welcomePager.setCurrentItem(binding.welcomePager.getCurrentItem() - 1, true);
|
||||||
} else {
|
} else {
|
||||||
if (defaultKvStore.getBoolean("firstrun", true)) {
|
if (defaultKvStore.getBoolean("firstrun", true)) {
|
||||||
finishAffinity();
|
finishAffinity();
|
||||||
|
|
@ -108,7 +101,6 @@ public class WelcomeActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.finishTutorialButton)
|
|
||||||
public void finishTutorial() {
|
public void finishTutorial() {
|
||||||
defaultKvStore.putBoolean("firstrun", false);
|
defaultKvStore.putBoolean("firstrun", false);
|
||||||
finish();
|
finish();
|
||||||
|
|
|
||||||
|
|
@ -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
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun checkActivityNotNull() {
|
fun checkActivityNotNull() {
|
||||||
assertNotNull(activity)
|
assertNotNull(activity)
|
||||||
assertNotNull(activity.pager)
|
|
||||||
assertNotNull(activity.indicator)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue