use of com.simplecity.amp_library.utils.SettingsManager in project Shuttle by timusus.
the class LibraryController method setupViewPager.
private void setupViewPager() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
CategoryItem.getCategoryItems(sharedPreferences);
if (pagerAdapter != null && refreshPagerAdapter) {
pagerAdapter.removeAllChildFragments();
refreshPagerAdapter = false;
pager.setAdapter(null);
}
int defaultPage = 1;
pagerAdapter = new PagerAdapter(getChildFragmentManager());
List<CategoryItem> categoryItems = Stream.of(CategoryItem.getCategoryItems(sharedPreferences)).filter(categoryItem -> categoryItem.isChecked).toList();
int defaultPageType = settingsManager.getDefaultPageType();
for (int i = 0; i < categoryItems.size(); i++) {
CategoryItem categoryItem = categoryItems.get(i);
pagerAdapter.addFragment(categoryItem.getFragment(getContext()));
if (categoryItem.type == defaultPageType) {
defaultPage = i;
}
}
int currentPage = Math.min(defaultPage, pagerAdapter.getCount());
pager.setAdapter(pagerAdapter);
pager.setOffscreenPageLimit(pagerAdapter.getCount() - 1);
pager.setCurrentItem(currentPage);
slidingTabLayout.setupWithViewPager(pager);
pager.postDelayed(() -> {
if (pager != null) {
new RatingSnackbar(settingsManager, analyticsManager).show(pager, () -> {
ShuttleUtils.openShuttleLink(getActivity(), getActivity().getPackageName(), getActivity().getPackageManager());
return Unit.INSTANCE;
});
}
}, 1000);
}
use of com.simplecity.amp_library.utils.SettingsManager in project Shuttle by timusus.
the class FolderFragment method changeDir.
@SuppressLint("CheckResult")
public void changeDir(File newDir) {
disposables.add(Single.zip(whitelistRepository.getWhitelistItems(songsRepository).first(Collections.emptyList()), blacklistRepository.getBlacklistItems(songsRepository).first(Collections.emptyList()), Single.fromCallable(() -> {
final String path = FileHelper.getPath(newDir);
if (TextUtils.isEmpty(path)) {
return new ArrayList<>();
}
currentDir = path;
return fileBrowser.loadDir(new File(path));
}), (Function3<List<InclExclItem>, List<InclExclItem>, List<BaseFileObject>, List<ViewModel>>) (whitelist, blacklist, baseFileObjects) -> {
List<ViewModel> items = Stream.of(baseFileObjects).map(baseFileObject -> {
// Look for an existing FolderView wrapping the BaseFileObject, we'll reuse it if it exists.
FolderView folderView = (FolderView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof FolderView && (((FolderView) viewModel).baseFileObject.equals(baseFileObject))).findFirst().orElse(null);
if (folderView == null) {
folderView = new FolderView(baseFileObject, whitelistRepository, blacklistRepository, settingsManager, Stream.of(whitelist).anyMatch(inclExclItem -> inclExclItem.path.equals(baseFileObject.path)), Stream.of(blacklist).anyMatch(inclExclItem -> inclExclItem.path.equals(baseFileObject.path)));
folderView.setShowWhitelist(isShowingWhitelist);
folderView.setShowBlacklist(isShowingBlacklist);
folderView.setClickListener(FolderFragment.this);
}
return folderView;
}).collect(Collectors.toList());
if (showBreadcrumbsInList && breadcrumbsView != null) {
breadcrumbsView.setBreadcrumbsPath(currentDir);
breadcrumbsView.setListener(FolderFragment.this);
items.add(0, breadcrumbsView);
}
return items;
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
if (adapter != null) {
analyticsManager.dropBreadcrumb(TAG, "setItems()");
setItemsDisposable = adapter.setItems(adaptableItems);
}
if (breadcrumb != null) {
breadcrumb.changeBreadcrumbPath(currentDir);
}
if (adapter != null) {
changeBreadcrumbPath();
}
updateMenuItems();
}, error -> LogUtils.logException(TAG, "Error changing dir", error)));
}
use of com.simplecity.amp_library.utils.SettingsManager in project Shuttle by timusus.
the class QueuePagerPresenter method bindView.
@Override
public void bindView(@NonNull QueuePagerView view) {
super.bindView(view);
IntentFilter filter = new IntentFilter();
filter.addAction(InternalIntents.META_CHANGED);
filter.addAction(InternalIntents.REPEAT_CHANGED);
filter.addAction(InternalIntents.SHUFFLE_CHANGED);
filter.addAction(InternalIntents.QUEUE_CHANGED);
filter.addAction(InternalIntents.SERVICE_CONNECTED);
addDisposable(RxBroadcast.fromBroadcast(application, filter).startWith(new Intent(InternalIntents.QUEUE_CHANGED)).toFlowable(BackpressureStrategy.LATEST).observeOn(AndroidSchedulers.mainThread()).subscribe(intent -> {
final String action = intent.getAction();
QueuePagerView queuePagerView = getView();
if (queuePagerView == null) {
return;
}
if (action != null) {
switch(action) {
case InternalIntents.META_CHANGED:
queuePagerView.updateQueuePosition(mediaManager.getQueuePosition());
break;
case InternalIntents.REPEAT_CHANGED:
case InternalIntents.SHUFFLE_CHANGED:
case InternalIntents.QUEUE_CHANGED:
case InternalIntents.SERVICE_CONNECTED:
List<ViewModel> items = Stream.of(mediaManager.getQueue()).map(queueItem -> new QueuePagerItemView(queueItem.getSong(), requestManager, settingsManager)).collect(Collectors.toList());
queuePagerView.loadData(items, mediaManager.getQueuePosition());
break;
}
}
}));
}
use of com.simplecity.amp_library.utils.SettingsManager in project Shuttle by timusus.
the class QueuePagerFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_queue_pager, container, false);
unbinder = ButterKnife.bind(this, rootView);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
if (ShuttleUtils.isLandscape(getContext())) {
textProtectionScrim.setVisibility(View.GONE);
}
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(viewModelAdapter);
SnapHelper snapHelper = new PagerSnapHelper() {
@Override
public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) {
int snapPosition = super.findTargetSnapPosition(layoutManager, velocityX, velocityY);
if (snapPosition < viewModelAdapter.items.size()) {
Observable.timer(200, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(o -> {
if (mediaManager.getQueuePosition() != snapPosition) {
mediaManager.setQueuePosition(snapPosition);
}
}, throwable -> LogUtils.logException(TAG, "Error setting queue position", throwable));
}
return snapPosition;
}
};
snapHelper.attachToRecyclerView(recyclerView);
recyclerView.addOnScrollListener(new RecyclerViewPreloader<>(new ListPreloader.PreloadModelProvider<QueuePagerItemView>() {
@Override
public List<QueuePagerItemView> getPreloadItems(int position) {
QueuePagerItemView queuePagerItemView = (QueuePagerItemView) viewModelAdapter.items.get(position);
return Collections.singletonList(queuePagerItemView);
}
@Override
public GenericRequestBuilder getPreloadRequestBuilder(QueuePagerItemView item) {
return requestManager.load(item.song).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(PlaceholderProvider.getInstance(getContext()).getPlaceHolderDrawable(item.song.name, true, settingsManager));
}
}, (item, adapterPosition, perItemPosition) -> imageSize, 3));
recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
// This null check doesn't make sense to me, but there was an NPE here..
if (recyclerView != null) {
imageSize = new int[] { recyclerView.getWidth(), recyclerView.getHeight() };
recyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
}
return false;
}
});
return rootView;
}
use of com.simplecity.amp_library.utils.SettingsManager in project Shuttle by timusus.
the class DeleteDialog method deleteSongsOrShowSafDialog.
@SuppressLint("CheckResult")
void deleteSongsOrShowSafDialog() {
disposables.add(getSongs().map(songs -> {
// Keep track of the songs we want to delete, for later.
Stream.of(songs).forEach(song -> {
if (SafManager.getInstance(getContext(), settingsManager).requiresPermission(new File(song.path))) {
songsForSafDeletion.add(song);
} else {
songsForNormalDeletion.add(song);
}
});
boolean requiresSafDialog = false;
if (!songsForSafDeletion.isEmpty()) {
// We're gonna need SAF access to delete some songs.
// We may be able to build a list of document files if the user has been here before..
List<DocumentFile> documentFiles = SafManager.getInstance(getContext(), settingsManager).getWriteableDocumentFiles(Stream.of(songsForSafDeletion).map(song -> new File(song.path)).toList());
if (documentFiles.size() == songsForSafDeletion.size()) {
// We have all the document files we need. No need to show SAF dialog.
this.documentFilesForDeletion.addAll(documentFiles);
} else {
// We'll have to show the SAF dialog
requiresSafDialog = true;
}
}
return requiresSafDialog;
}).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(requiresSafDialog -> {
if (requiresSafDialog) {
if (DeleteDialog.this.isAdded()) {
SafManager.SafDialog.show(DeleteDialog.this);
} else {
LogUtils.logException(TAG, "Failed to delete songs.. Couldn't show SAFDialog", null);
Toast.makeText(getContext(), getString(R.string.delete_songs_failure_toast), Toast.LENGTH_SHORT).show();
}
} else {
disposables.add(deleteSongs().observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(deletedSongs -> {
if (DeleteDialog.this.isAdded()) {
if (deletedSongs > 0) {
Toast.makeText(getContext(), getString(R.string.delete_songs_success_toast, deletedSongs), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getContext(), getString(R.string.delete_songs_failure_toast), Toast.LENGTH_SHORT).show();
}
dismiss();
}
}, error -> {
LogUtils.logException(TAG, "Failed to delete songs", error);
if (DeleteDialog.this.isAdded()) {
Toast.makeText(getContext(), getString(R.string.delete_songs_failure_toast), Toast.LENGTH_SHORT).show();
}
}));
}
}, error -> LogUtils.logException(TAG, "Failed to delete songs", error)));
}
Aggregations