1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-22 12:21:15 +00:00

Use view binding in FirstStartActivity

This commit is contained in:
Adam Szewera 2024-01-09 20:56:33 +01:00 committed by Simon Frei
parent e5574f0d62
commit 43d8ebfeca

View file

@ -31,13 +31,13 @@ import android.view.View;
import android.view.View.OnTouchListener; import android.view.View.OnTouchListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.material.color.MaterialColors; import com.google.android.material.color.MaterialColors;
import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.SyncthingApp; import com.nutomic.syncthingandroid.SyncthingApp;
import com.nutomic.syncthingandroid.databinding.ActivityFirstStartBinding;
import com.nutomic.syncthingandroid.service.Constants; import com.nutomic.syncthingandroid.service.Constants;
import com.nutomic.syncthingandroid.util.PermissionUtil; import com.nutomic.syncthingandroid.util.PermissionUtil;
import com.nutomic.syncthingandroid.util.Util; import com.nutomic.syncthingandroid.util.Util;
@ -69,12 +69,10 @@ public class FirstStartActivity extends Activity {
private static Slide[] slides = Slide.values(); private static Slide[] slides = Slide.values();
private static String TAG = "FirstStartActivity"; private static String TAG = "FirstStartActivity";
private ViewPager mViewPager;
private ViewPagerAdapter mViewPagerAdapter; private ViewPagerAdapter mViewPagerAdapter;
private LinearLayout mDotsLayout;
private TextView[] mDots; private TextView[] mDots;
private Button mBackButton;
private Button mNextButton; private ActivityFirstStartBinding binding;
@Inject @Inject
SharedPreferences mPreferences; SharedPreferences mPreferences;
@ -95,13 +93,10 @@ public class FirstStartActivity extends Activity {
} }
// Show first start welcome wizard UI. // Show first start welcome wizard UI.
setContentView(R.layout.activity_first_start); binding = ActivityFirstStartBinding.inflate(getLayoutInflater());
mViewPager = (ViewPager) findViewById(R.id.view_pager); setContentView(binding.getRoot());
mDotsLayout = (LinearLayout) findViewById(R.id.layoutDots);
mBackButton = (Button) findViewById(R.id.btn_back);
mNextButton = (Button) findViewById(R.id.btn_next);
mViewPager.setOnTouchListener(new OnTouchListener() { binding.viewPager.setOnTouchListener(new OnTouchListener() {
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
// Consume the event to prevent swiping through the slides. // Consume the event to prevent swiping through the slides.
@ -115,17 +110,17 @@ public class FirstStartActivity extends Activity {
setActiveBottomDot(0); setActiveBottomDot(0);
mViewPagerAdapter = new ViewPagerAdapter(); mViewPagerAdapter = new ViewPagerAdapter();
mViewPager.setAdapter(mViewPagerAdapter); binding.viewPager.setAdapter(mViewPagerAdapter);
mViewPager.addOnPageChangeListener(mViewPagerPageChangeListener); binding.viewPager.addOnPageChangeListener(mViewPagerPageChangeListener);
mBackButton.setOnClickListener(new View.OnClickListener() { binding.btnBack.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
onBtnBackClick(); onBtnBackClick();
} }
}); });
mNextButton.setOnClickListener(new View.OnClickListener() { binding.btnNext.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
onBtnNextClick(); onBtnNextClick();
@ -139,12 +134,12 @@ public class FirstStartActivity extends Activity {
} }
public void onBtnBackClick() { public void onBtnBackClick() {
int current = mViewPager.getCurrentItem() - 1; int current = binding.viewPager.getCurrentItem() - 1;
if (current >= 0) { if (current >= 0) {
// Move to previous slider. // Move to previous slider.
mViewPager.setCurrentItem(current); binding.viewPager.setCurrentItem(current);
if (current == 0) { if (current == 0) {
mBackButton.setVisibility(View.GONE); binding.btnBack.setVisibility(View.GONE);
} }
} }
} }
@ -171,11 +166,11 @@ public class FirstStartActivity extends Activity {
break; break;
} }
int next = mViewPager.getCurrentItem() + 1; int next = binding.viewPager.getCurrentItem() + 1;
while (next < slides.length) { while (next < slides.length) {
if (!shouldSkipSlide(slides[next])) { if (!shouldSkipSlide(slides[next])) {
mViewPager.setCurrentItem(next); binding.viewPager.setCurrentItem(next);
mBackButton.setVisibility(View.VISIBLE); binding.btnBack.setVisibility(View.VISIBLE);
break; break;
} }
next++; next++;
@ -231,7 +226,7 @@ public class FirstStartActivity extends Activity {
} }
private Slide currentSlide() { private Slide currentSlide() {
return slides[mViewPager.getCurrentItem()]; return slides[binding.viewPager.getCurrentItem()];
} }
private boolean shouldSkipSlide(Slide slide) { private boolean shouldSkipSlide(Slide slide) {
@ -259,7 +254,7 @@ public class FirstStartActivity extends Activity {
mDots[i] = new TextView(this); mDots[i] = new TextView(this);
mDots[i].setText(Html.fromHtml("&#8226;")); mDots[i].setText(Html.fromHtml("&#8226;"));
mDots[i].setTextSize(35); mDots[i].setTextSize(35);
mDotsLayout.addView(mDots[i]); binding.layoutDots.addView(mDots[i]);
} }
} }
@ -280,7 +275,7 @@ public class FirstStartActivity extends Activity {
setActiveBottomDot(position); setActiveBottomDot(position);
// Change the next button text from next to finish on last slide. // Change the next button text from next to finish on last slide.
mNextButton.setText(getString((position == slides.length - 1) ? R.string.finish : R.string.cont)); binding.btnNext.setText(getString((position == slides.length - 1) ? R.string.finish : R.string.cont));
} }
@Override @Override