Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Feature: Track title splits #50

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
<activity android:name="com.adam.aslfms.StatusActivity" />
<activity android:name="com.adam.aslfms.StatusInfoNetApp" />
<activity android:name="com.adam.aslfms.ViewScrobbleCacheActivity" />
<activity android:name="com.adam.aslfms.ViewSplitsActivity" />


<!-- the service -->
<service
Expand Down
23 changes: 23 additions & 0 deletions res/layout/split_row.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:drawable/menuitem_background"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="vertical"
android:paddingLeft="6dip"
android:paddingRight="6dip" >

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold" />

</LinearLayout>
22 changes: 22 additions & 0 deletions res/layout/splits_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

<TextView
android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="4dip"
android:gravity="center"
android:text="@string/splits_no_in_db"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold" />

</LinearLayout>
13 changes: 13 additions & 0 deletions res/menu/view_splits.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/menu_splits_add"
android:icon="@android:drawable/ic_menu_add"
android:title="@string/add"/>
<item
android:id="@+id/menu_splits_clear"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:title="@string/clear_creds"/>

</menu>
9 changes: 9 additions & 0 deletions res/menu/view_splits_context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/menu_remove_split"
android:icon="@android:drawable/ic_menu_delete"
android:title="@string/remove"/>

</menu>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
name="also_disable_np_title">Also disable now-playing</string>
<string
name="also_disable_np_summary">[Hmpf]</string>
<string name="add">Add</string>
</resources>
11 changes: 11 additions & 0 deletions res/values/strings_splits.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="splits_title">Title Splits</string>
<string name="splits_summary">List of track title splits</string>
<string name="splits_view_title">Title Splits</string>
<string name="splits_add_title">Add new title split</string>
<string name="splits_add_message">Enter new split text:</string>
<string name="splits_no_in_db">There are no title splits in database.</string>

</resources>
9 changes: 9 additions & 0 deletions res/xml/settings_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
android:targetPackage="com.adam.aslfms"
android:targetClass="com.adam.aslfms.OptionsScreen" />
</PreferenceScreen>

<PreferenceScreen
android:title="@string/splits_title"
android:summary="@string/splits_summary">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="com.adam.aslfms"
android:targetClass="com.adam.aslfms.ViewSplitsActivity" />
</PreferenceScreen>

<PreferenceCategory
android:title="@string/scrobble_cache_title" />
Expand Down
46 changes: 46 additions & 0 deletions src/com/adam/aslfms/SplitAddDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.adam.aslfms;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.database.Cursor;
import android.widget.EditText;

import com.adam.aslfms.util.SplitsDatabase;

public class SplitAddDialog {
@SuppressWarnings("unused")
private static final String TAG = "SplitAddDialog";

private final Context mCtx;
private final SplitsDatabase mDb;
private final Cursor mParentCursor;

public SplitAddDialog(Context context, SplitsDatabase db, Cursor cursor) {
this.mCtx = context;
this.mDb = db;
this.mParentCursor = cursor;
}

public void show() {
AlertDialog.Builder alert = new AlertDialog.Builder(mCtx);

alert.setTitle(R.string.splits_add_title);
alert.setMessage(R.string.splits_add_message);

final EditText input = new EditText(mCtx);

alert.setView(input);
alert.setNegativeButton(R.string.add, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mDb.insertTitleSplit(input.getText().toString());
mParentCursor.requery();
}
});

alert.setPositiveButton(R.string.close, null);
alert.show();
}
}
3 changes: 0 additions & 3 deletions src/com/adam/aslfms/StatusInfoNetApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@
import android.app.ListActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
Expand Down
126 changes: 126 additions & 0 deletions src/com/adam/aslfms/ViewSplitsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.adam.aslfms;

import com.adam.aslfms.util.SplitsDatabase;

import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.CursorAdapter;
import android.widget.TextView;
import android.widget.AdapterView.AdapterContextMenuInfo;

public class ViewSplitsActivity extends ListActivity {
@SuppressWarnings("unused")
private static final String TAG = "SplitsActivity";

private SplitsDatabase mDb;

private Cursor mSplitsCursor = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setTitle(getString(R.string.splits_view_title));
setContentView(R.layout.splits_list);

mDb = new SplitsDatabase(this);
mDb.open();

fillData();
registerForContextMenu(getListView());
}

@Override
protected void onDestroy() {
super.onDestroy();
mDb.close();
}

@Override
protected void onResume() {
super.onResume();

if (mSplitsCursor != null)
mSplitsCursor.requery();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.view_splits, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_splits_add:
new SplitAddDialog(this, mDb, mSplitsCursor).show();
mSplitsCursor.requery();
return true;
case R.id.menu_splits_clear:
mDb.clearAllSplits();
mSplitsCursor.requery();
return true;
}
return super.onOptionsItemSelected(item);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
if (info.id < 0)
return;

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.view_splits_context, menu);
}

@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.menu_remove_split:
mDb.removeSplit(info.id);
mSplitsCursor.requery();
return true;
}
return super.onContextItemSelected(item);
}

private void fillData() {
mSplitsCursor = mDb.fetchAllSplitsCursor();

startManagingCursor(mSplitsCursor);
CursorAdapter adapter = new MyAdapter(this, mSplitsCursor);
setListAdapter(adapter);
}

private class MyAdapter extends CursorAdapter {
public MyAdapter(Context context, Cursor c) {
super(context, c);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
String name = cursor.getString(cursor.getColumnIndex("split"));
TextView nameView = (TextView) view.findViewById(R.id.name);
nameView.setText(name);
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.split_row, parent, false);
}
}
}
2 changes: 1 addition & 1 deletion src/com/adam/aslfms/receiver/BuiltInMusicAppReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void parseIntent(Context ctx, String action, Bundle bundle)
MusicAPI musicAPI = getMusicAPI(ctx, bundle);
setMusicAPI(musicAPI);

Track.Builder b = new Track.Builder();
Track.Builder b = new Track.Builder(ctx);
b.setMusicAPI(musicAPI);
b.setWhen(Util.currentTimeSecsUTC());

Expand Down
2 changes: 1 addition & 1 deletion src/com/adam/aslfms/receiver/LastFmAPIReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void parseIntent(Context ctx, String action, Bundle bundle) throws Ill

if (action.equals(ACTION_LASTFMAPI_START)) {
setState(Track.State.START);
Track.Builder b = new Track.Builder();
Track.Builder b = new Track.Builder(ctx);
b.setMusicAPI(musicAPI);
b.setWhen(Util.currentTimeSecsUTC());

Expand Down
2 changes: 1 addition & 1 deletion src/com/adam/aslfms/receiver/RdioMusicReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ else if (isPaused)
else
setState(Track.State.COMPLETE);

Track.Builder b = new Track.Builder();
Track.Builder b = new Track.Builder(ctx);

b.setMusicAPI(musicAPI);
b.setWhen(Util.currentTimeSecsUTC());
Expand Down
2 changes: 1 addition & 1 deletion src/com/adam/aslfms/receiver/SLSAPIReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ else if (state == STATE_COMPLETE)
else
throw new IllegalArgumentException("bad state: " + state);

Track.Builder b = new Track.Builder();
Track.Builder b = new Track.Builder(ctx);
b.setMusicAPI(musicAPI);
b.setWhen(Util.currentTimeSecsUTC());
// artist name, required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected void parseIntent(Context ctx, String action, Bundle bundle)
}
int msid = bundle.getInt("id", -1);

Track.Builder b = new Track.Builder();
Track.Builder b = new Track.Builder(ctx);
b.setMusicAPI(musicAPI);
b.setWhen(Util.currentTimeSecsUTC());

Expand Down
2 changes: 1 addition & 1 deletion src/com/adam/aslfms/util/ScrobblesDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public boolean cleanUpTracks() {
}

private Track readTrack(Cursor c) {
Track.Builder b = new Track.Builder();
Track.Builder b = new Track.Builder(mCtx);
b.setMusicAPI(MusicAPI.fromDatabase(mCtx, c.getLong(c
.getColumnIndex("musicapp"))));
b.setArtist(c.getString(c.getColumnIndex("artist")));
Expand Down
Loading