Skip to content

Commit

Permalink
don't show animations when moving between lists if they are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
CampelloManuel committed Jan 27, 2024
1 parent aadc53b commit eccf272
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@
import androidx.viewpager.widget.ViewPager;

import com.nononsenseapps.helpers.NnnLogger;
import com.nononsenseapps.notepad.activities.main.ActivityMain;
import com.nononsenseapps.notepad.interfaces.ListOpener;
import com.nononsenseapps.notepad.activities.ActivitySearchDeleted;
import com.nononsenseapps.helpers.PreferencesHelper;
import com.nononsenseapps.notepad.R;
import com.nononsenseapps.notepad.activities.ActivitySearchDeleted;
import com.nononsenseapps.notepad.activities.main.ActivityMain;
import com.nononsenseapps.notepad.database.TaskList;
import com.nononsenseapps.notepad.databinding.FragmentTasklistViewpagerBinding;
import com.nononsenseapps.notepad.fragments.DialogEditList.EditListDialogListener;
import com.nononsenseapps.notepad.interfaces.ListOpener;
import com.nononsenseapps.notepad.interfaces.MenuStateController;
import com.nononsenseapps.ui.ViewsHelper;

Expand Down Expand Up @@ -81,6 +82,12 @@ public class TaskListViewPagerFragment extends Fragment implements

private long mListIdToSelect = -1;

/**
* If transitions between note lists should be animated, with smooth scrolling
* The value is regularly updated by {@link TaskListViewPagerFragment#onResume()}
*/
private boolean mShouldAnimate = true;

/**
* for {@link R.layout#fragment_tasklist_viewpager}
*/
Expand Down Expand Up @@ -126,6 +133,12 @@ public SectionsPagerAdapter getSectionsPagerAdapter() {
return mSectionsPagerAdapter;
}

@Override
public void onResume() {
super.onResume();
mShouldAnimate = PreferencesHelper.areAnimationsEnabled(this.getContext());
}

@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
Expand Down Expand Up @@ -168,13 +181,12 @@ public void onLoadFinished(@NonNull Loader<Cursor> arg0, Cursor c) {
mTaskListsAdapter.swapCursor(c);
final int pos;
if (mListIdToSelect != -1) {
pos = mSectionsPagerAdapter
.getItemPosition(mListIdToSelect);
pos = mSectionsPagerAdapter.getItemPosition(mListIdToSelect);
} else {
pos = -1;
}
if (pos >= 0) {
pager.setCurrentItem(pos);
pager.setCurrentItem(pos, mShouldAnimate);
mListIdToSelect = -1;
}
}
Expand Down Expand Up @@ -290,7 +302,7 @@ public void openList(final long id) {
pos = mSectionsPagerAdapter.getItemPosition(id);

if (pos > -1) {
pager.setCurrentItem(pos, true);
pager.setCurrentItem(pos, mShouldAnimate);
mListIdToSelect = -1;
}
}
Expand Down Expand Up @@ -370,9 +382,9 @@ public void destroy() {
wrappedAdapter.unregisterDataSetObserver(subObserver);
}
if (prefListener != null) {
PreferenceManager.getDefaultSharedPreferences(getActivity())
.unregisterOnSharedPreferenceChangeListener(
prefListener);
PreferenceManager
.getDefaultSharedPreferences(getActivity())
.unregisterOnSharedPreferenceChangeListener(prefListener);
}
}

Expand Down

0 comments on commit eccf272

Please sign in to comment.