Search in sources :

Example 1 with InclExclItem

use of com.simplecity.amp_library.model.InclExclItem in project Shuttle by timusus.

the class FolderFragment method changeDir.

@SuppressLint("CheckResult")
public void changeDir(File newDir) {
    if (setItemsDisposable != null) {
        setItemsDisposable.dispose();
    }
    disposables.add(Single.zip(DataManager.getInstance().getIncludeItems().first(Collections.emptyList()), DataManager.getInstance().getExcludeItems().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, 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) {
            setItemsDisposable = adapter.setItems(adaptableItems);
        }
        if (breadcrumb != null) {
            breadcrumb.changeBreadcrumbPath(currentDir);
        }
        if (adapter != null) {
            changeBreadcrumbPath();
        }
        updateMenuItems();
    }, error -> LogUtils.logException(TAG, "Error changing dir", error)));
}
Also used : R(com.simplecity.amp_library.R) Bundle(android.os.Bundle) Rx.onErrorLogAndRethrow(com.afollestad.aesthetic.Rx.onErrorLogAndRethrow) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) Song(com.simplecity.amp_library.model.Song) Aesthetic(com.afollestad.aesthetic.Aesthetic) CheckBox(android.widget.CheckBox) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) Unbinder(butterknife.Unbinder) BackPressListener(test.com.androidnavigation.fragment.BackPressListener) LogUtils(com.simplecity.amp_library.utils.LogUtils) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) SortManager(com.simplecity.amp_library.utils.SortManager) FileHelper(com.simplecity.amp_library.utils.FileHelper) PopupMenu(android.support.v7.widget.PopupMenu) ViewGroup(android.view.ViewGroup) Breadcrumb(com.simplecity.amp_library.interfaces.Breadcrumb) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) InclExclItem(com.simplecity.amp_library.model.InclExclItem) IntStream(com.annimon.stream.IntStream) BreadcrumbListener(com.simplecity.amp_library.interfaces.BreadcrumbListener) FileType(com.simplecity.amp_library.interfaces.FileType) AppBarLayout(android.support.design.widget.AppBarLayout) Stream(com.annimon.stream.Stream) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) ButterKnife(butterknife.ButterKnife) DrawerLockManager(com.simplecity.amp_library.ui.drawer.DrawerLockManager) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) Single(io.reactivex.Single) FolderView(com.simplecity.amp_library.ui.modelviews.FolderView) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) ViewBackgroundAction(com.afollestad.aesthetic.ViewBackgroundAction) BaseFileObject(com.simplecity.amp_library.model.BaseFileObject) Observable(io.reactivex.Observable) UpgradeDialog(com.simplecity.amp_library.ui.dialog.UpgradeDialog) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) Rx.distinctToMainThread(com.afollestad.aesthetic.Rx.distinctToMainThread) Nullable(io.reactivex.annotations.Nullable) Collectors(com.annimon.stream.Collectors) FileBrowser(com.simplecity.amp_library.utils.FileBrowser) LayoutInflater(android.view.LayoutInflater) Function3(io.reactivex.functions.Function3) ThemedStatusBarView(com.simplecity.amp_library.ui.views.ThemedStatusBarView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextUtils(android.text.TextUtils) File(java.io.File) RecyclerView(android.support.v7.widget.RecyclerView) Toolbar(android.support.v7.widget.Toolbar) BreadcrumbItem(com.simplecity.amp_library.ui.views.BreadcrumbItem) BreadcrumbsView(com.simplecity.amp_library.ui.modelviews.BreadcrumbsView) DataManager(com.simplecity.amp_library.utils.DataManager) Collections(java.util.Collections) FolderView(com.simplecity.amp_library.ui.modelviews.FolderView) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) SuppressLint(android.annotation.SuppressLint)

Example 2 with InclExclItem

use of com.simplecity.amp_library.model.InclExclItem in project Shuttle by timusus.

the class FolderView method setWhitelisted.

public void setWhitelisted(boolean whitelisted) {
    isWhitelisted = whitelisted;
    InclExclItem inclExclItem = new InclExclItem(baseFileObject.path, InclExclItem.Type.INCLUDE);
    if (whitelisted) {
        InclExclHelper.addToInclExcl(inclExclItem);
    } else {
        InclExclHelper.deleteInclExclItem(inclExclItem);
    }
}
Also used : InclExclItem(com.simplecity.amp_library.model.InclExclItem)

Example 3 with InclExclItem

use of com.simplecity.amp_library.model.InclExclItem in project Shuttle by timusus.

the class FolderView method setBlacklisted.

public void setBlacklisted(boolean blacklisted) {
    isBlacklisted = blacklisted;
    InclExclItem inclExclItem = new InclExclItem(baseFileObject.path, InclExclItem.Type.EXCLUDE);
    if (blacklisted) {
        InclExclHelper.addToInclExcl(inclExclItem);
    } else {
        InclExclHelper.deleteInclExclItem(inclExclItem);
    }
}
Also used : InclExclItem(com.simplecity.amp_library.model.InclExclItem)

Example 4 with InclExclItem

use of com.simplecity.amp_library.model.InclExclItem in project Shuttle by timusus.

the class InclExclHelper method addToInclExcl.

public static void addToInclExcl(List<InclExclItem> inclExclItems) {
    BriteDatabase db = DataManager.getInstance().getInclExclDatabase();
    BriteDatabase.Transaction transaction = db.newTransaction();
    try {
        Stream.of(inclExclItems).map(inclExclItem -> {
            ContentValues contentValues = new ContentValues(2);
            contentValues.put(InclExclDbOpenHelper.COLUMN_PATH, inclExclItem.path);
            contentValues.put(InclExclDbOpenHelper.COLUMN_TYPE, inclExclItem.type);
            return contentValues;
        }).forEach(contentValues -> db.insert(InclExclDbOpenHelper.TABLE_NAME, contentValues));
        transaction.markSuccessful();
    } finally {
        transaction.end();
    }
}
Also used : Song(com.simplecity.amp_library.model.Song) List(java.util.List) BriteDatabase(com.squareup.sqlbrite2.BriteDatabase) Stream(com.annimon.stream.Stream) DataManager(com.simplecity.amp_library.utils.DataManager) ContentValues(android.content.ContentValues) InclExclItem(com.simplecity.amp_library.model.InclExclItem) ContentValues(android.content.ContentValues) BriteDatabase(com.squareup.sqlbrite2.BriteDatabase)

Aggregations

InclExclItem (com.simplecity.amp_library.model.InclExclItem)4 Stream (com.annimon.stream.Stream)2 Song (com.simplecity.amp_library.model.Song)2 SuppressLint (android.annotation.SuppressLint)1 ContentValues (android.content.ContentValues)1 Bundle (android.os.Bundle)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 PopupMenu (android.support.v7.widget.PopupMenu)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 TextUtils (android.text.TextUtils)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 CheckBox (android.widget.CheckBox)1 Toast (android.widget.Toast)1