aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-02-17 17:28:47 -0800
committerScott Jackson <daneren2005@gmail.com>2016-02-17 17:28:47 -0800
commitb347afd7ba73219852d59c4f43d363f24449d8cd (patch)
tree5f6feb5577bdf4ae83429a5e667d309d99a5febe /app
parent7e16b7b7ebc8e5e00e11eaa862527903ccc1f58a (diff)
parentd5900f8e94e9111699ddaab717a2b3ad5c664003 (diff)
downloaddsub-b347afd7ba73219852d59c4f43d363f24449d8cd.tar.gz
dsub-b347afd7ba73219852d59c4f43d363f24449d8cd.tar.bz2
dsub-b347afd7ba73219852d59c4f43d363f24449d8cd.zip
Merge branch 'switch-network'
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java12
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/User.java4
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java5
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java3
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java4
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java3
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java78
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/UpdateHelper.java1
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/SettingView.java2
-rw-r--r--app/src/main/res/values/strings.xml1
11 files changed, 76 insertions, 39 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
index 3bcd0864..487ad83c 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java
@@ -200,11 +200,13 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo
@Override
public void onPanelCollapsed(View panel) {
isPanelClosing = false;
- bottomBar.setVisibility(View.VISIBLE);
- nowPlayingToolbar.setVisibility(View.GONE);
- nowPlayingFragment.setPrimaryFragment(false);
- setSupportActionBar(mainToolbar);
- recreateSpinner();
+ if(bottomBar.getVisibility() == View.GONE) {
+ bottomBar.setVisibility(View.VISIBLE);
+ nowPlayingToolbar.setVisibility(View.GONE);
+ nowPlayingFragment.setPrimaryFragment(false);
+ setSupportActionBar(mainToolbar);
+ recreateSpinner();
+ }
}
@Override
diff --git a/app/src/main/java/github/daneren2005/dsub/domain/User.java b/app/src/main/java/github/daneren2005/dsub/domain/User.java
index b5ee6188..5307828a 100644
--- a/app/src/main/java/github/daneren2005/dsub/domain/User.java
+++ b/app/src/main/java/github/daneren2005/dsub/domain/User.java
@@ -33,8 +33,9 @@ public class User implements Serializable {
public static final String STREAM = "streamRole";
public static final String JUKEBOX = "jukeboxRole";
public static final String SHARE = "shareRole";
+ public static final String VIDEO_CONVERSION = "videoConversionRole";
public static final String LASTFM = "lastFMRole";
- public static final List<String> ROLES = new ArrayList<String>();
+ public static final List<String> ROLES = new ArrayList<>();
static {
ROLES.add(ADMIN);
@@ -47,6 +48,7 @@ public class User implements Serializable {
ROLES.add(PODCAST);
ROLES.add(JUKEBOX);
ROLES.add(SHARE);
+ ROLES.add(VIDEO_CONVERSION);
}
private String username;
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java
index 7044410b..21fe3fd5 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadFile.java
@@ -529,8 +529,9 @@ public class DownloadFile implements BufferFile {
}
// Only run these if not interrupted, ie: cancelled
- if(!isCancelled()) {
- new CacheCleaner(context, DownloadService.getInstance()).cleanSpace();
+ DownloadService downloadService = DownloadService.getInstance();
+ if(downloadService != null && !isCancelled()) {
+ new CacheCleaner(context, downloadService).cleanSpace();
checkDownloads();
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java b/app/src/main/java/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java
index 8da83be1..bcb7b92f 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/sync/MostRecentSyncAdapter.java
@@ -49,7 +49,7 @@ public class MostRecentSyncAdapter extends SubsonicSyncAdapter {
}
@Override
- public void onExecuteSync(Context context, int instance) {
+ public void onExecuteSync(Context context, int instance) throws NetworkNotValidException {
try {
ArrayList<String> syncedList = SyncUtil.getSyncedMostRecent(context, instance);
MusicDirectory albumList = musicService.getAlbumList("newest", 20, 0, tagBrowsing, context, null);
diff --git a/app/src/main/java/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java b/app/src/main/java/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java
index 6c017472..cb3c3877 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/sync/PlaylistSyncAdapter.java
@@ -56,7 +56,7 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter {
}
@Override
- public void onExecuteSync(Context context, int instance) {
+ public void onExecuteSync(Context context, int instance) throws NetworkNotValidException {
String serverName = Util.getServerName(context, instance);
List<Playlist> remainder = null;
@@ -95,6 +95,7 @@ public class PlaylistSyncAdapter extends SubsonicSyncAdapter {
DownloadFile file = new DownloadFile(context, entry, true);
String path = file.getCompleteFile().getPath();
while(!file.isSaved() && !file.isFailedMax()) {
+ throwIfNetworkInvalid();
file.downloadNow(musicService);
if(file.isSaved() && !updated.contains(playlist.getName())) {
updated.add(playlist.getName());
diff --git a/app/src/main/java/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java b/app/src/main/java/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java
index ce8e7a91..7afcad25 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/sync/PodcastSyncAdapter.java
@@ -23,7 +23,6 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.util.Log;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
@@ -54,7 +53,7 @@ public class PodcastSyncAdapter extends SubsonicSyncAdapter {
}
@Override
- public void onExecuteSync(Context context, int instance) {
+ public void onExecuteSync(Context context, int instance) throws NetworkNotValidException {
ArrayList<SyncSet> podcastList = SyncUtil.getSyncedPodcasts(context, instance);
try {
@@ -81,6 +80,7 @@ public class PodcastSyncAdapter extends SubsonicSyncAdapter {
if(entry.getId() != null && "completed".equals(((PodcastEpisode)entry).getStatus()) && !existingEpisodes.contains(entry.getId())) {
DownloadFile file = new DownloadFile(context, entry, false);
while(!file.isCompleteFileAvailable() && !file.isFailedMax()) {
+ throwIfNetworkInvalid();
file.downloadNow(musicService);
}
// Only add if actualy downloaded correctly
diff --git a/app/src/main/java/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java b/app/src/main/java/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java
index cf985227..0af8886b 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/sync/StarredSyncAdapter.java
@@ -20,7 +20,6 @@
package github.daneren2005.dsub.service.sync;
import android.annotation.TargetApi;
-import android.app.Notification;
import android.content.Context;
import android.util.Log;
@@ -50,7 +49,7 @@ public class StarredSyncAdapter extends SubsonicSyncAdapter {
}
@Override
- public void onExecuteSync(Context context, int instance) {
+ public void onExecuteSync(Context context, int instance) throws NetworkNotValidException {
try {
ArrayList<String> syncedList = new ArrayList<String>();
MusicDirectory starredList = musicService.getStarredList(context, null);
diff --git a/app/src/main/java/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java b/app/src/main/java/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java
index 661f126d..4879d032 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/sync/SubsonicSyncAdapter.java
@@ -65,39 +65,54 @@ public class SubsonicSyncAdapter extends AbstractThreadedSyncAdapter {
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
- ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- NetworkInfo networkInfo = manager.getActiveNetworkInfo();
-
- // Don't try to sync if no network!
- if(networkInfo == null || !networkInfo.isConnected() || Util.isOffline(context)) {
- Log.w(TAG, "Not running sync, not connected to network");
+ String invalidMessage = isNetworkValid();
+ if(invalidMessage != null) {
+ Log.w(TAG, "Not running sync: " + invalidMessage);
return;
}
-
+
// Make sure battery > x% or is charging
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, intentFilter);
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
- if(status != BatteryManager.BATTERY_STATUS_CHARGING && status != BatteryManager.BATTERY_STATUS_FULL) {
+ if (status != BatteryManager.BATTERY_STATUS_CHARGING && status != BatteryManager.BATTERY_STATUS_FULL) {
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
-
- if((level / (float)scale) < 0.15) {
+
+ if ((level / (float) scale) < 0.15) {
Log.w(TAG, "Not running sync, battery too low");
return;
}
}
+ executeSync(context);
+ }
+
+ private String isNetworkValid() {
+ ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo = manager.getActiveNetworkInfo();
+
+ // Don't try to sync if no network!
+ if(networkInfo == null || !networkInfo.isConnected() || Util.isOffline(context)) {
+ return "Not connected to any network";
+ }
+
// Check if user wants to only sync on wifi
SharedPreferences prefs = Util.getPreferences(context);
if(prefs.getBoolean(Constants.PREFERENCES_KEY_SYNC_WIFI, true)) {
if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
- executeSync(context);
+ return null;
} else {
- Log.w(TAG, "Not running sync, not connected to wifi");
+ return "Not connected to WIFI";
}
} else {
- executeSync(context);
+ return null;
+ }
+ }
+ protected void throwIfNetworkInvalid() throws NetworkNotValidException {
+ String invalidMessage = isNetworkValid();
+ if(invalidMessage != null) {
+ throw new NetworkNotValidException(invalidMessage);
}
}
@@ -106,32 +121,39 @@ public class SubsonicSyncAdapter extends AbstractThreadedSyncAdapter {
Log.i(TAG, "Running sync for " + className);
long start = System.currentTimeMillis();
int servers = Util.getServerCount(context);
- for(int i = 1; i <= servers; i++) {
- try {
- if(isValidServer(context, i) && Util.isSyncEnabled(context, i)) {
- tagBrowsing = Util.isTagBrowsing(context, i);
- musicService.setInstance(i);
- onExecuteSync(context, i);
- } else {
- Log.i(TAG, "Skipped sync for " + i);
+ try {
+ for (int i = 1; i <= servers; i++) {
+ try {
+ throwIfNetworkInvalid();
+
+ if (isValidServer(context, i) && Util.isSyncEnabled(context, i)) {
+ tagBrowsing = Util.isTagBrowsing(context, i);
+ musicService.setInstance(i);
+ onExecuteSync(context, i);
+ } else {
+ Log.i(TAG, "Skipped sync for " + i);
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Failed sync for " + className + "(" + i + ")", e);
}
- } catch(Exception e) {
- Log.e(TAG, "Failed sync for " + className + "(" + i + ")", e);
}
+ } catch (NetworkNotValidException e) {
+ Log.e(TAG, "Stopped sync due to network loss", e);
}
Log.i(TAG, className + " executed in " + (System.currentTimeMillis() - start) + " ms");
}
- public void onExecuteSync(Context context, int instance) {
+ public void onExecuteSync(Context context, int instance) throws NetworkNotValidException {
}
- protected boolean downloadRecursively(List<String> paths, MusicDirectory parent, Context context, boolean save) throws Exception {
+ protected boolean downloadRecursively(List<String> paths, MusicDirectory parent, Context context, boolean save) throws Exception,NetworkNotValidException {
boolean downloaded = false;
for (MusicDirectory.Entry song: parent.getChildren(false, true)) {
if (!song.isVideo()) {
DownloadFile file = new DownloadFile(context, song, save);
while(!(save && file.isSaved() || !save && file.isCompleteFileAvailable()) && !file.isFailedMax()) {
+ throwIfNetworkInvalid();
file.downloadNow(musicService);
if(!file.isFailed()) {
downloaded = true;
@@ -171,4 +193,10 @@ public class SubsonicSyncAdapter extends AbstractThreadedSyncAdapter {
String url = Util.getRestUrl(context, "null", instance, false);
return !(url.contains("demo.subsonic.org") || url.contains("yourhost"));
}
+
+ public class NetworkNotValidException extends Throwable {
+ public NetworkNotValidException(String reason) {
+ super("Not running sync: " + reason);
+ }
+ }
}
diff --git a/app/src/main/java/github/daneren2005/dsub/util/UpdateHelper.java b/app/src/main/java/github/daneren2005/dsub/util/UpdateHelper.java
index 79d3cf30..4cf25b30 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/UpdateHelper.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/UpdateHelper.java
@@ -248,6 +248,7 @@ public final class UpdateHelper {
msg = context.getResources().getString(rating > 0 ? R.string.rating_set_rating_failed : R.string.rating_remove_rating_failed, entry.getTitle()) + " " + getErrorMessage(error);
}
+ Log.e(TAG, "Failed to setRating", error);
Util.toast(context, msg, false);
}
}.execute();
diff --git a/app/src/main/java/github/daneren2005/dsub/view/SettingView.java b/app/src/main/java/github/daneren2005/dsub/view/SettingView.java
index efd8bc83..6dc116f8 100644
--- a/app/src/main/java/github/daneren2005/dsub/view/SettingView.java
+++ b/app/src/main/java/github/daneren2005/dsub/view/SettingView.java
@@ -81,6 +81,8 @@ public class SettingView extends UpdateView2<Setting, Boolean> {
res = R.string.admin_role_jukebox;
} else if(User.SHARE.equals(name)) {
res = R.string.admin_role_share;
+ } else if(User.VIDEO_CONVERSION.equals(name)) {
+ res = R.string.admin_role_video_conversion;
} else if(User.LASTFM.equals(name)) {
res = R.string.admin_role_lastfm;
} else {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e783d641..545cc153 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -548,6 +548,7 @@
<string name="admin.role.stream">Stream music</string>
<string name="admin.role.jukebox">Control jukebox</string>
<string name="admin.role.share">Manage shares</string>
+ <string name="admin.role.video_conversion">Convert videos</string>
<string name="admin.role.lastfm">Use Last.FM feature</string>
<string name="music_service.retry">A network error occurred. Retrying %1$d of %2$d.</string>