Skip to content

Commit

Permalink
Merge pull request #611 from ooni/issues/1709/onboarding-fragments
Browse files Browse the repository at this point in the history
Chore: Update Onboarding fragments to `ViewBinding`
  • Loading branch information
aanorbel authored Sep 13, 2023
2 parents d3903f6 + b384881 commit 44ea55b
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,21 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import org.openobservatory.ooniprobe.R;

import butterknife.ButterKnife;
import butterknife.OnClick;
import org.openobservatory.ooniprobe.databinding.FragmentOnboarding1Binding;

public class Onboarding1Fragment extends Fragment {
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_onboarding_1, container, false);
ButterKnife.bind(this, v);
return v;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
FragmentOnboarding1Binding binding = FragmentOnboarding1Binding.inflate(inflater, container, false);
binding.master.setOnClickListener(v -> masterClick());
return binding.getRoot();
}

@OnClick(R.id.master) void masterClick() {
void masterClick() {
getParentFragmentManager().beginTransaction().replace(android.R.id.content, new Onboarding2Fragment()).commit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,36 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import org.openobservatory.ooniprobe.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import org.openobservatory.ooniprobe.databinding.FragmentOnboarding2Binding;

public class Onboarding2Fragment extends Fragment implements OnboardingDialogPopquizFragment.OnboardingPopquizInterface, OnboardingDialogWarningFragment.OnboardingWarningInterface {
@BindView(R.id.bullet1) TextView bullet1;
@BindView(R.id.bullet2) TextView bullet2;
@BindView(R.id.bullet3) TextView bullet3;

@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_onboarding_2, container, false);
ButterKnife.bind(this, v);
bullet1.setText(getString(R.string.bullet, getString(R.string.Onboarding_ThingsToKnow_Bullet_1)));
bullet2.setText(getString(R.string.bullet, getString(R.string.Onboarding_ThingsToKnow_Bullet_2)));
bullet3.setText(getString(R.string.bullet, getString(R.string.Onboarding_ThingsToKnow_Bullet_3)));
return v;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
FragmentOnboarding2Binding binding = FragmentOnboarding2Binding.inflate(inflater, container, false);
binding.bullet1.setText(getString(R.string.bullet, getString(R.string.Onboarding_ThingsToKnow_Bullet_1)));
binding.bullet2.setText(getString(R.string.bullet, getString(R.string.Onboarding_ThingsToKnow_Bullet_2)));
binding.bullet3.setText(getString(R.string.bullet, getString(R.string.Onboarding_ThingsToKnow_Bullet_3)));
binding.master.setOnClickListener(v -> masterClick());
binding.slave.setOnClickListener(v -> slaveClick());
return binding.getRoot();
}

@OnClick(R.id.master) void masterClick() {
void masterClick() {
OnboardingDialogPopquizFragment.newInstance(R.string.Onboarding_PopQuiz_1_Title, R.string.Onboarding_PopQuiz_1_Question).show(getChildFragmentManager(), null);
}

@OnClick(R.id.slave) void slaveClick() {
void slaveClick() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://ooni.io/about/risks/")));
}

@Override public void onPopquizResult(int questionResId, boolean positive) {
@Override
public void onPopquizResult(int questionResId, boolean positive) {
if (questionResId == R.string.Onboarding_PopQuiz_1_Question) {
if (positive)
OnboardingDialogPopquizFragment.newInstance(R.string.Onboarding_PopQuiz_2_Title, R.string.Onboarding_PopQuiz_2_Question).show(getChildFragmentManager(), null);
Expand All @@ -54,7 +49,8 @@ public class Onboarding2Fragment extends Fragment implements OnboardingDialogPop
}
}

@Override public void onWarningResult(int questionResId) {
@Override
public void onWarningResult(int questionResId) {
if (questionResId == R.string.Onboarding_PopQuiz_1_Wrong_Paragraph)
OnboardingDialogPopquizFragment.newInstance(R.string.Onboarding_PopQuiz_2_Title, R.string.Onboarding_PopQuiz_2_Question).show(getChildFragmentManager(), null);
else if (questionResId == R.string.Onboarding_PopQuiz_2_Wrong_Paragraph)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,50 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.activity.MainActivity;
import org.openobservatory.ooniprobe.common.Application;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ThirdPartyServices;
import org.openobservatory.ooniprobe.common.service.ServiceUtil;
import org.openobservatory.ooniprobe.databinding.FragmentOnboarding3Binding;
import ru.noties.markwon.Markwon;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ru.noties.markwon.Markwon;

public class Onboarding3Fragment extends Fragment {

@Inject PreferenceManager preferenceManager;

@BindView(R.id.bullet1) TextView bullet1;
@BindView(R.id.bullet2) TextView bullet2;
@BindView(R.id.bullet3) TextView bullet3;
@BindView(R.id.paragraph) TextView paragraph;

@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
((Application) getActivity().getApplication()).getFragmentComponent().inject(this);

View v = inflater.inflate(R.layout.fragment_onboarding_3, container, false);
ButterKnife.bind(this, v);
bullet1.setText(getString(R.string.bullet, getString(R.string.Onboarding_DefaultSettings_Bullet_1)));
bullet2.setText(getString(R.string.bullet, getString(R.string.Onboarding_DefaultSettings_Bullet_2)));
bullet3.setText(getString(R.string.bullet, getString(R.string.Onboarding_DefaultSettings_Bullet_3)));
Markwon.setMarkdown(paragraph, getString(R.string.Onboarding_DefaultSettings_Paragraph));
return v;
FragmentOnboarding3Binding binding = FragmentOnboarding3Binding.inflate(inflater, container, false);
binding.bullet1.setText(getString(R.string.bullet, getString(R.string.Onboarding_DefaultSettings_Bullet_1)));
binding.bullet2.setText(getString(R.string.bullet, getString(R.string.Onboarding_DefaultSettings_Bullet_2)));
binding.bullet3.setText(getString(R.string.bullet, getString(R.string.Onboarding_DefaultSettings_Bullet_3)));
Markwon.setMarkdown(binding.paragraph, getString(R.string.Onboarding_DefaultSettings_Paragraph));

binding.master.setOnClickListener(v -> masterClick());
binding.slave.setOnClickListener(v -> slaveClick());

return binding.getRoot();
}

@OnClick(R.id.master) void masterClick() {
void masterClick() {
preferenceManager.setShowOnboarding(false);
ThirdPartyServices.reloadConsents((Application) getActivity().getApplication());
startAutoTestIfNeeded();
startActivity(MainActivity.newIntent(getActivity(), R.id.dashboard));
getActivity().finish();
}

@OnClick(R.id.slave) void slaveClick() {
void slaveClick() {
preferenceManager.setShowOnboarding(false);
startAutoTestIfNeeded();
startActivity(MainActivity.newIntent(getActivity(), R.id.settings));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,39 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import localhost.toolkit.app.fragment.ConfirmDialogFragment;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.Application;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ThirdPartyServices;

import java.io.Serializable;
import org.openobservatory.ooniprobe.databinding.FragmentOnboardingAutotestBinding;

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.OnClick;
import localhost.toolkit.app.fragment.ConfirmDialogFragment;
import java.io.Serializable;

public class OnboardingAutoTestFragment extends Fragment implements ConfirmDialogFragment.OnConfirmedListener {
@Inject PreferenceManager preferenceManager;
public static final String BATTERY_DIALOG = "battery_optimization";

@Nullable
@Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
((Application) getActivity().getApplication()).getFragmentComponent().inject(this);

View v = inflater.inflate(R.layout.fragment_onboarding_autotest, container, false);
ButterKnife.bind(this, v);
return v;
FragmentOnboardingAutotestBinding binding = FragmentOnboardingAutotestBinding.inflate(inflater, container, false);
binding.master.setOnClickListener(v -> masterClick());
binding.slave.setOnClickListener(v -> slaveClick());
return binding.getRoot();
}

@OnClick(R.id.master) void masterClick() {
void masterClick() {
enableAutoTest();
}

@OnClick(R.id.slave) void slaveClick() {
void slaveClick() {
next();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,29 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.Application;
import org.openobservatory.ooniprobe.common.ThirdPartyServices;

import butterknife.ButterKnife;
import butterknife.OnClick;
import org.openobservatory.ooniprobe.databinding.FragmentOnboardingCrashBinding;

public class OnboardingCrashFragment extends Fragment {
@Nullable
@Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_onboarding_crash, container, false);
ButterKnife.bind(this, v);
return v;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
FragmentOnboardingCrashBinding binding = FragmentOnboardingCrashBinding.inflate(inflater, container, false);
binding.master.setOnClickListener(v -> masterClick());
binding.slave.setOnClickListener(v -> slaveClick());
return binding.getRoot();
}

@OnClick(R.id.master) void masterClick() {
void masterClick() {
ThirdPartyServices.acceptCrash((Application) getActivity().getApplication());
getParentFragmentManager().beginTransaction().replace(android.R.id.content, new Onboarding3Fragment()).commit();
}

@OnClick(R.id.slave) void slaveClick() {
void slaveClick() {
getParentFragmentManager().beginTransaction().replace(android.R.id.content, new Onboarding3Fragment()).commit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,16 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.airbnb.lottie.LottieAnimationView;

import org.openobservatory.ooniprobe.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import org.openobservatory.ooniprobe.databinding.FragmentOnboardingDialogPopquizBinding;

public class OnboardingDialogPopquizFragment extends DialogFragment {
private static final String TITLE_RES_ID = "titleResId";
private static final String QUESTION_RES_ID = "questionResId";
@BindView(R.id.title) @Nullable TextView title;
@BindView(R.id.question) TextView question;
@BindView(R.id.dialog) LinearLayout dialog;
@BindView(R.id.animation) LottieAnimationView animation;
private FragmentOnboardingDialogPopquizBinding binding;

public static OnboardingDialogPopquizFragment newInstance(int titleResId, int questionResId) {
Bundle args = new Bundle();
Expand All @@ -53,42 +41,45 @@ public void onStart() {

@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
assert getArguments() != null;
View v = inflater.inflate(R.layout.fragment_onboarding_dialog_popquiz, container, false);
ButterKnife.bind(this, v);
if (title != null)
title.setText(getArguments().getInt(TITLE_RES_ID));
question.setText(getArguments().getInt(QUESTION_RES_ID));
return v;
binding = FragmentOnboardingDialogPopquizBinding.inflate(inflater, container, false);
if (binding.title != null)
binding.title.setText(getArguments().getInt(TITLE_RES_ID));
binding.question.setText(getArguments().getInt(QUESTION_RES_ID));

binding.positive.setOnClickListener(v -> positiveClick());
binding.negative.setOnClickListener(v -> negativeClick());

return binding.getRoot();
}

@OnClick(R.id.positive) void positiveClick() {
animation.setBackgroundResource(R.drawable.dialog_green);
animation.setAnimation("anim/checkMark.json");
animation.setVisibility(View.VISIBLE);
dialog.setVisibility(View.INVISIBLE);
animation.addAnimatorListener(new AnimatorListenerAdapter() {
void positiveClick() {
binding.animation.setBackgroundResource(R.drawable.dialog_green);
binding.animation.setAnimation("anim/checkMark.json");
binding.animation.setVisibility(View.VISIBLE);
binding.dialog.setVisibility(View.INVISIBLE);
binding.animation.addAnimatorListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
dismiss();
((OnboardingPopquizInterface) getParentFragment()).onPopquizResult(getArguments().getInt(QUESTION_RES_ID), true);
}
});
animation.playAnimation();
binding.animation.playAnimation();
}

@OnClick(R.id.negative) void negativeClick() {
animation.setBackgroundResource(R.drawable.dialog_red);
animation.setAnimation("anim/crossMark.json");
animation.setVisibility(View.VISIBLE);
dialog.setVisibility(View.INVISIBLE);
animation.addAnimatorListener(new AnimatorListenerAdapter() {
void negativeClick() {
binding.animation.setBackgroundResource(R.drawable.dialog_red);
binding.animation.setAnimation("anim/crossMark.json");
binding.animation.setVisibility(View.VISIBLE);
binding.dialog.setVisibility(View.INVISIBLE);
binding.animation.addAnimatorListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
dismiss();
((OnboardingPopquizInterface) getParentFragment()).onPopquizResult(getArguments().getInt(QUESTION_RES_ID), false);
}
});
animation.playAnimation();
binding.animation.playAnimation();
}

public interface OnboardingPopquizInterface {
Expand Down
Loading

0 comments on commit 44ea55b

Please sign in to comment.