aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-06-10 06:50:54 -0700
committerScott Jackson <daneren2005@gmail.com>2013-06-10 06:50:54 -0700
commite18f29369683f6563164b43c49e9eaa41de3835f (patch)
treeefb9a7f42f8d42bb0c5eb1a7612437eea0aca29b /subsonic-android
parent0017012b94a597e4cf24f7425f2e348562f11137 (diff)
downloaddsub-e18f29369683f6563164b43c49e9eaa41de3835f.tar.gz
dsub-e18f29369683f6563164b43c49e9eaa41de3835f.tar.bz2
dsub-e18f29369683f6563164b43c49e9eaa41de3835f.zip
Moved scrobbling into MainFragment when toggling back to online mode
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java62
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java57
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java1
3 files changed, 62 insertions, 58 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
index bbe3c507..9a0f512a 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -1,10 +1,13 @@
package github.daneren2005.dsub.fragments;
+import android.app.AlertDialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.StatFs;
+import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
@@ -21,6 +24,8 @@ import github.daneren2005.dsub.util.Util;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.MenuInflater;
+import github.daneren2005.dsub.service.MusicService;
+import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.ModalBackgroundTask;
import github.daneren2005.dsub.view.ChangeLog;
import java.io.File;
@@ -29,6 +34,7 @@ import java.util.Arrays;
import java.util.List;
public class MainFragment extends SubsonicFragment {
+ private static final String TAG = MainFragment.class.getSimpleName();
private LayoutInflater inflater;
private static final int MENU_GROUP_SERVER = 10;
@@ -192,8 +198,16 @@ public class MainFragment extends SubsonicFragment {
}
private void toggleOffline() {
- Util.setOffline(context, !Util.isOffline(context));
+ boolean isOffline = Util.isOffline(context);
+ Util.setOffline(context, !isOffline);
context.getPagerAdapter().invalidate();
+
+ if(isOffline) {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ if(musicService.hasOfflineScrobbles()){
+ showOfflineScrobblesDialog();
+ }
+ }
}
private void showAlbumList(String type) {
@@ -211,6 +225,52 @@ public class MainFragment extends SubsonicFragment {
replaceFragment(fragment, R.id.home_layout);
}
}
+
+ private void showOfflineScrobblesDialog() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setIcon(android.R.drawable.ic_dialog_info);
+
+ builder.setTitle(R.string.select_album_offline_scrobbles_dialog_title);
+ builder.setMessage(R.string.select_album_offline_scrobbles_dialog_message);
+
+ //want this on the left and delete on the right hence the backwards button types
+ builder.setNegativeButton(R.string.select_album_offline_scrobbles_dialog_yes,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ new Thread("Scrobble offline") {
+ @Override
+ public void run() {
+ try {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.processOfflineScrobbles(context, null);
+ } catch (Exception x) {
+ Log.i(TAG, "Failed to process offline sc/robbles");
+ }
+ }
+ }.start();
+ }
+ });
+
+ builder.setPositiveButton(R.string.select_album_offline_scrobbles_dialog_delete,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ dialogInterface.dismiss();
+ FileUtil.getOfflineScrobblesFile().delete();
+ }
+ });
+
+ builder.setNeutralButton(R.string.select_album_offline_scrobbles_dialog_no,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialogInterface, int i) {
+ dialogInterface.dismiss();
+ }
+ });
+
+ builder.create().show();
+ }
private void showAboutDialog() {
try {
diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index 971bdd62..82b6c481 100644
--- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -27,7 +27,6 @@ import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.service.OfflineException;
import github.daneren2005.dsub.service.ServerTooOldException;
import github.daneren2005.dsub.util.Constants;
-import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.util.Pair;
import github.daneren2005.dsub.util.TabBackgroundTask;
@@ -273,12 +272,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
} else {
getMusicDirectory(id, name, refresh);
}
-
- //this may be done better elsewhere but it works for now :)
- MusicService musicService = MusicServiceFactory.getMusicService(context);
- if(musicService.hasOfflineScrobbles()){
- showOfflineScrobblesDialog();
- }
}
private void getMusicDirectory(final String id, final String name, final boolean refresh) {
@@ -640,56 +633,6 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
builder.create().show();
}
-
- private void showOfflineScrobblesDialog() {
-
-
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setIcon(android.R.drawable.ic_dialog_info);
-
- builder.setTitle(R.string.select_album_offline_scrobbles_dialog_title);
-
- builder.setMessage(R.string.select_album_offline_scrobbles_dialog_message);
-
- //want this on the left and delete on the right hence the backwards button types
- builder.setNegativeButton(R.string.select_album_offline_scrobbles_dialog_yes,
-
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- new Thread("Scrobble offline") {
- @Override
- public void run() {
- try {
- MusicService musicService = MusicServiceFactory.getMusicService(context);
- musicService.processOfflineScrobbles(context, null);
- } catch (Exception x) {
- Log.i(TAG, "Failed to process offline sc/robbles");
- }
- }
- }.start();
- }
- });
-
- builder.setPositiveButton(R.string.select_album_offline_scrobbles_dialog_delete,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- FileUtil.getOfflineScrobblesFile().delete();
- }
- });
-
- builder.setNeutralButton(R.string.select_album_offline_scrobbles_dialog_no,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- }
- });
-
- builder.create().show();
- }
private View createHeader(List<MusicDirectory.Entry> entries) {
View header = entryList.findViewById(R.id.select_album_header);
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java
index 3efb22dc..85d91b21 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -32,6 +32,7 @@ import java.util.Set;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
+import android.media.MediaMetadataRetriever;
import android.util.Log;
import github.daneren2005.dsub.domain.Artist;
import github.daneren2005.dsub.domain.Genre;