Skip to content

Commit

Permalink
Fix misc issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Doomsdayrs committed Jun 22, 2022
1 parent b6b6ad3 commit e5ac71c
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}

@Override
protected void onSaveInstanceState(Bundle outState) {
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(KEY_CURRENT_ITEM, miPager.getCurrentItem());
outState.putBoolean(KEY_FULLSCREEN, fullscreen);
Expand Down Expand Up @@ -333,21 +333,11 @@ public void setButtonBackOnClickListener(View.OnClickListener onClickListener) {
}

public void resetButtonNextOnClickListener() {
miButtonNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nextSlide();
}
});
miButtonNext.setOnClickListener(v -> nextSlide());
}

public void resetButtonBackOnClickListener() {
miButtonBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
performButtonBackPress();
}
});
miButtonBack.setOnClickListener(v -> performButtonBackPress());
}

private void smoothScrollPagerTo(final int position) {
Expand Down Expand Up @@ -960,17 +950,14 @@ private void updateButtonBackDrawable() {
public void autoplay(@IntRange(from = 1) long delay, @IntRange(from = -1) int repeatCount) {
autoplayCounter = repeatCount;
autoplayDelay = delay;
autoplayCallback = new Runnable() {
@Override
public void run() {
if (autoplayCounter == 0) {
cancelAutoplay();
return;
}
int distance = nextSlideAuto();
if (distance != 0)
autoplayHandler.postDelayed(autoplayCallback, autoplayDelay + calculateScrollDuration(distance));
autoplayCallback = () -> {
if (autoplayCounter == 0) {
cancelAutoplay();
return;
}
int distance = nextSlideAuto();
if (distance != 0)
autoplayHandler.postDelayed(autoplayCallback, autoplayDelay + calculateScrollDuration(distance));
};
autoplayHandler.postDelayed(autoplayCallback, autoplayDelay);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.os.Bundle;
import androidx.annotation.ColorRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.annotation.StyleRes;
import androidx.fragment.app.Fragment;
Expand All @@ -42,6 +43,8 @@
import com.heinrichreimersoftware.materialintro.app.SlideFragment;
import com.heinrichreimersoftware.materialintro.view.parallax.ParallaxFragment;

import java.util.Objects;

public class FragmentSlide implements Slide, RestorableSlide, ButtonCtaSlide {

private Fragment fragment;
Expand Down Expand Up @@ -139,11 +142,11 @@ public boolean equals(Object o) {
if (canGoForward != that.canGoForward) return false;
if (canGoBackward != that.canGoBackward) return false;
if (buttonCtaLabelRes != that.buttonCtaLabelRes) return false;
if (fragment != null ? !fragment.equals(that.fragment) : that.fragment != null)
if (!Objects.equals(fragment, that.fragment))
return false;
if (buttonCtaLabel != null ? !buttonCtaLabel.equals(that.buttonCtaLabel) : that.buttonCtaLabel != null)
if (!Objects.equals(buttonCtaLabel, that.buttonCtaLabel))
return false;
return buttonCtaClickListener != null ? buttonCtaClickListener.equals(that.buttonCtaClickListener) : that.buttonCtaClickListener == null;
return Objects.equals(buttonCtaClickListener, that.buttonCtaClickListener);

}

Expand Down Expand Up @@ -267,7 +270,7 @@ public static FragmentSlideFragment newInstance(@LayoutRes int layoutRes) {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
int themeRes = getArguments().getInt(ARGUMENT_THEME_RES);
Context contextThemeWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class SimpleSlide implements Slide, RestorableSlide, ButtonCtaSlide {

Expand Down Expand Up @@ -146,13 +147,10 @@ public View.OnClickListener getButtonCtaClickListener() {
if (permissions == null) {
return buttonCtaClickListener;
}
return new View.OnClickListener() {
@Override
public void onClick(View v) {
if (fragment.getActivity() != null)
ActivityCompat.requestPermissions(fragment.getActivity(), permissions,
permissionsRequestCode);
}
return v -> {
if (fragment.getActivity() != null)
ActivityCompat.requestPermissions(fragment.getActivity(), permissions,
permissionsRequestCode);
};
}

Expand Down Expand Up @@ -218,15 +216,15 @@ public boolean equals(Object o) {
if (canGoBackward != that.canGoBackward) return false;
if (permissionsRequestCode != that.permissionsRequestCode) return false;
if (buttonCtaLabelRes != that.buttonCtaLabelRes) return false;
if (fragment != null ? !fragment.equals(that.fragment) : that.fragment != null)
if (!Objects.equals(fragment, that.fragment))
return false;
if (title != null ? !title.equals(that.title) : that.title != null) return false;
if (description != null ? !description.equals(that.description) : that.description != null)
if (!Objects.equals(title, that.title)) return false;
if (!Objects.equals(description, that.description))
return false;
if (!Arrays.equals(permissions, that.permissions)) return false;
if (buttonCtaLabel != null ? !buttonCtaLabel.equals(that.buttonCtaLabel) : that.buttonCtaLabel != null)
if (!Objects.equals(buttonCtaLabel, that.buttonCtaLabel))
return false;
return buttonCtaClickListener != null ? buttonCtaClickListener.equals(that.buttonCtaClickListener) : that.buttonCtaClickListener == null;
return Objects.equals(buttonCtaClickListener, that.buttonCtaClickListener);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ public Slide getSlide(int location) {
return data.get(location);
}

@NonNull
@Override
public Fragment getItem(int position) {
return data.get(position).getFragment();
}

@Override
public int getItemPosition(Object object) {
public int getItemPosition(@NonNull Object object) {
if (object instanceof Fragment) {
fragmentManager.beginTransaction()
.detach((Fragment) object)
Expand All @@ -136,8 +137,9 @@ public int getItemPosition(Object object) {
return super.getItemPosition(object);
}

@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
public Object instantiateItem(@NonNull ViewGroup container, int position) {
Fragment fragment = getItem(position);
if (fragment.isAdded()) {
return fragment;
Expand All @@ -157,7 +159,7 @@ public Object instantiateItem(ViewGroup container, int position) {
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
Fragment fragment = (Fragment) object;
if (fragment == null)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ public class CheatSheet {
* @param view The view to add a cheat sheet for.
*/
public static void setup(View view) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return showCheatSheet(view, view.getContentDescription());
}
});
view.setOnLongClickListener(view1 -> showCheatSheet(view1, view1.getContentDescription()));
}

/**
Expand All @@ -65,12 +60,7 @@ public boolean onLongClick(View view) {
* @param textResId The string resource containing the text to show on long-press.
*/
public static void setup(View view, final int textResId) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return showCheatSheet(view, view.getContext().getString(textResId));
}
});
view.setOnLongClickListener(view1 -> showCheatSheet(view1, view1.getContext().getString(textResId)));
}

/**
Expand All @@ -83,12 +73,7 @@ public boolean onLongClick(View view) {
* @param text The text to show on long-press.
*/
public static void setup(View view, final CharSequence text) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return showCheatSheet(view, text);
}
});
view.setOnLongClickListener(view1 -> showCheatSheet(view1, text));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
import android.content.Context;
import android.database.DataSetObserver;
import android.os.Parcelable;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

public class FadeableViewPager extends SwipeBlockableViewPager {

public FadeableViewPager(Context context) {
Expand Down Expand Up @@ -133,50 +134,50 @@ public int getCount() {
}

@Override
public boolean isViewFromObject(View view, Object object) {
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return object != null && adapter.isViewFromObject(view, object);
}

@Override
public void startUpdate(ViewGroup container) {
public void startUpdate(@NonNull ViewGroup container) {
adapter.startUpdate(container);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
public Object instantiateItem(@NonNull ViewGroup container, int position) {
if (position < adapter.getCount())
return adapter.instantiateItem(container, position);
return null;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
if (position < adapter.getCount())
adapter.destroyItem(container, position, object);
}

@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
public void setPrimaryItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
if (position < adapter.getCount())
adapter.setPrimaryItem(container, position, object);
}

@Override
public void finishUpdate(ViewGroup container) {
public void finishUpdate(@NonNull ViewGroup container) {
adapter.finishUpdate(container);
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public void startUpdate(View container) {
public void startUpdate(@NonNull View container) {
adapter.startUpdate(container);
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public Object instantiateItem(View container, int position) {
public Object instantiateItem(@NonNull View container, int position) {
if (position < adapter.getCount())
return adapter.instantiateItem(container, position);
return null;
Expand All @@ -185,23 +186,23 @@ public Object instantiateItem(View container, int position) {
@SuppressWarnings("deprecation")
@Deprecated
@Override
public void destroyItem(View container, int position, Object object) {
public void destroyItem(@NonNull View container, int position, @NonNull Object object) {
if (position < adapter.getCount())
adapter.destroyItem(container, position, object);
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public void setPrimaryItem(View container, int position, Object object) {
public void setPrimaryItem(@NonNull View container, int position, @NonNull Object object) {
if (position < adapter.getCount())
adapter.setPrimaryItem(container, position, object);
}

@SuppressWarnings("deprecation")
@Deprecated
@Override
public void finishUpdate(View container) {
public void finishUpdate(@NonNull View container) {
adapter.finishUpdate(container);
}

Expand All @@ -216,19 +217,19 @@ public void restoreState(Parcelable state, ClassLoader loader) {
}

@Override
public int getItemPosition(Object object) {
public int getItemPosition(@NonNull Object object) {
int position = adapter.getItemPosition(object);
if (position < adapter.getCount()) return position;
return POSITION_NONE;
}

@Override
public void registerDataSetObserver(DataSetObserver observer) {
public void registerDataSetObserver(@NonNull DataSetObserver observer) {
adapter.registerDataSetObserver(observer);
}

@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
public void unregisterDataSetObserver(@NonNull DataSetObserver observer) {
adapter.unregisterDataSetObserver(observer);
}

Expand Down Expand Up @@ -257,7 +258,7 @@ private PageTransformerWrapper(PageTransformer pageTransformer, PagerAdapter ada
}

@Override
public void transformPage(View page, float position) {
public void transformPage(@NonNull View page, float position) {
pageTransformer.transformPage(page, Math.min(position, adapter.getCount() - 1));
}
}
Expand Down
Loading

0 comments on commit e5ac71c

Please sign in to comment.