Search in sources :

Example 1 with AsyncBlacklistArtistTask

use of com.jams.music.player.BlacklistManagerActivity.BlacklistedArtistsMultiselectAdapter.AsyncBlacklistArtistTask in project JamsMusicPlayer by psaravan.

the class BlacklistedArtistsPickerFragment method onCreateView.

@SuppressLint("NewApi")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mApp = (Common) getActivity().getApplicationContext();
    View rootView = inflater.inflate(R.layout.fragment_artists_music_library_editor, null);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        rootView.setBackground(UIElementsHelper.getBackgroundGradientDrawable(getActivity()));
    } else {
        rootView.setBackgroundDrawable(UIElementsHelper.getBackgroundGradientDrawable(getActivity()));
    }
    cursor = mApp.getDBAccessHelper().getAllUniqueArtistsNoBlacklist("");
    listView = (ListView) rootView.findViewById(R.id.musicLibraryEditorArtistsListView);
    listView.setFastScrollEnabled(true);
    listView.setAdapter(new BlacklistedArtistsMultiselectAdapter(getActivity(), cursor));
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int which, long dbID) {
            CheckBox checkbox = (CheckBox) view.findViewById(R.id.artistCheckboxMusicLibraryEditor);
            checkbox.performClick();
            /* Since we've performed a software-click (checkbox.performClick()), all we have 
				 * to do now is determine the *new* state of the checkbox. If the checkbox is checked, 
				 * that means that the user tapped on it when it was unchecked, and we should add 
				 * the artist's songs to the HashSet. If the checkbox is unchecked, that means the user 
				 * tapped on it when it was checked, so we should remove the artist's songs from the 
				 * HashSet.
				 */
            if (checkbox.isChecked()) {
                view.setBackgroundColor(0xCCFF4444);
                AsyncBlacklistArtistTask task = new AsyncBlacklistArtistTask((String) view.getTag(R.string.artist));
                task.execute(new String[] { "ADD" });
            } else {
                view.setBackgroundColor(0x00000000);
                AsyncBlacklistArtistTask task = new AsyncBlacklistArtistTask((String) view.getTag(R.string.artist));
                task.execute(new String[] { "REMOVE" });
            }
        }
    });
    instructions = (TextView) rootView.findViewById(R.id.artists_music_library_editor_instructions);
    instructions.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light"));
    instructions.setPaintFlags(instructions.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    instructions.setText(R.string.blacklist_manager_artists_instructions);
    //KitKat translucent navigation/status bar.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        //Calculate navigation bar height.
        int navigationBarHeight = 0;
        int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            navigationBarHeight = getResources().getDimensionPixelSize(resourceId);
        }
        listView.setClipToPadding(false);
        listView.setPadding(0, 0, 0, navigationBarHeight);
    }
    return rootView;
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AsyncBlacklistArtistTask(com.jams.music.player.BlacklistManagerActivity.BlacklistedArtistsMultiselectAdapter.AsyncBlacklistArtistTask) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 CheckBox (android.widget.CheckBox)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 AsyncBlacklistArtistTask (com.jams.music.player.BlacklistManagerActivity.BlacklistedArtistsMultiselectAdapter.AsyncBlacklistArtistTask)1