Skip to content

Commit

Permalink
Merge branch 'edge'
Browse files Browse the repository at this point in the history
  • Loading branch information
daneren2005 committed Oct 22, 2016
2 parents 2b973ff + 2b4eb81 commit 61979e9
Show file tree
Hide file tree
Showing 50 changed files with 651 additions and 1,470 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ git submodule init
git submodule update
```

Go to DragSortListView/library and ServerProxy and build project files
Go to ServerProxy and build project files
```
android update project --path ./
```
Expand Down
17 changes: 8 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
compileSdkVersion 24
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'

defaultConfig {
applicationId "github.daneren2005.dsub"
minSdkVersion 14
targetSdkVersion 23
versionCode 187
versionName '5.3.1'
versionCode 190
versionName '5.3.2'
setProperty("archivesBaseName", "DSub $versionName")
resConfigs "de", "es", "fr", "hu", "nl", "pt-rPT", "ru", "sv"
}
Expand Down Expand Up @@ -47,11 +46,11 @@ android {
dependencies {
compile project(':Server Proxy')
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.4.+'
compile 'com.android.support:appcompat-v7:23.4.+'
compile 'com.android.support:mediarouter-v7:23.4.+'
compile 'com.android.support:recyclerview-v7:23.4.+'
compile 'com.android.support:design:23.4.+'
compile 'com.android.support:support-v4:24.2.+'
compile 'com.android.support:appcompat-v7:24.2.+'
compile 'com.android.support:mediarouter-v7:24.2.+'
compile 'com.android.support:recyclerview-v7:24.2.+'
compile 'com.android.support:design:24.2.+'
compile 'com.google.android.gms:play-services-cast:8.1.0'
compile 'com.sothree.slidinguppanel:library:3.0.0'
compile 'de.hdodenhof:circleimageview:1.2.1'
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
<uses-feature android:name="android.hardware.microphone" android:required="false" />
<uses-feature android:name="android.hardware.wifi" android:required="false" />
<uses-feature android:name="android.software.leanback" android:required="false"/>
<uses-feature android:name="android.hardware.location" android:required="false"/>
<uses-feature android:name="android.hardware.location.network" android:required="false"/>

<supports-screens android:anyDensity="true" android:xlargeScreens="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
protected static boolean actionbarColored;
private static final int MENU_GROUP_SERVER = 10;
private static final int MENU_ITEM_SERVER_BASE = 100;
private static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
public static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
public static final int PERMISSIONS_REQUEST_LOCATION = 2;

private final List<Runnable> afterServiceAvailable = new ArrayList<>();
private boolean drawerIdle = true;
Expand Down Expand Up @@ -245,7 +246,7 @@ protected void onResume() {
if (theme != null && !theme.equals(ThemeUtil.getTheme(this)) || fullScreen != prefs.getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false) || actionbarColored != prefs.getBoolean(Constants.PREFERENCES_KEY_COLOR_ACTION_BAR, true)) {
restart();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
DrawableTint.wipeTintCache();
DrawableTint.clearCache();
}

populateTabs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -48,9 +46,6 @@
import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
Expand All @@ -77,6 +72,7 @@
import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.updates.Updater;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.DrawableTint;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.UserUtil;
Expand Down Expand Up @@ -138,6 +134,7 @@ public void onCreate(Bundle savedInstanceState) {
stopService(new Intent(this, DownloadService.class));
finish();
getImageLoader().clearCache();
DrawableTint.clearCache();
} else if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) {
getIntent().putExtra(Constants.INTENT_EXTRA_FRAGMENT_TYPE, "Download");
lastSelectedPosition = R.id.drawer_downloading;
Expand Down Expand Up @@ -402,9 +399,12 @@ public void onNewIntent(Intent intent) {
if(currentFragment instanceof SearchFragment) {
String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY);
boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false);
String artist = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST);
String album = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM);
String title = intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE);

if (query != null) {
((SearchFragment)currentFragment).search(query, autoplay);
((SearchFragment)currentFragment).search(query, autoplay, artist, album, title);
}
getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_QUERY);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ public void onCreate(Bundle savedInstanceState) {
if(!GMS_SEARCH_ACTION.equals(getIntent().getAction())) {
intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
}

String artist = getIntent().getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST);
if(artist != null) {
intent.putExtra(MediaStore.EXTRA_MEDIA_ARTIST, artist);
}

String album = getIntent().getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM);
if(album != null) {
intent.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, album);
}

String title = getIntent().getStringExtra(MediaStore.EXTRA_MEDIA_TITLE);
if(title != null) {
intent.putExtra(MediaStore.EXTRA_MEDIA_TITLE, title);
}

intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, getIntent().getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS));
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Util.startActivityWithoutTransition(VoiceQueryReceiverActivity.this, intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import android.content.Intent;
import android.os.Bundle;
Expand All @@ -26,6 +29,7 @@
import github.daneren2005.dsub.adapter.SectionAdapter;
import github.daneren2005.dsub.domain.Artist;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.MusicDirectory.Entry;
import github.daneren2005.dsub.domain.SearchCritera;
import github.daneren2005.dsub.domain.SearchResult;
import github.daneren2005.dsub.service.MusicService;
Expand Down Expand Up @@ -132,7 +136,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
@Override
public void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<Serializable> updateView, Serializable item) {
onCreateContextMenuSupport(menu, menuInflater, updateView, item);
if(item instanceof MusicDirectory.Entry && !((MusicDirectory.Entry) item).isVideo() && !Util.isOffline(context)) {
if(item instanceof Entry && !((Entry) item).isVideo() && !Util.isOffline(context)) {
menu.removeItem(R.id.song_menu_remove_playlist);
}
recreateContextMenu(menu);
Expand All @@ -152,8 +156,8 @@ public void refresh(boolean refresh) {
public void onItemClicked(UpdateView<Serializable> updateView, Serializable item) {
if (item instanceof Artist) {
onArtistSelected((Artist) item, false);
} else if (item instanceof MusicDirectory.Entry) {
MusicDirectory.Entry entry = (MusicDirectory.Entry) item;
} else if (item instanceof Entry) {
Entry entry = (Entry) item;
if (entry.isDirectory()) {
onAlbumSelected(entry, false);
} else if (entry.isVideo()) {
Expand All @@ -165,12 +169,12 @@ public void onItemClicked(UpdateView<Serializable> updateView, Serializable item
}

@Override
protected List<MusicDirectory.Entry> getSelectedEntries() {
protected List<Entry> getSelectedEntries() {
List<Serializable> selected = adapter.getSelected();
List<MusicDirectory.Entry> selectedMedia = new ArrayList<>();
List<Entry> selectedMedia = new ArrayList<>();
for(Serializable ser: selected) {
if(ser instanceof MusicDirectory.Entry) {
selectedMedia.add((MusicDirectory.Entry) ser);
if(ser instanceof Entry) {
selectedMedia.add((Entry) ser);
}
}

Expand All @@ -182,7 +186,7 @@ protected boolean isShowArtistEnabled() {
return true;
}

public void search(final String query, final boolean autoplay) {
public void search(final String query, final boolean autoplay, final String artist, final String album, final String title) {
if(skipSearch) {
skipSearch = false;
return;
Expand All @@ -202,7 +206,7 @@ protected void done(SearchResult result) {
searchResult = result;
recyclerView.setAdapter(adapter = new SearchAdapter(context, searchResult, getImageLoader(), largeAlbums, SearchFragment.this));
if (autoplay) {
autoplay(query);
autoplay(query, artist, album, title);
}

}
Expand Down Expand Up @@ -232,7 +236,7 @@ private void onArtistSelected(Artist artist, boolean autoplay) {
replaceFragment(fragment);
}

private void onAlbumSelected(MusicDirectory.Entry album, boolean autoplay) {
private void onAlbumSelected(Entry album, boolean autoplay) {
SubsonicFragment fragment = new SelectDirectoryFragment();
Bundle args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_ID, album.getId());
Expand All @@ -245,7 +249,7 @@ private void onAlbumSelected(MusicDirectory.Entry album, boolean autoplay) {
replaceFragment(fragment);
}

private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext) {
private void onSongSelected(Entry song, boolean save, boolean append, boolean autoplay, boolean playNext) {
DownloadService downloadService = getDownloadService();
if (downloadService != null) {
if (!append) {
Expand All @@ -260,14 +264,63 @@ private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean app
}
}

private void onVideoSelected(MusicDirectory.Entry entry) {
private void onVideoSelected(Entry entry) {
int maxBitrate = Util.getMaxVideoBitrate(context);

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoUrl(maxBitrate, context, entry.getId())));
startActivity(intent);
}

private void autoplay(String query, String artistQuery, String albumQuery, String titleQuery) {
Log.i(TAG, "Query: '" + query + "' ( Artist: '" + artistQuery + "', Album: '" + albumQuery + "', Title: '" + titleQuery + "')");

if(titleQuery != null && !searchResult.getSongs().isEmpty()) {
titleQuery = titleQuery.toLowerCase();

TreeMap<Integer, Entry> tree = new TreeMap<>();
for(Entry song: searchResult.getSongs()) {
tree.put(Util.getStringDistance(song.getTitle().toLowerCase(), titleQuery), song);
}

Map.Entry<Integer, Entry> entry = tree.firstEntry();
if(entry.getKey() <= MIN_CLOSENESS) {
onSongSelected(entry.getValue(), false, false, true, false);
} else {
autoplay(query);
}
} else if(albumQuery != null && !searchResult.getAlbums().isEmpty()) {
albumQuery = albumQuery.toLowerCase();

TreeMap<Integer, Entry> tree = new TreeMap<>();
for(Entry album: searchResult.getAlbums()) {
tree.put(Util.getStringDistance(album.getTitle().toLowerCase(), albumQuery), album);
}

Map.Entry<Integer, Entry> entry = tree.firstEntry();
if(entry.getKey() <= MIN_CLOSENESS) {
onAlbumSelected(entry.getValue(), true);
} else {
autoplay(query);
}
} else if(artistQuery != null && !searchResult.getArtists().isEmpty()) {
artistQuery = artistQuery.toLowerCase();

TreeMap<Integer, Artist> tree = new TreeMap<>();
for(Artist artist: searchResult.getArtists()) {
tree.put(Util.getStringDistance(artist.getName().toLowerCase(), artistQuery), artist);
}
Map.Entry<Integer, Artist> entry = tree.firstEntry();
if(entry.getKey() <= MIN_CLOSENESS) {
onArtistSelected(entry.getValue(), true);
} else {
autoplay(query);
}
} else {
autoplay(query);
}
}

private void autoplay(String query) {
query = query.toLowerCase();

Expand All @@ -276,23 +329,23 @@ private void autoplay(String query) {
artist = searchResult.getArtists().get(0);
artist.setCloseness(Util.getStringDistance(artist.getName().toLowerCase(), query));
}
MusicDirectory.Entry album = null;
Entry album = null;
if(!searchResult.getAlbums().isEmpty()) {
album = searchResult.getAlbums().get(0);
album.setCloseness(Util.getStringDistance(album.getTitle().toLowerCase(), query));
}
MusicDirectory.Entry song = null;
Entry song = null;
if(!searchResult.getSongs().isEmpty()) {
song = searchResult.getSongs().get(0);
song.setCloseness(Util.getStringDistance(song.getTitle().toLowerCase(), query));
}

if(artist != null && (artist.getCloseness() <= MIN_CLOSENESS ||
(album == null || artist.getCloseness() <= album.getCloseness()) &&
(song == null || artist.getCloseness() <= song.getCloseness()))) {
(song == null || artist.getCloseness() <= song.getCloseness()))) {
onArtistSelected(artist, true);
} else if(album != null && (album.getCloseness() <= MIN_CLOSENESS ||
song == null || album.getCloseness() <= song.getCloseness())) {
song == null || album.getCloseness() <= song.getCloseness())) {
onAlbumSelected(album, true);
} else if(song != null) {
onSongSelected(song, false, false, true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,12 @@ protected MusicDirectory load(MusicService service) throws Exception {
}
List<Entry> songs = new ArrayList<Entry>();
getSongsRecursively(root, songs);
root.replaceChildren(songs);
return root;

// CachedMusicService is refreshing this data in the background, so will wipe out the songs list from root
MusicDirectory clonedRoot = new MusicDirectory(songs);
clonedRoot.setId(root.getId());
clonedRoot.setName(root.getName());
return clonedRoot;
}

private void getSongsRecursively(MusicDirectory parent, List<Entry> songs) throws Exception {
Expand Down Expand Up @@ -733,7 +737,7 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if(!artist) {
entryGridAdapter.setShowArtist(true);
}
if(topTracks) {
if(topTracks || showAll) {
entryGridAdapter.setShowAlbum(true);
}

Expand Down Expand Up @@ -916,7 +920,7 @@ protected void done(Void result) {
for(Integer index: indexes) {
entryGridAdapter.removeAt(index);
}
Util.toast(context, context.getResources().getString(R.string.removed_playlist, indexes.size(), name));
Util.toast(context, context.getResources().getString(R.string.removed_playlist, String.valueOf(indexes.size()), name));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void getStreamFromPlaylist(InternetRadioStation internetRadioStation) {
connection.disconnect();
}
} catch (Exception e) {
Log.e(TAG, "Failed to get stream data from playlist");
Log.e(TAG, "Failed to get stream data from playlist", e);
}

}
Expand Down
Loading

0 comments on commit 61979e9

Please sign in to comment.