Search in sources :

Example 1 with PrefixHighlighter

use of com.simplecity.amp_library.format.PrefixHighlighter in project Shuttle by timusus.

the class SearchActivity method refreshAdapterItems.

private void refreshAdapterItems() {
    subscriptions.add(DataManager.getInstance().getSongsRelay().first().map(songs -> {
        char[] prefix = filterString.toUpperCase().toCharArray();
        List<Album> albums = Operators.songsToAlbums(songs);
        Collections.sort(albums, Album::compareTo);
        List<AlbumArtist> albumArtists = Operators.albumsToAlbumArtists(albums);
        Collections.sort(albumArtists, AlbumArtist::compareTo);
        List<AdaptableItem> adaptableItems = Stream.of(albumArtists).filter(album -> album.name != null).map(albumArtist -> new SearchUtils.JaroWinklerObject<>(albumArtist, filterString, albumArtist.name)).filter(jaroWinklerObject -> jaroWinklerObject.score > SCORE_THRESHOLD || TextUtils.isEmpty(filterString)).sorted((a, b) -> a.object.compareTo(b.object)).sorted((a, b) -> Double.compare(b.score, a.score)).map(jaroWinklerObject -> jaroWinklerObject.object).map(albumArtist -> {
            AlbumArtistView albumArtistView = new AlbumArtistView(albumArtist, ViewType.ARTIST_LIST, requestManager);
            albumArtistView.setPrefix(prefixHighlighter, prefix);
            return (AdaptableItem) albumArtistView;
        }).collect(Collectors.toList());
        if (!adaptableItems.isEmpty()) {
            adaptableItems.add(0, artistsHeader);
        }
        List<AdaptableItem> albumItems = Stream.of(albums).filter(album -> album.name != null).map(album -> new SearchUtils.JaroWinklerObject<>(album, filterString, album.name, album.albumArtistName)).filter(jaroWinklerObject -> jaroWinklerObject.score > SCORE_THRESHOLD || TextUtils.isEmpty(filterString)).sorted((a, b) -> a.object.compareTo(b.object)).sorted((a, b) -> Double.compare(b.score, a.score)).map(jaroWinklerObject -> jaroWinklerObject.object).map(album -> {
            AlbumView albumView = new AlbumView(album, ViewType.ALBUM_LIST, requestManager);
            albumView.setPrefix(prefixHighlighter, prefix);
            return albumView;
        }).collect(Collectors.toList());
        if (!albumItems.isEmpty()) {
            albumItems.add(0, albumsHeader);
        }
        adaptableItems.addAll(albumItems);
        songs = Stream.of(songs).filter(song -> song.name != null).map(song -> new SearchUtils.JaroWinklerObject<>(song, filterString, song.name, song.albumName, song.artistName, song.albumArtistName)).filter(jaroWinklerObject -> jaroWinklerObject.score > SCORE_THRESHOLD || TextUtils.isEmpty(filterString)).sorted((a, b) -> a.object.compareTo(b.object)).sorted((a, b) -> Double.compare(b.score, a.score)).map(jaroWinklerObject -> jaroWinklerObject.object).collect(Collectors.toList());
        List<AdaptableItem> songItems = Stream.of(songs).map(song -> {
            SongView songView = new SongView(song, dummySelector, requestManager);
            songView.setPrefix(prefixHighlighter, prefix);
            return songView;
        }).collect(Collectors.toList());
        if (!songItems.isEmpty()) {
            songItems.add(0, songsHeader);
        }
        adaptableItems.addAll(songItems);
        return adaptableItems;
    }).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
        if (setItemsSubscription != null) {
            setItemsSubscription.unsubscribe();
        }
        setItemsSubscription = adapter.setItems(adaptableItems);
        recyclerView.scrollToPosition(0);
    }));
}
Also used : R(com.simplecity.amp_library.R) Bundle(android.os.Bundle) SongView(com.simplecity.amp_library.ui.modelviews.SongView) SearchView(android.support.v7.widget.SearchView) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) WindowManager(android.view.WindowManager) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Song(com.simplecity.amp_library.model.Song) RequestManager(com.bumptech.glide.RequestManager) Schedulers(rx.schedulers.Schedulers) View(android.view.View) SearchAdapter(com.simplecity.amp_library.ui.adapters.SearchAdapter) Header(com.simplecity.amp_library.model.Header) Playlist(com.simplecity.amp_library.model.Playlist) MenuItemCompat(android.support.v4.view.MenuItemCompat) SearchableInfo(android.app.SearchableInfo) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) Serializable(java.io.Serializable) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) SearchManager(android.app.SearchManager) Subscription(rx.Subscription) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) Intent(android.content.Intent) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Observable(rx.Observable) AlbumArtistView(com.simplecity.amp_library.ui.modelviews.AlbumArtistView) SuppressLint(android.annotation.SuppressLint) PrefixHighlighter(com.simplecity.amp_library.format.PrefixHighlighter) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ColorUtils(com.simplecity.amp_library.utils.ColorUtils) Toast(android.widget.Toast) Menu(android.view.Menu) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) ActionBar(android.support.v7.app.ActionBar) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) SearchUtils(com.simplecity.amp_library.utils.SearchUtils) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextUtils(android.text.TextUtils) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) FLAG_TRANSLUCENT_STATUS(android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) TimeUnit(java.util.concurrent.TimeUnit) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) Glide(com.bumptech.glide.Glide) Toolbar(android.support.v7.widget.Toolbar) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) DataManager(com.simplecity.amp_library.utils.DataManager) RxSearchView(com.jakewharton.rxbinding.support.v7.widget.RxSearchView) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) SearchHeaderView(com.simplecity.amp_library.ui.modelviews.SearchHeaderView) Operators(com.simplecity.amp_library.utils.Operators) Activity(android.app.Activity) Collections(java.util.Collections) SongView(com.simplecity.amp_library.ui.modelviews.SongView) AlbumArtistView(com.simplecity.amp_library.ui.modelviews.AlbumArtistView) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with PrefixHighlighter

use of com.simplecity.amp_library.format.PrefixHighlighter in project Shuttle by timusus.

the class SearchFragment method onCreate.

@SuppressLint("InlinedApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    searchPresenter = new SearchPresenter(new PrefixHighlighter(), Glide.with(this));
    query = getArguments().getString(ARG_QUERY);
    loadingView = new LoadingView();
    emptyView = new EmptyView(R.string.empty_search);
    emptyView.setHeight(ResourceUtils.toPixels(96));
    adapter = new ViewModelAdapter();
}
Also used : PrefixHighlighter(com.simplecity.amp_library.format.PrefixHighlighter) LoadingView(com.simplecity.amp_library.ui.modelviews.LoadingView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) SuppressLint(android.annotation.SuppressLint)

Example 3 with PrefixHighlighter

use of com.simplecity.amp_library.format.PrefixHighlighter in project Shuttle by timusus.

the class SearchActivity method onCreate.

@SuppressLint("InlinedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    ThemeUtils.setTheme(this);
    if (!ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
        getWindow().setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
        mTintManager = new SystemBarTintManager(this);
    }
    if (!ShuttleUtils.hasKitKat()) {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    }
    if (SettingsManager.getInstance().canTintNavBar()) {
        getWindow().setNavigationBarColor(ColorUtils.getPrimaryColorDark(this));
    }
    super.onCreate(savedInstanceState);
    final String query = getIntent().getStringExtra(SearchManager.QUERY);
    filterString = !TextUtils.isEmpty(query) ? query.toLowerCase().trim() : "";
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    setContentView(R.layout.activity_search);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Get the ActionBar
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(null);
    ThemeUtils.themeActionBar(this);
    ThemeUtils.themeStatusBar(this, mTintManager);
    adapter = new SearchAdapter();
    adapter.setListener(this);
    recyclerView = (FastScrollRecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adapter);
    ThemeUtils.themeRecyclerView(recyclerView);
    recyclerView.setThumbColor(ColorUtils.getAccentColor());
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            ThemeUtils.themeRecyclerView(recyclerView);
            super.onScrollStateChanged(recyclerView, newState);
        }
    });
    if (requestManager == null) {
        requestManager = Glide.with(this);
    }
    dummySelector = new MultiSelector();
    songsHeader = new SearchHeaderView(new Header(getString(R.string.tracks_title)));
    albumsHeader = new SearchHeaderView(new Header(getString(R.string.albums_title)));
    artistsHeader = new SearchHeaderView(new Header(getString(R.string.artists_title)));
    prefixHighlighter = new PrefixHighlighter(this);
}
Also used : SearchAdapter(com.simplecity.amp_library.ui.adapters.SearchAdapter) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SuppressLint(android.annotation.SuppressLint) SearchHeaderView(com.simplecity.amp_library.ui.modelviews.SearchHeaderView) Header(com.simplecity.amp_library.model.Header) PrefixHighlighter(com.simplecity.amp_library.format.PrefixHighlighter) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)3 PrefixHighlighter (com.simplecity.amp_library.format.PrefixHighlighter)3 ActionBar (android.support.v7.app.ActionBar)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 Toolbar (android.support.v7.widget.Toolbar)2 MultiSelector (com.bignerdranch.android.multiselector.MultiSelector)2 SystemBarTintManager (com.readystatesoftware.systembartint.SystemBarTintManager)2 Header (com.simplecity.amp_library.model.Header)2 SearchAdapter (com.simplecity.amp_library.ui.adapters.SearchAdapter)2 Activity (android.app.Activity)1 SearchManager (android.app.SearchManager)1 SearchableInfo (android.app.SearchableInfo)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 MenuItemCompat (android.support.v4.view.MenuItemCompat)1 PopupMenu (android.support.v7.widget.PopupMenu)1 SearchView (android.support.v7.widget.SearchView)1 TextUtils (android.text.TextUtils)1