<commit_before>package com.uid.DroidDoesMusic.UI;

import com.uid.DroidDoesMusic.R;

import android.app.ListActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore.Audio;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class Library extends ListActivity {
	protected static final String TAG = "DroidDoesMusic";
	public static final int ARTIST_VIEW = 0;
	public static final int ALBUM_VIEW = 1;
	public static final int SONG_VIEW = 2;
	int instanceView;
	boolean populated = false;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, getClass().getSimpleName() + ": onCreate");
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.library);

        // Get extra data from intent
        instanceView = getIntent().getExtras().getInt("view");
        
        // Populate ListView
        populateDataIfReady(instanceView);
    }
	
	@Override
	public void onResume() {
        Log.d(TAG, getClass().getSimpleName() + ": onResume");
		super.onResume();
		
		IntentFilter iff = new IntentFilter();
		iff.addAction(Intent.ACTION_MEDIA_SHARED);
		iff.addAction(Intent.ACTION_MEDIA_MOUNTED);
		iff.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
		iff.addAction(Intent.ACTION_UMS_CONNECTED);
		iff.addAction(Intent.ACTION_UMS_DISCONNECTED);
		registerReceiver(this.externalMediaListener, iff);
		
		populateDataIfReady(instanceView);
	}
	
	@Override
	public void onPause() {
        Log.d(TAG, getClass().getSimpleName() + ": onPause");
		super.onResume();
		
		unregisterReceiver(this.externalMediaListener);
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		Log.d(TAG, getClass().getSimpleName() + ": onListItemClick: " + ((TextView)v).getText() + " (" + id + ")");
		super.onListItemClick(l, v, position, id);
		
		Toast t = Toast.makeText(this, ((TextView)v).getText() + " (" + id + ")", Toast.LENGTH_LONG);
		t.setGravity(Gravity.CENTER, 0, 0);
		t.show();
	}
	
	public void getArtists() {
        // Grabs content URI for a unique list of Artists on the SDcard
        Uri extUri = Audio.Artists.EXTERNAL_CONTENT_URI;

        // Columns to grab from the DB, then the expected mappings
        String[] projection = new String[] {Audio.Artists._ID, Audio.Artists.ARTIST};
        String[] displayColumns = new String[] {Audio.ArtistColumns.ARTIST};
        int[] display = new int[] { android.R.id.text1 };
        int layout = android.R.layout.simple_list_item_1;
        
        getData(extUri, projection, displayColumns, display, layout);
	}
	
	public void getAlbums() {
        // Grabs content URI for a unique list of Artists on the SDcard
        Uri extUri = Audio.Albums.EXTERNAL_CONTENT_URI;

        // Columns to grab from the DB, then the expected mappings
        String[] projection = new String[] {Audio.Albums._ID, Audio.Albums.ALBUM, Audio.Albums.ARTIST};
        String[] displayColumns = new String[] {Audio.AlbumColumns.ALBUM, Audio.Albums.ARTIST};
        int[] display = new int[] { android.R.id.text1, android.R.id.text2 };
        int layout = android.R.layout.simple_list_item_2;
        
        getData(extUri, projection, displayColumns, display, layout);
	}
	
	public void getSongs() {
        // Grabs content URI for a unique list of Artists on the SDcard
        Uri extUri = Audio.Media.EXTERNAL_CONTENT_URI;

        // Columns to grab from the DB, then the expected mappings
        String[] projection = new String[] {Audio.Artists._ID, Audio.Media.TITLE, Audio.Media.ARTIST};
        String[] displayColumns = new String[] {Audio.Media.TITLE, Audio.Media.ARTIST};
        int[] display = new int[] { android.R.id.text1, android.R.id.text2 };
        int layout = android.R.layout.simple_list_item_2;
        
        getData(extUri, projection, displayColumns, display, layout);
	}
	
	public void getData(Uri datauri, String[] projection, String[] displayColumns, int[] display, int layout) {
		// Flag
		populated = true;
        
        // Activity-managed cursor to get sorted list of artists
        Cursor cur = managedQuery(datauri, projection, null, null, displayColumns[0] + " ASC");
        
        // SimpleCursorAdapter maps the cursor columns to simplelistitems
        SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, layout, cur, displayColumns, display);
        
        // Set adapter of listview to the SimpleCursorAdapter 
        setListAdapter(mAdapter);		
	}
	
	public void populateDataIfReady(int view) {<commit_msg>Better sorting of lists, sorts by: Artist: ARTIST ASC Album: ARTIST ASC, ALBUM ASC Songs: ARTIST ASC, ALBUM ASC<commit_after>package com.uid.DroidDoesMusic.UI;

import com.uid.DroidDoesMusic.R;

import android.app.ListActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore.Audio;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class Library extends ListActivity {
	protected static final String TAG = "DroidDoesMusic";
	public static final int ARTIST_VIEW = 0;
	public static final int ALBUM_VIEW = 1;
	public static final int SONG_VIEW = 2;
	int instanceView;
	boolean populated = false;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, getClass().getSimpleName() + ": onCreate");
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.library);

        // Get extra data from intent
        instanceView = getIntent().getExtras().getInt("view");
        
        // Populate ListView
        populateDataIfReady(instanceView);
    }
	
	@Override
	public void onResume() {
        Log.d(TAG, getClass().getSimpleName() + ": onResume");
		super.onResume();
		
		IntentFilter iff = new IntentFilter();
		iff.addAction(Intent.ACTION_MEDIA_SHARED);
		iff.addAction(Intent.ACTION_MEDIA_MOUNTED);
		iff.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
		iff.addAction(Intent.ACTION_UMS_CONNECTED);
		iff.addAction(Intent.ACTION_UMS_DISCONNECTED);
		registerReceiver(this.externalMediaListener, iff);
		
		populateDataIfReady(instanceView);
	}
	
	@Override
	public void onPause() {
        Log.d(TAG, getClass().getSimpleName() + ": onPause");
		super.onResume();
		
		unregisterReceiver(this.externalMediaListener);
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		Log.d(TAG, getClass().getSimpleName() + ": onListItemClick: (" + id + ")");
		super.onListItemClick(l, v, position, id);
		
		String selection = l.getItemAtPosition(position).toString();
		Toast t = Toast.makeText(this, selection + " (" + id + ")", Toast.LENGTH_LONG);
		t.setGravity(Gravity.CENTER, 0, 0);
		t.show();
	}
	
	public void getArtists() {
        // Grabs content URI for a unique list of Artists on the SDcard
        Uri extUri = Audio.Artists.EXTERNAL_CONTENT_URI;

        // Columns to grab from the DB, then the expected mappings
        String[] projection = new String[] {Audio.Artists._ID, Audio.Artists.ARTIST, Audio.Artists.NUMBER_OF_ALBUMS};
        String[] displayColumns = new String[] {Audio.Artists.ARTIST, Audio.Artists.NUMBER_OF_ALBUMS};
        int[] display = new int[] { android.R.id.text1, android.R.id.text2 };
        
        String sort = Audio.Media.ARTIST + " ASC";
        
        int layout = android.R.layout.simple_list_item_2;
        
        getData(extUri, projection, displayColumns, display, sort, layout);
	}
	
	public void getAlbums() {
        // Grabs content URI for a unique list of Artists on the SDcard
        Uri extUri = Audio.Albums.EXTERNAL_CONTENT_URI;

        // Columns to grab from the DB, then the expected mappings
        String[] projection = new String[] {Audio.Albums._ID, Audio.Albums.ALBUM, Audio.Albums.ARTIST};
        String[] displayColumns = new String[] {Audio.Albums.ALBUM, Audio.Albums.ARTIST};
        int[] display = new int[] { android.R.id.text1, android.R.id.text2 };

        String sort = Audio.Media.ARTIST + " ASC, " + Audio.Albums.ALBUM + " ASC";
        
        int layout = android.R.layout.simple_list_item_2;
        
        getData(extUri, projection, displayColumns, display, sort, layout);
	}
	
	public void getSongs() {
        // Grabs content URI for a unique list of Artists on the SDcard
        Uri extUri = Audio.Media.EXTERNAL_CONTENT_URI;

        // Columns to grab from the DB, then the expected mappings
        String[] projection = new String[] {Audio.Artists._ID, Audio.Media.TITLE, Audio.Media.ARTIST, Audio.Media.ALBUM};
        String[] displayColumns = new String[] {Audio.Media.TITLE, Audio.Media.ARTIST};
        int[] display = new int[] { android.R.id.text1, android.R.id.text2 };

        String sort = Audio.Media.ARTIST + " ASC, " + Audio.Media.ALBUM + " ASC";
        
        int layout = android.R.layout.simple_list_item_2;
        
        getData(extUri, projection, displayColumns, display, sort, layout);
	}
	
	public void getData(Uri datauri, String[] projection, String[] displayColumns, int[] display, String sort, int layout) {
		// Flag
		populated = true;

        // Activity-managed cursor to get sorted list of artists
        Cursor cur = managedQuery(datauri, projection, null, null, sort);
        
        // SimpleCursorAdapter maps the cursor columns to simplelistitems
        SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, layout, cur, displayColumns, display);
        
        // Set adapter of listview to the SimpleCursorAdapter 
        setListAdapter(mAdapter);		
	}
	
	public void populateDataIfReady(int view) {
{'fraction_non_alphanumeric': 0.10961817303044949, 'fraction_numerical': 0.002706621556307395, 'mean_word_length': 3.3988095238095237, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '921975', 'n_tokens_mistral': 3247, 'n_tokens_neox': 3045, 'n_words': 790}