Add drag and drop support to the playlist window

This commit is contained in:
Joshua Bahnsen 2013-12-21 09:58:21 -07:00
parent c22e48c1ef
commit 2a061c0cc1
19 changed files with 131 additions and 21 deletions

3
.gitmodules vendored
View File

@ -5,3 +5,6 @@
[submodule "pulltorefresh"]
path = pulltorefresh
url = git://github.com/chrisbanes/Android-PullToRefresh.git
[submodule "drag-sort-listview"]
path = drag-sort-listview
url = https://github.com/bauerca/drag-sort-listview

View File

@ -2,8 +2,6 @@
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false">
<file url="file://$PROJECT_DIR$/menudrawer" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/menudrawer/library" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/menudrawer/samples" charset="UTF-8" />
</component>
</project>

View File

@ -3,6 +3,7 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Subsonic-Android.iml" filepath="$PROJECT_DIR$/Subsonic-Android.iml" />
<module fileurl="file://$PROJECT_DIR$/drag-sort-listview.iml" filepath="$PROJECT_DIR$/drag-sort-listview.iml" />
<module fileurl="file://$PROJECT_DIR$/menudrawer.iml" filepath="$PROJECT_DIR$/menudrawer.iml" />
<module fileurl="file://$PROJECT_DIR$/pulltorefresh.iml" filepath="$PROJECT_DIR$/pulltorefresh.iml" />
</modules>

View File

@ -23,6 +23,7 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="menudrawer" />
<orderEntry type="module" module-name="pulltorefresh" />
<orderEntry type="module" module-name="drag-sort-listview" />
</component>
</module>

1
drag-sort-listview Submodule

@ -0,0 +1 @@
Subproject commit c3cfccee21676149dfdf8e803c0ec2eaebc6b841

34
drag-sort-listview.iml Normal file
View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android" name="Android">
<configuration>
<option name="GEN_FOLDER_RELATIVE_PATH_APT" value="/drag-sort-listview/library/gen" />
<option name="GEN_FOLDER_RELATIVE_PATH_AIDL" value="/drag-sort-listview/library/gen" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/drag-sort-listview/library/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/drag-sort-listview/library/res" />
<option name="LIBRARY_PROJECT" value="true" />
<option name="UPDATE_PROPERTY_FILES" value="true" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/drag-sort-listview/library">
<sourceFolder url="file://$MODULE_DIR$/drag-sort-listview/library/gen" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/drag-sort-listview/library/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/sdk/extras/android/support/v4/android-support-v4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -3,10 +3,10 @@
<component name="FacetManager">
<facet type="android" name="Android">
<configuration>
<option name="GEN_FOLDER_RELATIVE_PATH_APT" value="/menudrawer/library/gen" />
<option name="GEN_FOLDER_RELATIVE_PATH_AIDL" value="/menudrawer/library/gen" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/menudrawer/library/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/menudrawer/library/res" />
<option name="GEN_FOLDER_RELATIVE_PATH_APT" value="/menudrawer/menudrawer/library/gen" />
<option name="GEN_FOLDER_RELATIVE_PATH_AIDL" value="/menudrawer/menudrawer/library/gen" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/menudrawer/menudrawer/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/menudrawer/menudrawer/res" />
<option name="LIBRARY_PROJECT" value="true" />
<proGuardCfgFiles>
<file>file://D:/Data/Android/adt-bundle-windows/sdk/tools/proguard/proguard-android.txt</file>
@ -16,9 +16,9 @@
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/menudrawer">
<sourceFolder url="file://$MODULE_DIR$/menudrawer/library/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/menudrawer/library/gen" isTestSource="false" generated="true" />
<content url="file://$MODULE_DIR$/menudrawer/menudrawer">
<sourceFolder url="file://$MODULE_DIR$/menudrawer/menudrawer/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/menudrawer/menudrawer/library/gen" isTestSource="false" generated="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

View File

@ -10,7 +10,8 @@
# Project target.
target=android-19
android.library=false
android.library.reference.1=menudrawer
android.library.reference.1=menudrawer/menudrawer
android.library.reference.2=pulltorefresh
android.library.reference.3=drag-sort-listview/library

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

View File

@ -14,12 +14,21 @@
a:layout_height="wrap_content"
a:padding="10dip"/>
<ListView
<com.mobeta.android.dslv.DragSortListView
xmlns:dslv="http://schemas.android.com/apk/res/com.thejoshwa.ultrasonic.androidapp"
a:id="@+id/download_list"
a:layout_width="fill_parent"
a:layout_height="0dip"
a:layout_weight="1"
a:fastScrollEnabled="true"
a:textFilterEnabled="true" />
a:textFilterEnabled="true"
dslv:drag_handle_id="@+id/song_drag"
dslv:remove_enabled="true"
dslv:remove_mode="flingRemove"
dslv:fling_handle_id="@+id/song_drag"
dslv:drag_start_mode="onMove"
dslv:float_background_color="?attr/color_background"
dslv:float_alpha="0.7" />
</LinearLayout>

View File

@ -11,7 +11,7 @@
a:layout_height="fill_parent"
a:checkMark="?attr/button_check_custom"
a:gravity="center_vertical"
a:paddingLeft="1dip" />
a:paddingLeft="3dip" />
<include layout="@layout/song_details" />
@ -25,4 +25,14 @@
a:paddingRight="3dip"
a:src="?attr/star_hollow" />
<ImageView
a:id="@+id/song_drag"
a:layout_width="wrap_content"
a:layout_height="fill_parent"
a:background="@android:color/transparent"
a:focusable="false"
a:gravity="center_vertical"
a:paddingRight="3dip"
a:src="?attr/drag_and_drop" />
</LinearLayout>

View File

@ -18,4 +18,6 @@
<color name="opaque">#B0000000</color>
<color name="translucent">#80000000</color>
<color name="md__defaultBackground">#FF555555</color>
<color name="background_color_dark">#ff000000</color>
<color name="background_color_light">#fff3f3f3</color>
</resources>

View File

@ -88,6 +88,8 @@
<attr name="check_mark_off" format="reference" />
<attr name="check_mark_on" format="reference" />
<attr name="button_check_custom" format="reference" />
<attr name="color_background" format="reference" />
<attr name="drag_and_drop" format="reference" />
</resources>

View File

@ -2,6 +2,7 @@
<resources>
<style name="UltraSonicTheme" parent="@android:style/Theme.Holo">
<item name="color_background">@color/background_color_dark</item>
<item name="star_hollow">@drawable/ic_star_hollow_dark</item>
<item name="star_full">@drawable/ic_star_full_dark</item>
<item name="about">@drawable/ic_menu_about_dark</item>
@ -42,9 +43,11 @@
<item name="chat_send">@drawable/ic_menu_chat_send_dark</item>
<item name="bookmark">@drawable/ic_menu_bookmark_dark</item>
<item name="button_check_custom">@drawable/btn_check_custom_dark</item>
<item name="drag_and_drop">@drawable/ic_action_import_export_dark</item>
</style>
<style name="UltraSonicTheme.Light" parent="@android:style/Theme.Holo.Light">
<item name="color_background">@color/background_color_light</item>
<item name="star_hollow">@drawable/ic_star_hollow_light</item>
<item name="star_full">@drawable/ic_star_full_light</item>
<item name="about">@drawable/ic_menu_about_light</item>
@ -85,6 +88,7 @@
<item name="chat_send">@drawable/ic_menu_chat_send_light</item>
<item name="bookmark">@drawable/ic_menu_bookmark_light</item>
<item name="button_check_custom">@drawable/btn_check_custom_light</item>
<item name="drag_and_drop">@drawable/ic_action_import_export_light</item>
</style>
</resources>

View File

@ -46,11 +46,11 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ViewFlipper;
import com.mobeta.android.dslv.DragSortListView;
import com.thejoshwa.ultrasonic.androidapp.R;
import com.thejoshwa.ultrasonic.androidapp.domain.MusicDirectory;
import com.thejoshwa.ultrasonic.androidapp.domain.MusicDirectory.Entry;
@ -95,7 +95,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
private TextView albumTextView;
private TextView artistTextView;
private ImageView albumArtImageView;
private ListView playlistView;
private DragSortListView playlistView;
private TextView positionTextView;
private TextView downloadTrackTextView;
private TextView downloadTotalDurationTextView;
@ -153,7 +153,7 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
downloadTotalDurationTextView = (TextView) findViewById(R.id.download_total_duration);
durationTextView = (TextView) findViewById(R.id.download_duration);
progressBar = (SeekBar) findViewById(R.id.download_progress_bar);
playlistView = (ListView) findViewById(R.id.download_list);
playlistView = (DragSortListView) findViewById(R.id.download_list);
final AutoRepeatButton previousButton = (AutoRepeatButton) findViewById(R.id.download_previous);
final AutoRepeatButton nextButton = (AutoRepeatButton) findViewById(R.id.download_next);
pauseButton = findViewById(R.id.download_pause);
@ -1174,7 +1174,48 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
final List<DownloadFile> list = downloadService.getSongs();
emptyTextView.setText(R.string.download_empty);
playlistView.setAdapter(new SongListAdapter(this, list));
final SongListAdapter adapter = new SongListAdapter(this, list);
playlistView.setAdapter(adapter);
playlistView.setDragSortListener(new DragSortListView.DragSortListener()
{
@Override
public void drop(int from, int to)
{
if (from != to)
{
DownloadFile item = adapter.getItem(from);
adapter.remove(item);
adapter.insert(item, to);
onDownloadListChanged();
onCurrentChanged();
}
}
@Override
public void drag(int from, int to)
{
}
@Override
public void remove(int which)
{
DownloadFile item = adapter.getItem(which);
DownloadFile currentPlaying = getDownloadService().getCurrentPlaying();
if (currentPlaying == item)
{
getDownloadService().next();
}
adapter.remove(item);
onDownloadListChanged();
onCurrentChanged();
}
});
emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
currentRevision = downloadService.getDownloadListUpdateRevision();

View File

@ -98,7 +98,7 @@ public class EntryAdapter extends ArrayAdapter<Entry>
view = new SongView(activity);
}
view.setSong(entry, checkable);
view.setSong(entry, checkable, false);
return view;
}
}

View File

@ -46,7 +46,7 @@ public class SongListAdapter extends ArrayAdapter<DownloadFile>
view = new SongView(this.context);
}
view.setSong(entry, false);
view.setSong(entry, false, true);
return view;
}
}

View File

@ -61,6 +61,7 @@ public class SongView extends UpdateView implements Checkable
private CheckedTextView checkedTextView;
private ImageView starImageView;
private ImageView songDragImageView;
private TextView titleTextView;
private TextView statusTextView;
private Entry song;
@ -125,7 +126,7 @@ public class SongView extends UpdateView implements Checkable
return this.song;
}
protected void setSong(final Entry song, boolean checkable)
protected void setSong(final Entry song, boolean checkable, boolean dragable)
{
updateBackground();
@ -140,6 +141,7 @@ public class SongView extends UpdateView implements Checkable
checkedTextView = (CheckedTextView) findViewById(R.id.song_check);
starImageView = (ImageView) findViewById(R.id.song_star);
songDragImageView = (ImageView) findViewById(R.id.song_drag);
TextView trackTextView = (TextView) findViewById(R.id.song_track);
titleTextView = (TextView) findViewById(R.id.song_title);
TextView artistTextView = (TextView) findViewById(R.id.song_artist);
@ -204,6 +206,7 @@ public class SongView extends UpdateView implements Checkable
}
checkedTextView.setVisibility(checkable && !song.isVideo() ? View.VISIBLE : View.GONE);
songDragImageView.setVisibility(dragable ? View.VISIBLE : View.GONE);
if (Util.isOffline(this.context))
{