From a31c08a45adc84e9b6b7954f91eaa3d049964c45 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 3 Mar 2013 21:26:52 -0800 Subject: Start converting activities to fragments --- .../daneren2005/dsub/activity/MusicActivity.java | 146 ++++++++++++++++ .../dsub/activity/SubsonicActivity.java | 194 +++++++++++++++++++++ .../daneren2005/dsub/fragments/MainFragment.java | 124 +++++++++++++ .../dsub/fragments/SubsonicTabFragment.java | 95 ++++++++++ 4 files changed, 559 insertions(+) create mode 100644 subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java create mode 100644 subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java create mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java create mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java new file mode 100644 index 00000000..36d3f068 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java @@ -0,0 +1,146 @@ +package github.daneren2005.dsub.activity; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.fragments.MainFragment; +import github.daneren2005.dsub.fragments.SubsonicTabFragment; +import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.Util; + +public class MusicActivity extends SubsonicActivity { + private static final String TAG = MusicActivity.class.getSimpleName(); + private static boolean infoDialogDisplayed; + private MainActivityPagerAdapter pagerAdapter; + private ViewPager viewPager; + private SubsonicTabFragment prevPageFragment; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { + exit(); + } + setContentView(R.layout.music); + + pagerAdapter = new MainActivityPagerAdapter(getSupportFragmentManager()); + viewPager = (ViewPager) findViewById(R.id.pager); + viewPager.setAdapter(pagerAdapter); + viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + notifyFragmentOnPageSelected(position); + } + }); + + if (savedInstanceState == null) { + int position = Util.isOffline(this) ? 0 : 2; + if (position == viewPager.getCurrentItem()) { + notifyFragmentOnPageSelected(position); + } else { + viewPager.setCurrentItem(position); + } + } + + handleIntentAction(getIntent()); + } + + @Override + protected void onPostCreate(Bundle bundle) { + super.onPostCreate(bundle); + + getSupportActionBar().setDisplayHomeAsUpEnabled(false); + getSupportActionBar().setHomeButtonEnabled(false); + + showInfoDialog(); + } + + @Override + public void onResume() { + super.onResume(); + } + + @Override + protected void onNewIntent(Intent intent) { + handleIntentAction(intent); + // mPagerAdapter.notifyDataSetChanged(); + } + + private void handleIntentAction(Intent intent) { + if (intent.hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { + exit(); + } + } + + private void exit() { + stopService(new Intent(this, DownloadServiceImpl.class)); + finish(); + } + + private void showInfoDialog() { + if (!infoDialogDisplayed) { + infoDialogDisplayed = true; + if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) { + Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text); + } + } + } + + private void notifyFragmentOnPageSelected(int position) { + /*if (prevPageFragment != null) { + prevPageFragment.onPageDeselected(); + } + prevPageFragment = (SubsonicTabFragment) pagerAdapter.instantiateItem(viewPager, position); + prevPageFragment.onPageSelected();*/ + } + + public class MainActivityPagerAdapter extends FragmentPagerAdapter { + + private final String [] titles = new String [] { + "Home", + "Library" + }; + + public MainActivityPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int i) { + Fragment fragment; + Bundle args = new Bundle(); + switch(i) { + case 0: + fragment = new MainFragment(); + break; + + case 1: + fragment = new MainFragment(); + break; + default: + fragment = null; + } + + if (fragment != null) { + fragment.setArguments(args); + } + + return fragment; + } + + @Override + public int getCount() { + return 2; + } + + @Override + public CharSequence getPageTitle(int position) { + return titles[position]; + } + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java new file mode 100644 index 00000000..55ac514f --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -0,0 +1,194 @@ +package github.daneren2005.dsub.activity; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageInfo; +import android.media.AudioManager; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.util.Log; +import android.view.KeyEvent; +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.SherlockFragmentActivity; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.Window; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.updates.Updater; +import github.daneren2005.dsub.util.ImageLoader; +import github.daneren2005.dsub.util.Util; +import java.io.File; +import java.io.PrintWriter; + +public class SubsonicActivity extends SherlockFragmentActivity { + private static final String TAG = SubsonicActivity.class.getSimpleName(); + private static ImageLoader IMAGE_LOADER; + protected static String theme; + private boolean destroyed = false; + + @Override + protected void onCreate(Bundle bundle) { + setUncaughtExceptionHandler(); + applyTheme(); + super.onCreate(bundle); + startService(new Intent(this, DownloadServiceImpl.class)); + setVolumeControlStream(AudioManager.STREAM_MUSIC); + } + + @Override + protected void onResume() { + super.onResume(); + Util.registerMediaButtonEventReceiver(this); + + // Make sure to update theme + if (theme != null && !theme.equals(Util.getTheme(this))) { + restart(); + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + destroyed = true; + getImageLoader().clear(); + } + + @Override + public void finish() { + super.finish(); + Util.disablePendingTransition(this); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + boolean isVolumeDown = keyCode == KeyEvent.KEYCODE_VOLUME_DOWN; + boolean isVolumeUp = keyCode == KeyEvent.KEYCODE_VOLUME_UP; + boolean isVolumeAdjust = isVolumeDown || isVolumeUp; + boolean isJukebox = getDownloadService() != null && getDownloadService().isJukeboxEnabled(); + + if (isVolumeAdjust && isJukebox) { + getDownloadService().adjustJukeboxVolume(isVolumeUp); + return true; + } + return super.onKeyDown(keyCode, event); + } + + protected void restart() { + Intent intent = new Intent(this, this.getClass()); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtras(getIntent()); + Util.startActivityWithoutTransition(this, intent); + } + + private void applyTheme() { + theme = Util.getTheme(this); + if ("dark".equals(theme)) { + setTheme(R.style.Theme_DSub_Dark); + } else if ("light".equals(theme)) { + setTheme(R.style.Theme_DSub_Light); + } else if ("dark_fullscreen".equals(theme)) { + setTheme(R.style.Theme_DSub_Dark_Fullscreen); + } else if ("light_fullscreen".equals(theme)) { + setTheme(R.style.Theme_DSub_Light_Fullscreen); + } else if("holo".equals(theme)) { + setTheme(R.style.Theme_DSub_Holo); + } else if("holo_fullscreen".equals(theme)) { + setTheme(R.style.Theme_DSub_Holo_Fullscreen); + }else { + setTheme(R.style.Theme_DSub_Holo); + } + } + + public boolean isDestroyed() { + return destroyed; + } + + protected synchronized ImageLoader getImageLoader() { + if (IMAGE_LOADER == null) { + IMAGE_LOADER = new ImageLoader(this); + } + return IMAGE_LOADER; + } + public synchronized static ImageLoader getStaticImageLoader(Context context) { + if (IMAGE_LOADER == null) { + IMAGE_LOADER = new ImageLoader(context); + } + return IMAGE_LOADER; + } + + public DownloadService getDownloadService() { + // If service is not available, request it to start and wait for it. + for (int i = 0; i < 5; i++) { + DownloadService downloadService = DownloadServiceImpl.getInstance(); + if (downloadService != null) { + return downloadService; + } + Log.w(TAG, "DownloadService not running. Attempting to start it."); + startService(new Intent(this, DownloadServiceImpl.class)); + Util.sleepQuietly(50L); + } + return DownloadServiceImpl.getInstance(); + } + + private void setUncaughtExceptionHandler() { + Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); + if (!(handler instanceof SubsonicActivity.SubsonicUncaughtExceptionHandler)) { + Thread.setDefaultUncaughtExceptionHandler(new SubsonicActivity.SubsonicUncaughtExceptionHandler(this)); + } + } + + /** + * Logs the stack trace of uncaught exceptions to a file on the SD card. + */ + private static class SubsonicUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { + + private final Thread.UncaughtExceptionHandler defaultHandler; + private final Context context; + + private SubsonicUncaughtExceptionHandler(Context context) { + this.context = context; + defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); + } + + @Override + public void uncaughtException(Thread thread, Throwable throwable) { + File file = null; + PrintWriter printWriter = null; + try { + + PackageInfo packageInfo = context.getPackageManager().getPackageInfo("github.daneren2005.dsub", 0); + file = new File(Environment.getExternalStorageDirectory(), "subsonic-stacktrace.txt"); + printWriter = new PrintWriter(file); + printWriter.println("Android API level: " + Build.VERSION.SDK); + printWriter.println("Subsonic version name: " + packageInfo.versionName); + printWriter.println("Subsonic version code: " + packageInfo.versionCode); + printWriter.println(); + throwable.printStackTrace(printWriter); + Log.i(TAG, "Stack trace written to " + file); + } catch (Throwable x) { + Log.e(TAG, "Failed to write stack trace to " + file, x); + } finally { + Util.close(printWriter); + if (defaultHandler != null) { + defaultHandler.uncaughtException(thread, throwable); + } + + } + } + } + + public void checkUpdates() { + try { + String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; + int ver = Integer.parseInt(version.replace(".", "")); + Updater updater = new Updater(ver); + updater.checkUpdates(SubsonicActivity.this); + } + catch(Exception e) { + + } + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java new file mode 100644 index 00000000..cdde2e77 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -0,0 +1,124 @@ +package github.daneren2005.dsub.fragments; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.TextView; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.FileUtil; +import github.daneren2005.dsub.util.MergeAdapter; +import github.daneren2005.dsub.util.Util; +import java.util.Arrays; + +public class MainFragment extends SubsonicTabFragment { + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + View view = inflater.inflate(R.layout.main, container, false); + + loadSettings(); + + View buttons = inflater.inflate(R.layout.main_buttons, null); + + final View serverButton = buttons.findViewById(R.id.main_select_server); + final TextView serverTextView = (TextView) serverButton.findViewById(R.id.main_select_server_2); + final TextView offlineButton = (TextView) buttons.findViewById(R.id.main_offline); + offlineButton.setText(Util.isOffline(context) ? R.string.main_online : R.string.main_offline); + + final View albumsTitle = buttons.findViewById(R.id.main_albums); + final View albumsNewestButton = buttons.findViewById(R.id.main_albums_newest); + final View albumsRandomButton = buttons.findViewById(R.id.main_albums_random); + final View albumsHighestButton = buttons.findViewById(R.id.main_albums_highest); + final View albumsRecentButton = buttons.findViewById(R.id.main_albums_recent); + final View albumsFrequentButton = buttons.findViewById(R.id.main_albums_frequent); + final View albumsStarredButton = buttons.findViewById(R.id.main_albums_starred); + + final View dummyView = view.findViewById(R.id.main_dummy); + + int instance = Util.getActiveServer(context); + String name = Util.getServerName(context, instance); + serverTextView.setText(name); + + ListView list = (ListView) view.findViewById(R.id.main_list); + + MergeAdapter adapter = new MergeAdapter(); + if (!Util.isOffline(context)) { + adapter.addViews(Arrays.asList(serverButton), true); + } + adapter.addView(offlineButton, true); + if (!Util.isOffline(context)) { + adapter.addView(albumsTitle, false); + adapter.addViews(Arrays.asList(albumsNewestButton, albumsRandomButton, albumsHighestButton, albumsStarredButton, albumsRecentButton, albumsFrequentButton), true); + } + list.setAdapter(adapter); + registerForContextMenu(dummyView); + + list.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (view == serverButton) { + dummyView.showContextMenu(); + } else if (view == offlineButton) { + toggleOffline(); + } else if (view == albumsNewestButton) { + // showAlbumList("newest"); + } else if (view == albumsRandomButton) { + // showAlbumList("random"); + } else if (view == albumsHighestButton) { + // showAlbumList("highest"); + } else if (view == albumsRecentButton) { + // showAlbumList("recent"); + } else if (view == albumsFrequentButton) { + // showAlbumList("frequent"); + } else if (view == albumsStarredButton) { + // showAlbumList("starred"); + } + } + }); + + return view; + } + + @Override + public void onResume() { + super.onResume(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + private void loadSettings() { + PreferenceManager.setDefaultValues(context, R.xml.settings, false); + SharedPreferences prefs = Util.getPreferences(context); + if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION)) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory().getPath()); + editor.commit(); + } + + if (!prefs.contains(Constants.PREFERENCES_KEY_OFFLINE)) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean(Constants.PREFERENCES_KEY_OFFLINE, false); + editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); + editor.commit(); + } + } + + private void toggleOffline() { + Util.setOffline(this, !Util.isOffline(context)); + restart(); + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java new file mode 100644 index 00000000..df98c710 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -0,0 +1,95 @@ +/* + This file is part of Subsonic. + + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + + Copyright 2009 (C) Sindre Mehus + */ +package github.daneren2005.dsub.fragments; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageInfo; +import android.media.AudioManager; +import android.media.MediaMetadataRetriever; +import android.os.Build; +import android.os.Bundle; +import android.os.Environment; +import android.util.Log; +import android.view.KeyEvent; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; +import com.actionbarsherlock.app.SherlockFragment; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.activity.DownloadActivity; +import github.daneren2005.dsub.activity.SubsonicTabActivity; +import github.daneren2005.dsub.domain.Artist; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.Playlist; +import github.daneren2005.dsub.service.DownloadFile; +import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.service.OfflineException; +import github.daneren2005.dsub.service.ServerTooOldException; +import github.daneren2005.dsub.updates.Updater; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.FileUtil; +import github.daneren2005.dsub.util.ImageLoader; +import github.daneren2005.dsub.util.LoadingTask; +import github.daneren2005.dsub.util.ModalBackgroundTask; +import github.daneren2005.dsub.util.SilentBackgroundTask; +import github.daneren2005.dsub.util.Util; +import java.io.File; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class SubsonicTabFragment extends SherlockFragment { + private static final String TAG = SubsonicTabActivity.class.getSimpleName(); + private static ImageLoader IMAGE_LOADER; + protected Context context; + + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + } + + @Override + public void onResume() { + super.onResume(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + context = activity; + } + + protected void restart() { + + } +} -- cgit v1.2.3 From 4848668247161273b64ec69a90bbd594e68ecb5c Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 4 Mar 2013 21:52:26 -0800 Subject: Get working refresh on MainFragment --- .../daneren2005/dsub/fragments/MainFragment.java | 48 ++++++++++++++-------- .../dsub/fragments/SubsonicTabFragment.java | 2 +- 2 files changed, 31 insertions(+), 19 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index cdde2e77..1836bc9c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -17,7 +17,10 @@ import github.daneren2005.dsub.util.MergeAdapter; import github.daneren2005.dsub.util.Util; import java.util.Arrays; -public class MainFragment extends SubsonicTabFragment { +public class MainFragment extends SubsonicTabFragment { + private View rootView; + private LayoutInflater inflater; + @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); @@ -25,10 +28,31 @@ public class MainFragment extends SubsonicTabFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { - View view = inflater.inflate(R.layout.main, container, false); + this.inflater = inflater; + this.rootView = inflater.inflate(R.layout.main, container, false); loadSettings(); + createLayout(); + + return rootView; + } + + @Override + public void onResume() { + super.onResume(); + } + @Override + public void onDestroy() { + super.onDestroy(); + } + + @Override + protected void refresh() { + createLayout(); + } + + private void createLayout() { View buttons = inflater.inflate(R.layout.main_buttons, null); final View serverButton = buttons.findViewById(R.id.main_select_server); @@ -44,13 +68,13 @@ public class MainFragment extends SubsonicTabFragment { final View albumsFrequentButton = buttons.findViewById(R.id.main_albums_frequent); final View albumsStarredButton = buttons.findViewById(R.id.main_albums_starred); - final View dummyView = view.findViewById(R.id.main_dummy); + final View dummyView = rootView.findViewById(R.id.main_dummy); int instance = Util.getActiveServer(context); String name = Util.getServerName(context, instance); serverTextView.setText(name); - ListView list = (ListView) view.findViewById(R.id.main_list); + ListView list = (ListView) rootView.findViewById(R.id.main_list); MergeAdapter adapter = new MergeAdapter(); if (!Util.isOffline(context)) { @@ -86,18 +110,6 @@ public class MainFragment extends SubsonicTabFragment { } } }); - - return view; - } - - @Override - public void onResume() { - super.onResume(); - } - - @Override - public void onDestroy() { - super.onDestroy(); } private void loadSettings() { @@ -118,7 +130,7 @@ public class MainFragment extends SubsonicTabFragment { } private void toggleOffline() { - Util.setOffline(this, !Util.isOffline(context)); - restart(); + Util.setOffline(context, !Util.isOffline(context)); + refresh(); } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index df98c710..7db43db5 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -89,7 +89,7 @@ public class SubsonicTabFragment extends SherlockFragment { context = activity; } - protected void restart() { + protected void refresh() { } } -- cgit v1.2.3 From 525d9c9732f3d91ff44b010d40bc54c53dd12853 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 5 Mar 2013 21:17:52 -0800 Subject: Added back main tab server selection --- .../daneren2005/dsub/fragments/MainFragment.java | 59 ++++++++++++++++++++++ .../dsub/fragments/SubsonicTabFragment.java | 9 +++- 2 files changed, 66 insertions(+), 2 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 1836bc9c..1566a4ce 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; +import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -11,6 +12,7 @@ import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.MergeAdapter; @@ -21,6 +23,11 @@ public class MainFragment extends SubsonicTabFragment { private View rootView; private LayoutInflater inflater; + private static final int MENU_GROUP_SERVER = 10; + private static final int MENU_ITEM_SERVER_1 = 101; + private static final int MENU_ITEM_SERVER_2 = 102; + private static final int MENU_ITEM_SERVER_3 = 103; + @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); @@ -47,6 +54,48 @@ public class MainFragment extends SubsonicTabFragment { super.onDestroy(); } + @Override + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + + android.view.MenuItem menuItem1 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_1, MENU_ITEM_SERVER_1, Util.getServerName(context, 1)); + android.view.MenuItem menuItem2 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_2, MENU_ITEM_SERVER_2, Util.getServerName(context, 2)); + android.view.MenuItem menuItem3 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_3, MENU_ITEM_SERVER_3, Util.getServerName(context, 3)); + menu.setGroupCheckable(MENU_GROUP_SERVER, true, true); + menu.setHeaderTitle(R.string.main_select_server); + + switch (Util.getActiveServer(context)) { + case 1: + menuItem1.setChecked(true); + break; + case 2: + menuItem2.setChecked(true); + break; + case 3: + menuItem3.setChecked(true); + break; + } + } + + @Override + public boolean onContextItemSelected(android.view.MenuItem menuItem) { + switch (menuItem.getItemId()) { + case MENU_ITEM_SERVER_1: + setActiveServer(1); + break; + case MENU_ITEM_SERVER_2: + setActiveServer(2); + break; + case MENU_ITEM_SERVER_3: + setActiveServer(3); + break; + default: + return super.onContextItemSelected(menuItem); + } + + return true; + } + @Override protected void refresh() { createLayout(); @@ -129,6 +178,16 @@ public class MainFragment extends SubsonicTabFragment { } } + private void setActiveServer(int instance) { + if (Util.getActiveServer(context) != instance) { + DownloadService service = getDownloadService(); + if (service != null) { + service.clearIncomplete(); + } + Util.setActiveServer(context, instance); + } + } + private void toggleOffline() { Util.setOffline(context, !Util.isOffline(context)); refresh(); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index 7db43db5..b0170f97 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -38,6 +38,7 @@ import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragment; import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.DownloadActivity; +import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.activity.SubsonicTabActivity; import github.daneren2005.dsub.domain.Artist; import github.daneren2005.dsub.domain.MusicDirectory; @@ -66,7 +67,7 @@ import java.util.List; public class SubsonicTabFragment extends SherlockFragment { private static final String TAG = SubsonicTabActivity.class.getSimpleName(); private static ImageLoader IMAGE_LOADER; - protected Context context; + protected SubsonicActivity context; @Override public void onCreate(Bundle bundle) { @@ -86,7 +87,11 @@ public class SubsonicTabFragment extends SherlockFragment { @Override public void onAttach(Activity activity) { super.onAttach(activity); - context = activity; + context = (SubsonicActivity)activity; + } + + public DownloadService getDownloadService() { + return context != null ? context.getDownloadService() : null; } protected void refresh() { -- cgit v1.2.3 From c0b692f34cd8dfc9a4d99e7c57ac45d6006a70e5 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 6 Mar 2013 21:29:01 -0800 Subject: Added SelectArtistFragment --- .../daneren2005/dsub/activity/MusicActivity.java | 4 +- .../daneren2005/dsub/fragments/MainFragment.java | 3 +- .../dsub/fragments/SelectArtistFragment.java | 200 +++++++++++++++++++++ .../dsub/fragments/SubsonicTabFragment.java | 15 ++ .../daneren2005/dsub/util/TabBackgroundTask.java | 68 +++++++ .../daneren2005/dsub/view/ArtistAdapter.java | 5 +- 6 files changed, 289 insertions(+), 6 deletions(-) create mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java create mode 100644 subsonic-android/src/github/daneren2005/dsub/util/TabBackgroundTask.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java index 36d3f068..4bce1ab3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java @@ -8,6 +8,7 @@ import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import github.daneren2005.dsub.R; import github.daneren2005.dsub.fragments.MainFragment; +import github.daneren2005.dsub.fragments.SelectArtistFragment; import github.daneren2005.dsub.fragments.SubsonicTabFragment; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.util.Constants; @@ -118,9 +119,8 @@ public class MusicActivity extends SubsonicActivity { case 0: fragment = new MainFragment(); break; - case 1: - fragment = new MainFragment(); + fragment = new SelectArtistFragment(); break; default: fragment = null; diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 1566a4ce..88851d48 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -20,7 +20,6 @@ import github.daneren2005.dsub.util.Util; import java.util.Arrays; public class MainFragment extends SubsonicTabFragment { - private View rootView; private LayoutInflater inflater; private static final int MENU_GROUP_SERVER = 10; @@ -36,7 +35,7 @@ public class MainFragment extends SubsonicTabFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { this.inflater = inflater; - this.rootView = inflater.inflate(R.layout.main, container, false); + rootView = inflater.inflate(R.layout.main, container, false); loadSettings(); createLayout(); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java new file mode 100644 index 00000000..01c66886 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -0,0 +1,200 @@ +package github.daneren2005.dsub.fragments; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.ContextMenu; +import android.view.LayoutInflater; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.TextView; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.activity.SelectArtistActivity; +import github.daneren2005.dsub.activity.SubsonicTabActivity; +import github.daneren2005.dsub.domain.Artist; +import github.daneren2005.dsub.domain.Indexes; +import github.daneren2005.dsub.domain.MusicFolder; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.util.BackgroundTask; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.TabBackgroundTask; +import github.daneren2005.dsub.util.Util; +import github.daneren2005.dsub.view.ArtistAdapter; +import java.util.ArrayList; +import java.util.List; + +public class SelectArtistFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { + private static final String TAG = SelectArtistFragment.class.getSimpleName(); + private static final int MENU_GROUP_MUSIC_FOLDER = 10; + + private ListView artistList; + private View folderButton; + private TextView folderName; + private List musicFolders = null; + + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + rootView = inflater.inflate(R.layout.select_artist, container, false); + + artistList = (ListView) rootView.findViewById(R.id.select_artist_list); + artistList.setOnItemClickListener(this); + + folderButton = inflater.inflate(R.layout.select_artist_header, artistList, false); + folderName = (TextView) folderButton.findViewById(R.id.select_artist_folder_2); + + if (!Util.isOffline(context)) { + artistList.addHeaderView(folderButton); + } + + registerForContextMenu(artistList); + load(false); + + return rootView; + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + + if (artistList.getItemAtPosition(info.position) instanceof Artist) { + MenuInflater inflater = context.getMenuInflater(); + if(Util.isOffline(context)) + inflater.inflate(R.menu.select_artist_context_offline, menu); + else + inflater.inflate(R.menu.select_artist_context, menu); + } else if (info.position == 0) { + String musicFolderId = Util.getSelectedMusicFolderId(context); + MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders); + if (musicFolderId == null) { + menuItem.setChecked(true); + } + if (musicFolders != null) { + for (int i = 0; i < musicFolders.size(); i++) { + MusicFolder musicFolder = musicFolders.get(i); + menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName()); + if (musicFolder.getId().equals(musicFolderId)) { + menuItem.setChecked(true); + } + } + } + menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true); + } + } + + @Override + public boolean onContextItemSelected(MenuItem menuItem) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + + Artist artist = (Artist) artistList.getItemAtPosition(info.position); + + if (artist != null) { + switch (menuItem.getItemId()) { + case R.id.artist_menu_play_now: + // downloadRecursively(artist.getId(), false, false, true, false, false); + break; + case R.id.artist_menu_play_shuffled: + // downloadRecursively(artist.getId(), false, false, true, true, false); + break; + case R.id.artist_menu_play_last: + // downloadRecursively(artist.getId(), false, true, false, false, false); + break; + case R.id.artist_menu_download: + // downloadRecursively(artist.getId(), false, true, false, false, true); + break; + case R.id.artist_menu_pin: + // downloadRecursively(artist.getId(), true, true, false, false, true); + break; + case R.id.artist_menu_delete: + // deleteRecursively(artist); + break; + default: + // return super.onContextItemSelected(menuItem); + } + } else if (info.position == 0) { + MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId()); + String musicFolderId = selectedFolder == null ? null : selectedFolder.getId(); + String musicFolderName = selectedFolder == null ? context.getString(R.string.select_artist_all_folders) + : selectedFolder.getName(); + Util.setSelectedMusicFolderId(context, musicFolderId); + folderName.setText(musicFolderName); + refresh(); + } + + return true; + } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (view == folderButton) { + selectFolder(); + } else { + Artist artist = (Artist) parent.getItemAtPosition(position); + /*Intent intent = new Intent(this, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); + Util.startActivityWithoutTransition(this, intent);*/ + } + } + + @Override + protected void refresh() { + load(true); + } + + private void load(final boolean refresh) { + artistList.setVisibility(View.INVISIBLE); + + BackgroundTask task = new TabBackgroundTask(this) { + @Override + protected Indexes doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + if (!Util.isOffline(context)) { + musicFolders = musicService.getMusicFolders(refresh, context, this); + } + String musicFolderId = Util.getSelectedMusicFolderId(context); + return musicService.getIndexes(musicFolderId, refresh, context, this); + } + + @Override + protected void done(Indexes result) { + List artists = new ArrayList(result.getShortcuts().size() + result.getArtists().size()); + artists.addAll(result.getShortcuts()); + artists.addAll(result.getArtists()); + artistList.setAdapter(new ArtistAdapter(context, artists)); + + // Display selected music folder + if (musicFolders != null) { + String musicFolderId = Util.getSelectedMusicFolderId(context); + if (musicFolderId == null) { + folderName.setText(R.string.select_artist_all_folders); + } else { + for (MusicFolder musicFolder : musicFolders) { + if (musicFolder.getId().equals(musicFolderId)) { + folderName.setText(musicFolder.getName()); + break; + } + } + } + artistList.setVisibility(View.VISIBLE); + } + } + }; + task.execute(); + } + + private void selectFolder() { + folderButton.showContextMenu(); + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index b0170f97..b64bd217 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -68,6 +68,7 @@ public class SubsonicTabFragment extends SherlockFragment { private static final String TAG = SubsonicTabActivity.class.getSimpleName(); private static ImageLoader IMAGE_LOADER; protected SubsonicActivity context; + protected View rootView; @Override public void onCreate(Bundle bundle) { @@ -97,4 +98,18 @@ public class SubsonicTabFragment extends SherlockFragment { protected void refresh() { } + + public void setProgressVisible(boolean visible) { + View view = rootView.findViewById(R.id.tab_progress); + if (view != null) { + view.setVisibility(visible ? View.VISIBLE : View.GONE); + } + } + + public void updateProgress(String message) { + TextView view = (TextView) rootView.findViewById(R.id.tab_progress_message); + if (view != null) { + view.setText(message); + } + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/util/TabBackgroundTask.java b/subsonic-android/src/github/daneren2005/dsub/util/TabBackgroundTask.java new file mode 100644 index 00000000..57a36c1f --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/util/TabBackgroundTask.java @@ -0,0 +1,68 @@ +package github.daneren2005.dsub.util; + +import github.daneren2005.dsub.activity.SubsonicTabActivity; +import github.daneren2005.dsub.fragments.SubsonicTabFragment; + +/** + * @author Sindre Mehus + * @version $Id$ + */ +public abstract class TabBackgroundTask extends BackgroundTask { + + private final SubsonicTabFragment tabFragment; + + public TabBackgroundTask(SubsonicTabFragment fragment) { + super(fragment.getActivity()); + tabFragment = fragment; + } + + @Override + public void execute() { + tabFragment.setProgressVisible(true); + + new Thread() { + @Override + public void run() { + try { + final T result = doInBackground(); + if (isCancelled()) { + return; + } + + getHandler().post(new Runnable() { + @Override + public void run() { + tabFragment.setProgressVisible(false); + done(result); + } + }); + } catch (final Throwable t) { + if (isCancelled()) { + return; + } + getHandler().post(new Runnable() { + @Override + public void run() { + tabFragment.setProgressVisible(false); + error(t); + } + }); + } + } + }.start(); + } + + private boolean isCancelled() { + return !tabFragment.isAdded(); + } + + @Override + public void updateProgress(final String message) { + getHandler().post(new Runnable() { + @Override + public void run() { + tabFragment.updateProgress(message); + } + }); + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java b/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java index 0edb03c5..64e5f055 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java @@ -18,6 +18,7 @@ */ package github.daneren2005.dsub.view; +import android.content.Context; import github.daneren2005.dsub.R; import java.util.List; import android.view.View; @@ -35,13 +36,13 @@ import java.util.Set; */ public class ArtistAdapter extends ArrayAdapter implements SectionIndexer { - private final SubsonicTabActivity activity; + private final Context activity; // Both arrays are indexed by section ID. private final Object[] sections; private final Integer[] positions; - public ArtistAdapter(SubsonicTabActivity activity, List artists) { + public ArtistAdapter(Context activity, List artists) { super(activity, R.layout.artist_list_item, artists); this.activity = activity; -- cgit v1.2.3 From 4a32d662a22aef43896932e6cb122ec6de89e0cd Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 7 Mar 2013 20:25:58 -0800 Subject: Added Playlist fragment --- .../daneren2005/dsub/activity/MusicActivity.java | 9 +- .../dsub/fragments/SelectPlaylistFragment.java | 151 +++++++++++++++++++++ .../daneren2005/dsub/view/PlaylistAdapter.java | 5 +- 3 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java index 4bce1ab3..26dc575a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java @@ -9,6 +9,7 @@ import android.support.v4.view.ViewPager; import github.daneren2005.dsub.R; import github.daneren2005.dsub.fragments.MainFragment; import github.daneren2005.dsub.fragments.SelectArtistFragment; +import github.daneren2005.dsub.fragments.SelectPlaylistFragment; import github.daneren2005.dsub.fragments.SubsonicTabFragment; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.util.Constants; @@ -104,7 +105,8 @@ public class MusicActivity extends SubsonicActivity { private final String [] titles = new String [] { "Home", - "Library" + "Library", + "Playlists" }; public MainActivityPagerAdapter(FragmentManager fm) { @@ -122,6 +124,9 @@ public class MusicActivity extends SubsonicActivity { case 1: fragment = new SelectArtistFragment(); break; + case 2: + fragment = new SelectPlaylistFragment(); + break; default: fragment = null; } @@ -135,7 +140,7 @@ public class MusicActivity extends SubsonicActivity { @Override public int getCount() { - return 2; + return 3; } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java new file mode 100644 index 00000000..2d57b177 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -0,0 +1,151 @@ +package github.daneren2005.dsub.fragments; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.ContextMenu; +import android.view.LayoutInflater; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.TextView; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.activity.SelectArtistActivity; +import github.daneren2005.dsub.activity.SelectPlaylistActivity; +import github.daneren2005.dsub.activity.SubsonicTabActivity; +import github.daneren2005.dsub.domain.Artist; +import github.daneren2005.dsub.domain.Indexes; +import github.daneren2005.dsub.domain.MusicFolder; +import github.daneren2005.dsub.domain.Playlist; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.util.BackgroundTask; +import github.daneren2005.dsub.util.CacheCleaner; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.TabBackgroundTask; +import github.daneren2005.dsub.util.Util; +import github.daneren2005.dsub.view.ArtistAdapter; +import github.daneren2005.dsub.view.PlaylistAdapter; +import java.util.ArrayList; +import java.util.List; + +public class SelectPlaylistFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { + private static final String TAG = SelectPlaylistFragment.class.getSimpleName(); + + private ListView list; + private View emptyTextView; + private PlaylistAdapter playlistAdapter; + + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + rootView = inflater.inflate(R.layout.select_playlist, container, false); + + list = (ListView) rootView.findViewById(R.id.select_playlist_list); + emptyTextView = rootView.findViewById(R.id.select_playlist_empty); + list.setOnItemClickListener(this); + registerForContextMenu(list); + load(false); + + return rootView; + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + + MenuInflater inflater = context.getMenuInflater(); + if (Util.isOffline(context)) { + inflater.inflate(R.menu.select_playlist_context_offline, menu); + } + else { + inflater.inflate(R.menu.select_playlist_context, menu); + } + } + + @Override + public boolean onContextItemSelected(MenuItem menuItem) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + Playlist playlist = (Playlist) list.getItemAtPosition(info.position); + + Intent intent; + /*switch (menuItem.getItemId()) { + case R.id.playlist_menu_download: + downloadPlaylist(playlist.getId(), playlist.getName(), false, true, false, false, true); + break; + case R.id.playlist_menu_pin: + downloadPlaylist(playlist.getId(), playlist.getName(), true, true, false, false, true); + break; + case R.id.playlist_menu_play_now: + intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); + Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); + break; + case R.id.playlist_menu_play_shuffled: + intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); + intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); + Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); + break; + case R.id.playlist_menu_delete: + deletePlaylist(playlist); + break; + case R.id.playlist_info: + displayPlaylistInfo(playlist); + break; + case R.id.playlist_update_info: + updatePlaylistInfo(playlist); + break; + default: + return super.onContextItemSelected(menuItem); + }*/ + return true; + } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + Playlist playlist = (Playlist) parent.getItemAtPosition(position); + + /*Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent);*/ + } + + @Override + protected void refresh() { + load(true); + } + + private void load(final boolean refresh) { + BackgroundTask> task = new TabBackgroundTask>(this) { + @Override + protected List doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + List playlists = musicService.getPlaylists(refresh, context, this); + if(!Util.isOffline(context) && refresh) { + new CacheCleaner(context, getDownloadService()).cleanPlaylists(playlists); + } + return playlists; + } + + @Override + protected void done(List result) { + list.setAdapter(playlistAdapter = new PlaylistAdapter(context, result)); + emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE); + } + }; + task.execute(); + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java index c9377721..f50dd199 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java @@ -18,6 +18,7 @@ */ package github.daneren2005.dsub.view; +import android.content.Context; import github.daneren2005.dsub.R; import java.util.List; import android.view.View; @@ -33,9 +34,9 @@ import java.util.Comparator; */ public class PlaylistAdapter extends ArrayAdapter { - private final SubsonicTabActivity activity; + private final Context activity; - public PlaylistAdapter(SubsonicTabActivity activity, List Playlists) { + public PlaylistAdapter(Context activity, List Playlists) { super(activity, R.layout.playlist_list_item, Playlists); this.activity = activity; } -- cgit v1.2.3 From fea1f42af85563ecf6b716e907875b14b68588ff Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 7 Mar 2013 20:30:00 -0800 Subject: Convert spaces to tabs + get rid of unused imports --- .../daneren2005/dsub/activity/MusicActivity.java | 190 +++++++-------- .../daneren2005/dsub/fragments/MainFragment.java | 142 +++++------ .../dsub/fragments/SelectArtistFragment.java | 261 ++++++++++----------- .../dsub/fragments/SelectPlaylistFragment.java | 138 +++++------ .../dsub/fragments/SubsonicTabFragment.java | 66 ++---- .../daneren2005/dsub/view/PlaylistAdapter.java | 39 ++- .../github/daneren2005/dsub/view/PlaylistView.java | 28 +-- 7 files changed, 408 insertions(+), 456 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java index 26dc575a..300fb780 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java @@ -19,9 +19,9 @@ public class MusicActivity extends SubsonicActivity { private static final String TAG = MusicActivity.class.getSimpleName(); private static boolean infoDialogDisplayed; private MainActivityPagerAdapter pagerAdapter; - private ViewPager viewPager; + private ViewPager viewPager; private SubsonicTabFragment prevPageFragment; - + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -29,94 +29,94 @@ public class MusicActivity extends SubsonicActivity { exit(); } setContentView(R.layout.music); - + pagerAdapter = new MainActivityPagerAdapter(getSupportFragmentManager()); - viewPager = (ViewPager) findViewById(R.id.pager); - viewPager.setAdapter(pagerAdapter); - viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { - @Override - public void onPageSelected(int position) { - notifyFragmentOnPageSelected(position); - } - }); - - if (savedInstanceState == null) { - int position = Util.isOffline(this) ? 0 : 2; - if (position == viewPager.getCurrentItem()) { - notifyFragmentOnPageSelected(position); - } else { - viewPager.setCurrentItem(position); - } - } - - handleIntentAction(getIntent()); + viewPager = (ViewPager) findViewById(R.id.pager); + viewPager.setAdapter(pagerAdapter); + viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { + @Override + public void onPageSelected(int position) { + notifyFragmentOnPageSelected(position); + } + }); + + if (savedInstanceState == null) { + int position = Util.isOffline(this) ? 0 : 2; + if (position == viewPager.getCurrentItem()) { + notifyFragmentOnPageSelected(position); + } else { + viewPager.setCurrentItem(position); + } + } + + handleIntentAction(getIntent()); } - + @Override - protected void onPostCreate(Bundle bundle) { - super.onPostCreate(bundle); - - getSupportActionBar().setDisplayHomeAsUpEnabled(false); - getSupportActionBar().setHomeButtonEnabled(false); - - showInfoDialog(); - } - + protected void onPostCreate(Bundle bundle) { + super.onPostCreate(bundle); + + getSupportActionBar().setDisplayHomeAsUpEnabled(false); + getSupportActionBar().setHomeButtonEnabled(false); + + showInfoDialog(); + } + @Override - public void onResume() { - super.onResume(); - } - + public void onResume() { + super.onResume(); + } + @Override - protected void onNewIntent(Intent intent) { - handleIntentAction(intent); - // mPagerAdapter.notifyDataSetChanged(); - } - + protected void onNewIntent(Intent intent) { + handleIntentAction(intent); + // mPagerAdapter.notifyDataSetChanged(); + } + private void handleIntentAction(Intent intent) { - if (intent.hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { - exit(); - } - } - + if (intent.hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { + exit(); + } + } + private void exit() { - stopService(new Intent(this, DownloadServiceImpl.class)); - finish(); - } - + stopService(new Intent(this, DownloadServiceImpl.class)); + finish(); + } + private void showInfoDialog() { - if (!infoDialogDisplayed) { - infoDialogDisplayed = true; - if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) { - Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text); - } - } - } - + if (!infoDialogDisplayed) { + infoDialogDisplayed = true; + if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) { + Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text); + } + } + } + private void notifyFragmentOnPageSelected(int position) { - /*if (prevPageFragment != null) { - prevPageFragment.onPageDeselected(); - } + /*if (prevPageFragment != null) { + prevPageFragment.onPageDeselected(); + } prevPageFragment = (SubsonicTabFragment) pagerAdapter.instantiateItem(viewPager, position); prevPageFragment.onPageSelected();*/ - } - + } + public class MainActivityPagerAdapter extends FragmentPagerAdapter { - - private final String [] titles = new String [] { - "Home", - "Library", + + private final String [] titles = new String [] { + "Home", + "Library", "Playlists" - }; - - public MainActivityPagerAdapter(FragmentManager fm) { - super(fm); - } - - @Override - public Fragment getItem(int i) { - Fragment fragment; - Bundle args = new Bundle(); + }; + + public MainActivityPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int i) { + Fragment fragment; + Bundle args = new Bundle(); switch(i) { case 0: fragment = new MainFragment(); @@ -130,22 +130,22 @@ public class MusicActivity extends SubsonicActivity { default: fragment = null; } - - if (fragment != null) { - fragment.setArguments(args); - } - - return fragment; - } - - @Override - public int getCount() { - return 3; - } - - @Override - public CharSequence getPageTitle(int position) { - return titles[position]; - } - } + + if (fragment != null) { + fragment.setArguments(args); + } + + return fragment; + } + + @Override + public int getCount() { + return 3; + } + + @Override + public CharSequence getPageTitle(int position) { + return titles[position]; + } + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 88851d48..38140f87 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -21,12 +21,12 @@ import java.util.Arrays; public class MainFragment extends SubsonicTabFragment { private LayoutInflater inflater; - + private static final int MENU_GROUP_SERVER = 10; - private static final int MENU_ITEM_SERVER_1 = 101; - private static final int MENU_ITEM_SERVER_2 = 102; - private static final int MENU_ITEM_SERVER_3 = 103; - + private static final int MENU_ITEM_SERVER_1 = 101; + private static final int MENU_ITEM_SERVER_2 = 102; + private static final int MENU_ITEM_SERVER_3 = 103; + @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); @@ -39,7 +39,7 @@ public class MainFragment extends SubsonicTabFragment { loadSettings(); createLayout(); - + return rootView; } @@ -52,54 +52,54 @@ public class MainFragment extends SubsonicTabFragment { public void onDestroy() { super.onDestroy(); } - + @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - - android.view.MenuItem menuItem1 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_1, MENU_ITEM_SERVER_1, Util.getServerName(context, 1)); - android.view.MenuItem menuItem2 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_2, MENU_ITEM_SERVER_2, Util.getServerName(context, 2)); - android.view.MenuItem menuItem3 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_3, MENU_ITEM_SERVER_3, Util.getServerName(context, 3)); - menu.setGroupCheckable(MENU_GROUP_SERVER, true, true); - menu.setHeaderTitle(R.string.main_select_server); - - switch (Util.getActiveServer(context)) { - case 1: - menuItem1.setChecked(true); - break; - case 2: - menuItem2.setChecked(true); - break; - case 3: - menuItem3.setChecked(true); - break; - } - } - + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + + android.view.MenuItem menuItem1 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_1, MENU_ITEM_SERVER_1, Util.getServerName(context, 1)); + android.view.MenuItem menuItem2 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_2, MENU_ITEM_SERVER_2, Util.getServerName(context, 2)); + android.view.MenuItem menuItem3 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_3, MENU_ITEM_SERVER_3, Util.getServerName(context, 3)); + menu.setGroupCheckable(MENU_GROUP_SERVER, true, true); + menu.setHeaderTitle(R.string.main_select_server); + + switch (Util.getActiveServer(context)) { + case 1: + menuItem1.setChecked(true); + break; + case 2: + menuItem2.setChecked(true); + break; + case 3: + menuItem3.setChecked(true); + break; + } + } + @Override - public boolean onContextItemSelected(android.view.MenuItem menuItem) { - switch (menuItem.getItemId()) { - case MENU_ITEM_SERVER_1: - setActiveServer(1); - break; - case MENU_ITEM_SERVER_2: - setActiveServer(2); - break; - case MENU_ITEM_SERVER_3: - setActiveServer(3); - break; - default: - return super.onContextItemSelected(menuItem); - } - - return true; - } - + public boolean onContextItemSelected(android.view.MenuItem menuItem) { + switch (menuItem.getItemId()) { + case MENU_ITEM_SERVER_1: + setActiveServer(1); + break; + case MENU_ITEM_SERVER_2: + setActiveServer(2); + break; + case MENU_ITEM_SERVER_3: + setActiveServer(3); + break; + default: + return super.onContextItemSelected(menuItem); + } + + return true; + } + @Override protected void refresh() { createLayout(); } - + private void createLayout() { View buttons = inflater.inflate(R.layout.main_buttons, null); @@ -140,20 +140,20 @@ public class MainFragment extends SubsonicTabFragment { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if (view == serverButton) { - dummyView.showContextMenu(); - } else if (view == offlineButton) { - toggleOffline(); + dummyView.showContextMenu(); + } else if (view == offlineButton) { + toggleOffline(); } else if (view == albumsNewestButton) { - // showAlbumList("newest"); - } else if (view == albumsRandomButton) { - // showAlbumList("random"); - } else if (view == albumsHighestButton) { - // showAlbumList("highest"); - } else if (view == albumsRecentButton) { - // showAlbumList("recent"); - } else if (view == albumsFrequentButton) { - // showAlbumList("frequent"); - } else if (view == albumsStarredButton) { + // showAlbumList("newest"); + } else if (view == albumsRandomButton) { + // showAlbumList("random"); + } else if (view == albumsHighestButton) { + // showAlbumList("highest"); + } else if (view == albumsRecentButton) { + // showAlbumList("recent"); + } else if (view == albumsFrequentButton) { + // showAlbumList("frequent"); + } else if (view == albumsStarredButton) { // showAlbumList("starred"); } } @@ -176,17 +176,17 @@ public class MainFragment extends SubsonicTabFragment { editor.commit(); } } - + private void setActiveServer(int instance) { - if (Util.getActiveServer(context) != instance) { - DownloadService service = getDownloadService(); - if (service != null) { - service.clearIncomplete(); - } - Util.setActiveServer(context, instance); - } - } - + if (Util.getActiveServer(context) != instance) { + DownloadService service = getDownloadService(); + if (service != null) { + service.clearIncomplete(); + } + Util.setActiveServer(context, instance); + } + } + private void toggleOffline() { Util.setOffline(context, !Util.isOffline(context)); refresh(); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 01c66886..919010c1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -13,15 +13,12 @@ import android.widget.AdapterView; import android.widget.ListView; import android.widget.TextView; import github.daneren2005.dsub.R; -import github.daneren2005.dsub.activity.SelectArtistActivity; -import github.daneren2005.dsub.activity.SubsonicTabActivity; import github.daneren2005.dsub.domain.Artist; import github.daneren2005.dsub.domain.Indexes; import github.daneren2005.dsub.domain.MusicFolder; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.BackgroundTask; -import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.ArtistAdapter; @@ -31,170 +28,170 @@ import java.util.List; public class SelectArtistFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectArtistFragment.class.getSimpleName(); private static final int MENU_GROUP_MUSIC_FOLDER = 10; - + private ListView artistList; - private View folderButton; - private TextView folderName; - private List musicFolders = null; - + private View folderButton; + private TextView folderName; + private List musicFolders = null; + @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); } - + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.select_artist, container, false); - + artistList = (ListView) rootView.findViewById(R.id.select_artist_list); - artistList.setOnItemClickListener(this); + artistList.setOnItemClickListener(this); - folderButton = inflater.inflate(R.layout.select_artist_header, artistList, false); - folderName = (TextView) folderButton.findViewById(R.id.select_artist_folder_2); + folderButton = inflater.inflate(R.layout.select_artist_header, artistList, false); + folderName = (TextView) folderButton.findViewById(R.id.select_artist_folder_2); - if (!Util.isOffline(context)) { - artistList.addHeaderView(folderButton); - } + if (!Util.isOffline(context)) { + artistList.addHeaderView(folderButton); + } - registerForContextMenu(artistList); + registerForContextMenu(artistList); load(false); - + return rootView; } - + @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - if (artistList.getItemAtPosition(info.position) instanceof Artist) { - MenuInflater inflater = context.getMenuInflater(); + if (artistList.getItemAtPosition(info.position) instanceof Artist) { + MenuInflater inflater = context.getMenuInflater(); if(Util.isOffline(context)) inflater.inflate(R.menu.select_artist_context_offline, menu); else inflater.inflate(R.menu.select_artist_context, menu); - } else if (info.position == 0) { - String musicFolderId = Util.getSelectedMusicFolderId(context); - MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders); - if (musicFolderId == null) { - menuItem.setChecked(true); - } - if (musicFolders != null) { - for (int i = 0; i < musicFolders.size(); i++) { - MusicFolder musicFolder = musicFolders.get(i); - menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName()); - if (musicFolder.getId().equals(musicFolderId)) { - menuItem.setChecked(true); - } - } - } - menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true); - } - } - - @Override - public boolean onContextItemSelected(MenuItem menuItem) { - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - - Artist artist = (Artist) artistList.getItemAtPosition(info.position); - - if (artist != null) { - switch (menuItem.getItemId()) { - case R.id.artist_menu_play_now: - // downloadRecursively(artist.getId(), false, false, true, false, false); - break; + } else if (info.position == 0) { + String musicFolderId = Util.getSelectedMusicFolderId(context); + MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders); + if (musicFolderId == null) { + menuItem.setChecked(true); + } + if (musicFolders != null) { + for (int i = 0; i < musicFolders.size(); i++) { + MusicFolder musicFolder = musicFolders.get(i); + menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName()); + if (musicFolder.getId().equals(musicFolderId)) { + menuItem.setChecked(true); + } + } + } + menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true); + } + } + + @Override + public boolean onContextItemSelected(MenuItem menuItem) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + + Artist artist = (Artist) artistList.getItemAtPosition(info.position); + + if (artist != null) { + switch (menuItem.getItemId()) { + case R.id.artist_menu_play_now: + // downloadRecursively(artist.getId(), false, false, true, false, false); + break; case R.id.artist_menu_play_shuffled: // downloadRecursively(artist.getId(), false, false, true, true, false); - break; - case R.id.artist_menu_play_last: - // downloadRecursively(artist.getId(), false, true, false, false, false); - break; + break; + case R.id.artist_menu_play_last: + // downloadRecursively(artist.getId(), false, true, false, false, false); + break; case R.id.artist_menu_download: - // downloadRecursively(artist.getId(), false, true, false, false, true); - break; - case R.id.artist_menu_pin: - // downloadRecursively(artist.getId(), true, true, false, false, true); - break; + // downloadRecursively(artist.getId(), false, true, false, false, true); + break; + case R.id.artist_menu_pin: + // downloadRecursively(artist.getId(), true, true, false, false, true); + break; case R.id.artist_menu_delete: - // deleteRecursively(artist); - break; - default: - // return super.onContextItemSelected(menuItem); - } - } else if (info.position == 0) { - MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId()); - String musicFolderId = selectedFolder == null ? null : selectedFolder.getId(); - String musicFolderName = selectedFolder == null ? context.getString(R.string.select_artist_all_folders) - : selectedFolder.getName(); - Util.setSelectedMusicFolderId(context, musicFolderId); - folderName.setText(musicFolderName); - refresh(); - } - - return true; - } + // deleteRecursively(artist); + break; + default: + // return super.onContextItemSelected(menuItem); + } + } else if (info.position == 0) { + MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId()); + String musicFolderId = selectedFolder == null ? null : selectedFolder.getId(); + String musicFolderName = selectedFolder == null ? context.getString(R.string.select_artist_all_folders) + : selectedFolder.getName(); + Util.setSelectedMusicFolderId(context, musicFolderId); + folderName.setText(musicFolderName); + refresh(); + } + + return true; + } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if (view == folderButton) { - selectFolder(); - } else { - Artist artist = (Artist) parent.getItemAtPosition(position); - /*Intent intent = new Intent(this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); - Util.startActivityWithoutTransition(this, intent);*/ - } + selectFolder(); + } else { + Artist artist = (Artist) parent.getItemAtPosition(position); + /*Intent intent = new Intent(this, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); + Util.startActivityWithoutTransition(this, intent);*/ + } } - + @Override protected void refresh() { - load(true); - } - + load(true); + } + private void load(final boolean refresh) { artistList.setVisibility(View.INVISIBLE); - - BackgroundTask task = new TabBackgroundTask(this) { - @Override - protected Indexes doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); - if (!Util.isOffline(context)) { - musicFolders = musicService.getMusicFolders(refresh, context, this); - } - String musicFolderId = Util.getSelectedMusicFolderId(context); - return musicService.getIndexes(musicFolderId, refresh, context, this); - } - - @Override - protected void done(Indexes result) { - List artists = new ArrayList(result.getShortcuts().size() + result.getArtists().size()); - artists.addAll(result.getShortcuts()); - artists.addAll(result.getArtists()); - artistList.setAdapter(new ArtistAdapter(context, artists)); - - // Display selected music folder - if (musicFolders != null) { - String musicFolderId = Util.getSelectedMusicFolderId(context); - if (musicFolderId == null) { - folderName.setText(R.string.select_artist_all_folders); - } else { - for (MusicFolder musicFolder : musicFolders) { - if (musicFolder.getId().equals(musicFolderId)) { - folderName.setText(musicFolder.getName()); - break; - } - } - } + + BackgroundTask task = new TabBackgroundTask(this) { + @Override + protected Indexes doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + if (!Util.isOffline(context)) { + musicFolders = musicService.getMusicFolders(refresh, context, this); + } + String musicFolderId = Util.getSelectedMusicFolderId(context); + return musicService.getIndexes(musicFolderId, refresh, context, this); + } + + @Override + protected void done(Indexes result) { + List artists = new ArrayList(result.getShortcuts().size() + result.getArtists().size()); + artists.addAll(result.getShortcuts()); + artists.addAll(result.getArtists()); + artistList.setAdapter(new ArtistAdapter(context, artists)); + + // Display selected music folder + if (musicFolders != null) { + String musicFolderId = Util.getSelectedMusicFolderId(context); + if (musicFolderId == null) { + folderName.setText(R.string.select_artist_all_folders); + } else { + for (MusicFolder musicFolder : musicFolders) { + if (musicFolder.getId().equals(musicFolderId)) { + folderName.setText(musicFolder.getName()); + break; + } + } + } artistList.setVisibility(View.VISIBLE); - } - } - }; - task.execute(); - } - + } + } + }; + task.execute(); + } + private void selectFolder() { - folderButton.showContextMenu(); - } + folderButton.showContextMenu(); + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 2d57b177..eaba77e5 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -11,56 +11,46 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListView; -import android.widget.TextView; import github.daneren2005.dsub.R; -import github.daneren2005.dsub.activity.SelectArtistActivity; -import github.daneren2005.dsub.activity.SelectPlaylistActivity; -import github.daneren2005.dsub.activity.SubsonicTabActivity; -import github.daneren2005.dsub.domain.Artist; -import github.daneren2005.dsub.domain.Indexes; -import github.daneren2005.dsub.domain.MusicFolder; import github.daneren2005.dsub.domain.Playlist; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.CacheCleaner; -import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.view.ArtistAdapter; import github.daneren2005.dsub.view.PlaylistAdapter; -import java.util.ArrayList; import java.util.List; public class SelectPlaylistFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectPlaylistFragment.class.getSimpleName(); - + private ListView list; - private View emptyTextView; + private View emptyTextView; private PlaylistAdapter playlistAdapter; - + @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); } - + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.select_playlist, container, false); - + list = (ListView) rootView.findViewById(R.id.select_playlist_list); - emptyTextView = rootView.findViewById(R.id.select_playlist_empty); - list.setOnItemClickListener(this); - registerForContextMenu(list); + emptyTextView = rootView.findViewById(R.id.select_playlist_empty); + list.setOnItemClickListener(this); + registerForContextMenu(list); load(false); - + return rootView; } - + @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + MenuInflater inflater = context.getMenuInflater(); if (Util.isOffline(context)) { inflater.inflate(R.menu.select_playlist_context_offline, menu); @@ -68,36 +58,36 @@ public class SelectPlaylistFragment extends SubsonicTabFragment implements Adapt else { inflater.inflate(R.menu.select_playlist_context, menu); } - } + } - @Override - public boolean onContextItemSelected(MenuItem menuItem) { - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - Playlist playlist = (Playlist) list.getItemAtPosition(info.position); + @Override + public boolean onContextItemSelected(MenuItem menuItem) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + Playlist playlist = (Playlist) list.getItemAtPosition(info.position); Intent intent; - /*switch (menuItem.getItemId()) { + /*switch (menuItem.getItemId()) { case R.id.playlist_menu_download: downloadPlaylist(playlist.getId(), playlist.getName(), false, true, false, false, true); break; case R.id.playlist_menu_pin: downloadPlaylist(playlist.getId(), playlist.getName(), true, true, false, false, true); break; - case R.id.playlist_menu_play_now: - intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); - Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); - break; + case R.id.playlist_menu_play_now: + intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); + Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); + break; case R.id.playlist_menu_play_shuffled: intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); - Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); - break; + Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); + break; case R.id.playlist_menu_delete: deletePlaylist(playlist); break; @@ -107,45 +97,45 @@ public class SelectPlaylistFragment extends SubsonicTabFragment implements Adapt case R.id.playlist_update_info: updatePlaylistInfo(playlist); break; - default: - return super.onContextItemSelected(menuItem); - }*/ - return true; - } - + default: + return super.onContextItemSelected(menuItem); + }*/ + return true; + } + @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - Playlist playlist = (Playlist) parent.getItemAtPosition(position); - - /*Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); - Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent);*/ - } - + public void onItemClick(AdapterView parent, View view, int position, long id) { + Playlist playlist = (Playlist) parent.getItemAtPosition(position); + + /*Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent);*/ + } + @Override protected void refresh() { - load(true); - } - + load(true); + } + private void load(final boolean refresh) { - BackgroundTask> task = new TabBackgroundTask>(this) { - @Override - protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); - List playlists = musicService.getPlaylists(refresh, context, this); + BackgroundTask> task = new TabBackgroundTask>(this) { + @Override + protected List doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + List playlists = musicService.getPlaylists(refresh, context, this); if(!Util.isOffline(context) && refresh) { new CacheCleaner(context, getDownloadService()).cleanPlaylists(playlists); } return playlists; - } - - @Override - protected void done(List result) { - list.setAdapter(playlistAdapter = new PlaylistAdapter(context, result)); - emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE); - } - }; - task.execute(); - } + } + + @Override + protected void done(List result) { + list.setAdapter(playlistAdapter = new PlaylistAdapter(context, result)); + emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE); + } + }; + task.execute(); + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index b64bd217..6d115bb9 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -19,50 +19,16 @@ package github.daneren2005.dsub.fragments; import android.app.Activity; -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.PackageInfo; -import android.media.AudioManager; -import android.media.MediaMetadataRetriever; -import android.os.Build; import android.os.Bundle; -import android.os.Environment; import android.util.Log; -import android.view.KeyEvent; import android.view.View; -import android.widget.EditText; import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragment; import github.daneren2005.dsub.R; -import github.daneren2005.dsub.activity.DownloadActivity; import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.activity.SubsonicTabActivity; -import github.daneren2005.dsub.domain.Artist; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.domain.Playlist; -import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadService; -import github.daneren2005.dsub.service.DownloadServiceImpl; -import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.service.OfflineException; -import github.daneren2005.dsub.service.ServerTooOldException; -import github.daneren2005.dsub.updates.Updater; -import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.ImageLoader; -import github.daneren2005.dsub.util.LoadingTask; -import github.daneren2005.dsub.util.ModalBackgroundTask; -import github.daneren2005.dsub.util.SilentBackgroundTask; -import github.daneren2005.dsub.util.Util; -import java.io.File; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; public class SubsonicTabFragment extends SherlockFragment { private static final String TAG = SubsonicTabActivity.class.getSimpleName(); @@ -90,26 +56,26 @@ public class SubsonicTabFragment extends SherlockFragment { super.onAttach(activity); context = (SubsonicActivity)activity; } - + public DownloadService getDownloadService() { return context != null ? context.getDownloadService() : null; } - + protected void refresh() { - - } - + + } + public void setProgressVisible(boolean visible) { - View view = rootView.findViewById(R.id.tab_progress); - if (view != null) { - view.setVisibility(visible ? View.VISIBLE : View.GONE); - } - } + View view = rootView.findViewById(R.id.tab_progress); + if (view != null) { + view.setVisibility(visible ? View.VISIBLE : View.GONE); + } + } - public void updateProgress(String message) { - TextView view = (TextView) rootView.findViewById(R.id.tab_progress_message); - if (view != null) { - view.setText(message); - } - } + public void updateProgress(String message) { + TextView view = (TextView) rootView.findViewById(R.id.tab_progress_message); + if (view != null) { + view.setText(message); + } + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java index f50dd199..71727c04 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistAdapter.java @@ -24,7 +24,6 @@ import java.util.List; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import github.daneren2005.dsub.activity.SubsonicTabActivity; import github.daneren2005.dsub.domain.Playlist; import java.util.Collections; import java.util.Comparator; @@ -34,16 +33,16 @@ import java.util.Comparator; */ public class PlaylistAdapter extends ArrayAdapter { - private final Context activity; + private final Context activity; - public PlaylistAdapter(Context activity, List Playlists) { - super(activity, R.layout.playlist_list_item, Playlists); - this.activity = activity; - } + public PlaylistAdapter(Context activity, List Playlists) { + super(activity, R.layout.playlist_list_item, Playlists); + this.activity = activity; + } - @Override - public View getView(int position, View convertView, ViewGroup parent) { - Playlist entry = getItem(position); + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Playlist entry = getItem(position); PlaylistView view; if (convertView != null && convertView instanceof PlaylistView) { view = (PlaylistView) convertView; @@ -52,18 +51,18 @@ public class PlaylistAdapter extends ArrayAdapter { } view.setPlaylist(entry); return view; - } - + } + public static class PlaylistComparator implements Comparator { - @Override - public int compare(Playlist playlist1, Playlist playlist2) { - return playlist1.getName().compareToIgnoreCase(playlist2.getName()); - } + @Override + public int compare(Playlist playlist1, Playlist playlist2) { + return playlist1.getName().compareToIgnoreCase(playlist2.getName()); + } - public static List sort(List playlists) { - Collections.sort(playlists, new PlaylistComparator()); - return playlists; - } + public static List sort(List playlists) { + Collections.sort(playlists, new PlaylistComparator()); + return playlists; + } - } + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java index b09c91d4..effd5a98 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/PlaylistView.java @@ -36,32 +36,32 @@ import java.io.File; */ public class PlaylistView extends UpdateView { private static final String TAG = PlaylistView.class.getSimpleName(); - + private Playlist playlist; - private TextView titleView; + private TextView titleView; private ImageView moreButton; - public PlaylistView(Context context) { - super(context); - LayoutInflater.from(context).inflate(R.layout.playlist_list_item, this, true); + public PlaylistView(Context context) { + super(context); + LayoutInflater.from(context).inflate(R.layout.playlist_list_item, this, true); - titleView = (TextView) findViewById(R.id.playlist_name); + titleView = (TextView) findViewById(R.id.playlist_name); moreButton = (ImageView) findViewById(R.id.playlist_more); moreButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { v.showContextMenu(); } }); - } + } + + public void setPlaylist(Playlist playlist) { + this.playlist = playlist; - public void setPlaylist(Playlist playlist) { - this.playlist = playlist; - - titleView.setText(playlist.getName()); + titleView.setText(playlist.getName()); update(); - } - + } + @Override protected void update() { File file = FileUtil.getPlaylistFile(playlist.getName()); @@ -70,5 +70,5 @@ public class PlaylistView extends UpdateView { } else { moreButton.setImageResource(R.drawable.list_item_more); } - } + } } -- cgit v1.2.3 From c24948543ae5a304b3084da33733dc33bb8dfbce Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 7 Mar 2013 21:02:48 -0800 Subject: Got rid of some stuff I don't intend on using --- .../daneren2005/dsub/activity/MusicActivity.java | 41 ---------------------- 1 file changed, 41 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java index 300fb780..85dc730d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java @@ -20,36 +20,15 @@ public class MusicActivity extends SubsonicActivity { private static boolean infoDialogDisplayed; private MainActivityPagerAdapter pagerAdapter; private ViewPager viewPager; - private SubsonicTabFragment prevPageFragment; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { - exit(); - } setContentView(R.layout.music); pagerAdapter = new MainActivityPagerAdapter(getSupportFragmentManager()); viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(pagerAdapter); - viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { - @Override - public void onPageSelected(int position) { - notifyFragmentOnPageSelected(position); - } - }); - - if (savedInstanceState == null) { - int position = Util.isOffline(this) ? 0 : 2; - if (position == viewPager.getCurrentItem()) { - notifyFragmentOnPageSelected(position); - } else { - viewPager.setCurrentItem(position); - } - } - - handleIntentAction(getIntent()); } @Override @@ -67,18 +46,6 @@ public class MusicActivity extends SubsonicActivity { super.onResume(); } - @Override - protected void onNewIntent(Intent intent) { - handleIntentAction(intent); - // mPagerAdapter.notifyDataSetChanged(); - } - - private void handleIntentAction(Intent intent) { - if (intent.hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { - exit(); - } - } - private void exit() { stopService(new Intent(this, DownloadServiceImpl.class)); finish(); @@ -93,14 +60,6 @@ public class MusicActivity extends SubsonicActivity { } } - private void notifyFragmentOnPageSelected(int position) { - /*if (prevPageFragment != null) { - prevPageFragment.onPageDeselected(); - } - prevPageFragment = (SubsonicTabFragment) pagerAdapter.instantiateItem(viewPager, position); - prevPageFragment.onPageSelected();*/ - } - public class MainActivityPagerAdapter extends FragmentPagerAdapter { private final String [] titles = new String [] { -- cgit v1.2.3 From aceed12eba9a311860f9774b6c3a655042251913 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 8 Mar 2013 18:06:59 -0800 Subject: Start of adding album viewing --- .../dsub/fragments/SelectArtistFragment.java | 15 +++- .../dsub/fragments/SelectDirectoryFragment.java | 89 ++++++++++++++++++++++ 2 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 919010c1..51882c6c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -2,6 +2,7 @@ package github.daneren2005.dsub.fragments; import android.content.Intent; import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -19,6 +20,7 @@ import github.daneren2005.dsub.domain.MusicFolder; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.BackgroundTask; +import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.ArtistAdapter; @@ -138,10 +140,15 @@ public class SelectArtistFragment extends SubsonicTabFragment implements Adapter selectFolder(); } else { Artist artist = (Artist) parent.getItemAtPosition(position); - /*Intent intent = new Intent(this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); - Util.startActivityWithoutTransition(this, intent);*/ + SubsonicTabFragment fragment = new SelectDirectoryFragment(); + Bundle args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); + args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); + + final FragmentTransaction trans = getFragmentManager().beginTransaction(); + trans.replace(0, fragment); + trans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); + trans.commit(); } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java new file mode 100644 index 00000000..e5a721c5 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -0,0 +1,89 @@ +package github.daneren2005.dsub.fragments; + +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.ListView; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.view.EntryAdapter; +import java.util.List; +import com.mobeta.android.dslv.*; + +public class SelectDirectoryFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { + private static final String TAG = SelectDirectoryFragment.class.getSimpleName(); + + private DragSortListView entryList; + private View footer; + private View emptyView; + private boolean hideButtons = false; + private Button moreButton; + private Boolean licenseValid; + private boolean showHeader = true; + private EntryAdapter entryAdapter; + private List entries; + + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + rootView = inflater.inflate(R.layout.select_album, container, false); + + entryList = (DragSortListView) rootView.findViewById(R.id.select_album_entries); + footer = LayoutInflater.from(context).inflate(R.layout.select_album_footer, entryList, false); + entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); + entryList.setOnItemClickListener(this); + entryList.setDropListener(new DragSortListView.DropListener() { + @Override + public void drop(int from, int to) { + int max = entries.size(); + if(to >= max) { + to = max - 1; + } + else if(to < 0) { + to = 0; + } + entries.add(to, entries.remove(from)); + entryAdapter.notifyDataSetChanged(); + } + }); + + moreButton = (Button) footer.findViewById(R.id.select_album_more); + emptyView = rootView.findViewById(R.id.select_album_empty); + + registerForContextMenu(entryList); + + return rootView; + } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (position >= 0) { + MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position); + /*if (entry.isDirectory()) { + Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle()); + Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent); + } else if (entry.isVideo()) { + if(entryExists(entry)) { + playExternalPlayer(entry); + } else { + streamExternalPlayer(entry); + } + }*/ + } + } + + @Override + protected void refresh() { + // load(true); + } +} \ No newline at end of file -- cgit v1.2.3 From 5169f1181a45c0cefbb812c8a68f7e492dcef45f Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 9 Mar 2013 09:47:10 -0800 Subject: Switch MusicActivity to MainActivity --- subsonic-android/AndroidManifest.xml | 2 +- .../daneren2005/dsub/activity/MainActivity.java | 416 +++++---------------- .../daneren2005/dsub/activity/MusicActivity.java | 110 ------ 3 files changed, 85 insertions(+), 443 deletions(-) delete mode 100644 subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/AndroidManifest.xml b/subsonic-android/AndroidManifest.xml index d50083fa..b8513db8 100644 --- a/subsonic-android/AndroidManifest.xml +++ b/subsonic-android/AndroidManifest.xml @@ -22,7 +22,7 @@ - diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index fd2f31d4..807767d9 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -1,356 +1,108 @@ -/* - This file is part of Subsonic. - - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see . - - Copyright 2009 (C) Sindre Mehus - */ - package github.daneren2005.dsub.activity; -import java.util.Arrays; - +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; import github.daneren2005.dsub.R; -import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.fragments.MainFragment; +import github.daneren2005.dsub.fragments.SelectArtistFragment; +import github.daneren2005.dsub.fragments.SelectPlaylistFragment; import github.daneren2005.dsub.service.DownloadServiceImpl; -import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.MergeAdapter; import github.daneren2005.dsub.util.Util; -import github.daneren2005.dsub.util.FileUtil; -import com.actionbarsherlock.view.Menu; -import com.actionbarsherlock.view.MenuItem; -import com.actionbarsherlock.view.MenuInflater; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.net.Uri; -import android.os.Bundle; -import android.os.StatFs; -import android.preference.PreferenceManager; -import android.view.ContextMenu; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ImageButton; -import android.widget.ListView; -import android.widget.TextView; -import android.widget.PopupWindow; -import github.daneren2005.dsub.util.*; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -public class MainActivity extends SubsonicTabActivity { +public class MainActivity extends SubsonicActivity { + private static final String TAG = MainActivity.class.getSimpleName(); + private static boolean infoDialogDisplayed; + private MainActivityPagerAdapter pagerAdapter; + private ViewPager viewPager; - private static final int MENU_GROUP_SERVER = 10; - private static final int MENU_ITEM_SERVER_1 = 101; - private static final int MENU_ITEM_SERVER_2 = 102; - private static final int MENU_ITEM_SERVER_3 = 103; + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.music); - private static boolean infoDialogDisplayed; + pagerAdapter = new MainActivityPagerAdapter(getSupportFragmentManager()); + viewPager = (ViewPager) findViewById(R.id.pager); + viewPager.setAdapter(pagerAdapter); + } - /** - * Called when the activity is first created. - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { - exit(); - } - setContentView(R.layout.main); + @Override + protected void onPostCreate(Bundle bundle) { + super.onPostCreate(bundle); - loadSettings(); + getSupportActionBar().setDisplayHomeAsUpEnabled(false); + getSupportActionBar().setHomeButtonEnabled(false); - View buttons = LayoutInflater.from(this).inflate(R.layout.main_buttons, null); + showInfoDialog(); + } - final View serverButton = buttons.findViewById(R.id.main_select_server); - final TextView serverTextView = (TextView) serverButton.findViewById(R.id.main_select_server_2); - final TextView offlineButton = (TextView) buttons.findViewById(R.id.main_offline); - offlineButton.setText(Util.isOffline(this) ? R.string.main_online : R.string.main_offline); + @Override + public void onResume() { + super.onResume(); + } - final View albumsTitle = buttons.findViewById(R.id.main_albums); - final View albumsNewestButton = buttons.findViewById(R.id.main_albums_newest); - final View albumsRandomButton = buttons.findViewById(R.id.main_albums_random); - final View albumsHighestButton = buttons.findViewById(R.id.main_albums_highest); - final View albumsRecentButton = buttons.findViewById(R.id.main_albums_recent); - final View albumsFrequentButton = buttons.findViewById(R.id.main_albums_frequent); - final View albumsStarredButton = buttons.findViewById(R.id.main_albums_starred); + private void exit() { + stopService(new Intent(this, DownloadServiceImpl.class)); + finish(); + } - final View dummyView = findViewById(R.id.main_dummy); + private void showInfoDialog() { + if (!infoDialogDisplayed) { + infoDialogDisplayed = true; + if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) { + Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text); + } + } + } - int instance = Util.getActiveServer(this); - String name = Util.getServerName(this, instance); - serverTextView.setText(name); + public class MainActivityPagerAdapter extends FragmentPagerAdapter { - ListView list = (ListView) findViewById(R.id.main_list); + private final String [] titles = new String [] { + "Home", + "Library", + "Playlists" + }; - MergeAdapter adapter = new MergeAdapter(); - if (!Util.isOffline(this)) { - adapter.addViews(Arrays.asList(serverButton), true); + public MainActivityPagerAdapter(FragmentManager fm) { + super(fm); } - adapter.addView(offlineButton, true); - if (!Util.isOffline(this)) { - adapter.addView(albumsTitle, false); - adapter.addViews(Arrays.asList(albumsNewestButton, albumsRandomButton, albumsHighestButton, albumsStarredButton, albumsRecentButton, albumsFrequentButton), true); - } - list.setAdapter(adapter); - registerForContextMenu(dummyView); - list.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - if (view == serverButton) { - dummyView.showContextMenu(); - } else if (view == offlineButton) { - toggleOffline(); - } else if (view == albumsNewestButton) { - showAlbumList("newest"); - } else if (view == albumsRandomButton) { - showAlbumList("random"); - } else if (view == albumsHighestButton) { - showAlbumList("highest"); - } else if (view == albumsRecentButton) { - showAlbumList("recent"); - } else if (view == albumsFrequentButton) { - showAlbumList("frequent"); - } else if (view == albumsStarredButton) { - showAlbumList("starred"); + @Override + public Fragment getItem(int i) { + Fragment fragment; + Bundle args = new Bundle(); + switch(i) { + case 0: + fragment = new MainFragment(); + break; + case 1: + fragment = new SelectArtistFragment(); + break; + case 2: + fragment = new SelectPlaylistFragment(); + break; + default: + fragment = null; + } + + if (fragment != null) { + fragment.setArguments(args); + } + + return fragment; } - } - }); - - // Title: Subsonic - setTitle(R.string.common_appname); - showInfoDialog(); - - checkUpdates(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.main, menu); - return true; - } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - Intent intent; - switch (item.getItemId()) { - case R.id.menu_shuffle: - onShuffleRequested(); - return true; - case R.id.menu_search: - onSearchRequested(); - return true; - case R.id.menu_exit: - intent = new Intent(this, MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); - Util.startActivityWithoutTransition(this, intent); - return true; - case R.id.menu_settings: - startActivity(new Intent(this, SettingsActivity.class)); - return true; - case R.id.menu_help: - startActivity(new Intent(this, HelpActivity.class)); - return true; - case R.id.menu_log: - getLogs(); - return true; - case R.id.menu_about: - showAboutDialog(); - return true; - } - - return false; - } - - private void loadSettings() { - PreferenceManager.setDefaultValues(this, R.xml.settings, false); - SharedPreferences prefs = Util.getPreferences(this); - if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION)) { - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory().getPath()); - editor.commit(); - } - - if (!prefs.contains(Constants.PREFERENCES_KEY_OFFLINE)) { - SharedPreferences.Editor editor = prefs.edit(); - editor.putBoolean(Constants.PREFERENCES_KEY_OFFLINE, false); - editor.putInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1); - editor.commit(); - } - } - - @Override - protected void onResume() { - super.onResume(); - } - - @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - - android.view.MenuItem menuItem1 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_1, MENU_ITEM_SERVER_1, Util.getServerName(this, 1)); - android.view.MenuItem menuItem2 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_2, MENU_ITEM_SERVER_2, Util.getServerName(this, 2)); - android.view.MenuItem menuItem3 = menu.add(MENU_GROUP_SERVER, MENU_ITEM_SERVER_3, MENU_ITEM_SERVER_3, Util.getServerName(this, 3)); - menu.setGroupCheckable(MENU_GROUP_SERVER, true, true); - menu.setHeaderTitle(R.string.main_select_server); - - switch (Util.getActiveServer(this)) { - case 1: - menuItem1.setChecked(true); - break; - case 2: - menuItem2.setChecked(true); - break; - case 3: - menuItem3.setChecked(true); - break; - } - } - - @Override - public boolean onContextItemSelected(android.view.MenuItem menuItem) { - switch (menuItem.getItemId()) { - case MENU_ITEM_SERVER_1: - setActiveServer(1); - break; - case MENU_ITEM_SERVER_2: - setActiveServer(2); - break; - case MENU_ITEM_SERVER_3: - setActiveServer(3); - break; - default: - return super.onContextItemSelected(menuItem); - } - - // Restart activity - restart(); - return true; - } - - private void setActiveServer(int instance) { - if (Util.getActiveServer(this) != instance) { - DownloadService service = getDownloadService(); - if (service != null) { - service.clearIncomplete(); - } - Util.setActiveServer(this, instance); - } - } - - private void exit() { - stopService(new Intent(this, DownloadServiceImpl.class)); - finish(); - } - - private void showInfoDialog() { - if (!infoDialogDisplayed) { - infoDialogDisplayed = true; - if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) { - Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text); - } - } - } - - private void showAboutDialog() { - try { - File rootFolder = FileUtil.getMusicDirectory(MainActivity.this); - StatFs stat = new StatFs(rootFolder.getPath()); - long bytesTotalFs = (long) stat.getBlockCount() * (long) stat.getBlockSize(); - long bytesAvailableFs = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize(); - - String msg = getResources().getString(R.string.main_about_text, - getPackageManager().getPackageInfo(getPackageName(), 0).versionName, - Util.formatBytes(FileUtil.getUsedSize(MainActivity.this, rootFolder)), - Util.formatBytes(Util.getCacheSizeMB(MainActivity.this) * 1024L * 1024L), - Util.formatBytes(bytesAvailableFs), - Util.formatBytes(bytesTotalFs)); - Util.info(this, R.string.main_about_title, msg); - } catch(Exception e) { - Util.toast(MainActivity.this, "Failed to open dialog"); + @Override + public int getCount() { + return 3; } - // Util.toast(MainActivity.this, "Size: " + Util.formatBytes(FileUtil.getUsedSize(MainActivity.this, FileUtil.getMusicDirectory(MainActivity.this)))); - } - - private void showAlbumList(String type) { - Intent intent = new Intent(this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); - Util.startActivityWithoutTransition(this, intent); - } - - private void toggleOffline() { - Util.setOffline(this, !Util.isOffline(this)); - restart(); - } - - private void getLogs() { - try { - final String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; - new ModalBackgroundTask(this, false) { - @Override - protected File doInBackground() throws Throwable { - updateProgress("Gathering Logs"); - File logcat = new File(FileUtil.getSubsonicDirectory(), "logcat.txt"); - Process logcatProc = null; - try { - List progs = new ArrayList(); - progs.add("logcat"); - progs.add("-v"); - progs.add("time"); - progs.add("-d"); - progs.add("-f"); - progs.add(logcat.getPath()); - progs.add("*:I"); - - logcatProc = Runtime.getRuntime().exec(progs.toArray(new String[0])); - logcatProc.waitFor(); - } catch(Exception e) { - Util.toast(MainActivity.this, "Failed to gather logs"); - } finally { - if(logcatProc != null) { - logcatProc.destroy(); - } - } - - return logcat; - } - - @Override - protected void done(File logcat) { - Intent email = new Intent(android.content.Intent.ACTION_SEND); - email.setType("text/plain"); - email.putExtra(Intent.EXTRA_EMAIL, new String[] {"daneren2005@gmail.com"}); - email.putExtra(Intent.EXTRA_SUBJECT, "DSub " + version + " Error Logs"); - email.putExtra(Intent.EXTRA_TEXT, "Describe the problem here"); - Uri attachment = Uri.fromFile(logcat); - email.putExtra(Intent.EXTRA_STREAM, attachment); - startActivity(email); - } - }.execute(); - } catch(Exception e) {} + @Override + public CharSequence getPageTitle(int position) { + return titles[position]; + } } -} \ No newline at end of file +} diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java deleted file mode 100644 index 85dc730d..00000000 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java +++ /dev/null @@ -1,110 +0,0 @@ -package github.daneren2005.dsub.activity; - -import android.content.Intent; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.view.ViewPager; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.fragments.MainFragment; -import github.daneren2005.dsub.fragments.SelectArtistFragment; -import github.daneren2005.dsub.fragments.SelectPlaylistFragment; -import github.daneren2005.dsub.fragments.SubsonicTabFragment; -import github.daneren2005.dsub.service.DownloadServiceImpl; -import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.Util; - -public class MusicActivity extends SubsonicActivity { - private static final String TAG = MusicActivity.class.getSimpleName(); - private static boolean infoDialogDisplayed; - private MainActivityPagerAdapter pagerAdapter; - private ViewPager viewPager; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.music); - - pagerAdapter = new MainActivityPagerAdapter(getSupportFragmentManager()); - viewPager = (ViewPager) findViewById(R.id.pager); - viewPager.setAdapter(pagerAdapter); - } - - @Override - protected void onPostCreate(Bundle bundle) { - super.onPostCreate(bundle); - - getSupportActionBar().setDisplayHomeAsUpEnabled(false); - getSupportActionBar().setHomeButtonEnabled(false); - - showInfoDialog(); - } - - @Override - public void onResume() { - super.onResume(); - } - - private void exit() { - stopService(new Intent(this, DownloadServiceImpl.class)); - finish(); - } - - private void showInfoDialog() { - if (!infoDialogDisplayed) { - infoDialogDisplayed = true; - if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) { - Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text); - } - } - } - - public class MainActivityPagerAdapter extends FragmentPagerAdapter { - - private final String [] titles = new String [] { - "Home", - "Library", - "Playlists" - }; - - public MainActivityPagerAdapter(FragmentManager fm) { - super(fm); - } - - @Override - public Fragment getItem(int i) { - Fragment fragment; - Bundle args = new Bundle(); - switch(i) { - case 0: - fragment = new MainFragment(); - break; - case 1: - fragment = new SelectArtistFragment(); - break; - case 2: - fragment = new SelectPlaylistFragment(); - break; - default: - fragment = null; - } - - if (fragment != null) { - fragment.setArguments(args); - } - - return fragment; - } - - @Override - public int getCount() { - return 3; - } - - @Override - public CharSequence getPageTitle(int position) { - return titles[position]; - } - } -} -- cgit v1.2.3 From 613d6a816cb656007b067a85b72e684d3464595b Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 9 Mar 2013 10:03:23 -0800 Subject: Renamed main layout to home, music to main --- subsonic-android/res/layout/home.xml | 28 ++++++++++++ subsonic-android/res/layout/main.xml | 53 ++++++++++------------ subsonic-android/res/layout/music.xml | 25 ---------- .../daneren2005/dsub/activity/MainActivity.java | 2 +- .../dsub/activity/SubsonicTabActivity.java | 4 +- .../daneren2005/dsub/fragments/MainFragment.java | 2 +- 6 files changed, 57 insertions(+), 57 deletions(-) create mode 100644 subsonic-android/res/layout/home.xml delete mode 100644 subsonic-android/res/layout/music.xml (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout/home.xml b/subsonic-android/res/layout/home.xml new file mode 100644 index 00000000..56b013fe --- /dev/null +++ b/subsonic-android/res/layout/home.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + diff --git a/subsonic-android/res/layout/main.xml b/subsonic-android/res/layout/main.xml index 56b013fe..f5c95b3f 100644 --- a/subsonic-android/res/layout/main.xml +++ b/subsonic-android/res/layout/main.xml @@ -1,28 +1,25 @@ - - - - - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/subsonic-android/res/layout/music.xml b/subsonic-android/res/layout/music.xml deleted file mode 100644 index f5c95b3f..00000000 --- a/subsonic-android/res/layout/music.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 807767d9..c012e4c8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -22,7 +22,7 @@ public class MainActivity extends SubsonicActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.music); + setContentView(R.layout.main); pagerAdapter = new MainActivityPagerAdapter(getSupportFragmentManager()); viewPager = (ViewPager) findViewById(R.id.pager); diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index 938bf624..4df7fb96 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -124,9 +124,9 @@ public class SubsonicTabActivity extends SherlockActivity { } }); - if (this instanceof MainActivity) { + /*if (this instanceof MainActivity) { homeButton.setEnabled(false); - } else if (this instanceof SelectAlbumActivity || this instanceof SelectArtistActivity) { + } else*/ if (this instanceof SelectAlbumActivity || this instanceof SelectArtistActivity) { musicButton.setEnabled(false); } else if (this instanceof SelectPlaylistActivity) { playlistButton.setEnabled(false); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 38140f87..d179c150 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -35,7 +35,7 @@ public class MainFragment extends SubsonicTabFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { this.inflater = inflater; - rootView = inflater.inflate(R.layout.main, container, false); + rootView = inflater.inflate(R.layout.home, container, false); loadSettings(); createLayout(); -- cgit v1.2.3 From 321ac57465e72f704f7348943e082e892bccbb4d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 9 Mar 2013 10:22:48 -0800 Subject: Fix artist album selection --- subsonic-android/res/layout/select_artist.xml | 32 +++++++++++----------- .../dsub/fragments/SelectArtistFragment.java | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout/select_artist.xml b/subsonic-android/res/layout/select_artist.xml index bebfdec4..4dd3471f 100644 --- a/subsonic-android/res/layout/select_artist.xml +++ b/subsonic-android/res/layout/select_artist.xml @@ -1,24 +1,24 @@ + android:id="@+id/select_artist_layout" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent"> - + - + - - - + + diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 51882c6c..17e944dd 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -146,8 +146,8 @@ public class SelectArtistFragment extends SubsonicTabFragment implements Adapter args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); final FragmentTransaction trans = getFragmentManager().beginTransaction(); - trans.replace(0, fragment); - trans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); + trans.replace(R.id.select_artist_layout, fragment); + trans.addToBackStack(null); trans.commit(); } } -- cgit v1.2.3 From 563a6645470a5d9d1a28e7ae49df1801e2bbc294 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 9 Mar 2013 10:51:31 -0800 Subject: Got a working album view --- .../dsub/activity/SubsonicActivity.java | 2 +- .../dsub/fragments/SelectArtistFragment.java | 1 + .../dsub/fragments/SelectDirectoryFragment.java | 195 ++++++++++++++++++++- .../dsub/fragments/SubsonicTabFragment.java | 9 +- .../github/daneren2005/dsub/view/EntryAdapter.java | 8 +- 5 files changed, 207 insertions(+), 8 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 55ac514f..bada0da0 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -106,7 +106,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { return destroyed; } - protected synchronized ImageLoader getImageLoader() { + public synchronized ImageLoader getImageLoader() { if (IMAGE_LOADER == null) { IMAGE_LOADER = new ImageLoader(this); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 17e944dd..12a58678 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -144,6 +144,7 @@ public class SelectArtistFragment extends SubsonicTabFragment implements Adapter Bundle args = new Bundle(); args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); + fragment.setArguments(args); final FragmentTransaction trans = getFragmentManager().beginTransaction(); trans.replace(R.id.select_artist_layout, fragment); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index e5a721c5..b393521b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -2,17 +2,26 @@ package github.daneren2005.dsub.fragments; import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.Button; import android.widget.ListView; +import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.view.EntryAdapter; import java.util.List; import com.mobeta.android.dslv.*; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.Pair; +import github.daneren2005.dsub.util.TabBackgroundTask; +import java.util.HashSet; +import java.util.Set; public class SelectDirectoryFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectDirectoryFragment.class.getSimpleName(); @@ -59,6 +68,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap emptyView = rootView.findViewById(R.id.select_album_empty); registerForContextMenu(entryList); + load(false); return rootView; } @@ -84,6 +94,189 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap @Override protected void refresh() { - // load(true); + load(true); + } + + private void load(boolean refresh) { + Bundle args = getArguments(); + if(args != null) { + String id = args.getString(Constants.INTENT_EXTRA_NAME_ID); + String name = args.getString(Constants.INTENT_EXTRA_NAME_NAME); + String playlistId = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); + String playlistName = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); + String albumListType = args.getString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); + int albumListSize = args.getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0); + int albumListOffset = args.getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); + + if (playlistId != null) { + getPlaylist(playlistId, playlistName); + } else if (albumListType != null) { + getAlbumList(albumListType, albumListSize, albumListOffset); + } else { + getMusicDirectory(id, name, refresh); + } + } + } + + private void getMusicDirectory(final String id, final String name, final boolean refresh) { + // setTitle(name); + + new LoadTask() { + @Override + protected MusicDirectory load(MusicService service) throws Exception { + return service.getMusicDirectory(id, name, refresh, context, this); + } + }.execute(); + } + + private void getPlaylist(final String playlistId, final String playlistName) { + // setTitle(playlistName); + + new LoadTask() { + @Override + protected MusicDirectory load(MusicService service) throws Exception { + return service.getPlaylist(playlistId, playlistName, context, this); + } + }.execute(); + } + + private void getAlbumList(final String albumListType, final int size, final int offset) { + showHeader = false; + + /*if ("newest".equals(albumListType)) { + setTitle(R.string.main_albums_newest); + } else if ("random".equals(albumListType)) { + setTitle(R.string.main_albums_random); + } else if ("highest".equals(albumListType)) { + setTitle(R.string.main_albums_highest); + } else if ("recent".equals(albumListType)) { + setTitle(R.string.main_albums_recent); + } else if ("frequent".equals(albumListType)) { + setTitle(R.string.main_albums_frequent); + } else if ("starred".equals(albumListType)) { + setTitle(R.string.main_albums_starred); + }*/ + + new LoadTask() { + @Override + protected MusicDirectory load(MusicService service) throws Exception { + MusicDirectory result; + if ("starred".equals(albumListType)) { + result = service.getStarredList(context, this); + } else { + result = service.getAlbumList(albumListType, size, offset, context, this); + } + return result; + } + + @Override + protected void done(Pair result) { + if (!result.getFirst().getChildren().isEmpty()) { + if (!("starred".equals(albumListType))) { + moreButton.setVisibility(View.VISIBLE); + entryList.addFooterView(footer); + } + + moreButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + /*Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class); + String type = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); + int size = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0); + int offset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0) + size; + + intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type); + intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, size); + intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, offset); + Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent);*/ + } + }); + } + super.done(result); + } + }.execute(); + } + + private abstract class LoadTask extends TabBackgroundTask> { + + public LoadTask() { + super(SelectDirectoryFragment.this); + } + + protected abstract MusicDirectory load(MusicService service) throws Exception; + + @Override + protected Pair doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + MusicDirectory dir = load(musicService); + boolean valid = musicService.isLicenseValid(context, this); + return new Pair(dir, valid); + } + + @Override + protected void done(Pair result) { + entries = result.getFirst().getChildren(); + + int songCount = 0; + for (MusicDirectory.Entry entry : entries) { + if (!entry.isDirectory()) { + songCount++; + } + } + + if (songCount > 0) { + if(showHeader) { + entryList.addHeaderView(createHeader(entries), null, false); + } + } else { + hideButtons = true; + } + + emptyView.setVisibility(entries.isEmpty() ? View.VISIBLE : View.GONE); + entryList.setAdapter(entryAdapter = new EntryAdapter(context, getImageLoader(), entries, true)); + licenseValid = result.getSecond(); + // invalidateOptionsMenu(); + + /*boolean playAll = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); + if (playAll && songCount > 0) { + playAll(getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false), false); + }*/ + } + } + + private View createHeader(List entries) { + View header = LayoutInflater.from(context).inflate(R.layout.select_album_header, entryList, false); + + View coverArtView = header.findViewById(R.id.select_album_art); + getImageLoader().loadImage(coverArtView, entries.get(0), true, true); + + TextView titleView = (TextView) header.findViewById(R.id.select_album_title); + // titleView.setText(getTitle()); + + int songCount = 0; + + Set artists = new HashSet(); + for (MusicDirectory.Entry entry : entries) { + if (!entry.isDirectory()) { + songCount++; + if (entry.getArtist() != null) { + artists.add(entry.getArtist()); + } + } + } + + TextView artistView = (TextView) header.findViewById(R.id.select_album_artist); + if (artists.size() == 1) { + artistView.setText(artists.iterator().next()); + artistView.setVisibility(View.VISIBLE); + } else { + artistView.setVisibility(View.GONE); + } + + TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count); + String s = context.getResources().getQuantityString(R.plurals.select_album_n_songs, songCount, songCount); + songCountView.setText(s.toUpperCase()); + + return header; } } \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index 6d115bb9..9b79fd19 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -19,6 +19,7 @@ package github.daneren2005.dsub.fragments; import android.app.Activity; +import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.View; @@ -32,7 +33,6 @@ import github.daneren2005.dsub.util.ImageLoader; public class SubsonicTabFragment extends SherlockFragment { private static final String TAG = SubsonicTabActivity.class.getSimpleName(); - private static ImageLoader IMAGE_LOADER; protected SubsonicActivity context; protected View rootView; @@ -78,4 +78,11 @@ public class SubsonicTabFragment extends SherlockFragment { view.setText(message); } } + + protected synchronized ImageLoader getImageLoader() { + return context.getImageLoader(); + } + public synchronized static ImageLoader getStaticImageLoader(Context context) { + return SubsonicActivity.getStaticImageLoader(context); + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/view/EntryAdapter.java b/subsonic-android/src/github/daneren2005/dsub/view/EntryAdapter.java index 476d3478..0d67c4c4 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/EntryAdapter.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/EntryAdapter.java @@ -18,14 +18,12 @@ */ package github.daneren2005.dsub.view; -import github.daneren2005.dsub.view.AlbumView; -import github.daneren2005.dsub.view.SongView; +import android.content.Context; import java.util.List; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import github.daneren2005.dsub.activity.SubsonicTabActivity; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.util.ImageLoader; @@ -34,12 +32,12 @@ import github.daneren2005.dsub.util.ImageLoader; */ public class EntryAdapter extends ArrayAdapter { - private final SubsonicTabActivity activity; + private final Context activity; private final ImageLoader imageLoader; private final boolean checkable; private List entries; - public EntryAdapter(SubsonicTabActivity activity, ImageLoader imageLoader, List entries, boolean checkable) { + public EntryAdapter(Context activity, ImageLoader imageLoader, List entries, boolean checkable) { super(activity, android.R.layout.simple_list_item_1, entries); this.entries = entries; this.activity = activity; -- cgit v1.2.3 From bfef1d147657ce579ef52841201719b62f68c406 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 15 Mar 2013 18:33:21 -0700 Subject: Added clicking to get to directory fragment from home/playlist --- subsonic-android/res/layout/home.xml | 40 ++++++++++---------- subsonic-android/res/layout/select_playlist.xml | 44 +++++++++++----------- .../daneren2005/dsub/fragments/MainFragment.java | 27 ++++++++++--- .../dsub/fragments/SelectPlaylistFragment.java | 18 ++++++--- 4 files changed, 76 insertions(+), 53 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout/home.xml b/subsonic-android/res/layout/home.xml index 56b013fe..7f5d1255 100644 --- a/subsonic-android/res/layout/home.xml +++ b/subsonic-android/res/layout/home.xml @@ -1,28 +1,28 @@ + android:id="@+id/home_layout" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent"> - + - + - - - + + diff --git a/subsonic-android/res/layout/select_playlist.xml b/subsonic-android/res/layout/select_playlist.xml index 2555687d..07c818b5 100644 --- a/subsonic-android/res/layout/select_playlist.xml +++ b/subsonic-android/res/layout/select_playlist.xml @@ -1,32 +1,32 @@ + android:id="@+id/select_playlist_layout" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent"> - + - + - + - + - + diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index d179c150..6b753a22 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; +import android.support.v4.app.FragmentTransaction; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.View; @@ -144,17 +145,17 @@ public class MainFragment extends SubsonicTabFragment { } else if (view == offlineButton) { toggleOffline(); } else if (view == albumsNewestButton) { - // showAlbumList("newest"); + showAlbumList("newest"); } else if (view == albumsRandomButton) { - // showAlbumList("random"); + showAlbumList("random"); } else if (view == albumsHighestButton) { - // showAlbumList("highest"); + showAlbumList("highest"); } else if (view == albumsRecentButton) { - // showAlbumList("recent"); + showAlbumList("recent"); } else if (view == albumsFrequentButton) { - // showAlbumList("frequent"); + showAlbumList("frequent"); } else if (view == albumsStarredButton) { - // showAlbumList("starred"); + showAlbumList("starred"); } } }); @@ -191,4 +192,18 @@ public class MainFragment extends SubsonicTabFragment { Util.setOffline(context, !Util.isOffline(context)); refresh(); } + + private void showAlbumList(String type) { + SubsonicTabFragment fragment = new SelectDirectoryFragment(); + Bundle args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type); + args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20); + args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); + fragment.setArguments(args); + + final FragmentTransaction trans = getFragmentManager().beginTransaction(); + trans.replace(R.id.home_layout, fragment); + trans.addToBackStack(null); + trans.commit(); + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index eaba77e5..06fc9f66 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -2,6 +2,7 @@ package github.daneren2005.dsub.fragments; import android.content.Intent; import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -17,6 +18,7 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.CacheCleaner; +import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.PlaylistAdapter; @@ -106,11 +108,17 @@ public class SelectPlaylistFragment extends SubsonicTabFragment implements Adapt @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Playlist playlist = (Playlist) parent.getItemAtPosition(position); - - /*Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); - Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent);*/ + + SubsonicTabFragment fragment = new SelectDirectoryFragment(); + Bundle args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + fragment.setArguments(args); + + final FragmentTransaction trans = getFragmentManager().beginTransaction(); + trans.replace(R.id.select_playlist_layout, fragment); + trans.addToBackStack(null); + trans.commit(); } @Override -- cgit v1.2.3 From ebf090d1a6ce40f582625340d072a8428446dde7 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 16 Mar 2013 18:05:52 -0700 Subject: Removed bottom tabs + added clicks in Directory fragment --- subsonic-android/res/layout/home.xml | 5 -- subsonic-android/res/layout/select_album.xml | 38 +++++---- subsonic-android/res/layout/select_artist.xml | 2 - subsonic-android/res/layout/select_playlist.xml | 2 - .../dsub/fragments/SelectDirectoryFragment.java | 89 +++++++++++++--------- 5 files changed, 71 insertions(+), 65 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout/home.xml b/subsonic-android/res/layout/home.xml index 7f5d1255..018061fa 100644 --- a/subsonic-android/res/layout/home.xml +++ b/subsonic-android/res/layout/home.xml @@ -19,10 +19,5 @@ - - diff --git a/subsonic-android/res/layout/select_album.xml b/subsonic-android/res/layout/select_album.xml index b688a95b..0bf5367f 100644 --- a/subsonic-android/res/layout/select_album.xml +++ b/subsonic-android/res/layout/select_album.xml @@ -1,25 +1,26 @@ + android:id="@+id/select_album_layout" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent"> - + - + - + - - - - - + \ No newline at end of file diff --git a/subsonic-android/res/layout/select_artist.xml b/subsonic-android/res/layout/select_artist.xml index 4dd3471f..fef51d3c 100644 --- a/subsonic-android/res/layout/select_artist.xml +++ b/subsonic-android/res/layout/select_artist.xml @@ -18,7 +18,5 @@ android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1.0"/> - - diff --git a/subsonic-android/res/layout/select_playlist.xml b/subsonic-android/res/layout/select_playlist.xml index 07c818b5..e18283bd 100644 --- a/subsonic-android/res/layout/select_playlist.xml +++ b/subsonic-android/res/layout/select_playlist.xml @@ -26,7 +26,5 @@ android:layout_weight="1.0" android:fastScrollEnabled="true"/> - - diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index b393521b..392bf1c8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -2,6 +2,7 @@ package github.daneren2005.dsub.fragments; import android.content.Intent; import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -35,6 +36,14 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap private boolean showHeader = true; private EntryAdapter entryAdapter; private List entries; + + String id; + String name; + String playlistId; + String playlistName; + String albumListType; + int albumListSize; + int albumListOffset; @Override public void onCreate(Bundle bundle) { @@ -68,6 +77,17 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap emptyView = rootView.findViewById(R.id.select_album_empty); registerForContextMenu(entryList); + + Bundle args = getArguments(); + if(args != null) { + id = args.getString(Constants.INTENT_EXTRA_NAME_ID); + name = args.getString(Constants.INTENT_EXTRA_NAME_NAME); + playlistId = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); + playlistName = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); + albumListType = args.getString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); + albumListSize = args.getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0); + albumListOffset = args.getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); + } load(false); return rootView; @@ -77,18 +97,24 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap public void onItemClick(AdapterView parent, View view, int position, long id) { if (position >= 0) { MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position); - /*if (entry.isDirectory()) { - Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle()); - Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent); + if (entry.isDirectory()) { + SubsonicTabFragment fragment = new SelectDirectoryFragment(); + Bundle args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getId()); + args.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle()); + fragment.setArguments(args); + + final FragmentTransaction trans = getFragmentManager().beginTransaction(); + trans.replace(R.id.select_album_layout, fragment); + trans.addToBackStack(null); + trans.commit(); } else if (entry.isVideo()) { - if(entryExists(entry)) { + /*if(entryExists(entry)) { playExternalPlayer(entry); } else { streamExternalPlayer(entry); - } - }*/ + }*/ + } } } @@ -98,23 +124,14 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap } private void load(boolean refresh) { - Bundle args = getArguments(); - if(args != null) { - String id = args.getString(Constants.INTENT_EXTRA_NAME_ID); - String name = args.getString(Constants.INTENT_EXTRA_NAME_NAME); - String playlistId = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); - String playlistName = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); - String albumListType = args.getString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); - int albumListSize = args.getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0); - int albumListOffset = args.getInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); - - if (playlistId != null) { - getPlaylist(playlistId, playlistName); - } else if (albumListType != null) { - getAlbumList(albumListType, albumListSize, albumListOffset); - } else { - getMusicDirectory(id, name, refresh); - } + entryList.setVisibility(View.INVISIBLE); + emptyView.setVisibility(View.INVISIBLE); + if (playlistId != null) { + getPlaylist(playlistId, playlistName); + } else if (albumListType != null) { + getAlbumList(albumListType, albumListSize, albumListOffset); + } else { + getMusicDirectory(id, name, refresh); } } @@ -174,21 +191,16 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap if (!result.getFirst().getChildren().isEmpty()) { if (!("starred".equals(albumListType))) { moreButton.setVisibility(View.VISIBLE); - entryList.addFooterView(footer); + if(entryList.getFooterViewsCount() == 0) { + entryList.addFooterView(footer); + } } moreButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - /*Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class); - String type = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); - int size = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0); - int offset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0) + size; - - intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, size); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, offset); - Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent);*/ + albumListOffset += albumListSize; + refresh(); } }); } @@ -234,6 +246,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap emptyView.setVisibility(entries.isEmpty() ? View.VISIBLE : View.GONE); entryList.setAdapter(entryAdapter = new EntryAdapter(context, getImageLoader(), entries, true)); + entryList.setVisibility(View.VISIBLE); licenseValid = result.getSecond(); // invalidateOptionsMenu(); @@ -251,7 +264,11 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap getImageLoader().loadImage(coverArtView, entries.get(0), true, true); TextView titleView = (TextView) header.findViewById(R.id.select_album_title); - // titleView.setText(getTitle()); + if(playlistName != null) { + titleView.setText(playlistName); + } else if(name != null) { + titleView.setText(name); + } int songCount = 0; -- cgit v1.2.3 From 230762201cb64a54805f0350028841265f74bc3f Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 28 Mar 2013 21:00:34 -0700 Subject: Moved to using ActionBar tabs --- subsonic-android/res/layout/main.xml | 12 --- .../daneren2005/dsub/activity/MainActivity.java | 113 ++++++++++++++------- 2 files changed, 78 insertions(+), 47 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout/main.xml b/subsonic-android/res/layout/main.xml index f5c95b3f..823922dc 100644 --- a/subsonic-android/res/layout/main.xml +++ b/subsonic-android/res/layout/main.xml @@ -9,17 +9,5 @@ android:layout_width="match_parent" android:layout_height="0px" android:layout_weight="1" > - - - - \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index c012e4c8..a53be72a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -1,10 +1,15 @@ package github.daneren2005.dsub.activity; +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.ActionBar.Tab; +import com.actionbarsherlock.app.ActionBar.TabListener; +import com.actionbarsherlock.app.SherlockFragmentActivity; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; import github.daneren2005.dsub.R; import github.daneren2005.dsub.fragments.MainFragment; @@ -12,6 +17,8 @@ import github.daneren2005.dsub.fragments.SelectArtistFragment; import github.daneren2005.dsub.fragments.SelectPlaylistFragment; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.util.Util; +import java.util.ArrayList; +import java.util.List; public class MainActivity extends SubsonicActivity { private static final String TAG = MainActivity.class.getSimpleName(); @@ -23,10 +30,15 @@ public class MainActivity extends SubsonicActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); - - pagerAdapter = new MainActivityPagerAdapter(getSupportFragmentManager()); + viewPager = (ViewPager) findViewById(R.id.pager); + pagerAdapter = new MainActivityPagerAdapter(this, viewPager); viewPager.setAdapter(pagerAdapter); + viewPager.setOnPageChangeListener(pagerAdapter); + + addTab("Home", MainFragment.class, null); + addTab("Library", SelectArtistFragment.class, null); + addTab("Playlists", SelectPlaylistFragment.class, null); } @Override @@ -35,6 +47,7 @@ public class MainActivity extends SubsonicActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setHomeButtonEnabled(false); + getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); showInfoDialog(); } @@ -44,6 +57,13 @@ public class MainActivity extends SubsonicActivity { super.onResume(); } + protected void addTab(int titleRes, Class fragmentClass, Bundle args) { + pagerAdapter.addTab(getString(titleRes), fragmentClass, args); + } + protected void addTab(CharSequence title, Class fragmentClass, Bundle args) { + pagerAdapter.addTab(title, fragmentClass, args); + } + private void exit() { stopService(new Intent(this, DownloadServiceImpl.class)); finish(); @@ -58,51 +78,74 @@ public class MainActivity extends SubsonicActivity { } } - public class MainActivityPagerAdapter extends FragmentPagerAdapter { - private final String [] titles = new String [] { - "Home", - "Library", - "Playlists" - }; - public MainActivityPagerAdapter(FragmentManager fm) { - super(fm); + public class MainActivityPagerAdapter extends FragmentPagerAdapter implements TabListener, ViewPager.OnPageChangeListener { + private SherlockFragmentActivity activity; + private ViewPager pager; + private ActionBar actionBar; + private List tabs = new ArrayList(); + + public MainActivityPagerAdapter(SherlockFragmentActivity activity, ViewPager pager) { + super(activity.getSupportFragmentManager()); + this.activity = activity; + this.actionBar = activity.getSupportActionBar(); + this.pager = pager; } @Override public Fragment getItem(int i) { - Fragment fragment; - Bundle args = new Bundle(); - switch(i) { - case 0: - fragment = new MainFragment(); - break; - case 1: - fragment = new SelectArtistFragment(); - break; - case 2: - fragment = new SelectPlaylistFragment(); - break; - default: - fragment = null; - } - - if (fragment != null) { - fragment.setArguments(args); - } - - return fragment; + final TabInfo tabInfo = (TabInfo)tabs.get(i); + return (Fragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args ); } @Override public int getCount() { - return 3; + return tabs.size(); + } + + public void onTabSelected(Tab tab, FragmentTransaction ft) { + TabInfo tabInfo = (TabInfo) tab.getTag(); + for (int i = 0; i < tabs.size(); i++) { + if ( tabs.get(i) == tabInfo ) { + pager.setCurrentItem(i); + } + } + } + + public void onTabUnselected(Tab tab, FragmentTransaction ft) {} + + public void onTabReselected(Tab tab, FragmentTransaction ft) {} + + public void onPageScrollStateChanged(int arg0) {} + + public void onPageScrolled(int arg0, float arg1, int arg2) {} + + public void onPageSelected(int position) { + actionBar.setSelectedNavigationItem(position); + } + + public void addTab(CharSequence title, Class fragmentClass, Bundle args) { + final TabInfo tabInfo = new TabInfo(fragmentClass, args); + + Tab tab = actionBar.newTab(); + tab.setText(title); + tab.setTabListener(this); + tab.setTag(tabInfo); + + tabs.add(tabInfo); + + actionBar.addTab(tab); + notifyDataSetChanged(); } - @Override - public CharSequence getPageTitle(int position) { - return titles[position]; + private class TabInfo { + public final Class fragmentClass; + public final Bundle args; + public TabInfo(Class fragmentClass, Bundle args) { + this.fragmentClass = fragmentClass; + this.args = args; + } } } } -- cgit v1.2.3 From 5ac0c33e682709c0c079f47da271f837b4edfe9b Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 29 Mar 2013 20:27:22 -0700 Subject: Added menu to MainFragment, start of abstracted list of common functions --- .../daneren2005/dsub/activity/MainActivity.java | 44 ++++---- .../dsub/fragments/LibraryFunctionsFragment.java | 62 +++++++++++ .../daneren2005/dsub/fragments/MainFragment.java | 119 ++++++++++++++++++++- .../dsub/fragments/SubsonicTabFragment.java | 14 ++- 4 files changed, 212 insertions(+), 27 deletions(-) create mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index a53be72a..50fea96e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -30,12 +30,12 @@ public class MainActivity extends SubsonicActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); - + viewPager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new MainActivityPagerAdapter(this, viewPager); viewPager.setAdapter(pagerAdapter); viewPager.setOnPageChangeListener(pagerAdapter); - + addTab("Home", MainFragment.class, null); addTab("Library", SelectArtistFragment.class, null); addTab("Playlists", SelectPlaylistFragment.class, null); @@ -96,34 +96,34 @@ public class MainActivity extends SubsonicActivity { @Override public Fragment getItem(int i) { final TabInfo tabInfo = (TabInfo)tabs.get(i); - return (Fragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args ); + return (Fragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args ); } @Override public int getCount() { return tabs.size(); } - + public void onTabSelected(Tab tab, FragmentTransaction ft) { - TabInfo tabInfo = (TabInfo) tab.getTag(); - for (int i = 0; i < tabs.size(); i++) { - if ( tabs.get(i) == tabInfo ) { - pager.setCurrentItem(i); - } - } - } - - public void onTabUnselected(Tab tab, FragmentTransaction ft) {} - - public void onTabReselected(Tab tab, FragmentTransaction ft) {} - + TabInfo tabInfo = (TabInfo) tab.getTag(); + for (int i = 0; i < tabs.size(); i++) { + if ( tabs.get(i) == tabInfo ) { + pager.setCurrentItem(i); + } + } + } + + public void onTabUnselected(Tab tab, FragmentTransaction ft) {} + + public void onTabReselected(Tab tab, FragmentTransaction ft) {} + public void onPageScrollStateChanged(int arg0) {} - - public void onPageScrolled(int arg0, float arg1, int arg2) {} - - public void onPageSelected(int position) { - actionBar.setSelectedNavigationItem(position); - } + + public void onPageScrolled(int arg0, float arg1, int arg2) {} + + public void onPageSelected(int position) { + actionBar.setSelectedNavigationItem(position); + } public void addTab(CharSequence title, Class fragmentClass, Bundle args) { final TabInfo tabInfo = new TabInfo(fragmentClass, args); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java new file mode 100644 index 00000000..e21f164e --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java @@ -0,0 +1,62 @@ +package github.daneren2005.dsub.fragments; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.view.View; +import android.widget.EditText; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.activity.DownloadActivity; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.Util; + +public class LibraryFunctionsFragment extends SubsonicTabFragment { + protected void onShuffleRequested() { + if(Util.isOffline(context)) { + Intent intent = new Intent(context, DownloadActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); + Util.startActivityWithoutTransition(context, intent); + return; + } + + View dialogView = context.getLayoutInflater().inflate(R.layout.shuffle_dialog, null); + final EditText startYearBox = (EditText)dialogView.findViewById(R.id.start_year); + final EditText endYearBox = (EditText)dialogView.findViewById(R.id.end_year); + final EditText genreBox = (EditText)dialogView.findViewById(R.id.genre); + + final SharedPreferences prefs = Util.getPreferences(context); + final String oldStartYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, ""); + final String oldEndYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, ""); + final String oldGenre = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, ""); + + startYearBox.setText(oldStartYear); + endYearBox.setText(oldEndYear); + genreBox.setText(oldGenre); + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Shuffle By") + .setView(dialogView) + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + Intent intent = new Intent(context, DownloadActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); + String genre = genreBox.getText().toString(); + String startYear = startYearBox.getText().toString(); + String endYear = endYearBox.getText().toString(); + + SharedPreferences.Editor editor = prefs.edit(); + editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYear); + editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYear); + editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre); + editor.commit(); + + Util.startActivityWithoutTransition(context, intent); + } + }) + .setNegativeButton("Cancel", null); + AlertDialog dialog = builder.create(); + dialog.show(); + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 6b753a22..6f920896 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -1,8 +1,11 @@ package github.daneren2005.dsub.fragments; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Bundle; +import android.os.StatFs; import android.preference.PreferenceManager; import android.support.v4.app.FragmentTransaction; import android.view.ContextMenu; @@ -18,9 +21,19 @@ import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.MergeAdapter; 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.activity.HelpActivity; +import github.daneren2005.dsub.activity.MainActivity; +import github.daneren2005.dsub.activity.SettingsActivity; +import github.daneren2005.dsub.util.ModalBackgroundTask; +import java.io.File; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; -public class MainFragment extends SubsonicTabFragment { +public class MainFragment extends LibraryFunctionsFragment { private LayoutInflater inflater; private static final int MENU_GROUP_SERVER = 10; @@ -54,6 +67,41 @@ public class MainFragment extends SubsonicTabFragment { super.onDestroy(); } + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { + menuInflater.inflate(R.menu.main, menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + Intent intent; + switch (item.getItemId()) { + case R.id.menu_shuffle: + onShuffleRequested(); + return true; + case R.id.menu_search: + context.onSearchRequested(); + return true; + case R.id.menu_exit: + exit(); + return true; + case R.id.menu_settings: + startActivity(new Intent(context, SettingsActivity.class)); + return true; + case R.id.menu_help: + startActivity(new Intent(context, HelpActivity.class)); + return true; + case R.id.menu_log: + getLogs(); + return true; + case R.id.menu_about: + showAboutDialog(); + return true; + } + + return false; + } + @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); @@ -192,7 +240,7 @@ public class MainFragment extends SubsonicTabFragment { Util.setOffline(context, !Util.isOffline(context)); refresh(); } - + private void showAlbumList(String type) { SubsonicTabFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); @@ -206,4 +254,71 @@ public class MainFragment extends SubsonicTabFragment { trans.addToBackStack(null); trans.commit(); } + + private void showAboutDialog() { + try { + File rootFolder = FileUtil.getMusicDirectory(context); + StatFs stat = new StatFs(rootFolder.getPath()); + long bytesTotalFs = (long) stat.getBlockCount() * (long) stat.getBlockSize(); + long bytesAvailableFs = (long) stat.getAvailableBlocks() * (long) stat.getBlockSize(); + + String msg = getResources().getString(R.string.main_about_text, + context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName, + Util.formatBytes(FileUtil.getUsedSize(context, rootFolder)), + Util.formatBytes(Util.getCacheSizeMB(context) * 1024L * 1024L), + Util.formatBytes(bytesAvailableFs), + Util.formatBytes(bytesTotalFs)); + Util.info(context, R.string.main_about_title, msg); + } catch(Exception e) { + Util.toast(context, "Failed to open dialog"); + } + } + + private void getLogs() { + try { + final String version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; + new ModalBackgroundTask(context, false) { + @Override + protected File doInBackground() throws Throwable { + updateProgress("Gathering Logs"); + File logcat = new File(FileUtil.getSubsonicDirectory(), "logcat.txt"); + Process logcatProc = null; + + try { + List progs = new ArrayList(); + progs.add("logcat"); + progs.add("-v"); + progs.add("time"); + progs.add("-d"); + progs.add("-f"); + progs.add(logcat.getPath()); + progs.add("*:I"); + + logcatProc = Runtime.getRuntime().exec(progs.toArray(new String[0])); + logcatProc.waitFor(); + } catch(Exception e) { + Util.toast(context, "Failed to gather logs"); + } finally { + if(logcatProc != null) { + logcatProc.destroy(); + } + } + + return logcat; + } + + @Override + protected void done(File logcat) { + Intent email = new Intent(android.content.Intent.ACTION_SEND); + email.setType("text/plain"); + email.putExtra(Intent.EXTRA_EMAIL, new String[] {"daneren2005@gmail.com"}); + email.putExtra(Intent.EXTRA_SUBJECT, "DSub " + version + " Error Logs"); + email.putExtra(Intent.EXTRA_TEXT, "Describe the problem here"); + Uri attachment = Uri.fromFile(logcat); + email.putExtra(Intent.EXTRA_STREAM, attachment); + startActivity(email); + } + }.execute(); + } catch(Exception e) {} + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index 9b79fd19..ee608378 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -20,6 +20,7 @@ package github.daneren2005.dsub.fragments; import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; @@ -29,6 +30,7 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.activity.SubsonicTabActivity; import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.util.ImageLoader; public class SubsonicTabFragment extends SherlockFragment { @@ -39,6 +41,7 @@ public class SubsonicTabFragment extends SherlockFragment { @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); + setHasOptionsMenu(true); } @Override @@ -65,6 +68,11 @@ public class SubsonicTabFragment extends SherlockFragment { } + protected void exit() { + context.stopService(new Intent(context, DownloadServiceImpl.class)); + context.finish(); + } + public void setProgressVisible(boolean visible) { View view = rootView.findViewById(R.id.tab_progress); if (view != null) { @@ -78,10 +86,10 @@ public class SubsonicTabFragment extends SherlockFragment { view.setText(message); } } - + protected synchronized ImageLoader getImageLoader() { - return context.getImageLoader(); - } + return context.getImageLoader(); + } public synchronized static ImageLoader getStaticImageLoader(Context context) { return SubsonicActivity.getStaticImageLoader(context); } -- cgit v1.2.3 From 00e4dd2979924373a1fdce33beba6018144c59a3 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 29 Mar 2013 21:26:02 -0700 Subject: Abstracted out common menu items --- .../dsub/fragments/LibraryFunctionsFragment.java | 30 ++++++++++++++++++++++ .../daneren2005/dsub/fragments/MainFragment.java | 23 +++-------------- 2 files changed, 34 insertions(+), 19 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java index e21f164e..ff238a9f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java @@ -10,8 +10,38 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.DownloadActivity; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.Util; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuItem; +import github.daneren2005.dsub.activity.HelpActivity; +import github.daneren2005.dsub.activity.SettingsActivity; public class LibraryFunctionsFragment extends SubsonicTabFragment { + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_refresh: + refresh(); + return true; + case R.id.menu_shuffle: + onShuffleRequested(); + return true; + case R.id.menu_search: + context.onSearchRequested(); + return true; + case R.id.menu_exit: + exit(); + return true; + case R.id.menu_settings: + startActivity(new Intent(context, SettingsActivity.class)); + return true; + case R.id.menu_help: + startActivity(new Intent(context, HelpActivity.class)); + return true; + } + + return false; + } + protected void onShuffleRequested() { if(Util.isOffline(context)) { Intent intent = new Intent(context, DownloadActivity.class); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 6f920896..8217839a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -24,9 +24,6 @@ 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.activity.HelpActivity; -import github.daneren2005.dsub.activity.MainActivity; -import github.daneren2005.dsub.activity.SettingsActivity; import github.daneren2005.dsub.util.ModalBackgroundTask; import java.io.File; import java.util.ArrayList; @@ -74,23 +71,11 @@ public class MainFragment extends LibraryFunctionsFragment { @Override public boolean onOptionsItemSelected(MenuItem item) { - Intent intent; + if(super.onOptionsItemSelected(item)) { + return true; + } + switch (item.getItemId()) { - case R.id.menu_shuffle: - onShuffleRequested(); - return true; - case R.id.menu_search: - context.onSearchRequested(); - return true; - case R.id.menu_exit: - exit(); - return true; - case R.id.menu_settings: - startActivity(new Intent(context, SettingsActivity.class)); - return true; - case R.id.menu_help: - startActivity(new Intent(context, HelpActivity.class)); - return true; case R.id.menu_log: getLogs(); return true; -- cgit v1.2.3 From 28a6d2c923f78d8e14ee5ec38f920c8e7a64debd Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 30 Mar 2013 10:08:19 -0700 Subject: Added menus to other fragments as well --- .../dsub/fragments/SelectArtistFragment.java | 19 +++++- .../dsub/fragments/SelectDirectoryFragment.java | 79 ++++++++++++++++++++-- .../dsub/fragments/SelectPlaylistFragment.java | 18 ++++- .../dsub/fragments/SubsonicTabFragment.java | 7 ++ 4 files changed, 114 insertions(+), 9 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 12a58678..5cb5c454 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -8,6 +8,7 @@ import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.MenuInflater; import android.view.MenuItem; +import com.actionbarsherlock.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -27,7 +28,7 @@ import github.daneren2005.dsub.view.ArtistAdapter; import java.util.ArrayList; import java.util.List; -public class SelectArtistFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { +public class SelectArtistFragment extends LibraryFunctionsFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectArtistFragment.class.getSimpleName(); private static final int MENU_GROUP_MUSIC_FOLDER = 10; @@ -61,6 +62,20 @@ public class SelectArtistFragment extends SubsonicTabFragment implements Adapter return rootView; } + @Override + public void onCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + menuInflater.inflate(R.menu.select_artist, menu); + } + + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + if(super.onOptionsItemSelected(item)) { + return true; + } + + return false; + } + @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); @@ -145,7 +160,7 @@ public class SelectArtistFragment extends SubsonicTabFragment implements Adapter args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); fragment.setArguments(args); - + final FragmentTransaction trans = getFragmentManager().beginTransaction(); trans.replace(R.id.select_artist_layout, fragment); trans.addToBackStack(null); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 392bf1c8..cc3baf2e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -21,6 +21,7 @@ import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.Pair; import github.daneren2005.dsub.util.TabBackgroundTask; +import github.daneren2005.dsub.util.Util; import java.util.HashSet; import java.util.Set; @@ -92,6 +93,74 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap return rootView; } + + @Override + public void onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + if(licenseValid == null) { + menuInflater.inflate(R.menu.empty, menu); + } + else if(hideButtons) { + if(albumListType != null) { + menuInflater.inflate(R.menu.select_album_list, menu); + } else { + menuInflater.inflate(R.menu.select_album, menu); + } + hideButtons = false; + } else { + if(Util.isOffline(context)) { + menuInflater.inflate(R.menu.select_song_offline, menu); + } + else { + menuInflater.inflate(R.menu.select_song, menu); + + if(playlistId == null) { + menu.removeItem(R.id.menu_remove_playlist); + } + } + } + } + + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + /*switch (item.getItemId()) { + case R.id.menu_play_now: + playNow(false, false); + return true; + case R.id.menu_play_last: + playNow(false, true); + return true; + case R.id.menu_shuffle: + playNow(true, false); + return true; + case R.id.menu_select: + selectAllOrNone(); + return true; + case R.id.menu_download: + downloadBackground(false); + selectAll(false, false); + return true; + case R.id.menu_cache: + downloadBackground(true); + selectAll(false, false); + return true; + case R.id.menu_delete: + delete(); + selectAll(false, false); + return true; + case R.id.menu_add_playlist: + addToPlaylist(getSelectedSongs()); + return true; + case R.id.menu_remove_playlist: + removeFromPlaylist(playlistId, playlistName, getSelectedIndexes()); + return true; + }*/ + + if(super.onOptionsItemSelected(item)) { + return true; + } + + return false; + } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -136,7 +205,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap } private void getMusicDirectory(final String id, final String name, final boolean refresh) { - // setTitle(name); + setTitle(name); new LoadTask() { @Override @@ -147,7 +216,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap } private void getPlaylist(final String playlistId, final String playlistName) { - // setTitle(playlistName); + setTitle(playlistName); new LoadTask() { @Override @@ -160,7 +229,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap private void getAlbumList(final String albumListType, final int size, final int offset) { showHeader = false; - /*if ("newest".equals(albumListType)) { + if ("newest".equals(albumListType)) { setTitle(R.string.main_albums_newest); } else if ("random".equals(albumListType)) { setTitle(R.string.main_albums_random); @@ -172,7 +241,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap setTitle(R.string.main_albums_frequent); } else if ("starred".equals(albumListType)) { setTitle(R.string.main_albums_starred); - }*/ + } new LoadTask() { @Override @@ -248,7 +317,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap entryList.setAdapter(entryAdapter = new EntryAdapter(context, getImageLoader(), entries, true)); entryList.setVisibility(View.VISIBLE); licenseValid = result.getSecond(); - // invalidateOptionsMenu(); + context.invalidateOptionsMenu(); /*boolean playAll = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); if (playAll && songCount > 0) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 06fc9f66..04fe700b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -24,7 +24,7 @@ import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.PlaylistAdapter; import java.util.List; -public class SelectPlaylistFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { +public class SelectPlaylistFragment extends LibraryFunctionsFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectPlaylistFragment.class.getSimpleName(); private ListView list; @@ -49,6 +49,20 @@ public class SelectPlaylistFragment extends SubsonicTabFragment implements Adapt return rootView; } + @Override + public void onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + menuInflater.inflate(R.menu.select_playlist, menu); + } + + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + if(super.onOptionsItemSelected(item)) { + return true; + } + + return false; + } + @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); @@ -108,7 +122,7 @@ public class SelectPlaylistFragment extends SubsonicTabFragment implements Adapt @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Playlist playlist = (Playlist) parent.getItemAtPosition(position); - + SubsonicTabFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index ee608378..e853c594 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -93,4 +93,11 @@ public class SubsonicTabFragment extends SherlockFragment { public synchronized static ImageLoader getStaticImageLoader(Context context) { return SubsonicActivity.getStaticImageLoader(context); } + + protected void setTitle(CharSequence title) { + context.setTitle(title); + } + protected void setTitle(int title) { + context.setTitle(title); + } } -- cgit v1.2.3 From ad6f8cccb59632110076d4c7d1b5b9add9603734 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 31 Mar 2013 21:27:14 -0700 Subject: Added back a lot of the common menus for SelectDirectoryFragment --- .../dsub/fragments/LibraryFunctionsFragment.java | 297 ++++++++++++++++++++ .../dsub/fragments/SelectDirectoryFragment.java | 307 +++++++++++++++++++-- 2 files changed, 585 insertions(+), 19 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java index ff238a9f..6f90107b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java @@ -4,6 +4,8 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.media.MediaMetadataRetriever; +import android.util.Log; import android.view.View; import android.widget.EditText; import github.daneren2005.dsub.R; @@ -14,8 +16,28 @@ import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; import github.daneren2005.dsub.activity.HelpActivity; import github.daneren2005.dsub.activity.SettingsActivity; +import github.daneren2005.dsub.activity.SubsonicTabActivity; +import github.daneren2005.dsub.domain.Artist; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.Playlist; +import github.daneren2005.dsub.service.DownloadFile; +import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.service.OfflineException; +import github.daneren2005.dsub.service.ServerTooOldException; +import github.daneren2005.dsub.util.FileUtil; +import github.daneren2005.dsub.util.LoadingTask; +import github.daneren2005.dsub.util.ModalBackgroundTask; +import github.daneren2005.dsub.util.SilentBackgroundTask; +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; public class LibraryFunctionsFragment extends SubsonicTabFragment { + private static final String TAG = LibraryFunctionsFragment.class.getSimpleName(); + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { @@ -89,4 +111,279 @@ public class LibraryFunctionsFragment extends SubsonicTabFragment { AlertDialog dialog = builder.create(); dialog.show(); } + + public void toggleStarred(final MusicDirectory.Entry entry) { + final boolean starred = !entry.isStarred(); + entry.setStarred(starred); + + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.setStarred(entry.getId(), starred, context, null); + return null; + } + + @Override + protected void done(Void result) { + // UpdateView + Util.toast(context, context.getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getTitle())); + } + + @Override + protected void error(Throwable error) { + entry.setStarred(!starred); + + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.starring_content_error, entry.getTitle()) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute(); + } + public void toggleStarred(final Artist entry) { + final boolean starred = !entry.isStarred(); + entry.setStarred(starred); + + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.setStarred(entry.getId(), starred, context, null); + return null; + } + + @Override + protected void done(Void result) { + // UpdateView + Util.toast(context, context.getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getName())); + } + + @Override + protected void error(Throwable error) { + entry.setStarred(!starred); + + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.starring_content_error, entry.getName()) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute(); + } + + protected void downloadRecursively(final String id, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { + downloadRecursively(id, "", true, save, append, autoplay, shuffle, background); + } + protected void downloadPlaylist(final String id, final String name, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { + downloadRecursively(id, name, false, save, append, autoplay, shuffle, background); + } + protected void downloadRecursively(final String id, final String name, final boolean isDirectory, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { + ModalBackgroundTask> task = new ModalBackgroundTask>(context, false) { + private static final int MAX_SONGS = 500; + + @Override + protected List doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + MusicDirectory root; + if(isDirectory) + root = musicService.getMusicDirectory(id, name, false, context, this); + else + root = musicService.getPlaylist(id, name, context, this); + List songs = new LinkedList(); + getSongsRecursively(root, songs); + return songs; + } + + private void getSongsRecursively(MusicDirectory parent, List songs) throws Exception { + if (songs.size() > MAX_SONGS) { + return; + } + + for (MusicDirectory.Entry song : parent.getChildren(false, true)) { + if (!song.isVideo()) { + songs.add(song); + } + } + for (MusicDirectory.Entry dir : parent.getChildren(true, false)) { + MusicService musicService = MusicServiceFactory.getMusicService(context); + getSongsRecursively(musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, context, this), songs); + } + } + + @Override + protected void done(List songs) { + DownloadService downloadService = getDownloadService(); + if (!songs.isEmpty() && downloadService != null) { + if (!append) { + downloadService.clear(); + } + warnIfNetworkOrStorageUnavailable(); + if(!background) { + downloadService.download(songs, save, autoplay, false, shuffle); + if(!append) { + Util.startActivityWithoutTransition(context, DownloadActivity.class); + } + } + else { + downloadService.downloadBackground(songs, save); + } + } + } + }; + + task.execute(); + } + + protected void addToPlaylist(final List songs) { + if(songs.isEmpty()) { + Util.toast(context, "No songs selected"); + return; + } + + /*new LoadingTask>(context, true) { + @Override + protected List doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + return musicService.getPlaylists(false, context, this); + } + + @Override + protected void done(final List playlists) { + List names = new ArrayList(); + for(Playlist playlist: playlists) { + names.add(playlist.getName()); + } + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Add to Playlist") + .setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + addToPlaylist(playlists.get(which), songs); + } + }); + AlertDialog dialog = builder.create(); + dialog.show(); + } + + @Override + protected void error(Throwable error) { + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.playlist_error) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute();*/ + } + + private void addToPlaylist(final Playlist playlist, final List songs) { + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.addToPlaylist(playlist.getId(), songs, context, null); + return null; + } + + @Override + protected void done(Void result) { + Util.toast(context, context.getResources().getString(R.string.updated_playlist, songs.size(), playlist.getName())); + } + + @Override + protected void error(Throwable error) { + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.updated_playlist_error, playlist.getName()) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute(); + } + + public void displaySongInfo(final MusicDirectory.Entry song) { + Integer bitrate = null; + String format = null; + long size = 0; + try { + DownloadFile downloadFile = new DownloadFile(context, song, false); + File file = downloadFile.getCompleteFile(); + if(file.exists()) { + MediaMetadataRetriever metadata = new MediaMetadataRetriever(); + metadata.setDataSource(file.getAbsolutePath()); + String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); + bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000; + format = FileUtil.getExtension(file.getName()); + size = file.length(); + + if(Util.isOffline(context)) { + song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)); + String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR); + song.setYear(Integer.parseInt((year != null) ? year : "0")); + } + } + } catch(Exception e) { + Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver"); + } + + String msg = ""; + if(!song.isVideo()) { + msg += "Artist: " + song.getArtist() + "\nAlbum: " + song.getAlbum(); + } + if(song.getTrack() != null && song.getTrack() != 0) { + msg += "\nTrack: " + song.getTrack(); + } + if(song.getGenre() != null && !"".equals(song.getGenre())) { + msg += "\nGenre: " + song.getGenre(); + } + if(song.getYear() != null && song.getYear() != 0) { + msg += "\nYear: " + song.getYear(); + } + if(!Util.isOffline(context)) { + msg += "\nServer Format: " + song.getSuffix(); + if(song.getBitRate() != null && song.getBitRate() != 0) { + msg += "\nServer Bitrate: " + song.getBitRate() + " kpbs"; + } + } + if(format != null && !"".equals(format)) { + msg += "\nCached Format: " + format; + } + if(bitrate != null && bitrate != 0) { + msg += "\nCached Bitrate: " + bitrate + " kpbs"; + } + if(size != 0) { + msg += "\nSize: " + Util.formatBytes(size); + } + if(song.getDuration() != null && song.getDuration() != 0) { + msg += "\nLength: " + Util.formatDuration(song.getDuration()); + } + + new AlertDialog.Builder(context) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle(song.getTitle()) + .setMessage(msg) + .show(); + } + + protected void warnIfNetworkOrStorageUnavailable() { + if (!Util.isExternalStoragePresent()) { + Util.toast(context, R.string.select_album_no_sdcard); + } else if (!Util.isOffline(context) && !Util.isNetworkConnected(context)) { + Util.toast(context, R.string.select_album_no_network); + } + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index cc3baf2e..8ce9d6d5 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -1,6 +1,11 @@ package github.daneren2005.dsub.fragments; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.net.Uri; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; import android.util.Log; @@ -16,16 +21,21 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.view.EntryAdapter; import java.util.List; import com.mobeta.android.dslv.*; +import github.daneren2005.dsub.activity.DownloadActivity; +import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.Pair; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; +import java.io.File; +import java.util.ArrayList; import java.util.HashSet; import java.util.Set; -public class SelectDirectoryFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { +public class SelectDirectoryFragment extends LibraryFunctionsFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectDirectoryFragment.class.getSimpleName(); private DragSortListView entryList; @@ -37,7 +47,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap private boolean showHeader = true; private EntryAdapter entryAdapter; private List entries; - + String id; String name; String playlistId; @@ -78,7 +88,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap emptyView = rootView.findViewById(R.id.select_album_empty); registerForContextMenu(entryList); - + Bundle args = getArguments(); if(args != null) { id = args.getString(Constants.INTENT_EXTRA_NAME_ID); @@ -93,7 +103,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap return rootView; } - + @Override public void onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { if(licenseValid == null) { @@ -112,17 +122,17 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap } else { menuInflater.inflate(R.menu.select_song, menu); - + if(playlistId == null) { menu.removeItem(R.id.menu_remove_playlist); } } } } - + @Override - public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { - /*switch (item.getItemId()) { + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + switch (item.getItemId()) { case R.id.menu_play_now: playNow(false, false); return true; @@ -137,30 +147,30 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap return true; case R.id.menu_download: downloadBackground(false); - selectAll(false, false); + selectAll(false, false); return true; case R.id.menu_cache: downloadBackground(true); - selectAll(false, false); + selectAll(false, false); return true; case R.id.menu_delete: delete(); - selectAll(false, false); + selectAll(false, false); return true; case R.id.menu_add_playlist: - addToPlaylist(getSelectedSongs()); + // addToPlaylist(getSelectedSongs()); return true; case R.id.menu_remove_playlist: - removeFromPlaylist(playlistId, playlistName, getSelectedIndexes()); + // removeFromPlaylist(playlistId, playlistName, getSelectedIndexes()); return true; - }*/ - + } + if(super.onOptionsItemSelected(item)) { return true; } - return false; - } + return false; + } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -178,11 +188,11 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap trans.addToBackStack(null); trans.commit(); } else if (entry.isVideo()) { - /*if(entryExists(entry)) { + if(entryExists(entry)) { playExternalPlayer(entry); } else { streamExternalPlayer(entry); - }*/ + } } } } @@ -326,6 +336,265 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap } } + private void playNow(final boolean shuffle, final boolean append) { + if(getSelectedSongs().size() > 0) { + download(append, false, !append, false, shuffle); + selectAll(false, false); + } + else { + playAll(shuffle, append); + } + } + private void playAll(final boolean shuffle, final boolean append) { + boolean hasSubFolders = false; + for (int i = 0; i < entryList.getCount(); i++) { + MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i); + if (entry != null && entry.isDirectory()) { + hasSubFolders = true; + break; + } + } + + if (hasSubFolders && id != null) { + downloadRecursively(id, false, append, !append, shuffle, false); + } else { + selectAll(true, false); + download(append, false, !append, false, shuffle); + selectAll(false, false); + } + } + + private void selectAllOrNone() { + boolean someUnselected = false; + int count = entryList.getCount(); + for (int i = 0; i < count; i++) { + if (!entryList.isItemChecked(i) && entryList.getItemAtPosition(i) instanceof MusicDirectory.Entry) { + someUnselected = true; + break; + } + } + selectAll(someUnselected, true); + } + + private void selectAll(boolean selected, boolean toast) { + int count = entryList.getCount(); + int selectedCount = 0; + for (int i = 0; i < count; i++) { + MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i); + if (entry != null && !entry.isDirectory() && !entry.isVideo()) { + entryList.setItemChecked(i, selected); + selectedCount++; + } + } + + // Display toast: N tracks selected / N tracks unselected + if (toast) { + int toastResId = selected ? R.string.select_album_n_selected + : R.string.select_album_n_unselected; + Util.toast(context, context.getString(toastResId, selectedCount)); + } + } + + private List getSelectedSongs() { + List songs = new ArrayList(10); + int count = entryList.getCount(); + for (int i = 0; i < count; i++) { + if (entryList.isItemChecked(i)) { + songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(i)); + } + } + return songs; + } + + private List getSelectedIndexes() { + List indexes = new ArrayList(); + + int count = entryList.getCount(); + for (int i = 0; i < count; i++) { + if (entryList.isItemChecked(i)) { + indexes.add(i - 1); + } + } + + return indexes; + } + + private void download(final boolean append, final boolean save, final boolean autoplay, final boolean playNext, final boolean shuffle) { + if (getDownloadService() == null) { + return; + } + + final List songs = getSelectedSongs(); + Runnable onValid = new Runnable() { + @Override + public void run() { + if (!append) { + getDownloadService().clear(); + } + + warnIfNetworkOrStorageUnavailable(); + getDownloadService().download(songs, save, autoplay, playNext, shuffle); + if (playlistName != null) { + getDownloadService().setSuggestedPlaylistName(playlistName); + } + if (autoplay) { + Util.startActivityWithoutTransition(context, DownloadActivity.class); + } else if (save) { + Util.toast(context, + context.getResources().getQuantityString(R.plurals.select_album_n_songs_downloading, songs.size(), songs.size())); + } else if (append) { + Util.toast(context, + context.getResources().getQuantityString(R.plurals.select_album_n_songs_added, songs.size(), songs.size())); + } + } + }; + + checkLicenseAndTrialPeriod(onValid); + } + private void downloadBackground(final boolean save) { + List songs = getSelectedSongs(); + if(songs.isEmpty()) { + selectAll(true, false); + songs = getSelectedSongs(); + } + downloadBackground(save, songs); + } + private void downloadBackground(final boolean save, final List songs) { + if (getDownloadService() == null) { + return; + } + + Runnable onValid = new Runnable() { + @Override + public void run() { + warnIfNetworkOrStorageUnavailable(); + getDownloadService().downloadBackground(songs, save); + + Util.toast(context, + context.getResources().getQuantityString(R.plurals.select_album_n_songs_downloading, songs.size(), songs.size())); + } + }; + + checkLicenseAndTrialPeriod(onValid); + } + + private void delete() { + List songs = getSelectedSongs(); + if(songs.isEmpty()) { + selectAll(true, false); + songs = getSelectedSongs(); + } + if (getDownloadService() != null) { + getDownloadService().delete(songs); + } + } + + private boolean entryExists(MusicDirectory.Entry entry) { + DownloadFile check = new DownloadFile(context, entry, false); + return check.isCompleteFileAvailable(); + } + + private void playWebView(MusicDirectory.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 playExternalPlayer(MusicDirectory.Entry entry) { + if(!entryExists(entry)) { + Util.toast(context, R.string.download_need_download); + } else { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.parse(entry.getPath()), "video/*"); + + List intents = context.getPackageManager() + .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); + if(intents != null && intents.size() > 0) { + startActivity(intent); + }else { + Util.toast(context, R.string.download_no_streaming_player); + } + } + } + private void streamExternalPlayer(MusicDirectory.Entry entry) { + int maxBitrate = Util.getMaxVideoBitrate(context); + + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoStreamUrl(maxBitrate, context, entry.getId())), "video/*"); + + List intents = context.getPackageManager() + .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); + if(intents != null && intents.size() > 0) { + startActivity(intent); + } else { + Util.toast(context, R.string.download_no_streaming_player); + } + } + + public void deleteRecursively(MusicDirectory.Entry album) { + File dir = FileUtil.getAlbumDirectory(context, album); + Util.recursiveDelete(dir); + if(Util.isOffline(context)) { + refresh(); + } + } + + private void checkLicenseAndTrialPeriod(Runnable onValid) { + if (licenseValid) { + onValid.run(); + return; + } + + int trialDaysLeft = Util.getRemainingTrialDays(context); + Log.i(TAG, trialDaysLeft + " trial days left."); + + if (trialDaysLeft == 0) { + showDonationDialog(trialDaysLeft, null); + } else if (trialDaysLeft < Constants.FREE_TRIAL_DAYS / 2) { + showDonationDialog(trialDaysLeft, onValid); + } else { + Util.toast(context, context.getResources().getString(R.string.select_album_not_licensed, trialDaysLeft)); + onValid.run(); + } + } + + private void showDonationDialog(int trialDaysLeft, final Runnable onValid) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setIcon(android.R.drawable.ic_dialog_info); + + if (trialDaysLeft == 0) { + builder.setTitle(R.string.select_album_donate_dialog_0_trial_days_left); + } else { + builder.setTitle(context.getResources().getQuantityString(R.plurals.select_album_donate_dialog_n_trial_days_left, + trialDaysLeft, trialDaysLeft)); + } + + builder.setMessage(R.string.select_album_donate_dialog_message); + + builder.setPositiveButton(R.string.select_album_donate_dialog_now, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.DONATION_URL))); + } + }); + + builder.setNegativeButton(R.string.select_album_donate_dialog_later, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + dialogInterface.dismiss(); + if (onValid != null) { + onValid.run(); + } + } + }); + + builder.create().show(); + } + private View createHeader(List entries) { View header = LayoutInflater.from(context).inflate(R.layout.select_album_header, entryList, false); -- cgit v1.2.3 From b3841c04a7961cac98a8ec0e63e07d0613d7a08d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 31 Mar 2013 21:35:36 -0700 Subject: Put back others --- .../dsub/fragments/SelectDirectoryFragment.java | 37 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 8ce9d6d5..d6f35479 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -158,10 +158,10 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements selectAll(false, false); return true; case R.id.menu_add_playlist: - // addToPlaylist(getSelectedSongs()); + addToPlaylist(getSelectedSongs()); return true; case R.id.menu_remove_playlist: - // removeFromPlaylist(playlistId, playlistName, getSelectedIndexes()); + removeFromPlaylist(playlistId, playlistName, getSelectedIndexes()); return true; } @@ -541,6 +541,39 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements } } + public void removeFromPlaylist(final String id, final String name, final List indexes) { + /*new LoadingTask(this, true) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this); + musicService.removeFromPlaylist(id, indexes, SelectAlbumActivity.this, null); + return null; + } + + @Override + protected void done(Void result) { + for(int i = indexes.size() - 1; i >= 0; i--) { + entryList.setItemChecked(indexes.get(i) + 1, false); + entryAdapter.removeAt(indexes.get(i)); + } + entryAdapter.notifyDataSetChanged(); + Util.toast(SelectAlbumActivity.this, getResources().getString(R.string.removed_playlist, indexes.size(), name)); + } + + @Override + protected void error(Throwable error) { + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = getResources().getString(R.string.updated_playlist_error, name) + " " + getErrorMessage(error); + } + + Util.toast(SelectAlbumActivity.this, msg, false); + } + }.execute();*/ + } + private void checkLicenseAndTrialPeriod(Runnable onValid) { if (licenseValid) { onValid.run(); -- cgit v1.2.3 From 118f50723871c30290fea0b4ea52f1d6f535da27 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 4 Apr 2013 19:51:56 -0700 Subject: Pressing back goes to home tab, confirm to exit --- .../daneren2005/dsub/activity/MainActivity.java | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 50fea96e..454a729d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -1,5 +1,7 @@ package github.daneren2005.dsub.activity; +import android.app.AlertDialog; +import android.content.DialogInterface; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.ActionBar.Tab; import com.actionbarsherlock.app.ActionBar.TabListener; @@ -56,6 +58,32 @@ public class MainActivity extends SubsonicActivity { public void onResume() { super.onResume(); } + + @Override + public void onBackPressed() { + int backStack = getSupportFragmentManager().getBackStackEntryCount(); + int currentTab = viewPager.getCurrentItem(); + + if(backStack == 0) { + if(currentTab == 0) { + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setTitle("Confirm Exit") + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + MainActivity.super.onBackPressed(); + } + }) + .setNegativeButton("Cancel", null); + AlertDialog dialog = builder.create(); + dialog.show(); + } else { + viewPager.setCurrentItem(0); + } + } else { + super.onBackPressed(); + } + } protected void addTab(int titleRes, Class fragmentClass, Bundle args) { pagerAdapter.addTab(getString(titleRes), fragmentClass, args); @@ -109,6 +137,7 @@ public class MainActivity extends SubsonicActivity { for (int i = 0; i < tabs.size(); i++) { if ( tabs.get(i) == tabInfo ) { pager.setCurrentItem(i); + break; } } } -- cgit v1.2.3 From 10c34bbef00729ec3e9c234cc6b8a1b582d1a58d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 8 Apr 2013 21:24:12 -0700 Subject: Merged from master --- .../src/github/daneren2005/dsub/activity/MainActivity.java | 6 +++--- .../github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java | 4 ++-- .../src/github/daneren2005/dsub/fragments/MainFragment.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index c2a49751..565e0264 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -67,14 +67,14 @@ public class MainActivity extends SubsonicActivity { if(backStack == 0) { if(currentTab == 0) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - builder.setTitle("Confirm Exit") - .setPositiveButton("OK", new DialogInterface.OnClickListener() { + builder.setTitle(R.string.common_confirm) + .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { MainActivity.super.onBackPressed(); } }) - .setNegativeButton("Cancel", null); + .setNegativeButton(R.string.common_cancel, null); AlertDialog dialog = builder.create(); dialog.show(); } else { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java index 6f90107b..1bfd2e39 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java @@ -89,7 +89,7 @@ public class LibraryFunctionsFragment extends SubsonicTabFragment { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Shuffle By") .setView(dialogView) - .setPositiveButton("OK", new DialogInterface.OnClickListener() { + .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(context, DownloadActivity.class); @@ -107,7 +107,7 @@ public class LibraryFunctionsFragment extends SubsonicTabFragment { Util.startActivityWithoutTransition(context, intent); } }) - .setNegativeButton("Cancel", null); + .setNegativeButton(R.string.common_cancel, null); AlertDialog dialog = builder.create(); dialog.show(); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 8217839a..3ebc09aa 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -296,7 +296,7 @@ public class MainFragment extends LibraryFunctionsFragment { protected void done(File logcat) { Intent email = new Intent(android.content.Intent.ACTION_SEND); email.setType("text/plain"); - email.putExtra(Intent.EXTRA_EMAIL, new String[] {"daneren2005@gmail.com"}); + email.putExtra(Intent.EXTRA_EMAIL, new String[] {"dsub.android@gmail.com"}); email.putExtra(Intent.EXTRA_SUBJECT, "DSub " + version + " Error Logs"); email.putExtra(Intent.EXTRA_TEXT, "Describe the problem here"); Uri attachment = Uri.fromFile(logcat); -- cgit v1.2.3 From 4cfab2e30b973e824381205271f55bb808282051 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 8 Apr 2013 21:58:21 -0700 Subject: Added context menus to SelectPlaylistFragment --- .../dsub/activity/SelectAlbumActivity.java | 4 +- .../dsub/activity/SelectPlaylistActivity.java | 8 +- .../dsub/activity/SubsonicTabActivity.java | 4 +- .../dsub/fragments/SelectDirectoryFragment.java | 24 +-- .../dsub/fragments/SelectPlaylistFragment.java | 161 +++++++++++++++++++-- .../github/daneren2005/dsub/util/LoadingTask.java | 6 +- 6 files changed, 170 insertions(+), 37 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java index 5016135c..6432c385 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java @@ -764,7 +764,7 @@ public class SelectAlbumActivity extends SubsonicTabActivity { } public void removeFromPlaylist(final String id, final String name, final List indexes) { - new LoadingTask(this, true) { + /*new LoadingTask(this, true) { @Override protected Void doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this); @@ -793,6 +793,6 @@ public class SelectAlbumActivity extends SubsonicTabActivity { Util.toast(SelectAlbumActivity.this, msg, false); } - }.execute(); + }.execute();*/ } } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java index 855f4502..7e6775ab 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java @@ -197,7 +197,7 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - new LoadingTask(SelectPlaylistActivity.this, false) { + /*new LoadingTask(SelectPlaylistActivity.this, false) { @Override protected Void doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); @@ -223,7 +223,7 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt Util.toast(SelectPlaylistActivity.this, msg, false); } - }.execute(); + }.execute();*/ } }) @@ -266,7 +266,7 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - new LoadingTask(SelectPlaylistActivity.this, false) { + /*new LoadingTask(SelectPlaylistActivity.this, false) { @Override protected Void doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); @@ -291,7 +291,7 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt Util.toast(SelectPlaylistActivity.this, msg, false); } - }.execute(); + }.execute();*/ } }) diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index 9d868255..2a457073 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -389,7 +389,7 @@ public class SubsonicTabActivity extends SherlockActivity { return; } - new LoadingTask>(this, true) { + /*new LoadingTask>(this, true) { @Override protected List doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this); @@ -425,7 +425,7 @@ public class SubsonicTabActivity extends SherlockActivity { Util.toast(SubsonicTabActivity.this, msg, false); } - }.execute(); + }.execute();*/ } private void addToPlaylist(final Playlist playlist, final List songs) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index d6f35479..c4e9c625 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -25,8 +25,11 @@ import github.daneren2005.dsub.activity.DownloadActivity; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.MusicService; 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; import github.daneren2005.dsub.util.Util; @@ -329,10 +332,11 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements licenseValid = result.getSecond(); context.invalidateOptionsMenu(); - /*boolean playAll = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); + Bundle args = getArguments(); + boolean playAll = args.getBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); if (playAll && songCount > 0) { - playAll(getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false), false); - }*/ + playAll(args.getBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, false), false); + } } } @@ -542,11 +546,11 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements } public void removeFromPlaylist(final String id, final String name, final List indexes) { - /*new LoadingTask(this, true) { + new LoadingTask(context, true) { @Override protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this); - musicService.removeFromPlaylist(id, indexes, SelectAlbumActivity.this, null); + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.removeFromPlaylist(id, indexes, context, null); return null; } @@ -557,7 +561,7 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements entryAdapter.removeAt(indexes.get(i)); } entryAdapter.notifyDataSetChanged(); - Util.toast(SelectAlbumActivity.this, getResources().getString(R.string.removed_playlist, indexes.size(), name)); + Util.toast(context, context.getResources().getString(R.string.removed_playlist, indexes.size(), name)); } @Override @@ -566,12 +570,12 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements if (error instanceof OfflineException || error instanceof ServerTooOldException) { msg = getErrorMessage(error); } else { - msg = getResources().getString(R.string.updated_playlist_error, name) + " " + getErrorMessage(error); + msg = context.getResources().getString(R.string.updated_playlist_error, name) + " " + getErrorMessage(error); } - Util.toast(SelectAlbumActivity.this, msg, false); + Util.toast(context, msg, false); } - }.execute();*/ + }.execute(); } private void checkLicenseAndTrialPeriod(Runnable onValid) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 04fe700b..49bff0fe 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -1,5 +1,7 @@ package github.daneren2005.dsub.fragments; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; @@ -11,14 +13,19 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; +import android.widget.CheckBox; +import android.widget.EditText; import android.widget.ListView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.Playlist; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.service.OfflineException; +import github.daneren2005.dsub.service.ServerTooOldException; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.CacheCleaner; import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.PlaylistAdapter; @@ -81,8 +88,10 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); Playlist playlist = (Playlist) list.getItemAtPosition(info.position); - Intent intent; - /*switch (menuItem.getItemId()) { + SubsonicTabFragment fragment; + Bundle args; + FragmentTransaction trans; + switch (menuItem.getItemId()) { case R.id.playlist_menu_download: downloadPlaylist(playlist.getId(), playlist.getName(), false, true, false, false, true); break; @@ -90,19 +99,29 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements downloadPlaylist(playlist.getId(), playlist.getName(), true, true, false, false, true); break; case R.id.playlist_menu_play_now: - intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); - Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); + fragment = new SelectDirectoryFragment(); + args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + fragment.setArguments(args); + + trans = getFragmentManager().beginTransaction(); + trans.replace(R.id.select_playlist_layout, fragment); + trans.addToBackStack(null); + trans.commit(); break; case R.id.playlist_menu_play_shuffled: - intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); - intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); - Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); + fragment = new SelectDirectoryFragment(); + args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + args.putBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); + fragment.setArguments(args); + + trans = getFragmentManager().beginTransaction(); + trans.replace(R.id.select_playlist_layout, fragment); + trans.addToBackStack(null); + trans.commit(); break; case R.id.playlist_menu_delete: deletePlaylist(playlist); @@ -114,8 +133,8 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements updatePlaylistInfo(playlist); break; default: - return super.onContextItemSelected(menuItem); - }*/ + return false; + } return true; } @@ -129,7 +148,7 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); fragment.setArguments(args); - final FragmentTransaction trans = getFragmentManager().beginTransaction(); + FragmentTransaction trans = getFragmentManager().beginTransaction(); trans.replace(R.id.select_playlist_layout, fragment); trans.addToBackStack(null); trans.commit(); @@ -160,4 +179,114 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements }; task.execute(); } + + private void deletePlaylist(final Playlist playlist) { + new AlertDialog.Builder(context) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle(R.string.common_confirm) + .setMessage(context.getResources().getString(R.string.delete_playlist, playlist.getName())) + .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + new LoadingTask(context, false) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.deletePlaylist(playlist.getId(), context, null); + return null; + } + + @Override + protected void done(Void result) { + playlistAdapter.remove(playlist); + playlistAdapter.notifyDataSetChanged(); + Util.toast(context, context.getResources().getString(R.string.menu_deleted_playlist, playlist.getName())); + } + + @Override + protected void error(Throwable error) { + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.menu_deleted_playlist_error, playlist.getName()) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute(); + } + + }) + .setNegativeButton(R.string.common_cancel, null) + .show(); + } + + private void displayPlaylistInfo(final Playlist playlist) { + String message = "Owner: " + playlist.getOwner() + "\nComments: " + + ((playlist.getComment() == null) ? "" : playlist.getComment()) + + "\nSong Count: " + playlist.getSongCount() + + ((playlist.getPublic() == null) ? "" : ("\nPublic: " + playlist.getPublic())) + + "\nCreation Date: " + playlist.getCreated().replace('T', ' '); + new AlertDialog.Builder(context) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle(playlist.getName()) + .setMessage(message) + .show(); + } + + private void updatePlaylistInfo(final Playlist playlist) { + View dialogView = context.getLayoutInflater().inflate(R.layout.update_playlist, null); + final EditText nameBox = (EditText)dialogView.findViewById(R.id.get_playlist_name); + final EditText commentBox = (EditText)dialogView.findViewById(R.id.get_playlist_comment); + final CheckBox publicBox = (CheckBox)dialogView.findViewById(R.id.get_playlist_public); + + nameBox.setText(playlist.getName()); + commentBox.setText(playlist.getComment()); + Boolean pub = playlist.getPublic(); + if(pub == null) { + publicBox.setEnabled(false); + } else { + publicBox.setChecked(pub); + } + + new AlertDialog.Builder(context) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle(R.string.playlist_update_info) + .setView(dialogView) + .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + new LoadingTask(context, false) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.updatePlaylist(playlist.getId(), nameBox.getText().toString(), commentBox.getText().toString(), publicBox.isChecked(), context, null); + return null; + } + + @Override + protected void done(Void result) { + refresh(); + Util.toast(context, context.getResources().getString(R.string.playlist_updated_info, playlist.getName())); + } + + @Override + protected void error(Throwable error) { + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.playlist_updated_info_error, playlist.getName()) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute(); + } + + }) + .setNegativeButton(R.string.common_cancel, null) + .show(); + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java b/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java index 0875742f..0b48a338 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/LoadingTask.java @@ -2,7 +2,7 @@ package github.daneren2005.dsub.util; import android.app.ProgressDialog; import android.content.DialogInterface; -import github.daneren2005.dsub.activity.SubsonicTabActivity; +import github.daneren2005.dsub.activity.SubsonicActivity; /** * @author Sindre Mehus @@ -10,11 +10,11 @@ import github.daneren2005.dsub.activity.SubsonicTabActivity; */ public abstract class LoadingTask extends BackgroundTask { - private final SubsonicTabActivity tabActivity; + private final SubsonicActivity tabActivity; private final boolean cancellable; private boolean cancelled = false; - public LoadingTask(SubsonicTabActivity activity, final boolean cancellable) { + public LoadingTask(SubsonicActivity activity, final boolean cancellable) { super(activity); tabActivity = activity; this.cancellable = cancellable; -- cgit v1.2.3 From f90950e5fe3ce29231683ff88b3a3b1e150857fe Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 10 Apr 2013 18:05:00 -0700 Subject: Move to a better way to know which fragment has priority --- .../github/daneren2005/dsub/activity/MainActivity.java | 15 ++++++++++++++- .../daneren2005/dsub/fragments/SubsonicTabFragment.java | 9 ++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 565e0264..15ae1ac5 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -8,6 +8,7 @@ import com.actionbarsherlock.app.ActionBar.TabListener; import com.actionbarsherlock.app.SherlockFragmentActivity; import android.content.Intent; import android.os.Bundle; +import com.actionbarsherlock.app.SherlockFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; @@ -17,6 +18,7 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.fragments.MainFragment; import github.daneren2005.dsub.fragments.SelectArtistFragment; import github.daneren2005.dsub.fragments.SelectPlaylistFragment; +import github.daneren2005.dsub.fragments.SubsonicTabFragment; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.util.Util; import java.util.ArrayList; @@ -112,7 +114,9 @@ public class MainActivity extends SubsonicActivity { private SherlockFragmentActivity activity; private ViewPager pager; private ActionBar actionBar; + private SubsonicTabFragment currentFragment; private List tabs = new ArrayList(); + private List frags = new ArrayList(); public MainActivityPagerAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); @@ -124,7 +128,9 @@ public class MainActivity extends SubsonicActivity { @Override public Fragment getItem(int i) { final TabInfo tabInfo = (TabInfo)tabs.get(i); - return (Fragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args ); + SherlockFragment frag = (SherlockFragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args); + frags.add(i, frag); + return frag; } @Override @@ -152,6 +158,13 @@ public class MainActivity extends SubsonicActivity { public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); + if(currentFragment != null) { + currentFragment.setPrimaryFragment(false); + } + currentFragment = (SubsonicTabFragment) frags.get(position); + if(currentFragment != null) { + currentFragment.setPrimaryFragment(true); + } } public void addTab(CharSequence title, Class fragmentClass, Bundle args) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index e853c594..75d6973c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -41,7 +41,6 @@ public class SubsonicTabFragment extends SherlockFragment { @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); - setHasOptionsMenu(true); } @Override @@ -93,6 +92,14 @@ public class SubsonicTabFragment extends SherlockFragment { public synchronized static ImageLoader getStaticImageLoader(Context context) { return SubsonicActivity.getStaticImageLoader(context); } + + public void setPrimaryFragment(boolean primary) { + if(primary) { + setHasOptionsMenu(true); + } else { + setHasOptionsMenu(false); + } + } protected void setTitle(CharSequence title) { context.setTitle(title); -- cgit v1.2.3 From b5045fbb838a941e4ba1114311ab5c67b254c7f0 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 10 Apr 2013 18:07:37 -0700 Subject: Make sure title is changed on primary fragment change --- .../src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index 75d6973c..cbb4d3a2 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -36,6 +36,7 @@ import github.daneren2005.dsub.util.ImageLoader; public class SubsonicTabFragment extends SherlockFragment { private static final String TAG = SubsonicTabActivity.class.getSimpleName(); protected SubsonicActivity context; + protected CharSequence title = "DSub"; protected View rootView; @Override @@ -96,15 +97,18 @@ public class SubsonicTabFragment extends SherlockFragment { public void setPrimaryFragment(boolean primary) { if(primary) { setHasOptionsMenu(true); + context.setTitle(title); } else { setHasOptionsMenu(false); } } protected void setTitle(CharSequence title) { + this.title = title; context.setTitle(title); } protected void setTitle(int title) { - context.setTitle(title); + this.title = context.getResources().getString(title); + context.setTitle(this.title); } } -- cgit v1.2.3 From 076dd2ca25d8d7a5f7a741a57ad66230937f0de2 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 10 Apr 2013 18:43:02 -0700 Subject: Show menu for default fragment --- .../src/github/daneren2005/dsub/activity/MainActivity.java | 4 ++++ .../src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 15ae1ac5..c64d87a8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -130,6 +130,10 @@ public class MainActivity extends SubsonicActivity { final TabInfo tabInfo = (TabInfo)tabs.get(i); SherlockFragment frag = (SherlockFragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args); frags.add(i, frag); + if(currentFragment == null) { + currentFragment = (SubsonicTabFragment) frag; + currentFragment.setPrimaryFragment(true); + } return frag; } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index cbb4d3a2..88696d00 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -97,7 +97,9 @@ public class SubsonicTabFragment extends SherlockFragment { public void setPrimaryFragment(boolean primary) { if(primary) { setHasOptionsMenu(true); - context.setTitle(title); + if(context != null) { + context.setTitle(title); + } } else { setHasOptionsMenu(false); } -- cgit v1.2.3 From e6fa8b0d0c201c8c788f9f0c9d8ecea71948bafd Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 10 Apr 2013 19:14:56 -0700 Subject: Smoother menu transition --- .../github/daneren2005/dsub/fragments/MainFragment.java | 2 +- .../dsub/fragments/SelectArtistFragment.java | 2 +- .../dsub/fragments/SelectDirectoryFragment.java | 2 +- .../dsub/fragments/SelectPlaylistFragment.java | 2 +- .../daneren2005/dsub/fragments/SubsonicTabFragment.java | 17 +++++++++++++++-- 5 files changed, 19 insertions(+), 6 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 3ebc09aa..e9134257 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -65,7 +65,7 @@ public class MainFragment extends LibraryFunctionsFragment { } @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { + public void onSupportCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { menuInflater.inflate(R.menu.main, menu); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 5cb5c454..cf53862b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -63,7 +63,7 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad } @Override - public void onCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + public void onSupportCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { menuInflater.inflate(R.menu.select_artist, menu); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index c4e9c625..ea730db7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -108,7 +108,7 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements } @Override - public void onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + public void onSupportCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { if(licenseValid == null) { menuInflater.inflate(R.menu.empty, menu); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 49bff0fe..67e26b9a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -57,7 +57,7 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements } @Override - public void onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + public void onSupportCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { menuInflater.inflate(R.menu.select_playlist, menu); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index 88696d00..f3e283e0 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -26,6 +26,7 @@ import android.util.Log; import android.view.View; import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragment; +import com.actionbarsherlock.view.Menu; import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.activity.SubsonicTabActivity; @@ -38,10 +39,12 @@ public class SubsonicTabFragment extends SherlockFragment { protected SubsonicActivity context; protected CharSequence title = "DSub"; protected View rootView; + private boolean primaryFragment = false; @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); + setHasOptionsMenu(true); } @Override @@ -59,6 +62,16 @@ public class SubsonicTabFragment extends SherlockFragment { super.onAttach(activity); context = (SubsonicActivity)activity; } + + @Override + public void onCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + if(primaryFragment) { + onSupportCreateOptionsMenu(menu, menuInflater); + } + } + public void onSupportCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + + } public DownloadService getDownloadService() { return context != null ? context.getDownloadService() : null; @@ -96,12 +109,12 @@ public class SubsonicTabFragment extends SherlockFragment { public void setPrimaryFragment(boolean primary) { if(primary) { - setHasOptionsMenu(true); + primaryFragment = true; if(context != null) { context.setTitle(title); } } else { - setHasOptionsMenu(false); + primaryFragment = false; } } -- cgit v1.2.3 From 1f8d2d2a0e600e502fea109be825034bc4725a31 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 10 Apr 2013 19:26:18 -0700 Subject: Use a centrally defined replace function --- .../github/daneren2005/dsub/fragments/MainFragment.java | 6 +----- .../daneren2005/dsub/fragments/SelectArtistFragment.java | 5 +---- .../dsub/fragments/SelectDirectoryFragment.java | 5 +---- .../dsub/fragments/SelectPlaylistFragment.java | 5 +---- .../daneren2005/dsub/fragments/SubsonicTabFragment.java | 15 ++++++++++++--- 5 files changed, 16 insertions(+), 20 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index e9134257..8f3682bd 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -7,7 +7,6 @@ import android.net.Uri; import android.os.Bundle; import android.os.StatFs; import android.preference.PreferenceManager; -import android.support.v4.app.FragmentTransaction; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.View; @@ -234,10 +233,7 @@ public class MainFragment extends LibraryFunctionsFragment { args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); fragment.setArguments(args); - final FragmentTransaction trans = getFragmentManager().beginTransaction(); - trans.replace(R.id.home_layout, fragment); - trans.addToBackStack(null); - trans.commit(); + replaceFragment(fragment, R.id.home_layout); } private void showAboutDialog() { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index cf53862b..0efac370 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -161,10 +161,7 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); fragment.setArguments(args); - final FragmentTransaction trans = getFragmentManager().beginTransaction(); - trans.replace(R.id.select_artist_layout, fragment); - trans.addToBackStack(null); - trans.commit(); + replaceFragment(fragment, R.id.select_artist_layout); } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index ea730db7..cba310a3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -186,10 +186,7 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements args.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle()); fragment.setArguments(args); - final FragmentTransaction trans = getFragmentManager().beginTransaction(); - trans.replace(R.id.select_album_layout, fragment); - trans.addToBackStack(null); - trans.commit(); + replaceFragment(fragment, R.id.select_album_layout); } else if (entry.isVideo()) { if(entryExists(entry)) { playExternalPlayer(entry); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 67e26b9a..35684be9 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -148,10 +148,7 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); fragment.setArguments(args); - FragmentTransaction trans = getFragmentManager().beginTransaction(); - trans.replace(R.id.select_playlist_layout, fragment); - trans.addToBackStack(null); - trans.commit(); + replaceFragment(fragment, R.id.select_playlist_layout); } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index f3e283e0..639284b8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -22,6 +22,7 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.View; import android.widget.TextView; @@ -80,6 +81,16 @@ public class SubsonicTabFragment extends SherlockFragment { protected void refresh() { } + + public void replaceFragment(SubsonicTabFragment fragment, int id) { + this.setPrimaryFragment(false); + fragment.setPrimaryFragment(true); + + FragmentTransaction trans = getFragmentManager().beginTransaction(); + trans.replace(id, fragment); + trans.addToBackStack(null); + trans.commit(); + } protected void exit() { context.stopService(new Intent(context, DownloadServiceImpl.class)); @@ -108,13 +119,11 @@ public class SubsonicTabFragment extends SherlockFragment { } public void setPrimaryFragment(boolean primary) { + primaryFragment = primary; if(primary) { - primaryFragment = true; if(context != null) { context.setTitle(title); } - } else { - primaryFragment = false; } } -- cgit v1.2.3 From d412253327b0009b1da083503bb91f2512f6a307 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 11 Apr 2013 18:36:47 -0700 Subject: Move to keeping track of which menus should be shown manually, fragment manager sucks at it --- .../daneren2005/dsub/activity/MainActivity.java | 126 ++--------------- .../dsub/activity/SubsonicActivity.java | 156 ++++++++++++++++++++- .../daneren2005/dsub/fragments/MainFragment.java | 2 +- .../dsub/fragments/SelectArtistFragment.java | 2 +- .../dsub/fragments/SelectDirectoryFragment.java | 2 +- .../dsub/fragments/SelectPlaylistFragment.java | 2 +- .../dsub/fragments/SubsonicTabFragment.java | 12 +- 7 files changed, 174 insertions(+), 128 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index c64d87a8..06925e8b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -2,33 +2,22 @@ package github.daneren2005.dsub.activity; import android.app.AlertDialog; import android.content.DialogInterface; -import com.actionbarsherlock.app.ActionBar; -import com.actionbarsherlock.app.ActionBar.Tab; -import com.actionbarsherlock.app.ActionBar.TabListener; -import com.actionbarsherlock.app.SherlockFragmentActivity; import android.content.Intent; import android.os.Bundle; -import com.actionbarsherlock.app.SherlockFragment; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.app.FragmentTransaction; +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.view.Menu; import android.support.v4.view.ViewPager; +import android.util.Log; import github.daneren2005.dsub.R; import github.daneren2005.dsub.fragments.MainFragment; import github.daneren2005.dsub.fragments.SelectArtistFragment; import github.daneren2005.dsub.fragments.SelectPlaylistFragment; -import github.daneren2005.dsub.fragments.SubsonicTabFragment; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.util.Util; -import java.util.ArrayList; -import java.util.List; public class MainActivity extends SubsonicActivity { private static final String TAG = MainActivity.class.getSimpleName(); private static boolean infoDialogDisplayed; - private MainActivityPagerAdapter pagerAdapter; - private ViewPager viewPager; @Override public void onCreate(Bundle savedInstanceState) { @@ -36,7 +25,7 @@ public class MainActivity extends SubsonicActivity { setContentView(R.layout.main); viewPager = (ViewPager) findViewById(R.id.pager); - pagerAdapter = new MainActivityPagerAdapter(this, viewPager); + pagerAdapter = new TabPagerAdapter(this, viewPager); viewPager.setAdapter(pagerAdapter); viewPager.setOnPageChangeListener(pagerAdapter); @@ -84,19 +73,19 @@ public class MainActivity extends SubsonicActivity { } } else { super.onBackPressed(); + pagerAdapter.removeCurrent(); } } - - protected void addTab(int titleRes, Class fragmentClass, Bundle args) { - pagerAdapter.addTab(getString(titleRes), fragmentClass, args); - } - protected void addTab(CharSequence title, Class fragmentClass, Bundle args) { - pagerAdapter.addTab(title, fragmentClass, args); + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + com.actionbarsherlock.view.MenuInflater menuInflater = getSupportMenuInflater(); + pagerAdapter.onCreateOptionsMenu(menu, menuInflater); + return true; } - - private void exit() { - stopService(new Intent(this, DownloadServiceImpl.class)); - finish(); + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + return pagerAdapter.onOptionsItemSelected(item); } private void showInfoDialog() { @@ -107,91 +96,4 @@ public class MainActivity extends SubsonicActivity { } } } - - - - public class MainActivityPagerAdapter extends FragmentPagerAdapter implements TabListener, ViewPager.OnPageChangeListener { - private SherlockFragmentActivity activity; - private ViewPager pager; - private ActionBar actionBar; - private SubsonicTabFragment currentFragment; - private List tabs = new ArrayList(); - private List frags = new ArrayList(); - - public MainActivityPagerAdapter(SherlockFragmentActivity activity, ViewPager pager) { - super(activity.getSupportFragmentManager()); - this.activity = activity; - this.actionBar = activity.getSupportActionBar(); - this.pager = pager; - } - - @Override - public Fragment getItem(int i) { - final TabInfo tabInfo = (TabInfo)tabs.get(i); - SherlockFragment frag = (SherlockFragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args); - frags.add(i, frag); - if(currentFragment == null) { - currentFragment = (SubsonicTabFragment) frag; - currentFragment.setPrimaryFragment(true); - } - return frag; - } - - @Override - public int getCount() { - return tabs.size(); - } - - public void onTabSelected(Tab tab, FragmentTransaction ft) { - TabInfo tabInfo = (TabInfo) tab.getTag(); - for (int i = 0; i < tabs.size(); i++) { - if ( tabs.get(i) == tabInfo ) { - pager.setCurrentItem(i); - break; - } - } - } - - public void onTabUnselected(Tab tab, FragmentTransaction ft) {} - - public void onTabReselected(Tab tab, FragmentTransaction ft) {} - - public void onPageScrollStateChanged(int arg0) {} - - public void onPageScrolled(int arg0, float arg1, int arg2) {} - - public void onPageSelected(int position) { - actionBar.setSelectedNavigationItem(position); - if(currentFragment != null) { - currentFragment.setPrimaryFragment(false); - } - currentFragment = (SubsonicTabFragment) frags.get(position); - if(currentFragment != null) { - currentFragment.setPrimaryFragment(true); - } - } - - public void addTab(CharSequence title, Class fragmentClass, Bundle args) { - final TabInfo tabInfo = new TabInfo(fragmentClass, args); - - Tab tab = actionBar.newTab(); - tab.setText(title); - tab.setTabListener(this); - tab.setTag(tabInfo); - - tabs.add(tabInfo); - - actionBar.addTab(tab); - notifyDataSetChanged(); - } - - private class TabInfo { - public final Class fragmentClass; - public final Bundle args; - public TabInfo(Class fragmentClass, Bundle args) { - this.fragmentClass = fragmentClass; - this.args = args; - } - } - } } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index bada0da0..61a8c18c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -7,14 +7,21 @@ import android.media.AudioManager; import android.os.Build; import android.os.Bundle; import android.os.Environment; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.app.FragmentTransaction; +import android.support.v4.view.ViewPager; import android.util.Log; import android.view.KeyEvent; import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.ActionBar.Tab; +import com.actionbarsherlock.app.ActionBar.TabListener; import com.actionbarsherlock.app.SherlockFragmentActivity; +import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; -import com.actionbarsherlock.view.Window; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.fragments.SubsonicTabFragment; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.updates.Updater; @@ -22,12 +29,16 @@ import github.daneren2005.dsub.util.ImageLoader; import github.daneren2005.dsub.util.Util; import java.io.File; import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; public class SubsonicActivity extends SherlockFragmentActivity { private static final String TAG = SubsonicActivity.class.getSimpleName(); private static ImageLoader IMAGE_LOADER; protected static String theme; private boolean destroyed = false; + protected TabPagerAdapter pagerAdapter; + protected ViewPager viewPager; @Override protected void onCreate(Bundle bundle) { @@ -75,6 +86,13 @@ public class SubsonicActivity extends SherlockFragmentActivity { } return super.onKeyDown(keyCode, event); } + + protected void addTab(int titleRes, Class fragmentClass, Bundle args) { + pagerAdapter.addTab(getString(titleRes), fragmentClass, args); + } + protected void addTab(CharSequence title, Class fragmentClass, Bundle args) { + pagerAdapter.addTab(title, fragmentClass, args); + } protected void restart() { Intent intent = new Intent(this, this.getClass()); @@ -132,6 +150,13 @@ public class SubsonicActivity extends SherlockFragmentActivity { } return DownloadServiceImpl.getInstance(); } + + public ViewPager getViewPager() { + return viewPager; + } + public TabPagerAdapter getPagerAdapter() { + return pagerAdapter; + } private void setUncaughtExceptionHandler() { Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); @@ -191,4 +216,133 @@ public class SubsonicActivity extends SherlockFragmentActivity { } } + + public class TabPagerAdapter extends FragmentPagerAdapter implements TabListener, ViewPager.OnPageChangeListener { + private SherlockFragmentActivity activity; + private ViewPager pager; + private ActionBar actionBar; + private SubsonicTabFragment currentFragment; + private List tabs = new ArrayList(); + private List frags = new ArrayList(); + private int currentPosition; + + public TabPagerAdapter(SherlockFragmentActivity activity, ViewPager pager) { + super(activity.getSupportFragmentManager()); + this.activity = activity; + this.actionBar = activity.getSupportActionBar(); + this.pager = pager; + this.currentPosition = 0; + } + + @Override + public Fragment getItem(int i) { + final TabInfo tabInfo = (TabInfo)tabs.get(i); + SherlockFragment frag = (SherlockFragment) Fragment.instantiate(activity, tabInfo.fragmentClass.getName(), tabInfo.args); + List fragStack = new ArrayList(); + fragStack.add(frag); + frags.add(i, fragStack); + if(currentFragment == null) { + currentFragment = (SubsonicTabFragment) frag; + currentFragment.setPrimaryFragment(true); + } + return frag; + } + + @Override + public int getCount() { + return tabs.size(); + } + + public void onCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + if(currentFragment != null) { + currentFragment.onCreateOptionsMenu(menu, menuInflater); + } + } + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + if(currentFragment != null) { + return currentFragment.onOptionsItemSelected(item); + } else { + return false; + } + } + + public void onTabSelected(Tab tab, FragmentTransaction ft) { + TabInfo tabInfo = (TabInfo) tab.getTag(); + for (int i = 0; i < tabs.size(); i++) { + if ( tabs.get(i) == tabInfo ) { + pager.setCurrentItem(i); + break; + } + } + } + + public void onTabUnselected(Tab tab, FragmentTransaction ft) {} + + public void onTabReselected(Tab tab, FragmentTransaction ft) {} + + public void onPageScrollStateChanged(int arg0) {} + + public void onPageScrolled(int arg0, float arg1, int arg2) {} + + public void onPageSelected(int position) { + currentPosition = position; + actionBar.setSelectedNavigationItem(position); + if(currentFragment != null) { + currentFragment.setPrimaryFragment(false); + } + List fragStack = (List)frags.get(position); + currentFragment = (SubsonicTabFragment) fragStack.get(fragStack.size() - 1); + if(currentFragment != null) { + currentFragment.setPrimaryFragment(true); + } + activity.invalidateOptionsMenu(); + } + + public void addTab(CharSequence title, Class fragmentClass, Bundle args) { + final TabInfo tabInfo = new TabInfo(fragmentClass, args); + + Tab tab = actionBar.newTab(); + tab.setText(title); + tab.setTabListener(this); + tab.setTag(tabInfo); + + tabs.add(tabInfo); + + actionBar.addTab(tab); + notifyDataSetChanged(); + } + + public void replaceCurrent(SubsonicTabFragment fragment) { + if(currentFragment != null) { + currentFragment.setPrimaryFragment(false); + } + List fragStack = (List)frags.get(currentPosition); + fragStack.add(fragment); + + currentFragment = fragment; + currentFragment.setPrimaryFragment(true); + activity.invalidateOptionsMenu(); + } + + public void removeCurrent() { + if(currentFragment != null) { + currentFragment.setPrimaryFragment(false); + } + List fragStack = (List)frags.get(currentPosition); + fragStack.remove(fragStack.size() - 1); + + currentFragment = (SubsonicTabFragment) fragStack.get(fragStack.size() - 1); + currentFragment.setPrimaryFragment(true); + activity.invalidateOptionsMenu(); + } + + private class TabInfo { + public final Class fragmentClass; + public final Bundle args; + public TabInfo(Class fragmentClass, Bundle args) { + this.fragmentClass = fragmentClass; + this.args = args; + } + } + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 8f3682bd..ae382cd1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -64,7 +64,7 @@ public class MainFragment extends LibraryFunctionsFragment { } @Override - public void onSupportCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { + public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { menuInflater.inflate(R.menu.main, menu); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 0efac370..4e8d26e9 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -63,7 +63,7 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad } @Override - public void onSupportCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + public void onCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { menuInflater.inflate(R.menu.select_artist, menu); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index cba310a3..92155fe1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -108,7 +108,7 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements } @Override - public void onSupportCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + public void onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { if(licenseValid == null) { menuInflater.inflate(R.menu.empty, menu); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 35684be9..b09fe802 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -57,7 +57,7 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements } @Override - public void onSupportCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + public void onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { menuInflater.inflate(R.menu.select_playlist, menu); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index 639284b8..017b2c89 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -45,7 +45,6 @@ public class SubsonicTabFragment extends SherlockFragment { @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); - setHasOptionsMenu(true); } @Override @@ -64,16 +63,6 @@ public class SubsonicTabFragment extends SherlockFragment { context = (SubsonicActivity)activity; } - @Override - public void onCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { - if(primaryFragment) { - onSupportCreateOptionsMenu(menu, menuInflater); - } - } - public void onSupportCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { - - } - public DownloadService getDownloadService() { return context != null ? context.getDownloadService() : null; } @@ -85,6 +74,7 @@ public class SubsonicTabFragment extends SherlockFragment { public void replaceFragment(SubsonicTabFragment fragment, int id) { this.setPrimaryFragment(false); fragment.setPrimaryFragment(true); + context.getPagerAdapter().replaceCurrent(fragment); FragmentTransaction trans = getFragmentManager().beginTransaction(); trans.replace(id, fragment); -- cgit v1.2.3 From 70024de8492ade279a2337b71864fb3d1284d169 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 14 Apr 2013 16:47:56 -0700 Subject: Manage own backstack since Google can't design a usable one --- .../daneren2005/dsub/activity/MainActivity.java | 34 ++++++++-------------- .../dsub/activity/SubsonicActivity.java | 30 +++++++++++++++++-- .../dsub/fragments/SelectDirectoryFragment.java | 1 - .../dsub/fragments/SubsonicTabFragment.java | 8 +---- 4 files changed, 41 insertions(+), 32 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 06925e8b..57423fb3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -52,28 +52,18 @@ public class MainActivity extends SubsonicActivity { @Override public void onBackPressed() { - int backStack = getSupportFragmentManager().getBackStackEntryCount(); - int currentTab = viewPager.getCurrentItem(); - - if(backStack == 0) { - if(currentTab == 0) { - AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - builder.setTitle(R.string.common_confirm) - .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - MainActivity.super.onBackPressed(); - } - }) - .setNegativeButton(R.string.common_cancel, null); - AlertDialog dialog = builder.create(); - dialog.show(); - } else { - viewPager.setCurrentItem(0); - } - } else { - super.onBackPressed(); - pagerAdapter.removeCurrent(); + if(pagerAdapter.onBackPressed()) { + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setTitle(R.string.menu_exit) + .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + MainActivity.super.onBackPressed(); + } + }) + .setNegativeButton(R.string.common_cancel, null); + AlertDialog dialog = builder.create(); + dialog.show(); } } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 61a8c18c..659d53db 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -224,6 +224,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { private SubsonicTabFragment currentFragment; private List tabs = new ArrayList(); private List frags = new ArrayList(); + private List ids = new ArrayList(); private int currentPosition; public TabPagerAdapter(SherlockFragmentActivity activity, ViewPager pager) { @@ -241,6 +242,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { List fragStack = new ArrayList(); fragStack.add(frag); frags.add(i, fragStack); + ids.add(i, 0); if(currentFragment == null) { currentFragment = (SubsonicTabFragment) frag; currentFragment.setPrimaryFragment(true); @@ -312,7 +314,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { notifyDataSetChanged(); } - public void replaceCurrent(SubsonicTabFragment fragment) { + public void replaceCurrent(SubsonicTabFragment fragment, int id) { if(currentFragment != null) { currentFragment.setPrimaryFragment(false); } @@ -322,6 +324,11 @@ public class SubsonicActivity extends SherlockFragmentActivity { currentFragment = fragment; currentFragment.setPrimaryFragment(true); activity.invalidateOptionsMenu(); + + ids.add(currentPosition, id); + FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); + trans.add(id, fragment); + trans.commit(); } public void removeCurrent() { @@ -329,11 +336,30 @@ public class SubsonicActivity extends SherlockFragmentActivity { currentFragment.setPrimaryFragment(false); } List fragStack = (List)frags.get(currentPosition); - fragStack.remove(fragStack.size() - 1); + Fragment oldFrag = (Fragment)fragStack.remove(fragStack.size() - 1); currentFragment = (SubsonicTabFragment) fragStack.get(fragStack.size() - 1); currentFragment.setPrimaryFragment(true); activity.invalidateOptionsMenu(); + + FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); + trans.remove(oldFrag); + trans.commit(); + } + + public boolean onBackPressed() { + List fragStack = (List)frags.get(currentPosition); + if(fragStack.size() > 1) { + removeCurrent(); + return false; + } else { + if(currentPosition == 0) { + return true; + } else { + viewPager.setCurrentItem(0); + return false; + } + } } private class TabInfo { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 92155fe1..9e8d42e9 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -118,7 +118,6 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements } else { menuInflater.inflate(R.menu.select_album, menu); } - hideButtons = false; } else { if(Util.isOffline(context)) { menuInflater.inflate(R.menu.select_song_offline, menu); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index 017b2c89..ee789382 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -22,7 +22,6 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.View; import android.widget.TextView; @@ -74,12 +73,7 @@ public class SubsonicTabFragment extends SherlockFragment { public void replaceFragment(SubsonicTabFragment fragment, int id) { this.setPrimaryFragment(false); fragment.setPrimaryFragment(true); - context.getPagerAdapter().replaceCurrent(fragment); - - FragmentTransaction trans = getFragmentManager().beginTransaction(); - trans.replace(id, fragment); - trans.addToBackStack(null); - trans.commit(); + context.getPagerAdapter().replaceCurrent(fragment, id); } protected void exit() { -- cgit v1.2.3 From 96c73e916cbec8c391ec2f9dde4c62623b9c915b Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 14 Apr 2013 19:56:03 -0700 Subject: Fixed context menus not hitting correct fragment --- .../src/github/daneren2005/dsub/fragments/MainFragment.java | 5 +++++ .../src/github/daneren2005/dsub/fragments/SelectArtistFragment.java | 4 ++++ .../github/daneren2005/dsub/fragments/SelectPlaylistFragment.java | 4 ++++ .../src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java | 3 ++- 4 files changed, 15 insertions(+), 1 deletion(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index ae382cd1..c9e264d7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -111,6 +111,10 @@ public class MainFragment extends LibraryFunctionsFragment { @Override public boolean onContextItemSelected(android.view.MenuItem menuItem) { + if(!primaryFragment) { + return false; + } + switch (menuItem.getItemId()) { case MENU_ITEM_SERVER_1: setActiveServer(1); @@ -125,6 +129,7 @@ public class MainFragment extends LibraryFunctionsFragment { return super.onContextItemSelected(menuItem); } + refresh(); return true; } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 4e8d26e9..bd5f7921 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -109,6 +109,10 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad @Override public boolean onContextItemSelected(MenuItem menuItem) { + if(!primaryFragment) { + return false; + } + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); Artist artist = (Artist) artistList.getItemAtPosition(info.position); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index b09fe802..05f64f67 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -85,6 +85,10 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements @Override public boolean onContextItemSelected(MenuItem menuItem) { + if(!primaryFragment) { + return false; + } + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); Playlist playlist = (Playlist) list.getItemAtPosition(info.position); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index ee789382..b4c94565 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -39,7 +39,7 @@ public class SubsonicTabFragment extends SherlockFragment { protected SubsonicActivity context; protected CharSequence title = "DSub"; protected View rootView; - private boolean primaryFragment = false; + protected boolean primaryFragment = false; @Override public void onCreate(Bundle bundle) { @@ -109,6 +109,7 @@ public class SubsonicTabFragment extends SherlockFragment { context.setTitle(title); } } + Log.d(TAG, "Primary (" + this.getClass().getName() + ": " + primaryFragment); } protected void setTitle(CharSequence title) { -- cgit v1.2.3 From 38e25911433ca87356b6f4fd3671c39785fb7798 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 14 Apr 2013 19:58:05 -0700 Subject: Remove log --- .../src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java | 1 - 1 file changed, 1 deletion(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index b4c94565..492ab74c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -109,7 +109,6 @@ public class SubsonicTabFragment extends SherlockFragment { context.setTitle(title); } } - Log.d(TAG, "Primary (" + this.getClass().getName() + ": " + primaryFragment); } protected void setTitle(CharSequence title) { -- cgit v1.2.3 From 634536648d7847fe648c18d7572d7717d6348e43 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 14 Apr 2013 20:01:46 -0700 Subject: Fix playNow from playlists --- .../daneren2005/dsub/fragments/SelectPlaylistFragment.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 05f64f67..09b5e437 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -107,12 +107,10 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements args = new Bundle(); args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + args.putBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); fragment.setArguments(args); - trans = getFragmentManager().beginTransaction(); - trans.replace(R.id.select_playlist_layout, fragment); - trans.addToBackStack(null); - trans.commit(); + replaceFragment(fragment, R.id.select_playlist_layout); break; case R.id.playlist_menu_play_shuffled: fragment = new SelectDirectoryFragment(); @@ -120,12 +118,10 @@ public class SelectPlaylistFragment extends LibraryFunctionsFragment implements args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); args.putBoolean(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); + args.putBoolean(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); fragment.setArguments(args); - trans = getFragmentManager().beginTransaction(); - trans.replace(R.id.select_playlist_layout, fragment); - trans.addToBackStack(null); - trans.commit(); + replaceFragment(fragment, R.id.select_playlist_layout); break; case R.id.playlist_menu_delete: deletePlaylist(playlist); -- cgit v1.2.3 From 85ab2efdd0a692c97bc9afce4851466585dec2d4 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 14 Apr 2013 20:22:42 -0700 Subject: Fix the remainder of the missing context menus --- .../dsub/fragments/SelectArtistFragment.java | 32 ++++-- .../dsub/fragments/SelectDirectoryFragment.java | 122 +++++++++++++++++++++ 2 files changed, 144 insertions(+), 10 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index bd5f7921..4f3a820f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -22,9 +22,11 @@ import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.BackgroundTask; import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.ArtistAdapter; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -84,10 +86,12 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad if (artistList.getItemAtPosition(info.position) instanceof Artist) { MenuInflater inflater = context.getMenuInflater(); - if(Util.isOffline(context)) + if(Util.isOffline(context)) { inflater.inflate(R.menu.select_artist_context_offline, menu); - else + } + else { inflater.inflate(R.menu.select_artist_context, menu); + } } else if (info.position == 0) { String musicFolderId = Util.getSelectedMusicFolderId(context); MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders); @@ -112,7 +116,7 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad if(!primaryFragment) { return false; } - + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); Artist artist = (Artist) artistList.getItemAtPosition(info.position); @@ -120,25 +124,25 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad if (artist != null) { switch (menuItem.getItemId()) { case R.id.artist_menu_play_now: - // downloadRecursively(artist.getId(), false, false, true, false, false); + downloadRecursively(artist.getId(), false, false, true, false, false); break; case R.id.artist_menu_play_shuffled: - // downloadRecursively(artist.getId(), false, false, true, true, false); + downloadRecursively(artist.getId(), false, false, true, true, false); break; case R.id.artist_menu_play_last: - // downloadRecursively(artist.getId(), false, true, false, false, false); + downloadRecursively(artist.getId(), false, true, false, false, false); break; case R.id.artist_menu_download: - // downloadRecursively(artist.getId(), false, true, false, false, true); + downloadRecursively(artist.getId(), false, true, false, false, true); break; case R.id.artist_menu_pin: - // downloadRecursively(artist.getId(), true, true, false, false, true); + downloadRecursively(artist.getId(), true, true, false, false, true); break; case R.id.artist_menu_delete: - // deleteRecursively(artist); + deleteRecursively(artist); break; default: - // return super.onContextItemSelected(menuItem); + return super.onContextItemSelected(menuItem); } } else if (info.position == 0) { MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId()); @@ -218,4 +222,12 @@ public class SelectArtistFragment extends LibraryFunctionsFragment implements Ad private void selectFolder() { folderButton.showContextMenu(); } + + public void deleteRecursively(Artist artist) { + File dir = FileUtil.getArtistDirectory(context, artist); + Util.recursiveDelete(dir); + if(Util.isOffline(context)) { + refresh(); + } + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 9e8d42e9..11e500b6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -9,7 +9,10 @@ import android.net.Uri; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; import android.util.Log; +import android.view.ContextMenu; import android.view.LayoutInflater; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -35,6 +38,7 @@ import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -174,6 +178,124 @@ public class SelectDirectoryFragment extends LibraryFunctionsFragment implements return false; } + @Override + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + + MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position); + + MenuInflater inflater = context.getMenuInflater(); + if (entry.isDirectory()) { + if(Util.isOffline(context)) { + inflater.inflate(R.menu.select_album_context_offline, menu); + } + else { + inflater.inflate(R.menu.select_album_context, menu); + } + } else if(!entry.isVideo()) { + if(Util.isOffline(context)) { + inflater.inflate(R.menu.select_song_context_offline, menu); + } + else { + inflater.inflate(R.menu.select_song_context, menu); + if(playlistId == null) { + menu.removeItem(R.id.song_menu_remove_playlist); + } + } + } else { + if(Util.isOffline(context)) { + inflater.inflate(R.menu.select_video_context_offline, menu); + } + else { + inflater.inflate(R.menu.select_video_context, menu); + } + } + + if (!Util.isOffline(context) && !entry.isVideo()) { + menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star).setTitle(entry.isStarred() ? R.string.common_unstar : R.string.common_star); + } + } + + @Override + public boolean onContextItemSelected(MenuItem menuItem) { + if(!primaryFragment) { + return false; + } + + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position); + List songs = new ArrayList(10); + songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(info.position)); + switch (menuItem.getItemId()) { + case R.id.album_menu_play_now: + downloadRecursively(entry.getId(), false, false, true, false, false); + break; + case R.id.album_menu_play_shuffled: + downloadRecursively(entry.getId(), false, false, true, true, false); + break; + case R.id.album_menu_play_last: + downloadRecursively(entry.getId(), false, true, false, false, false); + break; + case R.id.album_menu_download: + downloadRecursively(entry.getId(), false, true, false, false, true); + break; + case R.id.album_menu_pin: + downloadRecursively(entry.getId(), true, true, false, false, true); + break; + case R.id.album_menu_star: + toggleStarred(entry); + break; + case R.id.album_menu_delete: + deleteRecursively(entry); + break; + case R.id.song_menu_play_now: + getDownloadService().clear(); + getDownloadService().download(songs, false, true, true, false); + Util.startActivityWithoutTransition(context, DownloadActivity.class); + break; + case R.id.song_menu_play_next: + getDownloadService().download(songs, false, false, true, false); + break; + case R.id.song_menu_play_last: + getDownloadService().download(songs, false, false, false, false); + break; + case R.id.song_menu_download: + getDownloadService().downloadBackground(songs, false); + break; + case R.id.song_menu_pin: + getDownloadService().downloadBackground(songs, true); + break; + case R.id.song_menu_delete: + getDownloadService().delete(songs); + break; + case R.id.song_menu_add_playlist: + addToPlaylist(songs); + break; + case R.id.song_menu_star: + toggleStarred(entry); + break; + case R.id.song_menu_webview: + playWebView(entry); + break; + case R.id.song_menu_play_external: + playExternalPlayer(entry); + break; + case R.id.song_menu_info: + displaySongInfo(entry); + break; + case R.id.song_menu_stream_external: + streamExternalPlayer(entry); + break; + case R.id.song_menu_remove_playlist: + removeFromPlaylist(playlistId, playlistName, Arrays.asList(info.position - 1)); + break; + default: + return super.onContextItemSelected(menuItem); + } + return true; + } + @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if (position >= 0) { -- cgit v1.2.3 From 89f77932b6682aa5de88bf7739c1badfef646d8c Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 15 Apr 2013 19:04:21 -0700 Subject: Separated tab fragment from general fragment logic --- .../dsub/fragments/SubsonicFragment.java | 104 +++++++++++++++++++++ .../dsub/fragments/SubsonicTabFragment.java | 87 +---------------- 2 files changed, 106 insertions(+), 85 deletions(-) create mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java new file mode 100644 index 00000000..9a88d15a --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -0,0 +1,104 @@ +/* + This file is part of Subsonic. + + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + + Copyright 2009 (C) Sindre Mehus + */ +package github.daneren2005.dsub.fragments; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.TextView; +import com.actionbarsherlock.app.SherlockFragment; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.activity.SubsonicActivity; +import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.util.ImageLoader; + +public class SubsonicFragment extends SherlockFragment { + private static final String TAG = SubsonicFragment.class.getSimpleName(); + protected SubsonicActivity context; + protected CharSequence title = "DSub"; + protected View rootView; + + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + } + + @Override + public void onResume() { + super.onResume(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + context = (SubsonicActivity)activity; + } + + public DownloadService getDownloadService() { + return context != null ? context.getDownloadService() : null; + } + + protected void refresh() { + + } + + protected void exit() { + context.stopService(new Intent(context, DownloadServiceImpl.class)); + context.finish(); + } + + public void setProgressVisible(boolean visible) { + View view = rootView.findViewById(R.id.tab_progress); + if (view != null) { + view.setVisibility(visible ? View.VISIBLE : View.GONE); + } + } + + public void updateProgress(String message) { + TextView view = (TextView) rootView.findViewById(R.id.tab_progress_message); + if (view != null) { + view.setText(message); + } + } + + protected synchronized ImageLoader getImageLoader() { + return context.getImageLoader(); + } + public synchronized static ImageLoader getStaticImageLoader(Context context) { + return SubsonicActivity.getStaticImageLoader(context); + } + + protected void setTitle(CharSequence title) { + this.title = title; + context.setTitle(title); + } + protected void setTitle(int title) { + this.title = context.getResources().getString(title); + context.setTitle(this.title); + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index 492ab74c..19c3fd2c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -18,89 +18,15 @@ */ package github.daneren2005.dsub.fragments; -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.widget.TextView; -import com.actionbarsherlock.app.SherlockFragment; -import com.actionbarsherlock.view.Menu; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.activity.SubsonicActivity; -import github.daneren2005.dsub.activity.SubsonicTabActivity; -import github.daneren2005.dsub.service.DownloadService; -import github.daneren2005.dsub.service.DownloadServiceImpl; -import github.daneren2005.dsub.util.ImageLoader; - -public class SubsonicTabFragment extends SherlockFragment { - private static final String TAG = SubsonicTabActivity.class.getSimpleName(); - protected SubsonicActivity context; - protected CharSequence title = "DSub"; - protected View rootView; +public class SubsonicTabFragment extends SubsonicFragment { + private static final String TAG = SubsonicTabFragment.class.getSimpleName(); protected boolean primaryFragment = false; - - @Override - public void onCreate(Bundle bundle) { - super.onCreate(bundle); - } - - @Override - public void onResume() { - super.onResume(); - } - - @Override - public void onDestroy() { - super.onDestroy(); - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - context = (SubsonicActivity)activity; - } - - public DownloadService getDownloadService() { - return context != null ? context.getDownloadService() : null; - } - - protected void refresh() { - - } public void replaceFragment(SubsonicTabFragment fragment, int id) { this.setPrimaryFragment(false); fragment.setPrimaryFragment(true); context.getPagerAdapter().replaceCurrent(fragment, id); } - - protected void exit() { - context.stopService(new Intent(context, DownloadServiceImpl.class)); - context.finish(); - } - - public void setProgressVisible(boolean visible) { - View view = rootView.findViewById(R.id.tab_progress); - if (view != null) { - view.setVisibility(visible ? View.VISIBLE : View.GONE); - } - } - - public void updateProgress(String message) { - TextView view = (TextView) rootView.findViewById(R.id.tab_progress_message); - if (view != null) { - view.setText(message); - } - } - - protected synchronized ImageLoader getImageLoader() { - return context.getImageLoader(); - } - public synchronized static ImageLoader getStaticImageLoader(Context context) { - return SubsonicActivity.getStaticImageLoader(context); - } public void setPrimaryFragment(boolean primary) { primaryFragment = primary; @@ -110,13 +36,4 @@ public class SubsonicTabFragment extends SherlockFragment { } } } - - protected void setTitle(CharSequence title) { - this.title = title; - context.setTitle(title); - } - protected void setTitle(int title) { - this.title = context.getResources().getString(title); - context.setTitle(this.title); - } } -- cgit v1.2.3 From 770b5d3ea932be3a75c3f6bb1ee3d0bfcaaf5d52 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 15 Apr 2013 19:46:22 -0700 Subject: Start of porting over DownloadActivity --- .../dsub/activity/SubsonicActivity.java | 28 +- .../dsub/fragments/DownloadFragment.java | 1189 ++++++++++++++++++++ .../dsub/fragments/SubsonicFragment.java | 9 + 3 files changed, 1214 insertions(+), 12 deletions(-) create mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 659d53db..d0dbdde1 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -157,6 +157,22 @@ public class SubsonicActivity extends SherlockFragmentActivity { public TabPagerAdapter getPagerAdapter() { return pagerAdapter; } + + public void checkUpdates() { + try { + String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; + int ver = Integer.parseInt(version.replace(".", "")); + Updater updater = new Updater(ver); + updater.checkUpdates(SubsonicActivity.this); + } + catch(Exception e) { + + } + } + + public static String getThemeName() { + return theme; + } private void setUncaughtExceptionHandler() { Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); @@ -204,18 +220,6 @@ public class SubsonicActivity extends SherlockFragmentActivity { } } } - - public void checkUpdates() { - try { - String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; - int ver = Integer.parseInt(version.replace(".", "")); - Updater updater = new Updater(ver); - updater.checkUpdates(SubsonicActivity.this); - } - catch(Exception e) { - - } - } public class TabPagerAdapter extends FragmentPagerAdapter implements TabListener, ViewPager.OnPageChangeListener { private SherlockFragmentActivity activity; diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java new file mode 100644 index 00000000..de80ed7e --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -0,0 +1,1189 @@ +package github.daneren2005.dsub.fragments; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.Color; +import android.graphics.Typeface; +import android.os.Bundle; +import android.os.Handler; +import android.util.Log; +import android.view.ContextMenu; +import android.view.Display; +import android.view.GestureDetector; +import android.view.GestureDetector.OnGestureListener; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.view.WindowManager; +import android.view.animation.AnimationUtils; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.ViewFlipper; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuItem; +import com.actionbarsherlock.view.MenuInflater; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.PlayerState; +import github.daneren2005.dsub.domain.RepeatMode; +import github.daneren2005.dsub.service.DownloadFile; +import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.HorizontalSlider; +import github.daneren2005.dsub.util.SilentBackgroundTask; +import github.daneren2005.dsub.view.SongView; +import github.daneren2005.dsub.util.Util; +import github.daneren2005.dsub.view.VisualizerView; + +import static github.daneren2005.dsub.domain.PlayerState.*; +import github.daneren2005.dsub.util.*; +import github.daneren2005.dsub.view.AutoRepeatButton; +import java.util.ArrayList; +import java.util.concurrent.ScheduledFuture; +import com.mobeta.android.dslv.*; +import github.daneren2005.dsub.activity.EqualizerActivity; +import github.daneren2005.dsub.activity.SubsonicActivity; +import github.daneren2005.dsub.service.DownloadServiceImpl; + +public class DownloadFragment extends SubsonicFragment implements OnGestureListener { + private static final String TAG = DownloadFragment.class.getSimpleName(); + + private static final int DIALOG_SAVE_PLAYLIST = 100; + private static final int PERCENTAGE_OF_SCREEN_FOR_SWIPE = 10; + private static final int COLOR_BUTTON_ENABLED = Color.rgb(51, 181, 229); + private static final int COLOR_BUTTON_DISABLED = Color.rgb(206, 213, 211); + private static final int INCREMENT_TIME = 5000; + + private ViewFlipper playlistFlipper; + private TextView emptyTextView; + private TextView songTitleTextView; + private ImageView albumArtImageView; + private DragSortListView playlistView; + private TextView positionTextView; + private TextView durationTextView; + private TextView statusTextView; + private HorizontalSlider progressBar; + private AutoRepeatButton previousButton; + private AutoRepeatButton nextButton; + private View pauseButton; + private View stopButton; + private View startButton; + private ImageButton repeatButton; + private Button equalizerButton; + private Button visualizerButton; + private Button jukeboxButton; + private View toggleListButton; + private ImageButton starButton; + private ScheduledExecutorService executorService; + private DownloadFile currentPlaying; + private long currentRevision; + private EditText playlistNameView; + private GestureDetector gestureScanner; + private int swipeDistance; + private int swipeVelocity; + private VisualizerView visualizerView; + private boolean nowPlaying = true; + private ScheduledFuture hideControlsFuture; + private SongListAdapter songListAdapter; + private SilentBackgroundTask onProgressChangedTask; + + /** + * Called when the activity is first created. + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + rootView = inflater.inflate(R.layout.download, container, false); + setTitle(nowPlaying ? "Now Playing" : "Downloading"); + + WindowManager w = context.getWindowManager(); + Display d = w.getDefaultDisplay(); + swipeDistance = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100; + swipeVelocity = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100; + gestureScanner = new GestureDetector(this); + + playlistFlipper = (ViewFlipper)rootView.findViewById(R.id.download_playlist_flipper); + emptyTextView = (TextView)rootView.findViewById(R.id.download_empty); + songTitleTextView = (TextView)rootView.findViewById(R.id.download_song_title); + albumArtImageView = (ImageView)rootView.findViewById(R.id.download_album_art_image); + positionTextView = (TextView)rootView.findViewById(R.id.download_position); + durationTextView = (TextView)rootView.findViewById(R.id.download_duration); + statusTextView = (TextView)rootView.findViewById(R.id.download_status); + progressBar = (HorizontalSlider)rootView.findViewById(R.id.download_progress_bar); + playlistView = (DragSortListView)rootView.findViewById(R.id.download_list); + previousButton = (AutoRepeatButton)rootView.findViewById(R.id.download_previous); + nextButton = (AutoRepeatButton)rootView.findViewById(R.id.download_next); + pauseButton =rootView.findViewById(R.id.download_pause); + stopButton =rootView.findViewById(R.id.download_stop); + startButton =rootView.findViewById(R.id.download_start); + repeatButton = (ImageButton)rootView.findViewById(R.id.download_repeat); + equalizerButton = (Button)rootView.findViewById(R.id.download_equalizer); + visualizerButton = (Button)rootView.findViewById(R.id.download_visualizer); + jukeboxButton = (Button)rootView.findViewById(R.id.download_jukebox); + LinearLayout visualizerViewLayout = (LinearLayout)rootView.findViewById(R.id.download_visualizer_view_layout); + toggleListButton =rootView.findViewById(R.id.download_toggle_list); + + starButton = (ImageButton)rootView.findViewById(R.id.download_star); + starButton.setVisibility(Util.isOffline(context) ? View.GONE : View.VISIBLE); + starButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + DownloadFile currentDownload = getDownloadService().getCurrentPlaying(); + if (currentDownload != null) { + MusicDirectory.Entry currentSong = currentDownload.getSong(); + // toggleStarred(currentSong); + starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); + } + } + }); + + View.OnTouchListener touchListener = new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent me) { + return gestureScanner.onTouchEvent(me); + } + }; + pauseButton.setOnTouchListener(touchListener); + stopButton.setOnTouchListener(touchListener); + startButton.setOnTouchListener(touchListener); + equalizerButton.setOnTouchListener(touchListener); + visualizerButton.setOnTouchListener(touchListener); + jukeboxButton.setOnTouchListener(touchListener); + emptyTextView.setOnTouchListener(touchListener); + albumArtImageView.setOnTouchListener(touchListener); + + previousButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + warnIfNetworkOrStorageUnavailable(); + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + getDownloadService().previous(); + return null; + } + + @Override + protected void done(Void result) { + onCurrentChanged(); + onProgressChanged(); + } + }.execute(); + setControlsVisible(true); + } + }); + previousButton.setOnRepeatListener(new Runnable() { + public void run() { + changeProgress(-INCREMENT_TIME); + } + }); + + nextButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + warnIfNetworkOrStorageUnavailable(); + new SilentBackgroundTask(context) { + @Override + protected Boolean doInBackground() throws Throwable { + if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) { + getDownloadService().next(); + return true; + } else { + return false; + } + } + + @Override + protected void done(Boolean result) { + if(result) { + onCurrentChanged(); + onProgressChanged(); + } + } + }.execute(); + setControlsVisible(true); + } + }); + nextButton.setOnRepeatListener(new Runnable() { + public void run() { + changeProgress(INCREMENT_TIME); + } + }); + + pauseButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + getDownloadService().pause(); + return null; + } + + @Override + protected void done(Void result) { + onCurrentChanged(); + onProgressChanged(); + } + }.execute(); + } + }); + + stopButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + getDownloadService().reset(); + return null; + } + + @Override + protected void done(Void result) { + onCurrentChanged(); + onProgressChanged(); + } + }.execute(); + } + }); + + startButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + warnIfNetworkOrStorageUnavailable(); + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + start(); + return null; + } + + @Override + protected void done(Void result) { + onCurrentChanged(); + onProgressChanged(); + } + }.execute(); + } + }); + + repeatButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + RepeatMode repeatMode = getDownloadService().getRepeatMode().next(); + getDownloadService().setRepeatMode(repeatMode); + onDownloadListChanged(); + switch (repeatMode) { + case OFF: + Util.toast(context, R.string.download_repeat_off); + break; + case ALL: + Util.toast(context, R.string.download_repeat_all); + break; + case SINGLE: + Util.toast(context, R.string.download_repeat_single); + break; + default: + break; + } + setControlsVisible(true); + } + }); + + equalizerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DownloadService downloadService = getDownloadService(); + if(downloadService != null && downloadService.getEqualizerController() != null + && downloadService.getEqualizerController().getEqualizer() != null) { + context.startActivity(new Intent(context, EqualizerActivity.class)); + setControlsVisible(true); + } else { + Util.toast(context, "Failed to start equalizer. Try restarting."); + } + } + }); + + visualizerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + boolean active = !visualizerView.isActive(); + visualizerView.setActive(active); + boolean isActive = visualizerView.isActive(); + getDownloadService().setShowVisualization(isActive); + updateButtons(); + if(active == isActive) { + Util.toast(context, active ? R.string.download_visualizer_on : R.string.download_visualizer_off); + } else { + Util.toast(context, "Failed to start visualizer. Try restarting."); + } + setControlsVisible(true); + } + }); + + jukeboxButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled(); + getDownloadService().setJukeboxEnabled(jukeboxEnabled); + updateButtons(); + Util.toast(context, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false); + setControlsVisible(true); + } + }); + + toggleListButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + toggleFullscreenAlbumArt(); + setControlsVisible(true); + } + }); + + progressBar.setOnSliderChangeListener(new HorizontalSlider.OnSliderChangeListener() { + @Override + public void onSliderChanged(View view, final int position, boolean inProgress) { + Util.toast(context, Util.formatDuration(position / 1000), true); + if (!inProgress) { + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + getDownloadService().seekTo(position); + return null; + } + + @Override + protected void done(Void result) { + onProgressChanged(); + } + }.execute(); + } + setControlsVisible(true); + } + }); + playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, final int position, long id) { + if(nowPlaying) { + warnIfNetworkOrStorageUnavailable(); + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + getDownloadService().play(position); + return null; + } + + @Override + protected void done(Void result) { + onCurrentChanged(); + onProgressChanged(); + } + }.execute(); + } + } + }); + playlistView.setDropListener(new DragSortListView.DropListener() { + @Override + public void drop(int from, int to) { + getDownloadService().swap(nowPlaying, from, to); + onDownloadListChanged(); + } + }); + playlistView.setRemoveListener(new DragSortListView.RemoveListener() { + @Override + public void remove(int which) { + getDownloadService().remove(which); + onDownloadListChanged(); + } + }); + + registerForContextMenu(playlistView); + + DownloadService downloadService = getDownloadService(); + /*if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) { + context.getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE); + warnIfNetworkOrStorageUnavailable(); + downloadService.setShufflePlayEnabled(true); + }*/ + + boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerAvailable(); + boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerAvailable(); + + if (!equalizerAvailable) { + equalizerButton.setVisibility(View.GONE); + } + if (!visualizerAvailable) { + visualizerButton.setVisibility(View.GONE); + } else { + visualizerView = new VisualizerView(context); + visualizerViewLayout.addView(visualizerView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); + } + + // TODO: Extract to utility method and cache. + Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/Storopia.ttf"); + equalizerButton.setTypeface(typeface); + visualizerButton.setTypeface(typeface); + jukeboxButton.setTypeface(typeface); + + return rootView; + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { + if(Util.isOffline(context)) { + menuInflater.inflate(R.menu.nowplaying_offline, menu); + } else { + if(nowPlaying) { + menuInflater.inflate(R.menu.nowplaying, menu); + } + else { + menuInflater.inflate(R.menu.nowplaying_downloading, menu); + } + + if(getDownloadService() != null && getDownloadService().getSleepTimer()) { + menu.findItem(R.id.menu_toggle_timer).setTitle(R.string.download_stop_timer); + } + } + if(getDownloadService() != null && getDownloadService().getKeepScreenOn()) { + menu.findItem(R.id.menu_screen_on_off).setTitle(R.string.download_menu_screen_off); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem menuItem) { + if(super.onOptionsItemSelected(menuItem)) { + return true; + } + + return menuItemSelected(menuItem.getItemId(), null); + } + + @Override + public void onCreateContextMenu(android.view.ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + if (view == playlistView) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position); + + android.view.MenuInflater inflater = context.getMenuInflater(); + if(Util.isOffline(context)) { + inflater.inflate(R.menu.nowplaying_context_offline, menu); + } else { + inflater.inflate(R.menu.nowplaying_context, menu); + menu.findItem(R.id.menu_star).setTitle(downloadFile.getSong().isStarred() ? R.string.common_unstar : R.string.common_star); + } + + if (downloadFile.getSong().getParent() == null) { + menu.findItem(R.id.menu_show_album).setVisible(false); + } + } + } + + @Override + public boolean onContextItemSelected(android.view.MenuItem menuItem) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position); + return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem); + } + + private boolean menuItemSelected(int menuItemId, final DownloadFile song) { + /*switch (menuItemId) { + case R.id.menu_show_album: + Intent intent = new Intent(context, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, song.getSong().getParent()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, song.getSong().getAlbum()); + Util.startActivityWithoutTransition(context, intent); + return true; + case R.id.menu_lyrics: + intent = new Intent(context, LyricsActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, song.getSong().getArtist()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_TITLE, song.getSong().getTitle()); + Util.startActivityWithoutTransition(context, intent); + return true; + case R.id.menu_remove: + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + getDownloadService().remove(song); + return null; + } + + @Override + protected void done(Void result) { + onDownloadListChanged(); + } + }.execute(); + return true; + case R.id.menu_delete: + List songs = new ArrayList(1); + songs.add(song.getSong()); + getDownloadService().delete(songs); + return true; + case R.id.menu_remove_all: + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + getDownloadService().setShufflePlayEnabled(false); + if(nowPlaying) { + getDownloadService().clear(); + } + else { + getDownloadService().clearBackground(); + } + return null; + } + + @Override + protected void done(Void result) { + onDownloadListChanged(); + } + }.execute(); + return true; + case R.id.menu_screen_on_off: + if (getDownloadService().getKeepScreenOn()) { + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + getDownloadService().setKeepScreenOn(false); + } else { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + getDownloadService().setKeepScreenOn(true); + } + context.invalidateOptionsMenu(); + return true; + case R.id.menu_shuffle: + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + getDownloadService().shuffle(); + return null; + } + + @Override + protected void done(Void result) { + Util.toast(context, R.string.download_menu_shuffle_notification); + } + }.execute(); + return true; + case R.id.menu_save_playlist: + showDialog(DIALOG_SAVE_PLAYLIST); + return true; + case R.id.menu_star: + toggleStarred(song.getSong()); + return true; + case R.id.menu_toggle_now_playing: + toggleNowPlaying(); + context.invalidateOptionsMenu(); + return true; + case R.id.menu_toggle_timer: + if(getDownloadService().getSleepTimer()) { + getDownloadService().stopSleepTimer(); + context.invalidateOptionsMenu(); + } else { + startTimer(); + } + return true; + case R.id.menu_exit: + intent = new Intent(context, MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); + Util.startActivityWithoutTransition(context, intent); + return true; + case R.id.menu_add_playlist: + songs = new ArrayList(1); + songs.add(song.getSong()); + addToPlaylist(songs); + return true; + case R.id.menu_info: + displaySongInfo(song.getSong()); + return true; + default: + return false; + }*/ + return false; + } + + /*@Override + protected void onResume() { + super.onResume(); + + final Handler handler = new Handler(); + Runnable runnable = new Runnable() { + @Override + public void run() { + handler.post(new Runnable() { + @Override + public void run() { + update(); + } + }); + } + }; + + executorService = Executors.newSingleThreadScheduledExecutor(); + executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS); + + setControlsVisible(true); + + DownloadService downloadService = getDownloadService(); + if (downloadService == null || downloadService.getCurrentPlaying() == null) { + playlistFlipper.setDisplayedChild(1); + } + + onDownloadListChanged(); + onCurrentChanged(); + onProgressChanged(); + scrollToCurrent(); + if (downloadService != null && downloadService.getKeepScreenOn()) { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } else { + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + } + + if (visualizerView != null && downloadService != null && downloadService.getShowVisualization()) { + visualizerView.setActive(true); + } + + updateButtons(); + }*/ + + private void scheduleHideControls() { + if (hideControlsFuture != null) { + hideControlsFuture.cancel(false); + } + + final Handler handler = new Handler(); + Runnable runnable = new Runnable() { + @Override + public void run() { + handler.post(new Runnable() { + @Override + public void run() { + setControlsVisible(false); + } + }); + } + }; + hideControlsFuture = executorService.schedule(runnable, 3000L, TimeUnit.MILLISECONDS); + } + + private void setControlsVisible(boolean visible) { + try { + long duration = 1700L; + FadeOutAnimation.createAndStart(rootView.findViewById(R.id.download_overlay_buttons), !visible, duration); + + if (visible) { + scheduleHideControls(); + } + } catch(Exception e) { + + } + } + + private void updateButtons() { + SharedPreferences prefs = Util.getPreferences(context); + boolean equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false); + if(equalizerOn && getDownloadService() != null && getDownloadService().getEqualizerController() != null && + getDownloadService().getEqualizerController().isEnabled()) { + equalizerButton.setTextColor(COLOR_BUTTON_ENABLED); + } else { + equalizerButton.setTextColor(COLOR_BUTTON_DISABLED); + } + + if (visualizerView != null) { + visualizerButton.setTextColor(visualizerView.isActive() ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED); + } + + boolean jukeboxEnabled = getDownloadService() != null && getDownloadService().isJukeboxEnabled(); + jukeboxButton.setTextColor(jukeboxEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED); + } + + // Scroll to current playing/downloading. + private void scrollToCurrent() { + if (getDownloadService() == null || songListAdapter == null) { + return; + } + + for (int i = 0; i < songListAdapter.getCount(); i++) { + if (currentPlaying == playlistView.getItemAtPosition(i)) { + playlistView.setSelectionFromTop(i, 40); + return; + } + } + DownloadFile currentDownloading = getDownloadService().getCurrentDownloading(); + for (int i = 0; i < songListAdapter.getCount(); i++) { + if (currentDownloading == playlistView.getItemAtPosition(i)) { + playlistView.setSelectionFromTop(i, 40); + return; + } + } + } + + /*@Override + protected void onPause() { + super.onPause(); + executorService.shutdown(); + if (visualizerView != null && visualizerView.isActive()) { + visualizerView.setActive(false); + } + }*/ + + /*@Override + protected Dialog onCreateDialog(int id) { + if (id == DIALOG_SAVE_PLAYLIST) { + AlertDialog.Builder builder; + + LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); + final View layout = inflater.inflate(R.layout.save_playlist, (ViewGroup)rootView.findViewById(R.id.save_playlist_root)); + playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name); + + builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.download_playlist_title); + builder.setMessage(R.string.download_playlist_name); + builder.setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + savePlaylistInBackground(String.valueOf(playlistNameView.getText())); + } + }); + builder.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + builder.setView(layout); + builder.setCancelable(true); + + return builder.create(); + } else { + return super.onCreateDialog(id); + } + }*/ + + /*@Override + protected void onPrepareDialog(int id, Dialog dialog) { + if (id == DIALOG_SAVE_PLAYLIST) { + String playlistName = (getDownloadService() != null) ? getDownloadService().getSuggestedPlaylistName() : null; + if (playlistName != null) { + playlistNameView.setText(playlistName); + } else { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + playlistNameView.setText(dateFormat.format(new Date())); + } + } + }*/ + + private void update() { + if (getDownloadService() == null) { + return; + } + + if (currentRevision != getDownloadService().getDownloadListUpdateRevision()) { + onDownloadListChanged(); + } + + if (currentPlaying != getDownloadService().getCurrentPlaying()) { + onCurrentChanged(); + } + + onProgressChanged(); + } + + private void savePlaylistInBackground(final String playlistName) { + Util.toast(context, context.getResources().getString(R.string.download_playlist_saving, playlistName)); + getDownloadService().setSuggestedPlaylistName(playlistName); + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + List entries = new LinkedList(); + for (DownloadFile downloadFile : getDownloadService().getSongs()) { + entries.add(downloadFile.getSong()); + } + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.createPlaylist(null, playlistName, entries, context, null); + return null; + } + + @Override + protected void done(Void result) { + Util.toast(context, R.string.download_playlist_done); + } + + @Override + protected void error(Throwable error) { + String msg = context.getResources().getString(R.string.download_playlist_error) + " " + getErrorMessage(error); + Util.toast(context, msg); + } + }.execute(); + } + + protected void startTimer() { + View dialogView = context.getLayoutInflater().inflate(R.layout.start_timer, null); + final EditText lengthBox = (EditText)dialogView.findViewById(R.id.timer_length); + + final SharedPreferences prefs = Util.getPreferences(context); + lengthBox.setText(prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, "")); + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.menu_set_timer) + .setView(dialogView) + .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + String length = lengthBox.getText().toString(); + + SharedPreferences.Editor editor = prefs.edit(); + editor.putString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, length); + editor.commit(); + + getDownloadService().setSleepTimerDuration(Integer.parseInt(length)); + getDownloadService().startSleepTimer(); + context.invalidateOptionsMenu(); + } + }) + .setNegativeButton(R.string.common_cancel, null); + AlertDialog dialog = builder.create(); + dialog.show(); + } + + private void toggleFullscreenAlbumArt() { + scrollToCurrent(); + if (playlistFlipper.getDisplayedChild() == 1) { + playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(context, R.anim.push_down_in)); + playlistFlipper.setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.push_down_out)); + playlistFlipper.setDisplayedChild(0); + } else { + playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(context, R.anim.push_up_in)); + playlistFlipper.setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.push_up_out)); + playlistFlipper.setDisplayedChild(1); + } + } + + private void start() { + DownloadService service = getDownloadService(); + PlayerState state = service.getPlayerState(); + if (state == PAUSED || state == COMPLETED || state == STOPPED) { + service.start(); + } else if (state == STOPPED || state == IDLE) { + warnIfNetworkOrStorageUnavailable(); + int current = service.getCurrentPlayingIndex(); + // TODO: Use play() method. + if (current == -1) { + service.play(0); + } else { + service.play(current); + } + } + } + private void onDownloadListChanged() { + onDownloadListChanged(false); + } + private void onDownloadListChanged(boolean refresh) { + DownloadService downloadService = getDownloadService(); + if (downloadService == null) { + return; + } + + List list; + if(nowPlaying) { + list = downloadService.getSongs(); + } + else { + list = downloadService.getBackgroundDownloads(); + } + + if(downloadService.isShufflePlayEnabled()) { + emptyTextView.setText(R.string.download_shuffle_loading); + } + else { + emptyTextView.setText(R.string.download_empty); + } + + if(songListAdapter == null || refresh) { + playlistView.setAdapter(songListAdapter = new SongListAdapter(list)); + } else { + songListAdapter.notifyDataSetChanged(); + } + emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE); + currentRevision = downloadService.getDownloadListUpdateRevision(); + + switch (downloadService.getRepeatMode()) { + case OFF: + if("light".equals(SubsonicActivity.getThemeName()) | "light_fullscreen".equals(SubsonicActivity.getThemeName())) { + repeatButton.setImageResource(R.drawable.media_repeat_off_light); + } else { + repeatButton.setImageResource(R.drawable.media_repeat_off); + } + break; + case ALL: + repeatButton.setImageResource(R.drawable.media_repeat_all); + break; + case SINGLE: + repeatButton.setImageResource(R.drawable.media_repeat_single); + break; + default: + break; + } + } + + private void onCurrentChanged() { + if (getDownloadService() == null) { + return; + } + + currentPlaying = getDownloadService().getCurrentPlaying(); + if (currentPlaying != null) { + MusicDirectory.Entry song = currentPlaying.getSong(); + songTitleTextView.setText(song.getTitle()); + getImageLoader().loadImage(albumArtImageView, song, true, true); + starButton.setImageResource(song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); + } else { + songTitleTextView.setText(null); + getImageLoader().loadImage(albumArtImageView, null, true, false); + starButton.setImageResource(android.R.drawable.btn_star_big_off); + } + } + + private void onProgressChanged() { + // Make sure to only be trying to run one of these at a time + if (getDownloadService() == null || onProgressChangedTask != null) { + return; + } + + onProgressChangedTask = new SilentBackgroundTask(context) { + DownloadService downloadService; + boolean isJukeboxEnabled; + int millisPlayed; + Integer duration; + PlayerState playerState; + + @Override + protected Void doInBackground() throws Throwable { + downloadService = getDownloadService(); + isJukeboxEnabled = downloadService.isJukeboxEnabled(); + millisPlayed = Math.max(0, downloadService.getPlayerPosition()); + duration = downloadService.getPlayerDuration(); + playerState = getDownloadService().getPlayerState(); + return null; + } + + @Override + protected void done(Void result) { + if (currentPlaying != null) { + int millisTotal = duration == null ? 0 : duration; + + positionTextView.setText(Util.formatDuration(millisPlayed / 1000)); + durationTextView.setText(Util.formatDuration(millisTotal / 1000)); + progressBar.setMax(millisTotal == 0 ? 100 : millisTotal); // Work-around for apparent bug. + progressBar.setProgress(millisPlayed); + progressBar.setSlidingEnabled(currentPlaying.isWorkDone() || isJukeboxEnabled); + } else { + positionTextView.setText("0:00"); + durationTextView.setText("-:--"); + progressBar.setProgress(0); + progressBar.setSlidingEnabled(false); + } + + switch (playerState) { + case DOWNLOADING: + long bytes = currentPlaying.getPartialFile().length(); + statusTextView.setText(context.getResources().getString(R.string.download_playerstate_downloading, Util.formatLocalizedBytes(bytes, context))); + break; + case PREPARING: + statusTextView.setText(R.string.download_playerstate_buffering); + break; + case STARTED: + statusTextView.setText((currentPlaying != null) ? (currentPlaying.getSong().getArtist() + " - " + currentPlaying.getSong().getAlbum()) : null); + break; + default: + statusTextView.setText((currentPlaying != null) ? (currentPlaying.getSong().getArtist() + " - " + currentPlaying.getSong().getAlbum()) : null); + break; + } + + switch (playerState) { + case STARTED: + pauseButton.setVisibility(View.VISIBLE); + stopButton.setVisibility(View.INVISIBLE); + startButton.setVisibility(View.INVISIBLE); + break; + case DOWNLOADING: + case PREPARING: + pauseButton.setVisibility(View.INVISIBLE); + stopButton.setVisibility(View.VISIBLE); + startButton.setVisibility(View.INVISIBLE); + break; + default: + pauseButton.setVisibility(View.INVISIBLE); + stopButton.setVisibility(View.INVISIBLE); + startButton.setVisibility(View.VISIBLE); + break; + } + + jukeboxButton.setTextColor(isJukeboxEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED); + onProgressChangedTask = null; + } + }; + onProgressChangedTask.execute(); + } + + private void changeProgress(final int ms) { + final DownloadService downloadService = getDownloadService(); + if(downloadService == null) { + return; + } + + new SilentBackgroundTask(context) { + boolean isJukeboxEnabled; + int msPlayed; + Integer duration; + PlayerState playerState; + int seekTo; + + @Override + protected Void doInBackground() throws Throwable { + msPlayed = Math.max(0, downloadService.getPlayerPosition()); + duration = downloadService.getPlayerDuration(); + playerState = getDownloadService().getPlayerState(); + int msTotal = duration == null ? 0 : duration; + if(msPlayed + ms > msTotal) { + seekTo = msTotal; + } else { + seekTo = msPlayed + ms; + } + downloadService.seekTo(seekTo); + return null; + } + + @Override + protected void done(Void result) { + progressBar.setProgress(seekTo); + } + }.execute(); + } + + private class SongListAdapter extends ArrayAdapter { + public SongListAdapter(List entries) { + super(context, android.R.layout.simple_list_item_1, entries); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + SongView view; + if (convertView != null && convertView instanceof SongView) { + view = (SongView) convertView; + } else { + view = new SongView(context); + } + DownloadFile downloadFile = getItem(position); + view.setSong(downloadFile.getSong(), false); + return view; + } + } + + /*@Override + public boolean onTouchEvent(MotionEvent me) { + return gestureScanner.onTouchEvent(me); + }*/ + + @Override + public boolean onDown(MotionEvent me) { + setControlsVisible(true); + return false; + } + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + DownloadService downloadService = getDownloadService(); + if (downloadService == null) { + return false; + } + + // Right to Left swipe + if (e1.getX() - e2.getX() > swipeDistance && Math.abs(velocityX) > swipeVelocity) { + warnIfNetworkOrStorageUnavailable(); + if (downloadService.getCurrentPlayingIndex() < downloadService.size() - 1) { + downloadService.next(); + onCurrentChanged(); + onProgressChanged(); + } + return true; + } + + // Left to Right swipe + else if (e2.getX() - e1.getX() > swipeDistance && Math.abs(velocityX) > swipeVelocity) { + warnIfNetworkOrStorageUnavailable(); + downloadService.previous(); + onCurrentChanged(); + onProgressChanged(); + return true; + } + + // Top to Bottom swipe + else if (e2.getY() - e1.getY() > swipeDistance && Math.abs(velocityY) > swipeVelocity) { + warnIfNetworkOrStorageUnavailable(); + downloadService.seekTo(downloadService.getPlayerPosition() + 30000); + onProgressChanged(); + return true; + } + + // Bottom to Top swipe + else if (e1.getY() - e2.getY() > swipeDistance && Math.abs(velocityY) > swipeVelocity) { + warnIfNetworkOrStorageUnavailable(); + downloadService.seekTo(downloadService.getPlayerPosition() - 8000); + onProgressChanged(); + return true; + } + + return false; + } + + private void toggleNowPlaying() { + nowPlaying = !nowPlaying; + setTitle(nowPlaying ? "Now Playing" : "Downloading"); + onDownloadListChanged(true); + } + + @Override + public void onLongPress(MotionEvent e) { + } + + @Override + public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { + return false; + } + + @Override + public void onShowPress(MotionEvent e) { + } + + @Override + public boolean onSingleTapUp(MotionEvent e) { + return false; + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 9a88d15a..cf6ed641 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -31,6 +31,7 @@ import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.util.ImageLoader; +import github.daneren2005.dsub.util.Util; public class SubsonicFragment extends SherlockFragment { private static final String TAG = SubsonicFragment.class.getSimpleName(); @@ -101,4 +102,12 @@ public class SubsonicFragment extends SherlockFragment { this.title = context.getResources().getString(title); context.setTitle(this.title); } + + protected void warnIfNetworkOrStorageUnavailable() { + if (!Util.isExternalStoragePresent()) { + Util.toast(context, R.string.select_album_no_sdcard); + } else if (!Util.isOffline(context) && !Util.isNetworkConnected(context)) { + Util.toast(context, R.string.select_album_no_network); + } + } } -- cgit v1.2.3 From e300762952f92fe74b1ef0787faef9ba86771d10 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 16 Apr 2013 20:56:14 -0700 Subject: Embed DownloadFragment with logic into dummy activity --- subsonic-android/res/layout-land/download.xml | 3 - subsonic-android/res/layout-port/download.xml | 3 - subsonic-android/res/layout/download_activity.xml | 4 + subsonic-android/res/layout/download_slider.xml | 3 +- .../dsub/activity/DownloadActivity.java | 1181 +------------------- .../dsub/activity/SubsonicTabActivity.java | 4 +- .../dsub/fragments/DownloadFragment.java | 26 +- 7 files changed, 34 insertions(+), 1190 deletions(-) create mode 100644 subsonic-android/res/layout/download_activity.xml (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout-land/download.xml b/subsonic-android/res/layout-land/download.xml index 4992d169..f7ea3162 100644 --- a/subsonic-android/res/layout-land/download.xml +++ b/subsonic-android/res/layout-land/download.xml @@ -124,7 +124,4 @@ - - - diff --git a/subsonic-android/res/layout-port/download.xml b/subsonic-android/res/layout-port/download.xml index 2b61dd7b..33c94e1f 100644 --- a/subsonic-android/res/layout-port/download.xml +++ b/subsonic-android/res/layout-port/download.xml @@ -138,8 +138,5 @@ - - - diff --git a/subsonic-android/res/layout/download_activity.xml b/subsonic-android/res/layout/download_activity.xml new file mode 100644 index 00000000..3a1aa5e4 --- /dev/null +++ b/subsonic-android/res/layout/download_activity.xml @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/subsonic-android/res/layout/download_slider.xml b/subsonic-android/res/layout/download_slider.xml index 32e146e7..1794126b 100644 --- a/subsonic-android/res/layout/download_slider.xml +++ b/subsonic-android/res/layout/download_slider.xml @@ -3,7 +3,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="fill_parent" - android:background="@android:color/transparent"> + android:background="@android:color/transparent" + android:paddingBottom="10dip"> hideControlsFuture; - private SongListAdapter songListAdapter; - private SilentBackgroundTask onProgressChangedTask; - - /** - * Called when the activity is first created. - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setTitle(nowPlaying ? "Now Playing" : "Downloading"); - setContentView(R.layout.download); - - WindowManager w = getWindowManager(); - Display d = w.getDefaultDisplay(); - swipeDistance = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100; - swipeVelocity = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100; - gestureScanner = new GestureDetector(this); - - playlistFlipper = (ViewFlipper) findViewById(R.id.download_playlist_flipper); - emptyTextView = (TextView) findViewById(R.id.download_empty); - songTitleTextView = (TextView) findViewById(R.id.download_song_title); - albumArtImageView = (ImageView) findViewById(R.id.download_album_art_image); - positionTextView = (TextView) findViewById(R.id.download_position); - durationTextView = (TextView) findViewById(R.id.download_duration); - statusTextView = (TextView) findViewById(R.id.download_status); - progressBar = (HorizontalSlider) findViewById(R.id.download_progress_bar); - playlistView = (DragSortListView) findViewById(R.id.download_list); - previousButton = (AutoRepeatButton)findViewById(R.id.download_previous); - nextButton = (AutoRepeatButton)findViewById(R.id.download_next); - pauseButton = findViewById(R.id.download_pause); - stopButton = findViewById(R.id.download_stop); - startButton = findViewById(R.id.download_start); - repeatButton = (ImageButton) findViewById(R.id.download_repeat); - equalizerButton = (Button) findViewById(R.id.download_equalizer); - visualizerButton = (Button) findViewById(R.id.download_visualizer); - jukeboxButton = (Button) findViewById(R.id.download_jukebox); - LinearLayout visualizerViewLayout = (LinearLayout) findViewById(R.id.download_visualizer_view_layout); - toggleListButton = findViewById(R.id.download_toggle_list); - - starButton = (ImageButton) findViewById(R.id.download_star); - starButton.setVisibility(Util.isOffline(this) ? View.GONE : View.VISIBLE); - starButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - DownloadFile currentDownload = getDownloadService().getCurrentPlaying(); - if (currentDownload != null) { - MusicDirectory.Entry currentSong = currentDownload.getSong(); - toggleStarred(currentSong); - starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); - } - } - }); - - View.OnTouchListener touchListener = new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent me) { - return gestureScanner.onTouchEvent(me); - } - }; - pauseButton.setOnTouchListener(touchListener); - stopButton.setOnTouchListener(touchListener); - startButton.setOnTouchListener(touchListener); - equalizerButton.setOnTouchListener(touchListener); - visualizerButton.setOnTouchListener(touchListener); - jukeboxButton.setOnTouchListener(touchListener); - emptyTextView.setOnTouchListener(touchListener); - albumArtImageView.setOnTouchListener(touchListener); - - previousButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - warnIfNetworkOrStorageUnavailable(); - new SilentBackgroundTask(DownloadActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().previous(); - return null; - } - - @Override - protected void done(Void result) { - onCurrentChanged(); - onProgressChanged(); - } - }.execute(); - setControlsVisible(true); - } - }); - previousButton.setOnRepeatListener(new Runnable() { - public void run() { - changeProgress(-INCREMENT_TIME); - } - }); - - nextButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - warnIfNetworkOrStorageUnavailable(); - new SilentBackgroundTask(DownloadActivity.this) { - @Override - protected Boolean doInBackground() throws Throwable { - if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) { - getDownloadService().next(); - return true; - } else { - return false; - } - } - - @Override - protected void done(Boolean result) { - if(result) { - onCurrentChanged(); - onProgressChanged(); - } - } - }.execute(); - setControlsVisible(true); - } - }); - nextButton.setOnRepeatListener(new Runnable() { - public void run() { - changeProgress(INCREMENT_TIME); - } - }); - - pauseButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - new SilentBackgroundTask(DownloadActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().pause(); - return null; - } - - @Override - protected void done(Void result) { - onCurrentChanged(); - onProgressChanged(); - } - }.execute(); - } - }); - - stopButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - new SilentBackgroundTask(DownloadActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().reset(); - return null; - } - - @Override - protected void done(Void result) { - onCurrentChanged(); - onProgressChanged(); - } - }.execute(); - } - }); - - startButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - warnIfNetworkOrStorageUnavailable(); - new SilentBackgroundTask(DownloadActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - start(); - return null; - } - - @Override - protected void done(Void result) { - onCurrentChanged(); - onProgressChanged(); - } - }.execute(); - } - }); - - repeatButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - RepeatMode repeatMode = getDownloadService().getRepeatMode().next(); - getDownloadService().setRepeatMode(repeatMode); - onDownloadListChanged(); - switch (repeatMode) { - case OFF: - Util.toast(DownloadActivity.this, R.string.download_repeat_off); - break; - case ALL: - Util.toast(DownloadActivity.this, R.string.download_repeat_all); - break; - case SINGLE: - Util.toast(DownloadActivity.this, R.string.download_repeat_single); - break; - default: - break; - } - setControlsVisible(true); - } - }); - - equalizerButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - DownloadService downloadService = getDownloadService(); - if(downloadService != null && downloadService.getEqualizerController() != null - && downloadService.getEqualizerController().getEqualizer() != null) { - startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class)); - setControlsVisible(true); - } else { - Util.toast(DownloadActivity.this, "Failed to start equalizer. Try restarting."); - } - } - }); - - visualizerButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - boolean active = !visualizerView.isActive(); - visualizerView.setActive(active); - boolean isActive = visualizerView.isActive(); - getDownloadService().setShowVisualization(isActive); - updateButtons(); - if(active == isActive) { - Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off); - } else { - Util.toast(DownloadActivity.this, "Failed to start visualizer. Try restarting."); - } - setControlsVisible(true); - } - }); - - jukeboxButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled(); - getDownloadService().setJukeboxEnabled(jukeboxEnabled); - updateButtons(); - Util.toast(DownloadActivity.this, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false); - setControlsVisible(true); - } - }); - - toggleListButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - toggleFullscreenAlbumArt(); - setControlsVisible(true); - } - }); - - progressBar.setOnSliderChangeListener(new HorizontalSlider.OnSliderChangeListener() { - @Override - public void onSliderChanged(View view, final int position, boolean inProgress) { - Util.toast(DownloadActivity.this, Util.formatDuration(position / 1000), true); - if (!inProgress) { - new SilentBackgroundTask(DownloadActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().seekTo(position); - return null; - } - - @Override - protected void done(Void result) { - onProgressChanged(); - } - }.execute(); - } - setControlsVisible(true); - } - }); - playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, final int position, long id) { - if(nowPlaying) { - warnIfNetworkOrStorageUnavailable(); - new SilentBackgroundTask(DownloadActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().play(position); - return null; - } - - @Override - protected void done(Void result) { - onCurrentChanged(); - onProgressChanged(); - } - }.execute(); - } - } - }); - playlistView.setDropListener(new DragSortListView.DropListener() { - @Override - public void drop(int from, int to) { - getDownloadService().swap(nowPlaying, from, to); - onDownloadListChanged(); - } - }); - playlistView.setRemoveListener(new DragSortListView.RemoveListener() { - @Override - public void remove(int which) { - getDownloadService().remove(which); - onDownloadListChanged(); - } - }); - - registerForContextMenu(playlistView); - - DownloadService downloadService = getDownloadService(); - if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) { - getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE); - warnIfNetworkOrStorageUnavailable(); - downloadService.setShufflePlayEnabled(true); - } - - boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerAvailable(); - boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerAvailable(); - - if (!equalizerAvailable) { - equalizerButton.setVisibility(View.GONE); - } - if (!visualizerAvailable) { - visualizerButton.setVisibility(View.GONE); - } else { - visualizerView = new VisualizerView(this); - visualizerViewLayout.addView(visualizerView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); - } - - // TODO: Extract to utility method and cache. - Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Storopia.ttf"); - equalizerButton.setTypeface(typeface); - visualizerButton.setTypeface(typeface); - jukeboxButton.setTypeface(typeface); - } - - @Override - protected void onResume() { - super.onResume(); - - final Handler handler = new Handler(); - Runnable runnable = new Runnable() { - @Override - public void run() { - handler.post(new Runnable() { - @Override - public void run() { - update(); - } - }); - } - }; - - executorService = Executors.newSingleThreadScheduledExecutor(); - executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS); - - setControlsVisible(true); - - DownloadService downloadService = getDownloadService(); - if (downloadService == null || downloadService.getCurrentPlaying() == null) { - playlistFlipper.setDisplayedChild(1); - } - - onDownloadListChanged(); - onCurrentChanged(); - onProgressChanged(); - scrollToCurrent(); - if (downloadService != null && downloadService.getKeepScreenOn()) { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } else { - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - - if (visualizerView != null && downloadService != null && downloadService.getShowVisualization()) { - visualizerView.setActive(true); - } - - updateButtons(); - } - - private void scheduleHideControls() { - if (hideControlsFuture != null) { - hideControlsFuture.cancel(false); - } - - final Handler handler = new Handler(); - Runnable runnable = new Runnable() { - @Override - public void run() { - handler.post(new Runnable() { - @Override - public void run() { - setControlsVisible(false); - } - }); - } - }; - hideControlsFuture = executorService.schedule(runnable, 3000L, TimeUnit.MILLISECONDS); - } - - private void setControlsVisible(boolean visible) { - try { - long duration = 1700L; - FadeOutAnimation.createAndStart(findViewById(R.id.download_overlay_buttons), !visible, duration); - - if (visible) { - scheduleHideControls(); - } - } catch(Exception e) { - - } - } - - private void updateButtons() { - SharedPreferences prefs = Util.getPreferences(DownloadActivity.this); - boolean equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false); - if(equalizerOn && getDownloadService() != null && getDownloadService().getEqualizerController() != null && - getDownloadService().getEqualizerController().isEnabled()) { - equalizerButton.setTextColor(COLOR_BUTTON_ENABLED); - } else { - equalizerButton.setTextColor(COLOR_BUTTON_DISABLED); - } - - if (visualizerView != null) { - visualizerButton.setTextColor(visualizerView.isActive() ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED); - } - - boolean jukeboxEnabled = getDownloadService() != null && getDownloadService().isJukeboxEnabled(); - jukeboxButton.setTextColor(jukeboxEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED); - } - - // Scroll to current playing/downloading. - private void scrollToCurrent() { - if (getDownloadService() == null || songListAdapter == null) { - return; - } - - for (int i = 0; i < songListAdapter.getCount(); i++) { - if (currentPlaying == playlistView.getItemAtPosition(i)) { - playlistView.setSelectionFromTop(i, 40); - return; - } - } - DownloadFile currentDownloading = getDownloadService().getCurrentDownloading(); - for (int i = 0; i < songListAdapter.getCount(); i++) { - if (currentDownloading == playlistView.getItemAtPosition(i)) { - playlistView.setSelectionFromTop(i, 40); - return; - } - } - } - - @Override - protected void onPause() { - super.onPause(); - executorService.shutdown(); - if (visualizerView != null && visualizerView.isActive()) { - visualizerView.setActive(false); - } - } - - @Override - protected Dialog onCreateDialog(int id) { - if (id == DIALOG_SAVE_PLAYLIST) { - AlertDialog.Builder builder; - - LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); - final View layout = inflater.inflate(R.layout.save_playlist, (ViewGroup) findViewById(R.id.save_playlist_root)); - playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name); - - builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.download_playlist_title); - builder.setMessage(R.string.download_playlist_name); - builder.setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - savePlaylistInBackground(String.valueOf(playlistNameView.getText())); - } - }); - builder.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - builder.setView(layout); - builder.setCancelable(true); - - return builder.create(); - } else { - return super.onCreateDialog(id); - } - } - - @Override - protected void onPrepareDialog(int id, Dialog dialog) { - if (id == DIALOG_SAVE_PLAYLIST) { - String playlistName = (getDownloadService() != null) ? getDownloadService().getSuggestedPlaylistName() : null; - if (playlistName != null) { - playlistNameView.setText(playlistName); - } else { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - playlistNameView.setText(dateFormat.format(new Date())); - } - } - } - + /** + * Called when the activity is first created. + */ @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getSupportMenuInflater(); - if(Util.isOffline(this)) { - inflater.inflate(R.menu.nowplaying_offline, menu); - } else { - if(nowPlaying) - inflater.inflate(R.menu.nowplaying, menu); - else - inflater.inflate(R.menu.nowplaying_downloading, menu); - - if(getDownloadService() != null && getDownloadService().getSleepTimer()) { - menu.findItem(R.id.menu_toggle_timer).setTitle(R.string.download_stop_timer); - } - } - if(getDownloadService() != null && getDownloadService().getKeepScreenOn()) { - menu.findItem(R.id.menu_screen_on_off).setTitle(R.string.download_menu_screen_off); - } - return true; - } - - @Override - public void onCreateContextMenu(android.view.ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - if (view == playlistView) { - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position); - - android.view.MenuInflater inflater = getMenuInflater(); - if(Util.isOffline(this)) { - inflater.inflate(R.menu.nowplaying_context_offline, menu); - } else { - inflater.inflate(R.menu.nowplaying_context, menu); - menu.findItem(R.id.menu_star).setTitle(downloadFile.getSong().isStarred() ? R.string.common_unstar : R.string.common_star); - } - - if (downloadFile.getSong().getParent() == null) { - menu.findItem(R.id.menu_show_album).setVisible(false); - } - } - } - - @Override - public boolean onContextItemSelected(android.view.MenuItem menuItem) { - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position); - return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem); - } - - @Override - public boolean onOptionsItemSelected(MenuItem menuItem) { - return menuItemSelected(menuItem.getItemId(), null) || super.onOptionsItemSelected(menuItem); - } - - private boolean menuItemSelected(int menuItemId, final DownloadFile song) { - switch (menuItemId) { - case R.id.menu_show_album: - Intent intent = new Intent(this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, song.getSong().getParent()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, song.getSong().getAlbum()); - Util.startActivityWithoutTransition(this, intent); - return true; - case R.id.menu_lyrics: - intent = new Intent(this, LyricsActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, song.getSong().getArtist()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_TITLE, song.getSong().getTitle()); - Util.startActivityWithoutTransition(this, intent); - return true; - case R.id.menu_remove: - new SilentBackgroundTask(DownloadActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().remove(song); - return null; - } - - @Override - protected void done(Void result) { - onDownloadListChanged(); - } - }.execute(); - return true; - case R.id.menu_delete: - List songs = new ArrayList(1); - songs.add(song.getSong()); - getDownloadService().delete(songs); - return true; - case R.id.menu_remove_all: - new SilentBackgroundTask(DownloadActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().setShufflePlayEnabled(false); - if(nowPlaying) { - getDownloadService().clear(); - } - else { - getDownloadService().clearBackground(); - } - return null; - } - - @Override - protected void done(Void result) { - onDownloadListChanged(); - } - }.execute(); - return true; - case R.id.menu_screen_on_off: - if (getDownloadService().getKeepScreenOn()) { - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - getDownloadService().setKeepScreenOn(false); - } else { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - getDownloadService().setKeepScreenOn(true); - } - invalidateOptionsMenu(); - return true; - case R.id.menu_shuffle: - new SilentBackgroundTask(DownloadActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - getDownloadService().shuffle(); - return null; - } - - @Override - protected void done(Void result) { - Util.toast(DownloadActivity.this, R.string.download_menu_shuffle_notification); - } - }.execute(); - return true; - case R.id.menu_save_playlist: - showDialog(DIALOG_SAVE_PLAYLIST); - return true; - case R.id.menu_star: - toggleStarred(song.getSong()); - return true; - case R.id.menu_toggle_now_playing: - toggleNowPlaying(); - invalidateOptionsMenu(); - return true; - case R.id.menu_toggle_timer: - if(getDownloadService().getSleepTimer()) { - getDownloadService().stopSleepTimer(); - invalidateOptionsMenu(); - } else { - startTimer(); - } - return true; - case R.id.menu_exit: - intent = new Intent(this, MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); - Util.startActivityWithoutTransition(this, intent); - return true; - case R.id.menu_add_playlist: - songs = new ArrayList(1); - songs.add(song.getSong()); - addToPlaylist(songs); - return true; - case R.id.menu_info: - displaySongInfo(song.getSong()); - return true; - default: - return false; - } - } - - private void update() { - if (getDownloadService() == null) { - return; - } - - if (currentRevision != getDownloadService().getDownloadListUpdateRevision()) { - onDownloadListChanged(); - } - - if (currentPlaying != getDownloadService().getCurrentPlaying()) { - onCurrentChanged(); - } - - onProgressChanged(); - } - - private void savePlaylistInBackground(final String playlistName) { - Util.toast(DownloadActivity.this, getResources().getString(R.string.download_playlist_saving, playlistName)); - getDownloadService().setSuggestedPlaylistName(playlistName); - new SilentBackgroundTask(this) { - @Override - protected Void doInBackground() throws Throwable { - List entries = new LinkedList(); - for (DownloadFile downloadFile : getDownloadService().getSongs()) { - entries.add(downloadFile.getSong()); - } - MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this); - musicService.createPlaylist(null, playlistName, entries, DownloadActivity.this, null); - return null; - } - - @Override - protected void done(Void result) { - Util.toast(DownloadActivity.this, R.string.download_playlist_done); - } - - @Override - protected void error(Throwable error) { - String msg = getResources().getString(R.string.download_playlist_error) + " " + getErrorMessage(error); - Util.toast(DownloadActivity.this, msg); - } - }.execute(); - } - - protected void startTimer() { - View dialogView = getLayoutInflater().inflate(R.layout.start_timer, null); - final EditText lengthBox = (EditText)dialogView.findViewById(R.id.timer_length); - - final SharedPreferences prefs = Util.getPreferences(DownloadActivity.this); - lengthBox.setText(prefs.getString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, "")); - - AlertDialog.Builder builder = new AlertDialog.Builder(DownloadActivity.this); - builder.setTitle(R.string.menu_set_timer) - .setView(dialogView) - .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - String length = lengthBox.getText().toString(); - - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(Constants.PREFERENCES_KEY_SLEEP_TIMER_DURATION, length); - editor.commit(); - - getDownloadService().setSleepTimerDuration(Integer.parseInt(length)); - getDownloadService().startSleepTimer(); - invalidateOptionsMenu(); - } - }) - .setNegativeButton(R.string.common_cancel, null); - AlertDialog dialog = builder.create(); - dialog.show(); - } - - private void toggleFullscreenAlbumArt() { - scrollToCurrent(); - if (playlistFlipper.getDisplayedChild() == 1) { - playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_down_in)); - playlistFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_down_out)); - playlistFlipper.setDisplayedChild(0); - } else { - playlistFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in)); - playlistFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_out)); - playlistFlipper.setDisplayedChild(1); - } - } - - private void start() { - DownloadService service = getDownloadService(); - PlayerState state = service.getPlayerState(); - if (state == PAUSED || state == COMPLETED || state == STOPPED) { - service.start(); - } else if (state == STOPPED || state == IDLE) { - warnIfNetworkOrStorageUnavailable(); - int current = service.getCurrentPlayingIndex(); - // TODO: Use play() method. - if (current == -1) { - service.play(0); - } else { - service.play(current); - } - } - } - private void onDownloadListChanged() { - onDownloadListChanged(false); - } - private void onDownloadListChanged(boolean refresh) { - DownloadService downloadService = getDownloadService(); - if (downloadService == null) { - return; - } - - List list; - if(nowPlaying) { - list = downloadService.getSongs(); - } - else { - list = downloadService.getBackgroundDownloads(); - } - - if(downloadService.isShufflePlayEnabled()) { - emptyTextView.setText(R.string.download_shuffle_loading); - } - else { - emptyTextView.setText(R.string.download_empty); - } - - if(songListAdapter == null || refresh) { - playlistView.setAdapter(songListAdapter = new SongListAdapter(list)); - } else { - songListAdapter.notifyDataSetChanged(); - } - emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE); - currentRevision = downloadService.getDownloadListUpdateRevision(); - - switch (downloadService.getRepeatMode()) { - case OFF: - if("light".equals(theme) | "light_fullscreen".equals(theme)) { - repeatButton.setImageResource(R.drawable.media_repeat_off_light); - } else { - repeatButton.setImageResource(R.drawable.media_repeat_off); - } - break; - case ALL: - repeatButton.setImageResource(R.drawable.media_repeat_all); - break; - case SINGLE: - repeatButton.setImageResource(R.drawable.media_repeat_single); - break; - default: - break; - } - } - - private void onCurrentChanged() { - if (getDownloadService() == null) { - return; - } - - currentPlaying = getDownloadService().getCurrentPlaying(); - if (currentPlaying != null) { - MusicDirectory.Entry song = currentPlaying.getSong(); - songTitleTextView.setText(song.getTitle()); - getImageLoader().loadImage(albumArtImageView, song, true, true); - starButton.setImageResource(song.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); - } else { - songTitleTextView.setText(null); - getImageLoader().loadImage(albumArtImageView, null, true, false); - starButton.setImageResource(android.R.drawable.btn_star_big_off); - } - } - - private void onProgressChanged() { - // Make sure to only be trying to run one of these at a time - if (getDownloadService() == null || onProgressChangedTask != null) { - return; - } - - onProgressChangedTask = new SilentBackgroundTask(this) { - DownloadService downloadService; - boolean isJukeboxEnabled; - int millisPlayed; - Integer duration; - PlayerState playerState; - - @Override - protected Void doInBackground() throws Throwable { - downloadService = getDownloadService(); - isJukeboxEnabled = downloadService.isJukeboxEnabled(); - millisPlayed = Math.max(0, downloadService.getPlayerPosition()); - duration = downloadService.getPlayerDuration(); - playerState = getDownloadService().getPlayerState(); - return null; - } - - @Override - protected void done(Void result) { - if (currentPlaying != null) { - int millisTotal = duration == null ? 0 : duration; - - positionTextView.setText(Util.formatDuration(millisPlayed / 1000)); - durationTextView.setText(Util.formatDuration(millisTotal / 1000)); - progressBar.setMax(millisTotal == 0 ? 100 : millisTotal); // Work-around for apparent bug. - progressBar.setProgress(millisPlayed); - progressBar.setSlidingEnabled(currentPlaying.isWorkDone() || isJukeboxEnabled); - } else { - positionTextView.setText("0:00"); - durationTextView.setText("-:--"); - progressBar.setProgress(0); - progressBar.setSlidingEnabled(false); - } - - switch (playerState) { - case DOWNLOADING: - long bytes = currentPlaying.getPartialFile().length(); - statusTextView.setText(getResources().getString(R.string.download_playerstate_downloading, Util.formatLocalizedBytes(bytes, DownloadActivity.this))); - break; - case PREPARING: - statusTextView.setText(R.string.download_playerstate_buffering); - break; - case STARTED: - statusTextView.setText((currentPlaying != null) ? (currentPlaying.getSong().getArtist() + " - " + currentPlaying.getSong().getAlbum()) : null); - break; - default: - statusTextView.setText((currentPlaying != null) ? (currentPlaying.getSong().getArtist() + " - " + currentPlaying.getSong().getAlbum()) : null); - break; - } - - switch (playerState) { - case STARTED: - pauseButton.setVisibility(View.VISIBLE); - stopButton.setVisibility(View.INVISIBLE); - startButton.setVisibility(View.INVISIBLE); - break; - case DOWNLOADING: - case PREPARING: - pauseButton.setVisibility(View.INVISIBLE); - stopButton.setVisibility(View.VISIBLE); - startButton.setVisibility(View.INVISIBLE); - break; - default: - pauseButton.setVisibility(View.INVISIBLE); - stopButton.setVisibility(View.INVISIBLE); - startButton.setVisibility(View.VISIBLE); - break; - } - - jukeboxButton.setTextColor(isJukeboxEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED); - onProgressChangedTask = null; - } - }; - onProgressChangedTask.execute(); - } - - private void changeProgress(final int ms) { - final DownloadService downloadService = getDownloadService(); - if(downloadService == null) { - return; - } + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.download_activity); - new SilentBackgroundTask(this) { - boolean isJukeboxEnabled; - int msPlayed; - Integer duration; - PlayerState playerState; - int seekTo; - - @Override - protected Void doInBackground() throws Throwable { - msPlayed = Math.max(0, downloadService.getPlayerPosition()); - duration = downloadService.getPlayerDuration(); - playerState = getDownloadService().getPlayerState(); - int msTotal = duration == null ? 0 : duration; - if(msPlayed + ms > msTotal) { - seekTo = msTotal; - } else { - seekTo = msPlayed + ms; - } - downloadService.seekTo(seekTo); - return null; - } - - @Override - protected void done(Void result) { - progressBar.setProgress(seekTo); - } - }.execute(); - } - - private class SongListAdapter extends ArrayAdapter { - public SongListAdapter(List entries) { - super(DownloadActivity.this, android.R.layout.simple_list_item_1, entries); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - SongView view; - if (convertView != null && convertView instanceof SongView) { - view = (SongView) convertView; - } else { - view = new SongView(DownloadActivity.this); - } - DownloadFile downloadFile = getItem(position); - view.setSong(downloadFile.getSong(), false); - return view; - } - } - - @Override - public boolean onTouchEvent(MotionEvent me) { - return gestureScanner.onTouchEvent(me); - } - - @Override - public boolean onDown(MotionEvent me) { - setControlsVisible(true); - return false; - } - - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - DownloadService downloadService = getDownloadService(); - if (downloadService == null) { - return false; - } - - // Right to Left swipe - if (e1.getX() - e2.getX() > swipeDistance && Math.abs(velocityX) > swipeVelocity) { - warnIfNetworkOrStorageUnavailable(); - if (downloadService.getCurrentPlayingIndex() < downloadService.size() - 1) { - downloadService.next(); - onCurrentChanged(); - onProgressChanged(); - } - return true; - } - - // Left to Right swipe - else if (e2.getX() - e1.getX() > swipeDistance && Math.abs(velocityX) > swipeVelocity) { - warnIfNetworkOrStorageUnavailable(); - downloadService.previous(); - onCurrentChanged(); - onProgressChanged(); - return true; - } - - // Top to Bottom swipe - else if (e2.getY() - e1.getY() > swipeDistance && Math.abs(velocityY) > swipeVelocity) { - warnIfNetworkOrStorageUnavailable(); - downloadService.seekTo(downloadService.getPlayerPosition() + 30000); - onProgressChanged(); - return true; - } - - // Bottom to Top swipe - else if (e1.getY() - e2.getY() > swipeDistance && Math.abs(velocityY) > swipeVelocity) { - warnIfNetworkOrStorageUnavailable(); - downloadService.seekTo(downloadService.getPlayerPosition() - 8000); - onProgressChanged(); - return true; + if (findViewById(R.id.download_container) != null && savedInstanceState == null) { + fragment = new DownloadFragment(); + getSupportFragmentManager().beginTransaction().add(R.id.download_container, fragment).commit(); } - - return false; - } - - private void toggleNowPlaying() { - nowPlaying = !nowPlaying; - setTitle(nowPlaying ? "Now Playing" : "Downloading"); - onDownloadListChanged(true); - } - - @Override - public void onLongPress(MotionEvent e) { - } - - @Override - public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { - return false; - } - - @Override - public void onShowPress(MotionEvent e) { - } - - @Override - public boolean onSingleTapUp(MotionEvent e) { - return false; } } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index 2a457073..a9e20eae 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -130,9 +130,9 @@ public class SubsonicTabActivity extends SherlockActivity { musicButton.setEnabled(false); } else if (this instanceof SelectPlaylistActivity) { playlistButton.setEnabled(false); - } else if (this instanceof DownloadActivity || this instanceof LyricsActivity) { + } /*else if (this instanceof DownloadActivity || this instanceof LyricsActivity) { nowPlayingButton.setEnabled(false); - } + }*/ } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index de80ed7e..a6161790 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -454,7 +454,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe return rootView; } - + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { if(Util.isOffline(context)) { @@ -475,16 +475,16 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe menu.findItem(R.id.menu_screen_on_off).setTitle(R.string.download_menu_screen_off); } } - + @Override public boolean onOptionsItemSelected(MenuItem menuItem) { if(super.onOptionsItemSelected(menuItem)) { return true; } - + return menuItemSelected(menuItem.getItemId(), null); } - + @Override public void onCreateContextMenu(android.view.ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); @@ -505,7 +505,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe } } } - + @Override public boolean onContextItemSelected(android.view.MenuItem menuItem) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); @@ -628,8 +628,8 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe return false; } - /*@Override - protected void onResume() { + @Override + public void onResume() { super.onResume(); final Handler handler = new Handler(); @@ -660,9 +660,9 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe onProgressChanged(); scrollToCurrent(); if (downloadService != null && downloadService.getKeepScreenOn()) { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + context.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } else { - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + context.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } if (visualizerView != null && downloadService != null && downloadService.getShowVisualization()) { @@ -670,7 +670,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe } updateButtons(); - }*/ + } private void scheduleHideControls() { if (hideControlsFuture != null) { @@ -744,14 +744,14 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe } } - /*@Override - protected void onPause() { + @Override + public void onPause() { super.onPause(); executorService.shutdown(); if (visualizerView != null && visualizerView.isActive()) { visualizerView.setActive(false); } - }*/ + } /*@Override protected Dialog onCreateDialog(int id) { -- cgit v1.2.3 From e6641440c4184316a69d4c7ed67080ecb8242f33 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 17 Apr 2013 22:31:28 -0700 Subject: Add a bottom bar along main activity that links to download activity --- subsonic-android/res/layout/main.xml | 70 +++++++++++++++++++++- subsonic-android/res/values/styles.xml | 1 + .../daneren2005/dsub/activity/MainActivity.java | 69 ++++++++++++++++++++- .../dsub/fragments/DownloadFragment.java | 19 +++--- 4 files changed, 147 insertions(+), 12 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout/main.xml b/subsonic-android/res/layout/main.xml index 823922dc..fe79716c 100644 --- a/subsonic-android/res/layout/main.xml +++ b/subsonic-android/res/layout/main.xml @@ -6,8 +6,76 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/subsonic-android/res/values/styles.xml b/subsonic-android/res/values/styles.xml index 2d53a8d9..4dcce34f 100644 --- a/subsonic-android/res/values/styles.xml +++ b/subsonic-android/res/values/styles.xml @@ -12,6 +12,7 @@ diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 57423fb3..0240d5a3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -4,26 +4,50 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; +import android.os.Handler; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.view.Menu; import android.support.v4.view.ViewPager; import android.util.Log; +import android.view.View; +import android.widget.TextView; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.fragments.MainFragment; import github.daneren2005.dsub.fragments.SelectArtistFragment; import github.daneren2005.dsub.fragments.SelectPlaylistFragment; +import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.util.Util; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; public class MainActivity extends SubsonicActivity { private static final String TAG = MainActivity.class.getSimpleName(); private static boolean infoDialogDisplayed; + private ScheduledExecutorService executorService; + private View coverArtView; + private TextView trackView; + private TextView artistView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); + View bottomBar = findViewById(R.id.bottom_bar); + bottomBar.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + Intent intent = new Intent(); + intent.setClass(v.getContext(), DownloadActivity.class); + startActivity(intent); + } + }); + coverArtView = bottomBar.findViewById(R.id.album_art); + trackView = (TextView) bottomBar.findViewById(R.id.track_name); + artistView = (TextView) bottomBar.findViewById(R.id.artist_name); + viewPager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new TabPagerAdapter(this, viewPager); viewPager.setAdapter(pagerAdapter); @@ -48,8 +72,30 @@ public class MainActivity extends SubsonicActivity { @Override public void onResume() { super.onResume(); + + final Handler handler = new Handler(); + Runnable runnable = new Runnable() { + @Override + public void run() { + handler.post(new Runnable() { + @Override + public void run() { + update(); + } + }); + } + }; + + executorService = Executors.newSingleThreadScheduledExecutor(); + executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS); } + @Override + public void onPause() { + super.onPause(); + executorService.shutdown(); + } + @Override public void onBackPressed() { if(pagerAdapter.onBackPressed()) { @@ -66,7 +112,7 @@ public class MainActivity extends SubsonicActivity { dialog.show(); } } - + @Override public boolean onCreateOptionsMenu(Menu menu) { com.actionbarsherlock.view.MenuInflater menuInflater = getSupportMenuInflater(); @@ -74,9 +120,28 @@ public class MainActivity extends SubsonicActivity { return true; } @Override - public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { return pagerAdapter.onOptionsItemSelected(item); } + + private void update() { + if (getDownloadService() == null) { + return; + } + + DownloadFile current = getDownloadService().getCurrentPlaying(); + if(current == null) { + trackView.setText("Title"); + artistView.setText("Artist"); + getImageLoader().loadImage(coverArtView, null, false, false); + return; + } + + MusicDirectory.Entry song = current.getSong(); + trackView.setText(song.getTitle()); + artistView.setText(song.getArtist()); + getImageLoader().loadImage(coverArtView, song, false, false); + } private void showInfoDialog() { if (!infoDialogDisplayed) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index a6161790..3a05b059 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -120,6 +120,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.download, container, false); + setHasOptionsMenu(true); setTitle(nowPlaying ? "Now Playing" : "Downloading"); WindowManager w = context.getWindowManager(); @@ -671,6 +672,15 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe updateButtons(); } + + @Override + public void onPause() { + super.onPause(); + executorService.shutdown(); + if (visualizerView != null && visualizerView.isActive()) { + visualizerView.setActive(false); + } + } private void scheduleHideControls() { if (hideControlsFuture != null) { @@ -744,15 +754,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe } } - @Override - public void onPause() { - super.onPause(); - executorService.shutdown(); - if (visualizerView != null && visualizerView.isActive()) { - visualizerView.setActive(false); - } - } - /*@Override protected Dialog onCreateDialog(int id) { if (id == DIALOG_SAVE_PLAYLIST) { -- cgit v1.2.3 From f875b73b57da0156714cde8a2a086821a803daef Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 18 Apr 2013 18:33:25 -0700 Subject: Fix gestures on DownloadFragment --- .../src/github/daneren2005/dsub/activity/DownloadActivity.java | 10 ++++++++++ .../github/daneren2005/dsub/fragments/DownloadFragment.java | 10 +++++----- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index 81312aa6..a85fa139 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -20,6 +20,7 @@ package github.daneren2005.dsub.activity; import github.daneren2005.dsub.R; import android.os.Bundle; +import android.view.MotionEvent; import github.daneren2005.dsub.fragments.DownloadFragment; public class DownloadActivity extends SubsonicActivity { @@ -39,4 +40,13 @@ public class DownloadActivity extends SubsonicActivity { getSupportFragmentManager().beginTransaction().add(R.id.download_container, fragment).commit(); } } + + @Override + public boolean onTouchEvent(MotionEvent me) { + if(fragment != null) { + return fragment.getGestureDetector().onTouchEvent(me); + } else { + return false; + } + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 3a05b059..4e73a72b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -1107,16 +1107,15 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe } } - /*@Override - public boolean onTouchEvent(MotionEvent me) { - return gestureScanner.onTouchEvent(me); - }*/ - @Override public boolean onDown(MotionEvent me) { setControlsVisible(true); return false; } + + public GestureDetector getGestureDetector() { + return gestureScanner; + } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { @@ -1124,6 +1123,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe if (downloadService == null) { return false; } + Log.d(TAG, "onFling"); // Right to Left swipe if (e1.getX() - e2.getX() > swipeDistance && Math.abs(velocityX) > swipeVelocity) { -- cgit v1.2.3 From b821a78dbf0db79426a540ea119ef3b29a1c2865 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 18 Apr 2013 18:34:24 -0700 Subject: Fix redefining tabs when reopening activity --- .../github/daneren2005/dsub/activity/MainActivity.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 0240d5a3..fc283310 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -48,14 +48,16 @@ public class MainActivity extends SubsonicActivity { trackView = (TextView) bottomBar.findViewById(R.id.track_name); artistView = (TextView) bottomBar.findViewById(R.id.artist_name); - viewPager = (ViewPager) findViewById(R.id.pager); - pagerAdapter = new TabPagerAdapter(this, viewPager); - viewPager.setAdapter(pagerAdapter); - viewPager.setOnPageChangeListener(pagerAdapter); + if (savedInstanceState == null) { + viewPager = (ViewPager) findViewById(R.id.pager); + pagerAdapter = new TabPagerAdapter(this, viewPager); + viewPager.setAdapter(pagerAdapter); + viewPager.setOnPageChangeListener(pagerAdapter); - addTab("Home", MainFragment.class, null); - addTab("Library", SelectArtistFragment.class, null); - addTab("Playlists", SelectPlaylistFragment.class, null); + addTab("Home", MainFragment.class, null); + addTab("Library", SelectArtistFragment.class, null); + addTab("Playlists", SelectPlaylistFragment.class, null); + } } @Override -- cgit v1.2.3 From d641f0831535c8ff1996b45da76fced20e5e7544 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 19 Apr 2013 21:21:38 -0700 Subject: Fix a bunch of the download fragment menu functions --- .../dsub/activity/DownloadActivity.java | 97 ++++- .../dsub/fragments/DownloadFragment.java | 107 +----- .../dsub/fragments/LibraryFunctionsFragment.java | 389 --------------------- .../daneren2005/dsub/fragments/MainFragment.java | 2 +- .../dsub/fragments/SelectArtistFragment.java | 2 +- .../dsub/fragments/SelectDirectoryFragment.java | 2 +- .../dsub/fragments/SelectPlaylistFragment.java | 2 +- .../dsub/fragments/SubsonicFragment.java | 366 ++++++++++++++++++- 8 files changed, 477 insertions(+), 490 deletions(-) delete mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index a85fa139..b43bb58a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -22,10 +22,29 @@ import github.daneren2005.dsub.R; import android.os.Bundle; import android.view.MotionEvent; import github.daneren2005.dsub.fragments.DownloadFragment; +import android.app.Dialog; +import android.view.LayoutInflater; +import android.widget.EditText; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.view.View; +import android.view.ViewGroup; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.service.DownloadFile; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.util.SilentBackgroundTask; +import github.daneren2005.dsub.util.Util; +import java.util.LinkedList; +import java.util.List; public class DownloadActivity extends SubsonicActivity { private static final String TAG = DownloadActivity.class.getSimpleName(); private DownloadFragment fragment; + private EditText playlistNameView; /** * Called when the activity is first created. @@ -34,13 +53,13 @@ public class DownloadActivity extends SubsonicActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.download_activity); - + if (findViewById(R.id.download_container) != null && savedInstanceState == null) { fragment = new DownloadFragment(); getSupportFragmentManager().beginTransaction().add(R.id.download_container, fragment).commit(); } } - + @Override public boolean onTouchEvent(MotionEvent me) { if(fragment != null) { @@ -49,4 +68,78 @@ public class DownloadActivity extends SubsonicActivity { return false; } } + + @Override + public Dialog onCreateDialog(int id) { + if (id == DownloadFragment.DIALOG_SAVE_PLAYLIST) { + AlertDialog.Builder builder; + + LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); + final View layout = inflater.inflate(R.layout.save_playlist, null); + playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name); + + builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.download_playlist_title); + builder.setMessage(R.string.download_playlist_name); + builder.setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + savePlaylistInBackground(String.valueOf(playlistNameView.getText())); + } + }); + builder.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + } + }); + builder.setView(layout); + builder.setCancelable(true); + + return builder.create(); + } else { + return super.onCreateDialog(id); + } + } + + @Override + public void onPrepareDialog(int id, Dialog dialog) { + if (id == DownloadFragment.DIALOG_SAVE_PLAYLIST) { + String playlistName = (getDownloadService() != null) ? getDownloadService().getSuggestedPlaylistName() : null; + if (playlistName != null) { + playlistNameView.setText(playlistName); + } else { + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + playlistNameView.setText(dateFormat.format(new Date())); + } + } + } + + private void savePlaylistInBackground(final String playlistName) { + Util.toast(this, getResources().getString(R.string.download_playlist_saving, playlistName)); + getDownloadService().setSuggestedPlaylistName(playlistName); + new SilentBackgroundTask(DownloadActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + List entries = new LinkedList(); + for (DownloadFile downloadFile : getDownloadService().getSongs()) { + entries.add(downloadFile.getSong()); + } + MusicService musicService = MusicServiceFactory.getMusicService(DownloadActivity.this); + musicService.createPlaylist(null, playlistName, entries, DownloadActivity.this, null); + return null; + } + + @Override + protected void done(Void result) { + Util.toast(DownloadActivity.this, R.string.download_playlist_done); + } + + @Override + protected void error(Throwable error) { + String msg = getResources().getString(R.string.download_playlist_error) + " " + getErrorMessage(error); + Util.toast(DownloadActivity.this, msg); + } + }.execute(); + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 4e73a72b..68140328 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -1,8 +1,5 @@ package github.daneren2005.dsub.fragments; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.concurrent.Executors; @@ -10,7 +7,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import android.app.AlertDialog; -import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; @@ -64,13 +60,14 @@ import java.util.ArrayList; import java.util.concurrent.ScheduledFuture; import com.mobeta.android.dslv.*; import github.daneren2005.dsub.activity.EqualizerActivity; +import github.daneren2005.dsub.activity.LyricsActivity; import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.service.DownloadServiceImpl; public class DownloadFragment extends SubsonicFragment implements OnGestureListener { private static final String TAG = DownloadFragment.class.getSimpleName(); - private static final int DIALOG_SAVE_PLAYLIST = 100; + public static final int DIALOG_SAVE_PLAYLIST = 100; private static final int PERCENTAGE_OF_SCREEN_FOR_SWIPE = 10; private static final int COLOR_BUTTON_ENABLED = Color.rgb(51, 181, 229); private static final int COLOR_BUTTON_DISABLED = Color.rgb(206, 213, 211); @@ -99,7 +96,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe private ScheduledExecutorService executorService; private DownloadFile currentPlaying; private long currentRevision; - private EditText playlistNameView; private GestureDetector gestureScanner; private int swipeDistance; private int swipeVelocity; @@ -515,12 +511,13 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe } private boolean menuItemSelected(int menuItemId, final DownloadFile song) { - /*switch (menuItemId) { + Intent intent; + switch (menuItemId) { case R.id.menu_show_album: - Intent intent = new Intent(context, SelectAlbumActivity.class); + /*Intent intent = new Intent(context, SelectAlbumActivity.class); intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, song.getSong().getParent()); intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, song.getSong().getAlbum()); - Util.startActivityWithoutTransition(context, intent); + Util.startActivityWithoutTransition(context, intent);*/ return true; case R.id.menu_lyrics: intent = new Intent(context, LyricsActivity.class); @@ -569,10 +566,10 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe return true; case R.id.menu_screen_on_off: if (getDownloadService().getKeepScreenOn()) { - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + context.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getDownloadService().setKeepScreenOn(false); } else { - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + context.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getDownloadService().setKeepScreenOn(true); } context.invalidateOptionsMenu(); @@ -592,7 +589,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe }.execute(); return true; case R.id.menu_save_playlist: - showDialog(DIALOG_SAVE_PLAYLIST); + context.showDialog(DIALOG_SAVE_PLAYLIST); return true; case R.id.menu_star: toggleStarred(song.getSong()); @@ -610,10 +607,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe } return true; case R.id.menu_exit: - intent = new Intent(context, MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); - Util.startActivityWithoutTransition(context, intent); + exit(); return true; case R.id.menu_add_playlist: songs = new ArrayList(1); @@ -625,8 +619,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe return true; default: return false; - }*/ - return false; + } } @Override @@ -672,7 +665,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe updateButtons(); } - + @Override public void onPause() { super.onPause(); @@ -754,52 +747,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe } } - /*@Override - protected Dialog onCreateDialog(int id) { - if (id == DIALOG_SAVE_PLAYLIST) { - AlertDialog.Builder builder; - - LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); - final View layout = inflater.inflate(R.layout.save_playlist, (ViewGroup)rootView.findViewById(R.id.save_playlist_root)); - playlistNameView = (EditText) layout.findViewById(R.id.save_playlist_name); - - builder = new AlertDialog.Builder(context); - builder.setTitle(R.string.download_playlist_title); - builder.setMessage(R.string.download_playlist_name); - builder.setPositiveButton(R.string.common_save, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - savePlaylistInBackground(String.valueOf(playlistNameView.getText())); - } - }); - builder.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - builder.setView(layout); - builder.setCancelable(true); - - return builder.create(); - } else { - return super.onCreateDialog(id); - } - }*/ - - /*@Override - protected void onPrepareDialog(int id, Dialog dialog) { - if (id == DIALOG_SAVE_PLAYLIST) { - String playlistName = (getDownloadService() != null) ? getDownloadService().getSuggestedPlaylistName() : null; - if (playlistName != null) { - playlistNameView.setText(playlistName); - } else { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - playlistNameView.setText(dateFormat.format(new Date())); - } - } - }*/ - private void update() { if (getDownloadService() == null) { return; @@ -816,34 +763,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe onProgressChanged(); } - private void savePlaylistInBackground(final String playlistName) { - Util.toast(context, context.getResources().getString(R.string.download_playlist_saving, playlistName)); - getDownloadService().setSuggestedPlaylistName(playlistName); - new SilentBackgroundTask(context) { - @Override - protected Void doInBackground() throws Throwable { - List entries = new LinkedList(); - for (DownloadFile downloadFile : getDownloadService().getSongs()) { - entries.add(downloadFile.getSong()); - } - MusicService musicService = MusicServiceFactory.getMusicService(context); - musicService.createPlaylist(null, playlistName, entries, context, null); - return null; - } - - @Override - protected void done(Void result) { - Util.toast(context, R.string.download_playlist_done); - } - - @Override - protected void error(Throwable error) { - String msg = context.getResources().getString(R.string.download_playlist_error) + " " + getErrorMessage(error); - Util.toast(context, msg); - } - }.execute(); - } - protected void startTimer() { View dialogView = context.getLayoutInflater().inflate(R.layout.start_timer, null); final EditText lengthBox = (EditText)dialogView.findViewById(R.id.timer_length); @@ -1112,7 +1031,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe setControlsVisible(true); return false; } - + public GestureDetector getGestureDetector() { return gestureScanner; } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java deleted file mode 100644 index 1bfd2e39..00000000 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/LibraryFunctionsFragment.java +++ /dev/null @@ -1,389 +0,0 @@ -package github.daneren2005.dsub.fragments; - -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.media.MediaMetadataRetriever; -import android.util.Log; -import android.view.View; -import android.widget.EditText; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.activity.DownloadActivity; -import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.Util; -import com.actionbarsherlock.view.Menu; -import com.actionbarsherlock.view.MenuItem; -import github.daneren2005.dsub.activity.HelpActivity; -import github.daneren2005.dsub.activity.SettingsActivity; -import github.daneren2005.dsub.activity.SubsonicTabActivity; -import github.daneren2005.dsub.domain.Artist; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.domain.Playlist; -import github.daneren2005.dsub.service.DownloadFile; -import github.daneren2005.dsub.service.DownloadService; -import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.service.OfflineException; -import github.daneren2005.dsub.service.ServerTooOldException; -import github.daneren2005.dsub.util.FileUtil; -import github.daneren2005.dsub.util.LoadingTask; -import github.daneren2005.dsub.util.ModalBackgroundTask; -import github.daneren2005.dsub.util.SilentBackgroundTask; -import java.io.File; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -public class LibraryFunctionsFragment extends SubsonicTabFragment { - private static final String TAG = LibraryFunctionsFragment.class.getSimpleName(); - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_refresh: - refresh(); - return true; - case R.id.menu_shuffle: - onShuffleRequested(); - return true; - case R.id.menu_search: - context.onSearchRequested(); - return true; - case R.id.menu_exit: - exit(); - return true; - case R.id.menu_settings: - startActivity(new Intent(context, SettingsActivity.class)); - return true; - case R.id.menu_help: - startActivity(new Intent(context, HelpActivity.class)); - return true; - } - - return false; - } - - protected void onShuffleRequested() { - if(Util.isOffline(context)) { - Intent intent = new Intent(context, DownloadActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); - Util.startActivityWithoutTransition(context, intent); - return; - } - - View dialogView = context.getLayoutInflater().inflate(R.layout.shuffle_dialog, null); - final EditText startYearBox = (EditText)dialogView.findViewById(R.id.start_year); - final EditText endYearBox = (EditText)dialogView.findViewById(R.id.end_year); - final EditText genreBox = (EditText)dialogView.findViewById(R.id.genre); - - final SharedPreferences prefs = Util.getPreferences(context); - final String oldStartYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, ""); - final String oldEndYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, ""); - final String oldGenre = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, ""); - - startYearBox.setText(oldStartYear); - endYearBox.setText(oldEndYear); - genreBox.setText(oldGenre); - - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle("Shuffle By") - .setView(dialogView) - .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - Intent intent = new Intent(context, DownloadActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); - String genre = genreBox.getText().toString(); - String startYear = startYearBox.getText().toString(); - String endYear = endYearBox.getText().toString(); - - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYear); - editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYear); - editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre); - editor.commit(); - - Util.startActivityWithoutTransition(context, intent); - } - }) - .setNegativeButton(R.string.common_cancel, null); - AlertDialog dialog = builder.create(); - dialog.show(); - } - - public void toggleStarred(final MusicDirectory.Entry entry) { - final boolean starred = !entry.isStarred(); - entry.setStarred(starred); - - new SilentBackgroundTask(context) { - @Override - protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); - musicService.setStarred(entry.getId(), starred, context, null); - return null; - } - - @Override - protected void done(Void result) { - // UpdateView - Util.toast(context, context.getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getTitle())); - } - - @Override - protected void error(Throwable error) { - entry.setStarred(!starred); - - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = context.getResources().getString(R.string.starring_content_error, entry.getTitle()) + " " + getErrorMessage(error); - } - - Util.toast(context, msg, false); - } - }.execute(); - } - public void toggleStarred(final Artist entry) { - final boolean starred = !entry.isStarred(); - entry.setStarred(starred); - - new SilentBackgroundTask(context) { - @Override - protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); - musicService.setStarred(entry.getId(), starred, context, null); - return null; - } - - @Override - protected void done(Void result) { - // UpdateView - Util.toast(context, context.getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getName())); - } - - @Override - protected void error(Throwable error) { - entry.setStarred(!starred); - - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = context.getResources().getString(R.string.starring_content_error, entry.getName()) + " " + getErrorMessage(error); - } - - Util.toast(context, msg, false); - } - }.execute(); - } - - protected void downloadRecursively(final String id, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { - downloadRecursively(id, "", true, save, append, autoplay, shuffle, background); - } - protected void downloadPlaylist(final String id, final String name, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { - downloadRecursively(id, name, false, save, append, autoplay, shuffle, background); - } - protected void downloadRecursively(final String id, final String name, final boolean isDirectory, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { - ModalBackgroundTask> task = new ModalBackgroundTask>(context, false) { - private static final int MAX_SONGS = 500; - - @Override - protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); - MusicDirectory root; - if(isDirectory) - root = musicService.getMusicDirectory(id, name, false, context, this); - else - root = musicService.getPlaylist(id, name, context, this); - List songs = new LinkedList(); - getSongsRecursively(root, songs); - return songs; - } - - private void getSongsRecursively(MusicDirectory parent, List songs) throws Exception { - if (songs.size() > MAX_SONGS) { - return; - } - - for (MusicDirectory.Entry song : parent.getChildren(false, true)) { - if (!song.isVideo()) { - songs.add(song); - } - } - for (MusicDirectory.Entry dir : parent.getChildren(true, false)) { - MusicService musicService = MusicServiceFactory.getMusicService(context); - getSongsRecursively(musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, context, this), songs); - } - } - - @Override - protected void done(List songs) { - DownloadService downloadService = getDownloadService(); - if (!songs.isEmpty() && downloadService != null) { - if (!append) { - downloadService.clear(); - } - warnIfNetworkOrStorageUnavailable(); - if(!background) { - downloadService.download(songs, save, autoplay, false, shuffle); - if(!append) { - Util.startActivityWithoutTransition(context, DownloadActivity.class); - } - } - else { - downloadService.downloadBackground(songs, save); - } - } - } - }; - - task.execute(); - } - - protected void addToPlaylist(final List songs) { - if(songs.isEmpty()) { - Util.toast(context, "No songs selected"); - return; - } - - /*new LoadingTask>(context, true) { - @Override - protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); - return musicService.getPlaylists(false, context, this); - } - - @Override - protected void done(final List playlists) { - List names = new ArrayList(); - for(Playlist playlist: playlists) { - names.add(playlist.getName()); - } - - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle("Add to Playlist") - .setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - addToPlaylist(playlists.get(which), songs); - } - }); - AlertDialog dialog = builder.create(); - dialog.show(); - } - - @Override - protected void error(Throwable error) { - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = context.getResources().getString(R.string.playlist_error) + " " + getErrorMessage(error); - } - - Util.toast(context, msg, false); - } - }.execute();*/ - } - - private void addToPlaylist(final Playlist playlist, final List songs) { - new SilentBackgroundTask(context) { - @Override - protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); - musicService.addToPlaylist(playlist.getId(), songs, context, null); - return null; - } - - @Override - protected void done(Void result) { - Util.toast(context, context.getResources().getString(R.string.updated_playlist, songs.size(), playlist.getName())); - } - - @Override - protected void error(Throwable error) { - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = context.getResources().getString(R.string.updated_playlist_error, playlist.getName()) + " " + getErrorMessage(error); - } - - Util.toast(context, msg, false); - } - }.execute(); - } - - public void displaySongInfo(final MusicDirectory.Entry song) { - Integer bitrate = null; - String format = null; - long size = 0; - try { - DownloadFile downloadFile = new DownloadFile(context, song, false); - File file = downloadFile.getCompleteFile(); - if(file.exists()) { - MediaMetadataRetriever metadata = new MediaMetadataRetriever(); - metadata.setDataSource(file.getAbsolutePath()); - String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); - bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000; - format = FileUtil.getExtension(file.getName()); - size = file.length(); - - if(Util.isOffline(context)) { - song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)); - String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR); - song.setYear(Integer.parseInt((year != null) ? year : "0")); - } - } - } catch(Exception e) { - Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver"); - } - - String msg = ""; - if(!song.isVideo()) { - msg += "Artist: " + song.getArtist() + "\nAlbum: " + song.getAlbum(); - } - if(song.getTrack() != null && song.getTrack() != 0) { - msg += "\nTrack: " + song.getTrack(); - } - if(song.getGenre() != null && !"".equals(song.getGenre())) { - msg += "\nGenre: " + song.getGenre(); - } - if(song.getYear() != null && song.getYear() != 0) { - msg += "\nYear: " + song.getYear(); - } - if(!Util.isOffline(context)) { - msg += "\nServer Format: " + song.getSuffix(); - if(song.getBitRate() != null && song.getBitRate() != 0) { - msg += "\nServer Bitrate: " + song.getBitRate() + " kpbs"; - } - } - if(format != null && !"".equals(format)) { - msg += "\nCached Format: " + format; - } - if(bitrate != null && bitrate != 0) { - msg += "\nCached Bitrate: " + bitrate + " kpbs"; - } - if(size != 0) { - msg += "\nSize: " + Util.formatBytes(size); - } - if(song.getDuration() != null && song.getDuration() != 0) { - msg += "\nLength: " + Util.formatDuration(song.getDuration()); - } - - new AlertDialog.Builder(context) - .setIcon(android.R.drawable.ic_dialog_alert) - .setTitle(song.getTitle()) - .setMessage(msg) - .show(); - } - - protected void warnIfNetworkOrStorageUnavailable() { - if (!Util.isExternalStoragePresent()) { - Util.toast(context, R.string.select_album_no_sdcard); - } else if (!Util.isOffline(context) && !Util.isNetworkConnected(context)) { - Util.toast(context, R.string.select_album_no_network); - } - } -} diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index c9e264d7..0e2b92e6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -29,7 +29,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class MainFragment extends LibraryFunctionsFragment { +public class MainFragment extends SubsonicTabFragment { private LayoutInflater inflater; private static final int MENU_GROUP_SERVER = 10; diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 4f3a820f..8675f625 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -30,7 +30,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -public class SelectArtistFragment extends LibraryFunctionsFragment implements AdapterView.OnItemClickListener { +public class SelectArtistFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectArtistFragment.class.getSimpleName(); private static final int MENU_GROUP_MUSIC_FOLDER = 10; diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 11e500b6..87ca2c68 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -42,7 +42,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; -public class SelectDirectoryFragment extends LibraryFunctionsFragment implements AdapterView.OnItemClickListener { +public class SelectDirectoryFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectDirectoryFragment.class.getSimpleName(); private DragSortListView entryList; diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 09b5e437..826e5e66 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -31,7 +31,7 @@ import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.PlaylistAdapter; import java.util.List; -public class SelectPlaylistFragment extends LibraryFunctionsFragment implements AdapterView.OnItemClickListener { +public class SelectPlaylistFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectPlaylistFragment.class.getSimpleName(); private ListView list; diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index cf6ed641..d0a5edb6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -19,19 +19,42 @@ package github.daneren2005.dsub.fragments; import android.app.Activity; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; +import android.media.MediaMetadataRetriever; import android.os.Bundle; import android.util.Log; import android.view.View; +import android.widget.EditText; import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragment; import github.daneren2005.dsub.R; +import github.daneren2005.dsub.activity.DownloadActivity; +import github.daneren2005.dsub.activity.HelpActivity; +import github.daneren2005.dsub.activity.SettingsActivity; import github.daneren2005.dsub.activity.SubsonicActivity; +import github.daneren2005.dsub.domain.Artist; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.Playlist; +import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.service.MusicService; +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.ImageLoader; +import github.daneren2005.dsub.util.ModalBackgroundTask; +import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.Util; +import java.io.File; +import java.util.LinkedList; +import java.util.List; public class SubsonicFragment extends SherlockFragment { private static final String TAG = SubsonicFragment.class.getSimpleName(); @@ -59,7 +82,33 @@ public class SubsonicFragment extends SherlockFragment { super.onAttach(activity); context = (SubsonicActivity)activity; } - + + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_refresh: + refresh(); + return true; + case R.id.menu_shuffle: + onShuffleRequested(); + return true; + case R.id.menu_search: + context.onSearchRequested(); + return true; + case R.id.menu_exit: + exit(); + return true; + case R.id.menu_settings: + startActivity(new Intent(context, SettingsActivity.class)); + return true; + case R.id.menu_help: + startActivity(new Intent(context, HelpActivity.class)); + return true; + } + + return false; + } + public DownloadService getDownloadService() { return context != null ? context.getDownloadService() : null; } @@ -110,4 +159,319 @@ public class SubsonicFragment extends SherlockFragment { Util.toast(context, R.string.select_album_no_network); } } + + protected void onShuffleRequested() { + if(Util.isOffline(context)) { + Intent intent = new Intent(context, DownloadActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); + Util.startActivityWithoutTransition(context, intent); + return; + } + + View dialogView = context.getLayoutInflater().inflate(R.layout.shuffle_dialog, null); + final EditText startYearBox = (EditText)dialogView.findViewById(R.id.start_year); + final EditText endYearBox = (EditText)dialogView.findViewById(R.id.end_year); + final EditText genreBox = (EditText)dialogView.findViewById(R.id.genre); + + final SharedPreferences prefs = Util.getPreferences(context); + final String oldStartYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, ""); + final String oldEndYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, ""); + final String oldGenre = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, ""); + + startYearBox.setText(oldStartYear); + endYearBox.setText(oldEndYear); + genreBox.setText(oldGenre); + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Shuffle By") + .setView(dialogView) + .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + Intent intent = new Intent(context, DownloadActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); + String genre = genreBox.getText().toString(); + String startYear = startYearBox.getText().toString(); + String endYear = endYearBox.getText().toString(); + + SharedPreferences.Editor editor = prefs.edit(); + editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYear); + editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYear); + editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre); + editor.commit(); + + Util.startActivityWithoutTransition(context, intent); + } + }) + .setNegativeButton(R.string.common_cancel, null); + AlertDialog dialog = builder.create(); + dialog.show(); + } + + public void toggleStarred(final MusicDirectory.Entry entry) { + final boolean starred = !entry.isStarred(); + entry.setStarred(starred); + + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.setStarred(entry.getId(), starred, context, null); + return null; + } + + @Override + protected void done(Void result) { + // UpdateView + Util.toast(context, context.getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getTitle())); + } + + @Override + protected void error(Throwable error) { + entry.setStarred(!starred); + + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.starring_content_error, entry.getTitle()) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute(); + } + public void toggleStarred(final Artist entry) { + final boolean starred = !entry.isStarred(); + entry.setStarred(starred); + + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.setStarred(entry.getId(), starred, context, null); + return null; + } + + @Override + protected void done(Void result) { + // UpdateView + Util.toast(context, context.getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getName())); + } + + @Override + protected void error(Throwable error) { + entry.setStarred(!starred); + + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.starring_content_error, entry.getName()) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute(); + } + + protected void downloadRecursively(final String id, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { + downloadRecursively(id, "", true, save, append, autoplay, shuffle, background); + } + protected void downloadPlaylist(final String id, final String name, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { + downloadRecursively(id, name, false, save, append, autoplay, shuffle, background); + } + protected void downloadRecursively(final String id, final String name, final boolean isDirectory, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { + ModalBackgroundTask> task = new ModalBackgroundTask>(context, false) { + private static final int MAX_SONGS = 500; + + @Override + protected List doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + MusicDirectory root; + if(isDirectory) + root = musicService.getMusicDirectory(id, name, false, context, this); + else + root = musicService.getPlaylist(id, name, context, this); + List songs = new LinkedList(); + getSongsRecursively(root, songs); + return songs; + } + + private void getSongsRecursively(MusicDirectory parent, List songs) throws Exception { + if (songs.size() > MAX_SONGS) { + return; + } + + for (MusicDirectory.Entry song : parent.getChildren(false, true)) { + if (!song.isVideo()) { + songs.add(song); + } + } + for (MusicDirectory.Entry dir : parent.getChildren(true, false)) { + MusicService musicService = MusicServiceFactory.getMusicService(context); + getSongsRecursively(musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, context, this), songs); + } + } + + @Override + protected void done(List songs) { + DownloadService downloadService = getDownloadService(); + if (!songs.isEmpty() && downloadService != null) { + if (!append) { + downloadService.clear(); + } + warnIfNetworkOrStorageUnavailable(); + if(!background) { + downloadService.download(songs, save, autoplay, false, shuffle); + if(!append) { + Util.startActivityWithoutTransition(context, DownloadActivity.class); + } + } + else { + downloadService.downloadBackground(songs, save); + } + } + } + }; + + task.execute(); + } + + protected void addToPlaylist(final List songs) { + if(songs.isEmpty()) { + Util.toast(context, "No songs selected"); + return; + } + + /*new LoadingTask>(context, true) { + @Override + protected List doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + return musicService.getPlaylists(false, context, this); + } + + @Override + protected void done(final List playlists) { + List names = new ArrayList(); + for(Playlist playlist: playlists) { + names.add(playlist.getName()); + } + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle("Add to Playlist") + .setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + addToPlaylist(playlists.get(which), songs); + } + }); + AlertDialog dialog = builder.create(); + dialog.show(); + } + + @Override + protected void error(Throwable error) { + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.playlist_error) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute();*/ + } + + private void addToPlaylist(final Playlist playlist, final List songs) { + new SilentBackgroundTask(context) { + @Override + protected Void doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(context); + musicService.addToPlaylist(playlist.getId(), songs, context, null); + return null; + } + + @Override + protected void done(Void result) { + Util.toast(context, context.getResources().getString(R.string.updated_playlist, songs.size(), playlist.getName())); + } + + @Override + protected void error(Throwable error) { + String msg; + if (error instanceof OfflineException || error instanceof ServerTooOldException) { + msg = getErrorMessage(error); + } else { + msg = context.getResources().getString(R.string.updated_playlist_error, playlist.getName()) + " " + getErrorMessage(error); + } + + Util.toast(context, msg, false); + } + }.execute(); + } + + public void displaySongInfo(final MusicDirectory.Entry song) { + Integer bitrate = null; + String format = null; + long size = 0; + try { + DownloadFile downloadFile = new DownloadFile(context, song, false); + File file = downloadFile.getCompleteFile(); + if(file.exists()) { + MediaMetadataRetriever metadata = new MediaMetadataRetriever(); + metadata.setDataSource(file.getAbsolutePath()); + String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); + bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000; + format = FileUtil.getExtension(file.getName()); + size = file.length(); + + if(Util.isOffline(context)) { + song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)); + String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR); + song.setYear(Integer.parseInt((year != null) ? year : "0")); + } + } + } catch(Exception e) { + Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver"); + } + + String msg = ""; + if(!song.isVideo()) { + msg += "Artist: " + song.getArtist() + "\nAlbum: " + song.getAlbum(); + } + if(song.getTrack() != null && song.getTrack() != 0) { + msg += "\nTrack: " + song.getTrack(); + } + if(song.getGenre() != null && !"".equals(song.getGenre())) { + msg += "\nGenre: " + song.getGenre(); + } + if(song.getYear() != null && song.getYear() != 0) { + msg += "\nYear: " + song.getYear(); + } + if(!Util.isOffline(context)) { + msg += "\nServer Format: " + song.getSuffix(); + if(song.getBitRate() != null && song.getBitRate() != 0) { + msg += "\nServer Bitrate: " + song.getBitRate() + " kpbs"; + } + } + if(format != null && !"".equals(format)) { + msg += "\nCached Format: " + format; + } + if(bitrate != null && bitrate != 0) { + msg += "\nCached Bitrate: " + bitrate + " kpbs"; + } + if(size != 0) { + msg += "\nSize: " + Util.formatBytes(size); + } + if(song.getDuration() != null && song.getDuration() != 0) { + msg += "\nLength: " + Util.formatDuration(song.getDuration()); + } + + new AlertDialog.Builder(context) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle(song.getTitle()) + .setMessage(msg) + .show(); + } } -- cgit v1.2.3 From 7e8a48fc4e0fb31af944c867c9e2c1e133f4a451 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 20 Apr 2013 21:19:35 -0700 Subject: Fix a few DownloadFragment functions + added up on DownloadActivity --- .../daneren2005/dsub/activity/DownloadActivity.java | 21 +++++++++++++++++++-- .../dsub/fragments/DownloadFragment.java | 6 +++--- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index b43bb58a..2204cb64 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -30,8 +30,9 @@ import java.text.SimpleDateFormat; import java.util.Date; import android.app.AlertDialog; import android.content.DialogInterface; +import android.content.Intent; import android.view.View; -import android.view.ViewGroup; +import com.actionbarsherlock.view.MenuItem; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.MusicService; @@ -58,6 +59,22 @@ public class DownloadActivity extends SubsonicActivity { fragment = new DownloadFragment(); getSupportFragmentManager().beginTransaction().add(R.id.download_container, fragment).commit(); } + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if(item.getItemId() == android.R.id.home) { + Intent i = new Intent(); + i.setClass(this, MainActivity.class); + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(i); + return true; + } else { + return false; + } } @Override @@ -114,7 +131,7 @@ public class DownloadActivity extends SubsonicActivity { } } } - + private void savePlaylistInBackground(final String playlistName) { Util.toast(this, getResources().getString(R.string.download_playlist_saving, playlistName)); getDownloadService().setSuggestedPlaylistName(playlistName); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 68140328..a38f9fcd 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -154,7 +154,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe DownloadFile currentDownload = getDownloadService().getCurrentPlaying(); if (currentDownload != null) { MusicDirectory.Entry currentSong = currentDownload.getSong(); - // toggleStarred(currentSong); + toggleStarred(currentSong); starButton.setImageResource(currentSong.isStarred() ? android.R.drawable.btn_star_big_on : android.R.drawable.btn_star_big_off); } } @@ -424,11 +424,11 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe registerForContextMenu(playlistView); DownloadService downloadService = getDownloadService(); - /*if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) { + if (downloadService != null && context.getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) { context.getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE); warnIfNetworkOrStorageUnavailable(); downloadService.setShufflePlayEnabled(true); - }*/ + } boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerAvailable(); boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerAvailable(); -- cgit v1.2.3 From 061cc641396244f300f75e28b52ee7d8aa2c6ed9 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 21 Apr 2013 16:35:12 -0700 Subject: Remove unused activities --- .../dsub/activity/SelectAlbumActivity.java | 798 --------------------- .../dsub/activity/SelectArtistActivity.java | 264 ------- .../dsub/activity/SelectPlaylistActivity.java | 301 -------- 3 files changed, 1363 deletions(-) delete mode 100644 subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java delete mode 100644 subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java delete mode 100644 subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java deleted file mode 100644 index 6432c385..00000000 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectAlbumActivity.java +++ /dev/null @@ -1,798 +0,0 @@ -/* - This file is part of Subsonic. - - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see . - - Copyright 2009 (C) Sindre Mehus - */ -package github.daneren2005.dsub.activity; - -import github.daneren2005.dsub.view.EntryAdapter; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.net.Uri; -import android.os.Bundle; -import android.util.Log; -import android.view.ContextMenu; -import android.view.LayoutInflater; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.*; -import com.actionbarsherlock.view.Menu; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.service.*; -import github.daneren2005.dsub.util.*; -import com.mobeta.android.dslv.*; -import java.io.File; - -import java.util.*; - -public class SelectAlbumActivity extends SubsonicTabActivity { - - private static final String TAG = SelectAlbumActivity.class.getSimpleName(); - - private DragSortListView entryList; - private View footer; - private View emptyView; - private boolean hideButtons = false; - private Button moreButton; - private Boolean licenseValid; - private boolean showHeader = true; - private EntryAdapter entryAdapter; - private List entries; - - /** - * Called when the activity is first created. - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.select_album); - - entryList = (DragSortListView) findViewById(R.id.select_album_entries); - - footer = LayoutInflater.from(this).inflate(R.layout.select_album_footer, entryList, false); - entryList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); - entryList.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - if (position >= 0) { - MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position); - if (entry.isDirectory()) { - Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle()); - Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent); - } else if (entry.isVideo()) { - if(entryExists(entry)) { - playExternalPlayer(entry); - } else { - streamExternalPlayer(entry); - } - } - } - } - }); - entryList.setDropListener(new DragSortListView.DropListener() { - @Override - public void drop(int from, int to) { - int max = entries.size(); - if(to >= max) { - to = max - 1; - } - else if(to < 0) { - to = 0; - } - entries.add(to, entries.remove(from)); - entryAdapter.notifyDataSetChanged(); - } - }); - - moreButton = (Button) footer.findViewById(R.id.select_album_more); - emptyView = findViewById(R.id.select_album_empty); - - registerForContextMenu(entryList); - - String id = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID); - String name = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_NAME); - String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); - String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); - String albumListType = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); - int albumListSize = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0); - int albumListOffset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0); - - if (playlistId != null) { - getPlaylist(playlistId, playlistName); - } else if (albumListType != null) { - getAlbumList(albumListType, albumListSize, albumListOffset); - } else { - getMusicDirectory(id, name); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); - if(licenseValid == null) { - inflater.inflate(R.menu.empty, menu); - } - else if(hideButtons) { - String albumListType = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); - if(albumListType != null) { - inflater.inflate(R.menu.select_album_list, menu); - } else { - inflater.inflate(R.menu.select_album, menu); - } - hideButtons = false; - } else { - if(Util.isOffline(this)) { - inflater.inflate(R.menu.select_song_offline, menu); - } - else { - inflater.inflate(R.menu.select_song, menu); - - String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); - if(playlistId == null) { - menu.removeItem(R.id.menu_remove_playlist); - } - } - } - return true; - } - - @Override - public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { - Intent intent; - switch (item.getItemId()) { - case R.id.menu_play_now: - playNow(false, false); - return true; - case R.id.menu_play_last: - playNow(false, true); - return true; - case R.id.menu_shuffle: - playNow(true, false); - return true; - case R.id.menu_select: - selectAllOrNone(); - return true; - case R.id.menu_refresh: - refresh(); - return true; - case R.id.menu_download: - downloadBackground(false); - selectAll(false, false); - return true; - case R.id.menu_cache: - downloadBackground(true); - selectAll(false, false); - return true; - case R.id.menu_delete: - delete(); - selectAll(false, false); - return true; - case R.id.menu_add_playlist: - addToPlaylist(getSelectedSongs()); - return true; - case R.id.menu_remove_playlist: - String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); - String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); - removeFromPlaylist(playlistId, playlistName, getSelectedIndexes()); - return true; - case R.id.menu_exit: - intent = new Intent(this, MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); - Util.startActivityWithoutTransition(this, intent); - return true; - case R.id.menu_settings: - startActivity(new Intent(this, SettingsActivity.class)); - return true; - case R.id.menu_help: - startActivity(new Intent(this, HelpActivity.class)); - return true; - } - - return false; - } - - private void playNow(final boolean shuffle, final boolean append) { - if(getSelectedSongs().size() > 0) { - download(append, false, !append, false, shuffle); - selectAll(false, false); - } - else { - playAll(shuffle, append); - } - } - private void playAll(final boolean shuffle, final boolean append) { - boolean hasSubFolders = false; - for (int i = 0; i < entryList.getCount(); i++) { - MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i); - if (entry != null && entry.isDirectory()) { - hasSubFolders = true; - break; - } - } - - String id = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID); - if (hasSubFolders && id != null) { - downloadRecursively(id, false, append, !append, shuffle, false); - } else { - selectAll(true, false); - download(append, false, !append, false, shuffle); - selectAll(false, false); - } - } - - private void refresh() { - finish(); - Intent intent = getIntent(); - intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true); - Util.startActivityWithoutTransition(this, intent); - } - - @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - AdapterView.AdapterContextMenuInfo info = - (AdapterView.AdapterContextMenuInfo) menuInfo; - - MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position); - - if (entry.isDirectory()) { - MenuInflater inflater = getMenuInflater(); - if(Util.isOffline(this)) - inflater.inflate(R.menu.select_album_context_offline, menu); - else - inflater.inflate(R.menu.select_album_context, menu); - } else if(!entry.isVideo()) { - MenuInflater inflater = getMenuInflater(); - if(Util.isOffline(this)) { - inflater.inflate(R.menu.select_song_context_offline, menu); - } - else { - inflater.inflate(R.menu.select_song_context, menu); - String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); - if(playlistId == null) { - menu.removeItem(R.id.song_menu_remove_playlist); - } - } - } else { - MenuInflater inflater = getMenuInflater(); - if(Util.isOffline(this)) - inflater.inflate(R.menu.select_video_context_offline, menu); - else - inflater.inflate(R.menu.select_video_context, menu); - } - - if (!Util.isOffline(this) && !entry.isVideo()) { - menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star).setTitle(entry.isStarred() ? R.string.common_unstar : R.string.common_star); - } - } - - @Override - public boolean onContextItemSelected(MenuItem menuItem) { - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position); - List songs = new ArrayList(10); - songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(info.position)); - switch (menuItem.getItemId()) { - case R.id.album_menu_play_now: - downloadRecursively(entry.getId(), false, false, true, false, false); - break; - case R.id.album_menu_play_shuffled: - downloadRecursively(entry.getId(), false, false, true, true, false); - break; - case R.id.album_menu_play_last: - downloadRecursively(entry.getId(), false, true, false, false, false); - break; - case R.id.album_menu_download: - downloadRecursively(entry.getId(), false, true, false, false, true); - break; - case R.id.album_menu_pin: - downloadRecursively(entry.getId(), true, true, false, false, true); - break; - case R.id.album_menu_star: - toggleStarred(entry); - break; - case R.id.album_menu_delete: - deleteRecursively(entry); - break; - case R.id.song_menu_play_now: - getDownloadService().clear(); - getDownloadService().download(songs, false, true, true, false); - Util.startActivityWithoutTransition(SelectAlbumActivity.this, DownloadActivity.class); - break; - case R.id.song_menu_play_next: - getDownloadService().download(songs, false, false, true, false); - break; - case R.id.song_menu_play_last: - getDownloadService().download(songs, false, false, false, false); - break; - case R.id.song_menu_download: - getDownloadService().downloadBackground(songs, false); - break; - case R.id.song_menu_pin: - getDownloadService().downloadBackground(songs, true); - break; - case R.id.song_menu_delete: - getDownloadService().delete(songs); - break; - case R.id.song_menu_add_playlist: - addToPlaylist(songs); - break; - case R.id.song_menu_star: - toggleStarred(entry); - break; - case R.id.song_menu_webview: - playWebView(entry); - break; - case R.id.song_menu_play_external: - playExternalPlayer(entry); - break; - case R.id.song_menu_info: - displaySongInfo(entry); - break; - case R.id.song_menu_stream_external: - streamExternalPlayer(entry); - break; - case R.id.song_menu_remove_playlist: - String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID); - String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); - removeFromPlaylist(playlistId, playlistName, Arrays.asList(info.position - 1)); - break; - default: - return super.onContextItemSelected(menuItem); - } - return true; - } - - private void getMusicDirectory(final String id, final String name) { - setTitle(name); - - new LoadTask() { - @Override - protected MusicDirectory load(MusicService service) throws Exception { - boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false); - return service.getMusicDirectory(id, name, refresh, SelectAlbumActivity.this, this); - } - }.execute(); - } - - private void getPlaylist(final String playlistId, final String playlistName) { - setTitle(playlistName); - - new LoadTask() { - @Override - protected MusicDirectory load(MusicService service) throws Exception { - return service.getPlaylist(playlistId, playlistName, SelectAlbumActivity.this, this); - } - }.execute(); - } - - private void getAlbumList(final String albumListType, final int size, final int offset) { - showHeader = false; - - if ("newest".equals(albumListType)) { - setTitle(R.string.main_albums_newest); - } else if ("random".equals(albumListType)) { - setTitle(R.string.main_albums_random); - } else if ("highest".equals(albumListType)) { - setTitle(R.string.main_albums_highest); - } else if ("recent".equals(albumListType)) { - setTitle(R.string.main_albums_recent); - } else if ("frequent".equals(albumListType)) { - setTitle(R.string.main_albums_frequent); - } else if ("starred".equals(albumListType)) { - setTitle(R.string.main_albums_starred); - } - - if (!"starred".equals(albumListType)) { - entryList.setDragEnabled(false); - } - - new LoadTask() { - @Override - protected MusicDirectory load(MusicService service) throws Exception { - MusicDirectory result; - if ("starred".equals(albumListType)) { - result = service.getStarredList(SelectAlbumActivity.this, this); - } else { - result = service.getAlbumList(albumListType, size, offset, SelectAlbumActivity.this, this); - } - return result; - } - - @Override - protected void done(Pair result) { - if (!result.getFirst().getChildren().isEmpty()) { - if (!("starred".equals(albumListType))) { - moreButton.setVisibility(View.VISIBLE); - entryList.addFooterView(footer); - } - - moreButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class); - String type = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE); - int size = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0); - int offset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0) + size; - - intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, size); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, offset); - Util.startActivityWithoutTransition(SelectAlbumActivity.this, intent); - } - }); - } - super.done(result); - } - }.execute(); - } - - private void selectAllOrNone() { - boolean someUnselected = false; - int count = entryList.getCount(); - for (int i = 0; i < count; i++) { - if (!entryList.isItemChecked(i) && entryList.getItemAtPosition(i) instanceof MusicDirectory.Entry) { - someUnselected = true; - break; - } - } - selectAll(someUnselected, true); - } - - private void selectAll(boolean selected, boolean toast) { - int count = entryList.getCount(); - int selectedCount = 0; - for (int i = 0; i < count; i++) { - MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(i); - if (entry != null && !entry.isDirectory() && !entry.isVideo()) { - entryList.setItemChecked(i, selected); - selectedCount++; - } - } - - // Display toast: N tracks selected / N tracks unselected - if (toast) { - int toastResId = selected ? R.string.select_album_n_selected - : R.string.select_album_n_unselected; - Util.toast(this, getString(toastResId, selectedCount)); - } - } - - private List getSelectedSongs() { - List songs = new ArrayList(10); - int count = entryList.getCount(); - for (int i = 0; i < count; i++) { - if (entryList.isItemChecked(i)) { - songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(i)); - } - } - return songs; - } - - private List getSelectedIndexes() { - List indexes = new ArrayList(); - - int count = entryList.getCount(); - for (int i = 0; i < count; i++) { - if (entryList.isItemChecked(i)) { - indexes.add(i - 1); - } - } - - return indexes; - } - - private void download(final boolean append, final boolean save, final boolean autoplay, final boolean playNext, final boolean shuffle) { - if (getDownloadService() == null) { - return; - } - - final List songs = getSelectedSongs(); - Runnable onValid = new Runnable() { - @Override - public void run() { - if (!append) { - getDownloadService().clear(); - } - - warnIfNetworkOrStorageUnavailable(); - getDownloadService().download(songs, save, autoplay, playNext, shuffle); - String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME); - if (playlistName != null) { - getDownloadService().setSuggestedPlaylistName(playlistName); - } - if (autoplay) { - Util.startActivityWithoutTransition(SelectAlbumActivity.this, DownloadActivity.class); - } else if (save) { - Util.toast(SelectAlbumActivity.this, - getResources().getQuantityString(R.plurals.select_album_n_songs_downloading, songs.size(), songs.size())); - } else if (append) { - Util.toast(SelectAlbumActivity.this, - getResources().getQuantityString(R.plurals.select_album_n_songs_added, songs.size(), songs.size())); - } - } - }; - - checkLicenseAndTrialPeriod(onValid); - } - private void downloadBackground(final boolean save) { - List songs = getSelectedSongs(); - if(songs.isEmpty()) { - selectAll(true, false); - songs = getSelectedSongs(); - } - downloadBackground(save, songs); - } - private void downloadBackground(final boolean save, final List songs) { - if (getDownloadService() == null) { - return; - } - - Runnable onValid = new Runnable() { - @Override - public void run() { - warnIfNetworkOrStorageUnavailable(); - getDownloadService().downloadBackground(songs, save); - - Util.toast(SelectAlbumActivity.this, - getResources().getQuantityString(R.plurals.select_album_n_songs_downloading, songs.size(), songs.size())); - } - }; - - checkLicenseAndTrialPeriod(onValid); - } - - private void delete() { - List songs = getSelectedSongs(); - if(songs.isEmpty()) { - selectAll(true, false); - songs = getSelectedSongs(); - } - if (getDownloadService() != null) { - getDownloadService().delete(songs); - } - } - - private boolean entryExists(MusicDirectory.Entry entry) { - DownloadFile check = new DownloadFile(this, entry, false); - return check.isCompleteFileAvailable(); - } - - private void playWebView(MusicDirectory.Entry entry) { - int maxBitrate = Util.getMaxVideoBitrate(this); - - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(maxBitrate, this, entry.getId()))); - - startActivity(intent); - } - private void playExternalPlayer(MusicDirectory.Entry entry) { - if(!entryExists(entry)) { - Util.toast(this, R.string.download_need_download); - } else { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setDataAndType(Uri.parse(entry.getPath()), "video/*"); - - List intents = getPackageManager() - .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); - if(intents != null && intents.size() > 0) { - startActivity(intent); - }else { - Util.toast(this, R.string.download_no_streaming_player); - } - } - } - private void streamExternalPlayer(MusicDirectory.Entry entry) { - int maxBitrate = Util.getMaxVideoBitrate(this); - - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoStreamUrl(maxBitrate, this, entry.getId())), "video/*"); - - List intents = getPackageManager() - .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); - if(intents != null && intents.size() > 0) { - startActivity(intent); - } else { - Util.toast(this, R.string.download_no_streaming_player); - } - } - - public void deleteRecursively(MusicDirectory.Entry album) { - File dir = FileUtil.getAlbumDirectory(this, album); - Util.recursiveDelete(dir); - if(Util.isOffline(this)) { - refresh(); - } - } - - private void checkLicenseAndTrialPeriod(Runnable onValid) { - if (licenseValid) { - onValid.run(); - return; - } - - int trialDaysLeft = Util.getRemainingTrialDays(this); - Log.i(TAG, trialDaysLeft + " trial days left."); - - if (trialDaysLeft == 0) { - showDonationDialog(trialDaysLeft, null); - } else if (trialDaysLeft < Constants.FREE_TRIAL_DAYS / 2) { - showDonationDialog(trialDaysLeft, onValid); - } else { - Util.toast(this, getResources().getString(R.string.select_album_not_licensed, trialDaysLeft)); - onValid.run(); - } - } - - private void showDonationDialog(int trialDaysLeft, final Runnable onValid) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setIcon(android.R.drawable.ic_dialog_info); - - if (trialDaysLeft == 0) { - builder.setTitle(R.string.select_album_donate_dialog_0_trial_days_left); - } else { - builder.setTitle(getResources().getQuantityString(R.plurals.select_album_donate_dialog_n_trial_days_left, - trialDaysLeft, trialDaysLeft)); - } - - builder.setMessage(R.string.select_album_donate_dialog_message); - - builder.setPositiveButton(R.string.select_album_donate_dialog_now, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.DONATION_URL))); - } - }); - - builder.setNegativeButton(R.string.select_album_donate_dialog_later, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - dialogInterface.dismiss(); - if (onValid != null) { - onValid.run(); - } - } - }); - - builder.create().show(); - } - - private abstract class LoadTask extends TabActivityBackgroundTask> { - - public LoadTask() { - super(SelectAlbumActivity.this); - } - - protected abstract MusicDirectory load(MusicService service) throws Exception; - - @Override - protected Pair doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this); - MusicDirectory dir = load(musicService); - boolean valid = musicService.isLicenseValid(SelectAlbumActivity.this, this); - return new Pair(dir, valid); - } - - @Override - protected void done(Pair result) { - entries = result.getFirst().getChildren(); - - int songCount = 0; - for (MusicDirectory.Entry entry : entries) { - if (!entry.isDirectory()) { - songCount++; - } - } - - if (songCount > 0) { - if(showHeader) { - entryList.addHeaderView(createHeader(entries), null, false); - } - } else { - hideButtons = true; - } - - emptyView.setVisibility(entries.isEmpty() ? View.VISIBLE : View.GONE); - entryList.setAdapter(entryAdapter = new EntryAdapter(SelectAlbumActivity.this, getImageLoader(), entries, true)); - licenseValid = result.getSecond(); - invalidateOptionsMenu(); - - boolean playAll = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); - if (playAll && songCount > 0) { - playAll(getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false), false); - } - } - } - - private View createHeader(List entries) { - View header = LayoutInflater.from(this).inflate(R.layout.select_album_header, entryList, false); - - View coverArtView = header.findViewById(R.id.select_album_art); - getImageLoader().loadImage(coverArtView, entries.get(0), true, true); - - TextView titleView = (TextView) header.findViewById(R.id.select_album_title); - titleView.setText(getTitle()); - - int songCount = 0; - - Set artists = new HashSet(); - for (MusicDirectory.Entry entry : entries) { - if (!entry.isDirectory()) { - songCount++; - if (entry.getArtist() != null) { - artists.add(entry.getArtist()); - } - } - } - - TextView artistView = (TextView) header.findViewById(R.id.select_album_artist); - if (artists.size() == 1) { - artistView.setText(artists.iterator().next()); - artistView.setVisibility(View.VISIBLE); - } else { - artistView.setVisibility(View.GONE); - } - - TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count); - String s = getResources().getQuantityString(R.plurals.select_album_n_songs, songCount, songCount); - songCountView.setText(s.toUpperCase()); - - return header; - } - - public void removeFromPlaylist(final String id, final String name, final List indexes) { - /*new LoadingTask(this, true) { - @Override - protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SelectAlbumActivity.this); - musicService.removeFromPlaylist(id, indexes, SelectAlbumActivity.this, null); - return null; - } - - @Override - protected void done(Void result) { - for(int i = indexes.size() - 1; i >= 0; i--) { - entryList.setItemChecked(indexes.get(i) + 1, false); - entryAdapter.removeAt(indexes.get(i)); - } - entryAdapter.notifyDataSetChanged(); - Util.toast(SelectAlbumActivity.this, getResources().getString(R.string.removed_playlist, indexes.size(), name)); - } - - @Override - protected void error(Throwable error) { - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = getResources().getString(R.string.updated_playlist_error, name) + " " + getErrorMessage(error); - } - - Util.toast(SelectAlbumActivity.this, msg, false); - } - }.execute();*/ - } -} diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java deleted file mode 100644 index b439df15..00000000 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectArtistActivity.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - This file is part of Subsonic. - - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see . - - Copyright 2009 (C) Sindre Mehus - */ - -package github.daneren2005.dsub.activity; - -import android.content.Intent; -import android.os.Bundle; -import android.view.ContextMenu; -import android.view.LayoutInflater; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ListView; -import android.widget.TextView; -import com.actionbarsherlock.view.Menu; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.Artist; -import github.daneren2005.dsub.domain.Indexes; -import github.daneren2005.dsub.domain.MusicFolder; -import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.view.ArtistAdapter; -import github.daneren2005.dsub.util.BackgroundTask; -import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.FileUtil; -import github.daneren2005.dsub.util.TabActivityBackgroundTask; -import github.daneren2005.dsub.util.Util; -import java.io.File; - -import java.util.ArrayList; -import java.util.List; - -public class SelectArtistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener { - - private static final int MENU_GROUP_MUSIC_FOLDER = 10; - - private ListView artistList; - private View folderButton; - private TextView folderName; - private List musicFolders; - - /** - * Called when the activity is first created. - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.select_artist); - - artistList = (ListView) findViewById(R.id.select_artist_list); - artistList.setOnItemClickListener(this); - - folderButton = LayoutInflater.from(this).inflate(R.layout.select_artist_header, artistList, false); - folderName = (TextView) folderButton.findViewById(R.id.select_artist_folder_2); - - if (!Util.isOffline(this)) { - artistList.addHeaderView(folderButton); - } - - registerForContextMenu(artistList); - setTitle(Util.isOffline(this) ? R.string.music_library_label_offline : R.string.music_library_label); - - musicFolders = null; - load(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.select_artist, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { - Intent intent; - switch (item.getItemId()) { - case R.id.menu_refresh: - refresh(); - return true; - case R.id.menu_shuffle: - onShuffleRequested(); - return true; - case R.id.menu_exit: - intent = new Intent(this, MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); - Util.startActivityWithoutTransition(this, intent); - return true; - case R.id.menu_settings: - startActivity(new Intent(this, SettingsActivity.class)); - return true; - case R.id.menu_help: - startActivity(new Intent(this, HelpActivity.class)); - return true; - case R.id.menu_search: - onSearchRequested(); - return true; - } - - return false; - } - - private void refresh() { - finish(); - Intent intent = getIntent(); - intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true); - Util.startActivityWithoutTransition(this, intent); - } - - private void selectFolder() { - folderButton.showContextMenu(); - } - - public void deleteRecursively(Artist artist) { - File dir = FileUtil.getArtistDirectory(this, artist); - Util.recursiveDelete(dir); - if(Util.isOffline(this)) { - refresh(); - } - } - - private void load() { - BackgroundTask task = new TabActivityBackgroundTask(this) { - @Override - protected Indexes doInBackground() throws Throwable { - boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false); - MusicService musicService = MusicServiceFactory.getMusicService(SelectArtistActivity.this); - if (!Util.isOffline(SelectArtistActivity.this)) { - musicFolders = musicService.getMusicFolders(refresh, SelectArtistActivity.this, this); - } - String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this); - return musicService.getIndexes(musicFolderId, refresh, SelectArtistActivity.this, this); - } - - @Override - protected void done(Indexes result) { - List artists = new ArrayList(result.getShortcuts().size() + result.getArtists().size()); - artists.addAll(result.getShortcuts()); - artists.addAll(result.getArtists()); - artistList.setAdapter(new ArtistAdapter(SelectArtistActivity.this, artists)); - - // Display selected music folder - if (musicFolders != null) { - String musicFolderId = Util.getSelectedMusicFolderId(SelectArtistActivity.this); - if (musicFolderId == null) { - folderName.setText(R.string.select_artist_all_folders); - } else { - for (MusicFolder musicFolder : musicFolders) { - if (musicFolder.getId().equals(musicFolderId)) { - folderName.setText(musicFolder.getName()); - break; - } - } - } - } - } - }; - task.execute(); - } - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - if (view == folderButton) { - selectFolder(); - } else { - Artist artist = (Artist) parent.getItemAtPosition(position); - Intent intent = new Intent(this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); - Util.startActivityWithoutTransition(this, intent); - } - } - - @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - - if (artistList.getItemAtPosition(info.position) instanceof Artist) { - MenuInflater inflater = getMenuInflater(); - if(Util.isOffline(this)) - inflater.inflate(R.menu.select_artist_context_offline, menu); - else - inflater.inflate(R.menu.select_artist_context, menu); - } else if (info.position == 0) { - String musicFolderId = Util.getSelectedMusicFolderId(this); - MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders); - if (musicFolderId == null) { - menuItem.setChecked(true); - } - if (musicFolders != null) { - for (int i = 0; i < musicFolders.size(); i++) { - MusicFolder musicFolder = musicFolders.get(i); - menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName()); - if (musicFolder.getId().equals(musicFolderId)) { - menuItem.setChecked(true); - } - } - } - menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true); - } - } - - @Override - public boolean onContextItemSelected(MenuItem menuItem) { - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - - Artist artist = (Artist) artistList.getItemAtPosition(info.position); - - if (artist != null) { - switch (menuItem.getItemId()) { - case R.id.artist_menu_play_now: - downloadRecursively(artist.getId(), false, false, true, false, false); - break; - case R.id.artist_menu_play_shuffled: - downloadRecursively(artist.getId(), false, false, true, true, false); - break; - case R.id.artist_menu_play_last: - downloadRecursively(artist.getId(), false, true, false, false, false); - break; - case R.id.artist_menu_download: - downloadRecursively(artist.getId(), false, true, false, false, true); - break; - case R.id.artist_menu_pin: - downloadRecursively(artist.getId(), true, true, false, false, true); - break; - case R.id.artist_menu_delete: - deleteRecursively(artist); - break; - default: - return super.onContextItemSelected(menuItem); - } - } else if (info.position == 0) { - MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId()); - String musicFolderId = selectedFolder == null ? null : selectedFolder.getId(); - String musicFolderName = selectedFolder == null ? getString(R.string.select_artist_all_folders) - : selectedFolder.getName(); - Util.setSelectedMusicFolderId(this, musicFolderId); - folderName.setText(musicFolderName); - refresh(); - } - - return true; - } -} \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java deleted file mode 100644 index 7e6775ab..00000000 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SelectPlaylistActivity.java +++ /dev/null @@ -1,301 +0,0 @@ -/* - This file is part of Subsonic. - - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see . - - Copyright 2009 (C) Sindre Mehus - */ - -package github.daneren2005.dsub.activity; - -import github.daneren2005.dsub.view.PlaylistAdapter; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; -import android.view.*; -import android.widget.AdapterView; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.ListView; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.domain.Playlist; -import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.OfflineException; -import github.daneren2005.dsub.service.ServerTooOldException; -import github.daneren2005.dsub.util.*; - -import java.util.List; - -public class SelectPlaylistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener { - private ListView list; - private View emptyTextView; - private PlaylistAdapter playlistAdapter; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.select_playlist); - - list = (ListView) findViewById(R.id.select_playlist_list); - emptyTextView = findViewById(R.id.select_playlist_empty); - list.setOnItemClickListener(this); - registerForContextMenu(list); - - // Title: Playlists - setTitle(R.string.playlist_label); - - load(); - } - - @Override - public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { - com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.select_playlist, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { - Intent intent; - switch (item.getItemId()) { - case R.id.menu_refresh: - refresh(); - return true; - case R.id.menu_exit: - intent = new Intent(this, MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); - Util.startActivityWithoutTransition(this, intent); - return true; - case R.id.menu_settings: - startActivity(new Intent(this, SettingsActivity.class)); - return true; - case R.id.menu_help: - startActivity(new Intent(this, HelpActivity.class)); - return true; - case R.id.menu_search: - onSearchRequested(); - return true; - } - - return false; - } - - private void refresh() { - finish(); - Intent intent = new Intent(this, SelectPlaylistActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true); - Util.startActivityWithoutTransition(this, intent); - } - - private void load() { - final SelectPlaylistActivity me = this; - BackgroundTask> task = new TabActivityBackgroundTask>(this) { - @Override - protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); - boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false); - List playlists = musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this); - if(!Util.isOffline(me)) - new CacheCleaner(me, getDownloadService()).cleanPlaylists(playlists); - return playlists; - } - - @Override - protected void done(List result) { - list.setAdapter(playlistAdapter = new PlaylistAdapter(SelectPlaylistActivity.this, result)); - emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE); - } - }; - task.execute(); - } - - @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - - MenuInflater inflater = getMenuInflater(); - if (Util.isOffline(this)) - inflater.inflate(R.menu.select_playlist_context_offline, menu); - else - inflater.inflate(R.menu.select_playlist_context, menu); - } - - @Override - public boolean onContextItemSelected(MenuItem menuItem) { - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - Playlist playlist = (Playlist) list.getItemAtPosition(info.position); - - Intent intent; - switch (menuItem.getItemId()) { - case R.id.playlist_menu_download: - downloadPlaylist(playlist.getId(), playlist.getName(), false, true, false, false, true); - break; - case R.id.playlist_menu_pin: - downloadPlaylist(playlist.getId(), playlist.getName(), true, true, false, false, true); - break; - case R.id.playlist_menu_play_now: - intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); - Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); - break; - case R.id.playlist_menu_play_shuffled: - intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); - intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); - Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); - break; - case R.id.playlist_menu_delete: - deletePlaylist(playlist); - break; - case R.id.playlist_info: - displayPlaylistInfo(playlist); - break; - case R.id.playlist_update_info: - updatePlaylistInfo(playlist); - break; - default: - return super.onContextItemSelected(menuItem); - } - return true; - } - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - - Playlist playlist = (Playlist) parent.getItemAtPosition(position); - - Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); - Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); - } - - private void deletePlaylist(final Playlist playlist) { - new AlertDialog.Builder(this) - .setIcon(android.R.drawable.ic_dialog_alert) - .setTitle(R.string.common_confirm) - .setMessage(getResources().getString(R.string.delete_playlist, playlist.getName())) - .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - /*new LoadingTask(SelectPlaylistActivity.this, false) { - @Override - protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); - musicService.deletePlaylist(playlist.getId(), SelectPlaylistActivity.this, null); - return null; - } - - @Override - protected void done(Void result) { - playlistAdapter.remove(playlist); - playlistAdapter.notifyDataSetChanged(); - Util.toast(SelectPlaylistActivity.this, getResources().getString(R.string.menu_deleted_playlist, playlist.getName())); - } - - @Override - protected void error(Throwable error) { - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = getResources().getString(R.string.menu_deleted_playlist_error, playlist.getName()) + " " + getErrorMessage(error); - } - - Util.toast(SelectPlaylistActivity.this, msg, false); - } - }.execute();*/ - } - - }) - .setNegativeButton(R.string.common_cancel, null) - .show(); - } - - private void displayPlaylistInfo(final Playlist playlist) { - String message = "Owner: " + playlist.getOwner() + "\nComments: " + - ((playlist.getComment() == null) ? "" : playlist.getComment()) + - "\nSong Count: " + playlist.getSongCount() + - ((playlist.getPublic() == null) ? "" : ("\nPublic: " + playlist.getPublic())) + - "\nCreation Date: " + playlist.getCreated().replace('T', ' '); - new AlertDialog.Builder(this) - .setIcon(android.R.drawable.ic_dialog_alert) - .setTitle(playlist.getName()) - .setMessage(message) - .show(); - } - - private void updatePlaylistInfo(final Playlist playlist) { - View dialogView = getLayoutInflater().inflate(R.layout.update_playlist, null); - final EditText nameBox = (EditText)dialogView.findViewById(R.id.get_playlist_name); - final EditText commentBox = (EditText)dialogView.findViewById(R.id.get_playlist_comment); - final CheckBox publicBox = (CheckBox)dialogView.findViewById(R.id.get_playlist_public); - - nameBox.setText(playlist.getName()); - commentBox.setText(playlist.getComment()); - Boolean pub = playlist.getPublic(); - if(pub == null) { - publicBox.setEnabled(false); - } else { - publicBox.setChecked(pub); - } - - new AlertDialog.Builder(this) - .setIcon(android.R.drawable.ic_dialog_alert) - .setTitle(R.string.playlist_update_info) - .setView(dialogView) - .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - /*new LoadingTask(SelectPlaylistActivity.this, false) { - @Override - protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); - musicService.updatePlaylist(playlist.getId(), nameBox.getText().toString(), commentBox.getText().toString(), publicBox.isChecked(), SelectPlaylistActivity.this, null); - return null; - } - - @Override - protected void done(Void result) { - refresh(); - Util.toast(SelectPlaylistActivity.this, getResources().getString(R.string.playlist_updated_info, playlist.getName())); - } - - @Override - protected void error(Throwable error) { - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = getResources().getString(R.string.playlist_updated_info_error, playlist.getName()) + " " + getErrorMessage(error); - } - - Util.toast(SelectPlaylistActivity.this, msg, false); - } - }.execute();*/ - } - - }) - .setNegativeButton(R.string.common_cancel, null) - .show(); - } -} \ No newline at end of file -- cgit v1.2.3 From b8484584aa5fd20db66542a206256cf20d055d9f Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 21 Apr 2013 21:42:30 -0700 Subject: Remove references to removed activities --- .../src/github/daneren2005/dsub/activity/SubsonicTabActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java index a9e20eae..6bb7da6f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java @@ -86,7 +86,7 @@ public class SubsonicTabActivity extends SherlockActivity { protected void onPostCreate(Bundle bundle) { super.onPostCreate(bundle); - homeButton = findViewById(R.id.button_bar_home); + /*homeButton = findViewById(R.id.button_bar_home); homeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -126,11 +126,11 @@ public class SubsonicTabActivity extends SherlockActivity { /*if (this instanceof MainActivity) { homeButton.setEnabled(false); - } else*/ if (this instanceof SelectAlbumActivity || this instanceof SelectArtistActivity) { + } else if (this instanceof SelectAlbumActivity || this instanceof SelectArtistActivity) { musicButton.setEnabled(false); } else if (this instanceof SelectPlaylistActivity) { playlistButton.setEnabled(false); - } /*else if (this instanceof DownloadActivity || this instanceof LyricsActivity) { + } else if (this instanceof DownloadActivity || this instanceof LyricsActivity) { nowPlayingButton.setEnabled(false); }*/ } -- cgit v1.2.3 From c4e6b854fabe288d3c9b08c42416990ed8b769ad Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 21 Apr 2013 21:59:07 -0700 Subject: Start of converting search to fragment --- subsonic-android/res/layout/search.xml | 3 - .../daneren2005/dsub/activity/SearchActivity.java | 394 ++------------------- .../daneren2005/dsub/fragments/SearchFragment.java | 358 +++++++++++++++++++ 3 files changed, 391 insertions(+), 364 deletions(-) create mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout/search.xml b/subsonic-android/res/layout/search.xml index 5f5c26e0..d9bb301c 100644 --- a/subsonic-android/res/layout/search.xml +++ b/subsonic-android/res/layout/search.xml @@ -18,7 +18,4 @@ android:layout_weight="1.0" android:fastScrollEnabled="true" /> - - - \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java index 0bcaa28a..53864e7d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java @@ -19,376 +19,48 @@ package github.daneren2005.dsub.activity; -import java.util.ArrayList; -import java.util.List; -import java.util.Arrays; - +import github.daneren2005.dsub.R; import android.content.Intent; import android.os.Bundle; -import android.view.ContextMenu; -import android.view.LayoutInflater; -import android.view.MenuInflater; -import android.view.View; -import android.view.MenuItem; -import android.widget.AdapterView; -import android.widget.ImageButton; -import android.widget.ListAdapter; -import android.widget.ListView; -import android.widget.TextView; -import android.net.Uri; -import com.actionbarsherlock.view.Menu; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.Artist; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.domain.SearchCritera; -import github.daneren2005.dsub.domain.SearchResult; -import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.service.DownloadService; -import github.daneren2005.dsub.view.ArtistAdapter; -import github.daneren2005.dsub.util.BackgroundTask; +import github.daneren2005.dsub.fragments.SearchFragment; import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.view.EntryAdapter; import github.daneren2005.dsub.util.MergeAdapter; -import github.daneren2005.dsub.util.TabActivityBackgroundTask; -import github.daneren2005.dsub.util.Util; - -/** - * Performs searches and displays the matching artists, albums and songs. - * - * @author Sindre Mehus - */ -public class SearchActivity extends SubsonicTabActivity { - - private static final int DEFAULT_ARTISTS = 3; - private static final int DEFAULT_ALBUMS = 5; - private static final int DEFAULT_SONGS = 10; - - private static final int MAX_ARTISTS = 10; - private static final int MAX_ALBUMS = 20; - private static final int MAX_SONGS = 25; - private ListView list; - - private View artistsHeading; - private View albumsHeading; - private View songsHeading; - private TextView searchButton; - private View moreArtistsButton; - private View moreAlbumsButton; - private View moreSongsButton; - private SearchResult searchResult; - private MergeAdapter mergeAdapter; - private ArtistAdapter artistAdapter; - private ListAdapter moreArtistsAdapter; - private EntryAdapter albumAdapter; - private ListAdapter moreAlbumsAdapter; - private ListAdapter moreSongsAdapter; - private EntryAdapter songAdapter; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.search); - - setTitle(R.string.search_title); - - View buttons = LayoutInflater.from(this).inflate(R.layout.search_buttons, null); - artistsHeading = buttons.findViewById(R.id.search_artists); - albumsHeading = buttons.findViewById(R.id.search_albums); - songsHeading = buttons.findViewById(R.id.search_songs); +public class SearchActivity extends SubsonicActivity { + SearchFragment fragment; - searchButton = (TextView) buttons.findViewById(R.id.search_search); - moreArtistsButton = buttons.findViewById(R.id.search_more_artists); - moreAlbumsButton = buttons.findViewById(R.id.search_more_albums); - moreSongsButton = buttons.findViewById(R.id.search_more_songs); + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.download_activity); - list = (ListView) findViewById(R.id.search_list); + if (findViewById(R.id.download_container) != null && savedInstanceState == null) { + fragment = new SearchFragment(); + getSupportFragmentManager().beginTransaction().add(R.id.download_container, fragment).commit(); + } - list.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - if (view == searchButton) { - onSearchRequested(); - } else if (view == moreArtistsButton) { - expandArtists(); - } else if (view == moreAlbumsButton) { - expandAlbums(); - } else if (view == moreSongsButton) { - expandSongs(); - } else { - Object item = parent.getItemAtPosition(position); - if (item instanceof Artist) { - onArtistSelected((Artist) item); - } else if (item instanceof MusicDirectory.Entry) { - MusicDirectory.Entry entry = (MusicDirectory.Entry) item; - if (entry.isDirectory()) { - onAlbumSelected(entry, false); - } else if (entry.isVideo()) { - onVideoSelected(entry); - } else { - onSongSelected(entry, false, true, true, false); - } + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + } - } - } - } - }); - registerForContextMenu(list); - onNewIntent(getIntent()); - } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater(); - inflater.inflate(R.menu.search, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { - Intent intent; - switch (item.getItemId()) { - case R.id.menu_search: + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY); + boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); + boolean requestsearch = intent.getBooleanExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, false); + + if (query != null) { + fragment.search(query, autoplay); + } else { + fragment.populateList(); + if (requestsearch) { onSearchRequested(); - return true; - case R.id.menu_exit: - intent = new Intent(this, MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); - Util.startActivityWithoutTransition(this, intent); - return true; - case R.id.menu_settings: - startActivity(new Intent(this, SettingsActivity.class)); - return true; - case R.id.menu_help: - startActivity(new Intent(this, HelpActivity.class)); - return true; - } - - return false; - } - - @Override - protected void onNewIntent(Intent intent) { - super.onNewIntent(intent); - String query = intent.getStringExtra(Constants.INTENT_EXTRA_NAME_QUERY); - boolean autoplay = intent.getBooleanExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, false); - boolean requestsearch = intent.getBooleanExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, false); - - if (query != null) { - mergeAdapter = new MergeAdapter(); - list.setAdapter(mergeAdapter); - search(query, autoplay); - } else { - populateList(); - if (requestsearch) - onSearchRequested(); - } - } - - @Override - public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { - super.onCreateContextMenu(menu, view, menuInfo); - - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - Object selectedItem = list.getItemAtPosition(info.position); - - boolean isArtist = selectedItem instanceof Artist; - boolean isAlbum = selectedItem instanceof MusicDirectory.Entry && ((MusicDirectory.Entry) selectedItem).isDirectory(); - boolean isSong = selectedItem instanceof MusicDirectory.Entry && (!((MusicDirectory.Entry) selectedItem).isDirectory()) - && (!((MusicDirectory.Entry) selectedItem).isVideo()); - - if (isArtist || isAlbum) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.select_album_context, menu); - } else if (isSong) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.select_song_context, menu); - } - } - - @Override - public boolean onContextItemSelected(MenuItem menuItem) { - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - Object selectedItem = list.getItemAtPosition(info.position); - - Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null; - MusicDirectory.Entry entry = selectedItem instanceof MusicDirectory.Entry ? (MusicDirectory.Entry) selectedItem : null; - String id = artist != null ? artist.getId() : entry.getId(); - - switch (menuItem.getItemId()) { - case R.id.album_menu_play_now: - downloadRecursively(id, false, false, true, false, false); - break; - case R.id.album_menu_play_shuffled: - downloadRecursively(id, false, false, true, true, false); - break; - case R.id.album_menu_play_last: - downloadRecursively(id, false, true, false, false, false); - break; - case R.id.album_menu_download: - downloadRecursively(id, false, true, false, false, true); - break; - case R.id.album_menu_pin: - downloadRecursively(id, true, true, false, false, true); - break; - case R.id.song_menu_play_now: - onSongSelected(entry, false, false, true, false); - break; - case R.id.song_menu_play_next: - onSongSelected(entry, false, true, false, true); - break; - case R.id.song_menu_play_last: - onSongSelected(entry, false, true, false, false); - break; - default: - return super.onContextItemSelected(menuItem); - } - - return true; - } - - private void search(final String query, final boolean autoplay) { - BackgroundTask task = new TabActivityBackgroundTask(this) { - @Override - protected SearchResult doInBackground() throws Throwable { - SearchCritera criteria = new SearchCritera(query, MAX_ARTISTS, MAX_ALBUMS, MAX_SONGS); - MusicService service = MusicServiceFactory.getMusicService(SearchActivity.this); - return service.search(criteria, SearchActivity.this, this); - } - - @Override - protected void done(SearchResult result) { - searchResult = result; - populateList(); - if (autoplay) { - autoplay(); - } - - } - }; - task.execute(); - } - - private void populateList() { - mergeAdapter = new MergeAdapter(); - mergeAdapter.addView(searchButton, true); - - if (searchResult != null) { - List artists = searchResult.getArtists(); - if (!artists.isEmpty()) { - mergeAdapter.addView(artistsHeading); - List displayedArtists = new ArrayList(artists.subList(0, Math.min(DEFAULT_ARTISTS, artists.size()))); - artistAdapter = new ArtistAdapter(this, displayedArtists); - mergeAdapter.addAdapter(artistAdapter); - if (artists.size() > DEFAULT_ARTISTS) { - moreArtistsAdapter = mergeAdapter.addView(moreArtistsButton, true); - } - } - - List albums = searchResult.getAlbums(); - if (!albums.isEmpty()) { - mergeAdapter.addView(albumsHeading); - List displayedAlbums = new ArrayList(albums.subList(0, Math.min(DEFAULT_ALBUMS, albums.size()))); - albumAdapter = new EntryAdapter(this, getImageLoader(), displayedAlbums, false); - mergeAdapter.addAdapter(albumAdapter); - if (albums.size() > DEFAULT_ALBUMS) { - moreAlbumsAdapter = mergeAdapter.addView(moreAlbumsButton, true); - } - } - - List songs = searchResult.getSongs(); - if (!songs.isEmpty()) { - mergeAdapter.addView(songsHeading); - List displayedSongs = new ArrayList(songs.subList(0, Math.min(DEFAULT_SONGS, songs.size()))); - songAdapter = new EntryAdapter(this, getImageLoader(), displayedSongs, false); - mergeAdapter.addAdapter(songAdapter); - if (songs.size() > DEFAULT_SONGS) { - moreSongsAdapter = mergeAdapter.addView(moreSongsButton, true); - } - } - - boolean empty = searchResult.getArtists().isEmpty() && searchResult.getAlbums().isEmpty() && searchResult.getSongs().isEmpty(); - searchButton.setText(empty ? R.string.search_no_match : R.string.search_search); - } - - list.setAdapter(mergeAdapter); - } - - private void expandArtists() { - artistAdapter.clear(); - for (Artist artist : searchResult.getArtists()) { - artistAdapter.add(artist); - } - artistAdapter.notifyDataSetChanged(); - mergeAdapter.removeAdapter(moreArtistsAdapter); - mergeAdapter.notifyDataSetChanged(); - } - - private void expandAlbums() { - albumAdapter.clear(); - for (MusicDirectory.Entry album : searchResult.getAlbums()) { - albumAdapter.add(album); - } - albumAdapter.notifyDataSetChanged(); - mergeAdapter.removeAdapter(moreAlbumsAdapter); - mergeAdapter.notifyDataSetChanged(); - } - - private void expandSongs() { - songAdapter.clear(); - for (MusicDirectory.Entry song : searchResult.getSongs()) { - songAdapter.add(song); - } - songAdapter.notifyDataSetChanged(); - mergeAdapter.removeAdapter(moreSongsAdapter); - mergeAdapter.notifyDataSetChanged(); - } - - private void onArtistSelected(Artist artist) { - Intent intent = new Intent(this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); - Util.startActivityWithoutTransition(this, intent); - } - - private void onAlbumSelected(MusicDirectory.Entry album, boolean autoplay) { - Intent intent = new Intent(SearchActivity.this, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, album.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, album.getTitle()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, autoplay); - Util.startActivityWithoutTransition(SearchActivity.this, intent); - } - - private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext) { - DownloadService downloadService = getDownloadService(); - if (downloadService != null) { - if (!append) { - downloadService.clear(); - } - downloadService.download(Arrays.asList(song), save, false, playNext, false); - if (autoplay) { - downloadService.play(downloadService.size() - 1); - } - - Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_added, 1, 1)); - } - } - - private void onVideoSelected(MusicDirectory.Entry entry) { - int maxBitrate = Util.getMaxVideoBitrate(this); - - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(MusicServiceFactory.getMusicService(this).getVideoUrl(maxBitrate, this, entry.getId()))); - startActivity(intent); - } - - private void autoplay() { - if (!searchResult.getSongs().isEmpty()) { - onSongSelected(searchResult.getSongs().get(0), false, false, true, false); - } else if (!searchResult.getAlbums().isEmpty()) { - onAlbumSelected(searchResult.getAlbums().get(0), true); - } - } + } + } + } + + public void onSupportNewIntent(Intent intent) { + onNewIntent(intent); + } } \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java new file mode 100644 index 00000000..1b971cdf --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -0,0 +1,358 @@ +package github.daneren2005.dsub.fragments; + +import java.util.ArrayList; +import java.util.List; +import java.util.Arrays; + +import android.content.Intent; +import android.os.Bundle; +import android.view.ContextMenu; +import android.view.LayoutInflater; +import android.view.MenuInflater; +import android.view.View; +import android.view.MenuItem; +import android.widget.AdapterView; +import android.widget.ImageButton; +import android.widget.ListAdapter; +import android.widget.ListView; +import android.widget.TextView; +import android.net.Uri; +import android.view.ViewGroup; +import com.actionbarsherlock.view.Menu; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.activity.HelpActivity; +import github.daneren2005.dsub.activity.SearchActivity; +import github.daneren2005.dsub.activity.SettingsActivity; +import github.daneren2005.dsub.domain.Artist; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.SearchCritera; +import github.daneren2005.dsub.domain.SearchResult; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.view.ArtistAdapter; +import github.daneren2005.dsub.util.BackgroundTask; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.view.EntryAdapter; +import github.daneren2005.dsub.util.MergeAdapter; +import github.daneren2005.dsub.util.TabActivityBackgroundTask; +import github.daneren2005.dsub.util.TabBackgroundTask; +import github.daneren2005.dsub.util.Util; + +public class SearchFragment extends SubsonicTabFragment { + private static final int DEFAULT_ARTISTS = 3; + private static final int DEFAULT_ALBUMS = 5; + private static final int DEFAULT_SONGS = 10; + + private static final int MAX_ARTISTS = 10; + private static final int MAX_ALBUMS = 20; + private static final int MAX_SONGS = 25; + private ListView list; + + private View artistsHeading; + private View albumsHeading; + private View songsHeading; + private TextView searchButton; + private View moreArtistsButton; + private View moreAlbumsButton; + private View moreSongsButton; + private SearchResult searchResult; + private MergeAdapter mergeAdapter; + private ArtistAdapter artistAdapter; + private ListAdapter moreArtistsAdapter; + private EntryAdapter albumAdapter; + private ListAdapter moreAlbumsAdapter; + private ListAdapter moreSongsAdapter; + private EntryAdapter songAdapter; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + rootView = inflater.inflate(R.layout.search, container, false); + setHasOptionsMenu(true); + + setTitle(R.string.search_title); + + View buttons = inflater.inflate(R.layout.search_buttons, null); + + artistsHeading = buttons.findViewById(R.id.search_artists); + albumsHeading = buttons.findViewById(R.id.search_albums); + songsHeading = buttons.findViewById(R.id.search_songs); + + searchButton = (TextView) buttons.findViewById(R.id.search_search); + moreArtistsButton = buttons.findViewById(R.id.search_more_artists); + moreAlbumsButton = buttons.findViewById(R.id.search_more_albums); + moreSongsButton = buttons.findViewById(R.id.search_more_songs); + + list = (ListView) rootView.findViewById(R.id.search_list); + + list.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (view == searchButton) { + context.onSearchRequested(); + } else if (view == moreArtistsButton) { + expandArtists(); + } else if (view == moreAlbumsButton) { + expandAlbums(); + } else if (view == moreSongsButton) { + expandSongs(); + } else { + Object item = parent.getItemAtPosition(position); + if (item instanceof Artist) { + onArtistSelected((Artist) item); + } else if (item instanceof MusicDirectory.Entry) { + MusicDirectory.Entry entry = (MusicDirectory.Entry) item; + if (entry.isDirectory()) { + onAlbumSelected(entry, false); + } else if (entry.isVideo()) { + onVideoSelected(entry); + } else { + onSongSelected(entry, false, true, true, false); + } + + } + } + } + }); + registerForContextMenu(list); + ((SearchActivity)context).onSupportNewIntent(context.getIntent()); + return rootView; + } + + @Override + public void onCreateOptionsMenu(Menu menu, com.actionbarsherlock.view.MenuInflater menuInflater) { + menuInflater.inflate(R.menu.search, menu); + } + + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_search: + context.onSearchRequested(); + return true; + case R.id.menu_exit: + exit(); + return true; + case R.id.menu_settings: + startActivity(new Intent(context, SettingsActivity.class)); + return true; + case R.id.menu_help: + startActivity(new Intent(context, HelpActivity.class)); + return true; + } + + return false; + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + Object selectedItem = list.getItemAtPosition(info.position); + + boolean isArtist = selectedItem instanceof Artist; + boolean isAlbum = selectedItem instanceof MusicDirectory.Entry && ((MusicDirectory.Entry) selectedItem).isDirectory(); + boolean isSong = selectedItem instanceof MusicDirectory.Entry && (!((MusicDirectory.Entry) selectedItem).isDirectory()) + && (!((MusicDirectory.Entry) selectedItem).isVideo()); + + MenuInflater inflater = context.getMenuInflater(); + if (isArtist || isAlbum) { + inflater.inflate(R.menu.select_album_context, menu); + } else if (isSong) { + inflater.inflate(R.menu.select_song_context, menu); + } + } + + @Override + public boolean onContextItemSelected(MenuItem menuItem) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + Object selectedItem = list.getItemAtPosition(info.position); + + Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null; + MusicDirectory.Entry entry = selectedItem instanceof MusicDirectory.Entry ? (MusicDirectory.Entry) selectedItem : null; + String id = artist != null ? artist.getId() : entry.getId(); + + switch (menuItem.getItemId()) { + case R.id.album_menu_play_now: + downloadRecursively(id, false, false, true, false, false); + break; + case R.id.album_menu_play_shuffled: + downloadRecursively(id, false, false, true, true, false); + break; + case R.id.album_menu_play_last: + downloadRecursively(id, false, true, false, false, false); + break; + case R.id.album_menu_download: + downloadRecursively(id, false, true, false, false, true); + break; + case R.id.album_menu_pin: + downloadRecursively(id, true, true, false, false, true); + break; + case R.id.song_menu_play_now: + onSongSelected(entry, false, false, true, false); + break; + case R.id.song_menu_play_next: + onSongSelected(entry, false, true, false, true); + break; + case R.id.song_menu_play_last: + onSongSelected(entry, false, true, false, false); + break; + default: + return super.onContextItemSelected(menuItem); + } + + return true; + } + + public void search(final String query, final boolean autoplay) { + mergeAdapter = new MergeAdapter(); + list.setAdapter(mergeAdapter); + + BackgroundTask task = new TabBackgroundTask(this) { + @Override + protected SearchResult doInBackground() throws Throwable { + SearchCritera criteria = new SearchCritera(query, MAX_ARTISTS, MAX_ALBUMS, MAX_SONGS); + MusicService service = MusicServiceFactory.getMusicService(context); + return service.search(criteria, context, this); + } + + @Override + protected void done(SearchResult result) { + searchResult = result; + populateList(); + if (autoplay) { + autoplay(); + } + + } + }; + task.execute(); + } + + public void populateList() { + mergeAdapter = new MergeAdapter(); + mergeAdapter.addView(searchButton, true); + + if (searchResult != null) { + List artists = searchResult.getArtists(); + if (!artists.isEmpty()) { + mergeAdapter.addView(artistsHeading); + List displayedArtists = new ArrayList(artists.subList(0, Math.min(DEFAULT_ARTISTS, artists.size()))); + artistAdapter = new ArtistAdapter(context, displayedArtists); + mergeAdapter.addAdapter(artistAdapter); + if (artists.size() > DEFAULT_ARTISTS) { + moreArtistsAdapter = mergeAdapter.addView(moreArtistsButton, true); + } + } + + List albums = searchResult.getAlbums(); + if (!albums.isEmpty()) { + mergeAdapter.addView(albumsHeading); + List displayedAlbums = new ArrayList(albums.subList(0, Math.min(DEFAULT_ALBUMS, albums.size()))); + albumAdapter = new EntryAdapter(context, getImageLoader(), displayedAlbums, false); + mergeAdapter.addAdapter(albumAdapter); + if (albums.size() > DEFAULT_ALBUMS) { + moreAlbumsAdapter = mergeAdapter.addView(moreAlbumsButton, true); + } + } + + List songs = searchResult.getSongs(); + if (!songs.isEmpty()) { + mergeAdapter.addView(songsHeading); + List displayedSongs = new ArrayList(songs.subList(0, Math.min(DEFAULT_SONGS, songs.size()))); + songAdapter = new EntryAdapter(context, getImageLoader(), displayedSongs, false); + mergeAdapter.addAdapter(songAdapter); + if (songs.size() > DEFAULT_SONGS) { + moreSongsAdapter = mergeAdapter.addView(moreSongsButton, true); + } + } + + boolean empty = searchResult.getArtists().isEmpty() && searchResult.getAlbums().isEmpty() && searchResult.getSongs().isEmpty(); + searchButton.setText(empty ? R.string.search_no_match : R.string.search_search); + } + + list.setAdapter(mergeAdapter); + } + + private void expandArtists() { + artistAdapter.clear(); + for (Artist artist : searchResult.getArtists()) { + artistAdapter.add(artist); + } + artistAdapter.notifyDataSetChanged(); + mergeAdapter.removeAdapter(moreArtistsAdapter); + mergeAdapter.notifyDataSetChanged(); + } + + private void expandAlbums() { + albumAdapter.clear(); + for (MusicDirectory.Entry album : searchResult.getAlbums()) { + albumAdapter.add(album); + } + albumAdapter.notifyDataSetChanged(); + mergeAdapter.removeAdapter(moreAlbumsAdapter); + mergeAdapter.notifyDataSetChanged(); + } + + private void expandSongs() { + songAdapter.clear(); + for (MusicDirectory.Entry song : searchResult.getSongs()) { + songAdapter.add(song); + } + songAdapter.notifyDataSetChanged(); + mergeAdapter.removeAdapter(moreSongsAdapter); + mergeAdapter.notifyDataSetChanged(); + } + + private void onArtistSelected(Artist artist) { + /*Intent intent = new Intent(context, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); + Util.startActivityWithoutTransition(context, intent);*/ + } + + private void onAlbumSelected(MusicDirectory.Entry album, boolean autoplay) { + /*Intent intent = new Intent(context, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, album.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, album.getTitle()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, autoplay); + Util.startActivityWithoutTransition(context, intent);*/ + } + + private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext) { + DownloadService downloadService = getDownloadService(); + if (downloadService != null) { + if (!append) { + downloadService.clear(); + } + downloadService.download(Arrays.asList(song), save, false, playNext, false); + if (autoplay) { + downloadService.play(downloadService.size() - 1); + } + + Util.toast(context, getResources().getQuantityString(R.plurals.select_album_n_songs_added, 1, 1)); + } + } + + private void onVideoSelected(MusicDirectory.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() { + if (!searchResult.getSongs().isEmpty()) { + onSongSelected(searchResult.getSongs().get(0), false, false, true, false); + } else if (!searchResult.getAlbums().isEmpty()) { + onAlbumSelected(searchResult.getAlbums().get(0), true); + } + } +} -- cgit v1.2.3 From f5b2d1f6af2f96f468577ae943e128b25197f40b Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 25 Apr 2013 21:43:17 -0700 Subject: Fix swipes after orientation change --- .../src/github/daneren2005/dsub/activity/DownloadActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index 2204cb64..24f8181f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -44,7 +44,7 @@ import java.util.List; public class DownloadActivity extends SubsonicActivity { private static final String TAG = DownloadActivity.class.getSimpleName(); - private DownloadFragment fragment; + private static DownloadFragment fragment; private EditText playlistNameView; /** -- cgit v1.2.3 From 2718330401778f1420b91cb256c89da82047dcbd Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 25 Apr 2013 21:59:45 -0700 Subject: Got rid of extra stuff --- .../daneren2005/dsub/activity/MainActivity.java | 32 +++++++++++----------- .../dsub/activity/SubsonicActivity.java | 3 -- 2 files changed, 16 insertions(+), 19 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index fc283310..0074f30a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -48,16 +48,14 @@ public class MainActivity extends SubsonicActivity { trackView = (TextView) bottomBar.findViewById(R.id.track_name); artistView = (TextView) bottomBar.findViewById(R.id.artist_name); - if (savedInstanceState == null) { - viewPager = (ViewPager) findViewById(R.id.pager); - pagerAdapter = new TabPagerAdapter(this, viewPager); - viewPager.setAdapter(pagerAdapter); - viewPager.setOnPageChangeListener(pagerAdapter); - - addTab("Home", MainFragment.class, null); - addTab("Library", SelectArtistFragment.class, null); - addTab("Playlists", SelectPlaylistFragment.class, null); - } + viewPager = (ViewPager) findViewById(R.id.pager); + pagerAdapter = new TabPagerAdapter(this, viewPager); + viewPager.setAdapter(pagerAdapter); + viewPager.setOnPageChangeListener(pagerAdapter); + + addTab("Home", MainFragment.class, null); + addTab("Library", SelectArtistFragment.class, null); + addTab("Playlists", SelectPlaylistFragment.class, null); } @Override @@ -74,7 +72,7 @@ public class MainActivity extends SubsonicActivity { @Override public void onResume() { super.onResume(); - + final Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override @@ -91,7 +89,7 @@ public class MainActivity extends SubsonicActivity { executorService = Executors.newSingleThreadScheduledExecutor(); executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS); } - + @Override public void onPause() { super.onPause(); @@ -117,15 +115,17 @@ public class MainActivity extends SubsonicActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - com.actionbarsherlock.view.MenuInflater menuInflater = getSupportMenuInflater(); - pagerAdapter.onCreateOptionsMenu(menu, menuInflater); + if(pagerAdapter != null) { + com.actionbarsherlock.view.MenuInflater menuInflater = getSupportMenuInflater(); + pagerAdapter.onCreateOptionsMenu(menu, menuInflater); + } return true; } @Override public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { return pagerAdapter.onOptionsItemSelected(item); } - + private void update() { if (getDownloadService() == null) { return; @@ -138,7 +138,7 @@ public class MainActivity extends SubsonicActivity { getImageLoader().loadImage(coverArtView, null, false, false); return; } - + MusicDirectory.Entry song = current.getSong(); trackView.setText(song.getTitle()); artistView.setText(song.getArtist()); diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index d0dbdde1..eae6c56a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -228,7 +228,6 @@ public class SubsonicActivity extends SherlockFragmentActivity { private SubsonicTabFragment currentFragment; private List tabs = new ArrayList(); private List frags = new ArrayList(); - private List ids = new ArrayList(); private int currentPosition; public TabPagerAdapter(SherlockFragmentActivity activity, ViewPager pager) { @@ -246,7 +245,6 @@ public class SubsonicActivity extends SherlockFragmentActivity { List fragStack = new ArrayList(); fragStack.add(frag); frags.add(i, fragStack); - ids.add(i, 0); if(currentFragment == null) { currentFragment = (SubsonicTabFragment) frag; currentFragment.setPrimaryFragment(true); @@ -329,7 +327,6 @@ public class SubsonicActivity extends SherlockFragmentActivity { currentFragment.setPrimaryFragment(true); activity.invalidateOptionsMenu(); - ids.add(currentPosition, id); FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); trans.add(id, fragment); trans.commit(); -- cgit v1.2.3 From e6fcbc2dcc38e845017e7bf4280e982883fcc5fc Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 26 Apr 2013 20:14:42 -0700 Subject: Fix orientation changes crashing --- .../src/github/daneren2005/dsub/activity/MainActivity.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 0074f30a..0a437af6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -52,20 +52,25 @@ public class MainActivity extends SubsonicActivity { pagerAdapter = new TabPagerAdapter(this, viewPager); viewPager.setAdapter(pagerAdapter); viewPager.setOnPageChangeListener(pagerAdapter); - + addTab("Home", MainFragment.class, null); addTab("Library", SelectArtistFragment.class, null); addTab("Playlists", SelectPlaylistFragment.class, null); } - + + @Override + public void onSaveInstanceState(Bundle savedInstanceState) { + + } + @Override protected void onPostCreate(Bundle bundle) { super.onPostCreate(bundle); - + getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setHomeButtonEnabled(false); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); - + showInfoDialog(); } -- cgit v1.2.3 From f4e44095c6638253997316300c92f70ef23b66e7 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 26 Apr 2013 20:32:25 -0700 Subject: Added method to specify tabs need to be refreshed - used for server change --- .../daneren2005/dsub/activity/SubsonicActivity.java | 8 ++++++++ .../github/daneren2005/dsub/fragments/MainFragment.java | 4 ++-- .../daneren2005/dsub/fragments/SubsonicTabFragment.java | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index eae6c56a..5e89fbe6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -362,6 +362,14 @@ public class SubsonicActivity extends SherlockFragmentActivity { } } } + + public void invalidate() { + for (int i = 0; i < frags.size(); i++) { + List fragStack = (List)frags.get(i); + SubsonicTabFragment frag = (SubsonicTabFragment)fragStack.get(fragStack.size() - 1); + frag.invalidate(); + } + } private class TabInfo { public final Class fragmentClass; diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 0e2b92e6..eb3ee575 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -129,7 +129,7 @@ public class MainFragment extends SubsonicTabFragment { return super.onContextItemSelected(menuItem); } - refresh(); + context.getPagerAdapter().invalidate(); return true; } @@ -227,7 +227,7 @@ public class MainFragment extends SubsonicTabFragment { private void toggleOffline() { Util.setOffline(context, !Util.isOffline(context)); - refresh(); + context.getPagerAdapter().invalidate(); } private void showAlbumList(String type) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index 19c3fd2c..a1cd9557 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -18,9 +18,12 @@ */ package github.daneren2005.dsub.fragments; +import android.util.Log; + public class SubsonicTabFragment extends SubsonicFragment { private static final String TAG = SubsonicTabFragment.class.getSimpleName(); protected boolean primaryFragment = false; + protected boolean invalidated = false; public void replaceFragment(SubsonicTabFragment fragment, int id) { this.setPrimaryFragment(false); @@ -34,6 +37,18 @@ public class SubsonicTabFragment extends SubsonicFragment { if(context != null) { context.setTitle(title); } + if(invalidated) { + invalidated = false; + refresh(); + } + } + } + + public void invalidate() { + if(primaryFragment) { + refresh(); + } else { + invalidated = true; } } } -- cgit v1.2.3 From ed6fdeee1fc935265669eb45cad3348d024054a0 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 27 Apr 2013 18:08:48 -0700 Subject: Don't load other fragments until we actually go to them --- .../src/github/daneren2005/dsub/fragments/SelectArtistFragment.java | 2 +- .../src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 8675f625..20bd63a5 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -59,7 +59,7 @@ public class SelectArtistFragment extends SubsonicTabFragment implements Adapter } registerForContextMenu(artistList); - load(false); + invalidated = true; return rootView; } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 826e5e66..5581cae5 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -51,7 +51,7 @@ public class SelectPlaylistFragment extends SubsonicTabFragment implements Adapt emptyTextView = rootView.findViewById(R.id.select_playlist_empty); list.setOnItemClickListener(this); registerForContextMenu(list); - load(false); + invalidated = true; return rootView; } -- cgit v1.2.3 From cd737ca924cd305642ca712f38fb433153764bae Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 27 Apr 2013 18:33:55 -0700 Subject: Fix add to playlist option --- .../src/github/daneren2005/dsub/fragments/SubsonicFragment.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index d0a5edb6..8cc6badd 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -51,8 +51,10 @@ import github.daneren2005.dsub.util.FileUtil; import github.daneren2005.dsub.util.ImageLoader; import github.daneren2005.dsub.util.ModalBackgroundTask; import github.daneren2005.dsub.util.SilentBackgroundTask; +import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.Util; import java.io.File; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -344,7 +346,7 @@ public class SubsonicFragment extends SherlockFragment { return; } - /*new LoadingTask>(context, true) { + new LoadingTask>(context, true) { @Override protected List doInBackground() throws Throwable { MusicService musicService = MusicServiceFactory.getMusicService(context); @@ -380,7 +382,7 @@ public class SubsonicFragment extends SherlockFragment { Util.toast(context, msg, false); } - }.execute();*/ + }.execute(); } private void addToPlaylist(final Playlist playlist, final List songs) { -- cgit v1.2.3 From 636a46743e52f83ddcb4124bf3d78e1f3a35f2cf Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 27 Apr 2013 18:43:52 -0700 Subject: Don't always hard refresh artist/playlists --- .../src/github/daneren2005/dsub/fragments/MainFragment.java | 2 +- .../src/github/daneren2005/dsub/fragments/SelectArtistFragment.java | 4 ++-- .../github/daneren2005/dsub/fragments/SelectDirectoryFragment.java | 4 ++-- .../github/daneren2005/dsub/fragments/SelectPlaylistFragment.java | 4 ++-- .../src/github/daneren2005/dsub/fragments/SubsonicFragment.java | 5 ++++- .../src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java | 4 ++-- 6 files changed, 13 insertions(+), 10 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index eb3ee575..390f92fc 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -134,7 +134,7 @@ public class MainFragment extends SubsonicTabFragment { } @Override - protected void refresh() { + protected void refresh(boolean refresh) { createLayout(); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 20bd63a5..bac9c71d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -174,8 +174,8 @@ public class SelectArtistFragment extends SubsonicTabFragment implements Adapter } @Override - protected void refresh() { - load(true); + protected void refresh(boolean refresh) { + load(refresh); } private void load(final boolean refresh) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 87ca2c68..5bc15fb7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -319,8 +319,8 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap } @Override - protected void refresh() { - load(true); + protected void refresh(boolean refresh) { + load(refresh); } private void load(boolean refresh) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 5581cae5..79b8280a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -152,8 +152,8 @@ public class SelectPlaylistFragment extends SubsonicTabFragment implements Adapt } @Override - protected void refresh() { - load(true); + protected void refresh(boolean refresh) { + load(refresh); } private void load(final boolean refresh) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 8cc6badd..9fc1308e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -89,7 +89,7 @@ public class SubsonicFragment extends SherlockFragment { public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { switch (item.getItemId()) { case R.id.menu_refresh: - refresh(); + refresh(true); return true; case R.id.menu_shuffle: onShuffleRequested(); @@ -116,6 +116,9 @@ public class SubsonicFragment extends SherlockFragment { } protected void refresh() { + refresh(true); + } + protected void refresh(boolean refresh) { } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index a1cd9557..eeed999a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -39,14 +39,14 @@ public class SubsonicTabFragment extends SubsonicFragment { } if(invalidated) { invalidated = false; - refresh(); + refresh(false); } } } public void invalidate() { if(primaryFragment) { - refresh(); + refresh(false); } else { invalidated = true; } -- cgit v1.2.3 From de312e05db9d9c73217a91bbdee1794f5e0d8730 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 27 Apr 2013 19:13:12 -0700 Subject: Added in click handlers for bottom bar buttons --- .../daneren2005/dsub/activity/MainActivity.java | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 0a437af6..5342f367 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -1,6 +1,8 @@ package github.daneren2005.dsub.activity; import android.app.AlertDialog; +import android.app.PendingIntent; +import android.content.ComponentName; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; @@ -9,15 +11,19 @@ import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.view.Menu; import android.support.v4.view.ViewPager; import android.util.Log; +import android.view.KeyEvent; import android.view.View; +import android.widget.ImageButton; import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.PlayerState; import github.daneren2005.dsub.fragments.MainFragment; import github.daneren2005.dsub.fragments.SelectArtistFragment; import github.daneren2005.dsub.fragments.SelectPlaylistFragment; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.Util; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -30,6 +36,7 @@ public class MainActivity extends SubsonicActivity { private View coverArtView; private TextView trackView; private TextView artistView; + private ImageButton startButton; @Override public void onCreate(Bundle savedInstanceState) { @@ -47,6 +54,79 @@ public class MainActivity extends SubsonicActivity { coverArtView = bottomBar.findViewById(R.id.album_art); trackView = (TextView) bottomBar.findViewById(R.id.track_name); artistView = (TextView) bottomBar.findViewById(R.id.artist_name); + + ImageButton previousButton = (ImageButton) findViewById(R.id.download_previous); + previousButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new SilentBackgroundTask(MainActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + if(getDownloadService() == null) { + return null; + } + + getDownloadService().previous(); + return null; + } + + @Override + protected void done(Void result) { + update(); + } + }.execute(); + } + }); + + startButton = (ImageButton) findViewById(R.id.download_start); + startButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new SilentBackgroundTask(MainActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + PlayerState state = getDownloadService().getPlayerState(); + if(state == PlayerState.STARTED) { + getDownloadService().pause(); + } else { + getDownloadService().start(); + } + + return null; + } + + @Override + protected void done(Void result) { + update(); + } + }.execute(); + } + }); + + ImageButton nextButton = (ImageButton) findViewById(R.id.download_next); + nextButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new SilentBackgroundTask(MainActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + if(getDownloadService() == null) { + return null; + } + + if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) { + getDownloadService().next(); + } + return null; + } + + @Override + protected void done(Void result) { + update(); + } + }.execute(); + } + }); viewPager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new TabPagerAdapter(this, viewPager); @@ -148,6 +228,7 @@ public class MainActivity extends SubsonicActivity { trackView.setText(song.getTitle()); artistView.setText(song.getArtist()); getImageLoader().loadImage(coverArtView, song, false, false); + startButton.setImageResource((getDownloadService().getPlayerState() == PlayerState.STARTED) ? R.drawable.media_pause : R.drawable.media_start); } private void showInfoDialog() { -- cgit v1.2.3 From 47dd3bb22d39a31215a59b7e3fc1caea51033e3c Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 27 Apr 2013 20:00:29 -0700 Subject: Change from menu exit to double back press --- subsonic-android/res/values/strings.xml | 1 + .../github/daneren2005/dsub/activity/MainActivity.java | 18 +++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/values/strings.xml b/subsonic-android/res/values/strings.xml index 839a3e49..4e96ad5a 100644 --- a/subsonic-android/res/values/strings.xml +++ b/subsonic-android/res/values/strings.xml @@ -50,6 +50,7 @@ Top rated Starred Random + Press back again to exit Search Shuffle diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 5342f367..9930d2b0 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -37,6 +37,7 @@ public class MainActivity extends SubsonicActivity { private TextView trackView; private TextView artistView; private ImageButton startButton; + private long lastBackPressTime = 0; @Override public void onCreate(Bundle savedInstanceState) { @@ -184,17 +185,12 @@ public class MainActivity extends SubsonicActivity { @Override public void onBackPressed() { if(pagerAdapter.onBackPressed()) { - AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); - builder.setTitle(R.string.menu_exit) - .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - MainActivity.super.onBackPressed(); - } - }) - .setNegativeButton(R.string.common_cancel, null); - AlertDialog dialog = builder.create(); - dialog.show(); + if(lastBackPressTime < (System.currentTimeMillis() - 4000)) { + lastBackPressTime = System.currentTimeMillis(); + Util.toast(this, R.string.main_back_confirm); + } else { + super.onBackPressed(); + } } } -- cgit v1.2.3 From 1c2ea00cc33f81ae5de68fbc918fa91c50e51127 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 28 Apr 2013 17:06:36 -0700 Subject: Change to SubsonicFragment --- .../src/github/daneren2005/dsub/util/TabBackgroundTask.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/util/TabBackgroundTask.java b/subsonic-android/src/github/daneren2005/dsub/util/TabBackgroundTask.java index 57a36c1f..c345b982 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/TabBackgroundTask.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/TabBackgroundTask.java @@ -1,7 +1,6 @@ package github.daneren2005.dsub.util; -import github.daneren2005.dsub.activity.SubsonicTabActivity; -import github.daneren2005.dsub.fragments.SubsonicTabFragment; +import github.daneren2005.dsub.fragments.SubsonicFragment; /** * @author Sindre Mehus @@ -9,9 +8,9 @@ import github.daneren2005.dsub.fragments.SubsonicTabFragment; */ public abstract class TabBackgroundTask extends BackgroundTask { - private final SubsonicTabFragment tabFragment; + private final SubsonicFragment tabFragment; - public TabBackgroundTask(SubsonicTabFragment fragment) { + public TabBackgroundTask(SubsonicFragment fragment) { super(fragment.getActivity()); tabFragment = fragment; } -- cgit v1.2.3 From 68a033d58ac9bb4848244063089eae61cb7c968b Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 28 Apr 2013 17:19:01 -0700 Subject: Use same callbacks for search fragment --- .../daneren2005/dsub/fragments/SearchFragment.java | 54 +-------- .../dsub/fragments/SelectDirectoryFragment.java | 125 +------------------- .../dsub/fragments/SubsonicFragment.java | 131 +++++++++++++++++++++ .../dsub/fragments/SubsonicTabFragment.java | 10 ++ 4 files changed, 153 insertions(+), 167 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java index 1b971cdf..ea09328d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -32,14 +32,12 @@ import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.view.ArtistAdapter; import github.daneren2005.dsub.util.BackgroundTask; -import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.view.EntryAdapter; import github.daneren2005.dsub.util.MergeAdapter; -import github.daneren2005.dsub.util.TabActivityBackgroundTask; import github.daneren2005.dsub.util.TabBackgroundTask; import github.daneren2005.dsub.util.Util; -public class SearchFragment extends SubsonicTabFragment { +public class SearchFragment extends SubsonicFragment { private static final int DEFAULT_ARTISTS = 3; private static final int DEFAULT_ALBUMS = 5; private static final int DEFAULT_SONGS = 10; @@ -131,19 +129,8 @@ public class SearchFragment extends SubsonicTabFragment { @Override public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_search: - context.onSearchRequested(); - return true; - case R.id.menu_exit: - exit(); - return true; - case R.id.menu_settings: - startActivity(new Intent(context, SettingsActivity.class)); - return true; - case R.id.menu_help: - startActivity(new Intent(context, HelpActivity.class)); - return true; + if(super.onOptionsItemSelected(item)) { + return true; } return false; @@ -173,38 +160,9 @@ public class SearchFragment extends SubsonicTabFragment { public boolean onContextItemSelected(MenuItem menuItem) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); Object selectedItem = list.getItemAtPosition(info.position); - - Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null; - MusicDirectory.Entry entry = selectedItem instanceof MusicDirectory.Entry ? (MusicDirectory.Entry) selectedItem : null; - String id = artist != null ? artist.getId() : entry.getId(); - - switch (menuItem.getItemId()) { - case R.id.album_menu_play_now: - downloadRecursively(id, false, false, true, false, false); - break; - case R.id.album_menu_play_shuffled: - downloadRecursively(id, false, false, true, true, false); - break; - case R.id.album_menu_play_last: - downloadRecursively(id, false, true, false, false, false); - break; - case R.id.album_menu_download: - downloadRecursively(id, false, true, false, false, true); - break; - case R.id.album_menu_pin: - downloadRecursively(id, true, true, false, false, true); - break; - case R.id.song_menu_play_now: - onSongSelected(entry, false, false, true, false); - break; - case R.id.song_menu_play_next: - onSongSelected(entry, false, true, false, true); - break; - case R.id.song_menu_play_last: - onSongSelected(entry, false, true, false, false); - break; - default: - return super.onContextItemSelected(menuItem); + + if(super.onContextItemSelected(menuItem, selectedItem)) { + return true; } return true; diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 5bc15fb7..c518f73e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -219,80 +219,19 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap @Override public boolean onContextItemSelected(MenuItem menuItem) { - if(!primaryFragment) { - return false; + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + Object selectedItem = entries.get(info.position); + + if(super.onContextItemSelected(menuItem, selectedItem)) { + return true; } - AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position); - List songs = new ArrayList(10); - songs.add((MusicDirectory.Entry) entryList.getItemAtPosition(info.position)); switch (menuItem.getItemId()) { - case R.id.album_menu_play_now: - downloadRecursively(entry.getId(), false, false, true, false, false); - break; - case R.id.album_menu_play_shuffled: - downloadRecursively(entry.getId(), false, false, true, true, false); - break; - case R.id.album_menu_play_last: - downloadRecursively(entry.getId(), false, true, false, false, false); - break; - case R.id.album_menu_download: - downloadRecursively(entry.getId(), false, true, false, false, true); - break; - case R.id.album_menu_pin: - downloadRecursively(entry.getId(), true, true, false, false, true); - break; - case R.id.album_menu_star: - toggleStarred(entry); - break; - case R.id.album_menu_delete: - deleteRecursively(entry); - break; - case R.id.song_menu_play_now: - getDownloadService().clear(); - getDownloadService().download(songs, false, true, true, false); - Util.startActivityWithoutTransition(context, DownloadActivity.class); - break; - case R.id.song_menu_play_next: - getDownloadService().download(songs, false, false, true, false); - break; - case R.id.song_menu_play_last: - getDownloadService().download(songs, false, false, false, false); - break; - case R.id.song_menu_download: - getDownloadService().downloadBackground(songs, false); - break; - case R.id.song_menu_pin: - getDownloadService().downloadBackground(songs, true); - break; - case R.id.song_menu_delete: - getDownloadService().delete(songs); - break; - case R.id.song_menu_add_playlist: - addToPlaylist(songs); - break; - case R.id.song_menu_star: - toggleStarred(entry); - break; - case R.id.song_menu_webview: - playWebView(entry); - break; - case R.id.song_menu_play_external: - playExternalPlayer(entry); - break; - case R.id.song_menu_info: - displaySongInfo(entry); - break; - case R.id.song_menu_stream_external: - streamExternalPlayer(entry); - break; case R.id.song_menu_remove_playlist: removeFromPlaylist(playlistId, playlistName, Arrays.asList(info.position - 1)); break; - default: - return super.onContextItemSelected(menuItem); } + return true; } @@ -611,58 +550,6 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap } } - private boolean entryExists(MusicDirectory.Entry entry) { - DownloadFile check = new DownloadFile(context, entry, false); - return check.isCompleteFileAvailable(); - } - - private void playWebView(MusicDirectory.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 playExternalPlayer(MusicDirectory.Entry entry) { - if(!entryExists(entry)) { - Util.toast(context, R.string.download_need_download); - } else { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setDataAndType(Uri.parse(entry.getPath()), "video/*"); - - List intents = context.getPackageManager() - .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); - if(intents != null && intents.size() > 0) { - startActivity(intent); - }else { - Util.toast(context, R.string.download_no_streaming_player); - } - } - } - private void streamExternalPlayer(MusicDirectory.Entry entry) { - int maxBitrate = Util.getMaxVideoBitrate(context); - - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoStreamUrl(maxBitrate, context, entry.getId())), "video/*"); - - List intents = context.getPackageManager() - .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); - if(intents != null && intents.size() > 0) { - startActivity(intent); - } else { - Util.toast(context, R.string.download_no_streaming_player); - } - } - - public void deleteRecursively(MusicDirectory.Entry album) { - File dir = FileUtil.getAlbumDirectory(context, album); - Util.recursiveDelete(dir); - if(Util.isOffline(context)) { - refresh(); - } - } - public void removeFromPlaylist(final String id, final String name, final List indexes) { new LoadingTask(context, true) { @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 9fc1308e..043c7373 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -24,10 +24,15 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.media.MediaMetadataRetriever; +import android.net.Uri; import android.os.Bundle; import android.util.Log; +import android.view.MenuItem; import android.view.View; +import android.widget.AdapterView; import android.widget.EditText; import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragment; @@ -55,6 +60,7 @@ import github.daneren2005.dsub.util.LoadingTask; import github.daneren2005.dsub.util.Util; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -110,6 +116,79 @@ public class SubsonicFragment extends SherlockFragment { return false; } + + public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) { + Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null; + MusicDirectory.Entry entry = selectedItem instanceof MusicDirectory.Entry ? (MusicDirectory.Entry) selectedItem : null; + List songs = new ArrayList(10); + songs.add(entry); + + switch (menuItem.getItemId()) { + case R.id.album_menu_play_now: + downloadRecursively(entry.getId(), false, false, true, false, false); + break; + case R.id.album_menu_play_shuffled: + downloadRecursively(entry.getId(), false, false, true, true, false); + break; + case R.id.album_menu_play_last: + downloadRecursively(entry.getId(), false, true, false, false, false); + break; + case R.id.album_menu_download: + downloadRecursively(entry.getId(), false, true, false, false, true); + break; + case R.id.album_menu_pin: + downloadRecursively(entry.getId(), true, true, false, false, true); + break; + case R.id.album_menu_star: + toggleStarred(entry); + break; + case R.id.album_menu_delete: + deleteRecursively(entry); + break; + case R.id.song_menu_play_now: + getDownloadService().clear(); + getDownloadService().download(songs, false, true, true, false); + Util.startActivityWithoutTransition(context, DownloadActivity.class); + break; + case R.id.song_menu_play_next: + getDownloadService().download(songs, false, false, true, false); + break; + case R.id.song_menu_play_last: + getDownloadService().download(songs, false, false, false, false); + break; + case R.id.song_menu_download: + getDownloadService().downloadBackground(songs, false); + break; + case R.id.song_menu_pin: + getDownloadService().downloadBackground(songs, true); + break; + case R.id.song_menu_delete: + getDownloadService().delete(songs); + break; + case R.id.song_menu_add_playlist: + addToPlaylist(songs); + break; + case R.id.song_menu_star: + toggleStarred(entry); + break; + case R.id.song_menu_webview: + playWebView(entry); + break; + case R.id.song_menu_play_external: + playExternalPlayer(entry); + break; + case R.id.song_menu_info: + displaySongInfo(entry); + break; + case R.id.song_menu_stream_external: + streamExternalPlayer(entry); + break; + default: + return false; + } + + return true; + } public DownloadService getDownloadService() { return context != null ? context.getDownloadService() : null; @@ -479,4 +558,56 @@ public class SubsonicFragment extends SherlockFragment { .setMessage(msg) .show(); } + + protected void playWebView(MusicDirectory.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); + } + protected void playExternalPlayer(MusicDirectory.Entry entry) { + if(!entryExists(entry)) { + Util.toast(context, R.string.download_need_download); + } else { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.parse(entry.getPath()), "video/*"); + + List intents = context.getPackageManager() + .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); + if(intents != null && intents.size() > 0) { + startActivity(intent); + }else { + Util.toast(context, R.string.download_no_streaming_player); + } + } + } + protected void streamExternalPlayer(MusicDirectory.Entry entry) { + int maxBitrate = Util.getMaxVideoBitrate(context); + + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoStreamUrl(maxBitrate, context, entry.getId())), "video/*"); + + List intents = context.getPackageManager() + .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); + if(intents != null && intents.size() > 0) { + startActivity(intent); + } else { + Util.toast(context, R.string.download_no_streaming_player); + } + } + + protected boolean entryExists(MusicDirectory.Entry entry) { + DownloadFile check = new DownloadFile(context, entry, false); + return check.isCompleteFileAvailable(); + } + + public void deleteRecursively(MusicDirectory.Entry album) { + File dir = FileUtil.getAlbumDirectory(context, album); + Util.recursiveDelete(dir); + if(Util.isOffline(context)) { + refresh(); + } + } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index eeed999a..3045d99b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -19,12 +19,22 @@ package github.daneren2005.dsub.fragments; import android.util.Log; +import android.view.MenuItem; public class SubsonicTabFragment extends SubsonicFragment { private static final String TAG = SubsonicTabFragment.class.getSimpleName(); protected boolean primaryFragment = false; protected boolean invalidated = false; + @Override + public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) { + if(!primaryFragment) { + return true; + } + + return super.onContextItemSelected(menuItem, selectedItem); + } + public void replaceFragment(SubsonicTabFragment fragment, int id) { this.setPrimaryFragment(false); fragment.setPrimaryFragment(true); -- cgit v1.2.3 From ad7b26d6ff7221e1153732f815aae401e237e795 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 28 Apr 2013 19:46:01 -0700 Subject: Fix shuffle on download frag --- .../src/github/daneren2005/dsub/fragments/DownloadFragment.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index a38f9fcd..5093934b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -475,11 +475,11 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe @Override public boolean onOptionsItemSelected(MenuItem menuItem) { - if(super.onOptionsItemSelected(menuItem)) { + if(menuItemSelected(menuItem.getItemId(), null)) { return true; } - - return menuItemSelected(menuItem.getItemId(), null); + + return super.onOptionsItemSelected(menuItem); } @Override @@ -606,9 +606,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe startTimer(); } return true; - case R.id.menu_exit: - exit(); - return true; case R.id.menu_add_playlist: songs = new ArrayList(1); songs.add(song.getSong()); -- cgit v1.2.3 From 0de1b9a6d4edb75a6d855f6fc1e0b93dca20c307 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 28 Apr 2013 19:53:06 -0700 Subject: Fix menu -> exit from download activity --- .../daneren2005/dsub/activity/MainActivity.java | 5 +++++ .../dsub/fragments/SubsonicFragment.java | 24 ++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 9930d2b0..cc4d93ed 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -23,6 +23,7 @@ import github.daneren2005.dsub.fragments.SelectArtistFragment; import github.daneren2005.dsub.fragments.SelectPlaylistFragment; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.Util; import java.util.concurrent.Executors; @@ -42,6 +43,10 @@ public class MainActivity extends SubsonicActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { + stopService(new Intent(this, DownloadServiceImpl.class)); + finish(); + } setContentView(R.layout.main); View bottomBar = findViewById(R.id.bottom_bar); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 043c7373..4b52196f 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -39,6 +39,7 @@ import com.actionbarsherlock.app.SherlockFragment; import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.DownloadActivity; import github.daneren2005.dsub.activity.HelpActivity; +import github.daneren2005.dsub.activity.MainActivity; import github.daneren2005.dsub.activity.SettingsActivity; import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.domain.Artist; @@ -116,13 +117,13 @@ public class SubsonicFragment extends SherlockFragment { return false; } - + public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) { Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null; MusicDirectory.Entry entry = selectedItem instanceof MusicDirectory.Entry ? (MusicDirectory.Entry) selectedItem : null; List songs = new ArrayList(10); songs.add(entry); - + switch (menuItem.getItemId()) { case R.id.album_menu_play_now: downloadRecursively(entry.getId(), false, false, true, false, false); @@ -186,7 +187,7 @@ public class SubsonicFragment extends SherlockFragment { default: return false; } - + return true; } @@ -202,8 +203,15 @@ public class SubsonicFragment extends SherlockFragment { } protected void exit() { - context.stopService(new Intent(context, DownloadServiceImpl.class)); - context.finish(); + if(context.getClass() != MainActivity.class) { + Intent intent = new Intent(context, MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true); + Util.startActivityWithoutTransition(context, intent); + } else { + context.stopService(new Intent(context, DownloadServiceImpl.class)); + context.finish(); + } } public void setProgressVisible(boolean visible) { @@ -558,7 +566,7 @@ public class SubsonicFragment extends SherlockFragment { .setMessage(msg) .show(); } - + protected void playWebView(MusicDirectory.Entry entry) { int maxBitrate = Util.getMaxVideoBitrate(context); @@ -597,12 +605,12 @@ public class SubsonicFragment extends SherlockFragment { Util.toast(context, R.string.download_no_streaming_player); } } - + protected boolean entryExists(MusicDirectory.Entry entry) { DownloadFile check = new DownloadFile(context, entry, false); return check.isCompleteFileAvailable(); } - + public void deleteRecursively(MusicDirectory.Entry album) { File dir = FileUtil.getAlbumDirectory(context, album); Util.recursiveDelete(dir); -- cgit v1.2.3 From a9ed7c936d0e4c065b116d49c3abaff20f900a19 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 29 Apr 2013 21:29:49 -0700 Subject: Combine context menu builder --- .../daneren2005/dsub/fragments/SearchFragment.java | 13 +------ .../dsub/fragments/SelectArtistFragment.java | 11 ++---- .../dsub/fragments/SelectDirectoryFragment.java | 33 ++--------------- .../dsub/fragments/SubsonicFragment.java | 43 ++++++++++++++++++++++ 4 files changed, 50 insertions(+), 50 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java index ea09328d..b38beab4 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -142,18 +142,7 @@ public class SearchFragment extends SubsonicFragment { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; Object selectedItem = list.getItemAtPosition(info.position); - - boolean isArtist = selectedItem instanceof Artist; - boolean isAlbum = selectedItem instanceof MusicDirectory.Entry && ((MusicDirectory.Entry) selectedItem).isDirectory(); - boolean isSong = selectedItem instanceof MusicDirectory.Entry && (!((MusicDirectory.Entry) selectedItem).isDirectory()) - && (!((MusicDirectory.Entry) selectedItem).isVideo()); - - MenuInflater inflater = context.getMenuInflater(); - if (isArtist || isAlbum) { - inflater.inflate(R.menu.select_album_context, menu); - } else if (isSong) { - inflater.inflate(R.menu.select_song_context, menu); - } + onCreateContextMenu(menu, view, menuInfo, selectedItem); } @Override diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index bac9c71d..dba70ce8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -83,15 +83,10 @@ public class SelectArtistFragment extends SubsonicTabFragment implements Adapter super.onCreateContextMenu(menu, view, menuInfo); AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + Object entry = artistList.getItemAtPosition(info.position); - if (artistList.getItemAtPosition(info.position) instanceof Artist) { - MenuInflater inflater = context.getMenuInflater(); - if(Util.isOffline(context)) { - inflater.inflate(R.menu.select_artist_context_offline, menu); - } - else { - inflater.inflate(R.menu.select_artist_context, menu); - } + if (entry instanceof Artist) { + onCreateContextMenu(menu, view, menuInfo, entry); } else if (info.position == 0) { String musicFolderId = Util.getSelectedMusicFolderId(context); MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index c518f73e..c4d28995 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -184,36 +184,9 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; MusicDirectory.Entry entry = (MusicDirectory.Entry) entryList.getItemAtPosition(info.position); - - MenuInflater inflater = context.getMenuInflater(); - if (entry.isDirectory()) { - if(Util.isOffline(context)) { - inflater.inflate(R.menu.select_album_context_offline, menu); - } - else { - inflater.inflate(R.menu.select_album_context, menu); - } - } else if(!entry.isVideo()) { - if(Util.isOffline(context)) { - inflater.inflate(R.menu.select_song_context_offline, menu); - } - else { - inflater.inflate(R.menu.select_song_context, menu); - if(playlistId == null) { - menu.removeItem(R.id.song_menu_remove_playlist); - } - } - } else { - if(Util.isOffline(context)) { - inflater.inflate(R.menu.select_video_context_offline, menu); - } - else { - inflater.inflate(R.menu.select_video_context, menu); - } - } - - if (!Util.isOffline(context) && !entry.isVideo()) { - menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star).setTitle(entry.isStarred() ? R.string.common_unstar : R.string.common_star); + onCreateContextMenu(menu, view, menuInfo, entry); + if(!entry.isVideo() && !Util.isOffline(context) && playlistId == null) { + menu.removeItem(R.id.song_menu_remove_playlist); } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 4b52196f..e9da1827 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -30,6 +30,8 @@ import android.media.MediaMetadataRetriever; import android.net.Uri; import android.os.Bundle; import android.util.Log; +import android.view.ContextMenu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; @@ -117,6 +119,47 @@ public class SubsonicFragment extends SherlockFragment { return false; } + + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo, Object selected) { + MenuInflater inflater = context.getMenuInflater(); + + if(selected instanceof MusicDirectory.Entry) { + MusicDirectory.Entry entry = (MusicDirectory.Entry) selected; + if (entry.isDirectory()) { + if(Util.isOffline(context)) { + inflater.inflate(R.menu.select_album_context_offline, menu); + } + else { + inflater.inflate(R.menu.select_album_context, menu); + } + } else if(!entry.isVideo()) { + if(Util.isOffline(context)) { + inflater.inflate(R.menu.select_song_context_offline, menu); + } + else { + inflater.inflate(R.menu.select_song_context, menu); + } + } else { + if(Util.isOffline(context)) { + inflater.inflate(R.menu.select_video_context_offline, menu); + } + else { + inflater.inflate(R.menu.select_video_context, menu); + } + } + + if (!Util.isOffline(context) && !entry.isVideo()) { + menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star).setTitle(entry.isStarred() ? R.string.common_unstar : R.string.common_star); + } + } else if(selected instanceof Artist) { + if(Util.isOffline(context)) { + inflater.inflate(R.menu.select_artist_context_offline, menu); + } + else { + inflater.inflate(R.menu.select_artist_context, menu); + } + } + } public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) { Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null; -- cgit v1.2.3 From ab686aeb2f61987a817b7c41e45c1ee3dad4d5f6 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 29 Apr 2013 22:18:14 -0700 Subject: Fix some of the menus --- .../github/daneren2005/dsub/fragments/SearchFragment.java | 2 +- .../daneren2005/dsub/fragments/SelectDirectoryFragment.java | 9 +++++++-- .../daneren2005/dsub/fragments/SubsonicTabFragment.java | 12 +----------- 3 files changed, 9 insertions(+), 14 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java index b38beab4..5e53e71d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -150,7 +150,7 @@ public class SearchFragment extends SubsonicFragment { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); Object selectedItem = list.getItemAtPosition(info.position); - if(super.onContextItemSelected(menuItem, selectedItem)) { + if(onContextItemSelected(menuItem, selectedItem)) { return true; } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index c4d28995..a12adff3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -192,10 +192,14 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap @Override public boolean onContextItemSelected(MenuItem menuItem) { + if(!primaryFragment) { + return false; + } + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - Object selectedItem = entries.get(info.position); + Object selectedItem = entries.get(showHeader ? (info.position - 1) : info.position); - if(super.onContextItemSelected(menuItem, selectedItem)) { + if(onContextItemSelected(menuItem, selectedItem)) { return true; } @@ -353,6 +357,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap entryList.addHeaderView(createHeader(entries), null, false); } } else { + showHeader = false; hideButtons = true; } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index 3045d99b..da065501 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -26,22 +26,12 @@ public class SubsonicTabFragment extends SubsonicFragment { protected boolean primaryFragment = false; protected boolean invalidated = false; - @Override - public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) { - if(!primaryFragment) { - return true; - } - - return super.onContextItemSelected(menuItem, selectedItem); - } - public void replaceFragment(SubsonicTabFragment fragment, int id) { - this.setPrimaryFragment(false); - fragment.setPrimaryFragment(true); context.getPagerAdapter().replaceCurrent(fragment, id); } public void setPrimaryFragment(boolean primary) { + Log.i(TAG, this.getClass().getName() + ": " + primary); primaryFragment = primary; if(primary) { if(context != null) { -- cgit v1.2.3 From 572b78415cb7cebe1bb0e71e28c53bf5735434f3 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 29 Apr 2013 22:19:45 -0700 Subject: Remove log --- .../src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java | 1 - 1 file changed, 1 deletion(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java index da065501..c4079816 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java @@ -31,7 +31,6 @@ public class SubsonicTabFragment extends SubsonicFragment { } public void setPrimaryFragment(boolean primary) { - Log.i(TAG, this.getClass().getName() + ": " + primary); primaryFragment = primary; if(primary) { if(context != null) { -- cgit v1.2.3 From f1408cdb34a90b5e03c76bff7e5afeeb75ab46f0 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 29 Apr 2013 22:30:31 -0700 Subject: Remove "Remove from playlist" from search fragment --- .../src/github/daneren2005/dsub/fragments/SearchFragment.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java index 5e53e71d..82c44913 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -143,6 +143,9 @@ public class SearchFragment extends SubsonicFragment { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; Object selectedItem = list.getItemAtPosition(info.position); onCreateContextMenu(menu, view, menuInfo, selectedItem); + if(selectedItem instanceof MusicDirectory.Entry && !((MusicDirectory.Entry) selectedItem).isVideo() && !Util.isOffline(context)) { + menu.removeItem(R.id.song_menu_remove_playlist); + } } @Override -- cgit v1.2.3 From b0e3b154eab451ee0980aa7b2266bba5bde5e8f8 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 30 Apr 2013 20:35:09 -0700 Subject: Got rid of tab fragment --- subsonic-android/res/layout/search.xml | 1 + .../daneren2005/dsub/activity/MainActivity.java | 486 ++++++++++----------- .../dsub/activity/SubsonicActivity.java | 14 +- .../daneren2005/dsub/fragments/MainFragment.java | 4 +- .../daneren2005/dsub/fragments/SearchFragment.java | 27 +- .../dsub/fragments/SelectArtistFragment.java | 4 +- .../dsub/fragments/SelectDirectoryFragment.java | 4 +- .../dsub/fragments/SelectPlaylistFragment.java | 6 +- .../dsub/fragments/SubsonicFragment.java | 27 ++ .../dsub/fragments/SubsonicTabFragment.java | 53 --- 10 files changed, 303 insertions(+), 323 deletions(-) delete mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout/search.xml b/subsonic-android/res/layout/search.xml index d9bb301c..d1c5c84c 100644 --- a/subsonic-android/res/layout/search.xml +++ b/subsonic-android/res/layout/search.xml @@ -1,5 +1,6 @@ diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index cc4d93ed..b5ff4abb 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -1,243 +1,243 @@ -package github.daneren2005.dsub.activity; - -import android.app.AlertDialog; -import android.app.PendingIntent; -import android.content.ComponentName; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import com.actionbarsherlock.app.ActionBar; -import com.actionbarsherlock.view.Menu; -import android.support.v4.view.ViewPager; -import android.util.Log; -import android.view.KeyEvent; -import android.view.View; -import android.widget.ImageButton; -import android.widget.TextView; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.domain.PlayerState; -import github.daneren2005.dsub.fragments.MainFragment; -import github.daneren2005.dsub.fragments.SelectArtistFragment; -import github.daneren2005.dsub.fragments.SelectPlaylistFragment; -import github.daneren2005.dsub.service.DownloadFile; -import github.daneren2005.dsub.service.DownloadServiceImpl; -import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.SilentBackgroundTask; -import github.daneren2005.dsub.util.Util; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -public class MainActivity extends SubsonicActivity { - private static final String TAG = MainActivity.class.getSimpleName(); - private static boolean infoDialogDisplayed; - private ScheduledExecutorService executorService; - private View coverArtView; - private TextView trackView; - private TextView artistView; - private ImageButton startButton; - private long lastBackPressTime = 0; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { - stopService(new Intent(this, DownloadServiceImpl.class)); - finish(); - } - setContentView(R.layout.main); - - View bottomBar = findViewById(R.id.bottom_bar); - bottomBar.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - Intent intent = new Intent(); - intent.setClass(v.getContext(), DownloadActivity.class); - startActivity(intent); - } - }); - coverArtView = bottomBar.findViewById(R.id.album_art); - trackView = (TextView) bottomBar.findViewById(R.id.track_name); - artistView = (TextView) bottomBar.findViewById(R.id.artist_name); - - ImageButton previousButton = (ImageButton) findViewById(R.id.download_previous); - previousButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - new SilentBackgroundTask(MainActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - if(getDownloadService() == null) { - return null; - } - - getDownloadService().previous(); - return null; - } - - @Override - protected void done(Void result) { - update(); - } - }.execute(); - } - }); - - startButton = (ImageButton) findViewById(R.id.download_start); - startButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - new SilentBackgroundTask(MainActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - PlayerState state = getDownloadService().getPlayerState(); - if(state == PlayerState.STARTED) { - getDownloadService().pause(); - } else { - getDownloadService().start(); - } - - return null; - } - - @Override - protected void done(Void result) { - update(); - } - }.execute(); - } - }); - - ImageButton nextButton = (ImageButton) findViewById(R.id.download_next); - nextButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - new SilentBackgroundTask(MainActivity.this) { - @Override - protected Void doInBackground() throws Throwable { - if(getDownloadService() == null) { - return null; - } - - if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) { - getDownloadService().next(); - } - return null; - } - - @Override - protected void done(Void result) { - update(); - } - }.execute(); - } - }); - - viewPager = (ViewPager) findViewById(R.id.pager); - pagerAdapter = new TabPagerAdapter(this, viewPager); - viewPager.setAdapter(pagerAdapter); - viewPager.setOnPageChangeListener(pagerAdapter); - - addTab("Home", MainFragment.class, null); - addTab("Library", SelectArtistFragment.class, null); - addTab("Playlists", SelectPlaylistFragment.class, null); - } - - @Override - public void onSaveInstanceState(Bundle savedInstanceState) { - - } - - @Override - protected void onPostCreate(Bundle bundle) { - super.onPostCreate(bundle); - - getSupportActionBar().setDisplayHomeAsUpEnabled(false); - getSupportActionBar().setHomeButtonEnabled(false); - getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); - - showInfoDialog(); - } - - @Override - public void onResume() { - super.onResume(); - - final Handler handler = new Handler(); - Runnable runnable = new Runnable() { - @Override - public void run() { - handler.post(new Runnable() { - @Override - public void run() { - update(); - } - }); - } - }; - - executorService = Executors.newSingleThreadScheduledExecutor(); - executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS); - } - - @Override - public void onPause() { - super.onPause(); - executorService.shutdown(); - } - - @Override - public void onBackPressed() { - if(pagerAdapter.onBackPressed()) { - if(lastBackPressTime < (System.currentTimeMillis() - 4000)) { - lastBackPressTime = System.currentTimeMillis(); - Util.toast(this, R.string.main_back_confirm); - } else { - super.onBackPressed(); - } - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - if(pagerAdapter != null) { - com.actionbarsherlock.view.MenuInflater menuInflater = getSupportMenuInflater(); - pagerAdapter.onCreateOptionsMenu(menu, menuInflater); - } - return true; - } - @Override - public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { - return pagerAdapter.onOptionsItemSelected(item); - } - - private void update() { - if (getDownloadService() == null) { - return; - } - - DownloadFile current = getDownloadService().getCurrentPlaying(); - if(current == null) { - trackView.setText("Title"); - artistView.setText("Artist"); - getImageLoader().loadImage(coverArtView, null, false, false); - return; - } - - MusicDirectory.Entry song = current.getSong(); - trackView.setText(song.getTitle()); - artistView.setText(song.getArtist()); - getImageLoader().loadImage(coverArtView, song, false, false); - startButton.setImageResource((getDownloadService().getPlayerState() == PlayerState.STARTED) ? R.drawable.media_pause : R.drawable.media_start); - } - - private void showInfoDialog() { - if (!infoDialogDisplayed) { - infoDialogDisplayed = true; - if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) { - Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text); - } - } - } -} +package github.daneren2005.dsub.activity; + +import android.app.AlertDialog; +import android.app.PendingIntent; +import android.content.ComponentName; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.view.Menu; +import android.support.v4.view.ViewPager; +import android.util.Log; +import android.view.KeyEvent; +import android.view.View; +import android.widget.ImageButton; +import android.widget.TextView; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.MusicDirectory; +import github.daneren2005.dsub.domain.PlayerState; +import github.daneren2005.dsub.fragments.MainFragment; +import github.daneren2005.dsub.fragments.SelectArtistFragment; +import github.daneren2005.dsub.fragments.SelectPlaylistFragment; +import github.daneren2005.dsub.service.DownloadFile; +import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.SilentBackgroundTask; +import github.daneren2005.dsub.util.Util; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class MainActivity extends SubsonicActivity { + private static final String TAG = MainActivity.class.getSimpleName(); + private static boolean infoDialogDisplayed; + private ScheduledExecutorService executorService; + private View coverArtView; + private TextView trackView; + private TextView artistView; + private ImageButton startButton; + private long lastBackPressTime = 0; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { + stopService(new Intent(this, DownloadServiceImpl.class)); + finish(); + } + setContentView(R.layout.main); + + View bottomBar = findViewById(R.id.bottom_bar); + bottomBar.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + Intent intent = new Intent(); + intent.setClass(v.getContext(), DownloadActivity.class); + startActivity(intent); + } + }); + coverArtView = bottomBar.findViewById(R.id.album_art); + trackView = (TextView) bottomBar.findViewById(R.id.track_name); + artistView = (TextView) bottomBar.findViewById(R.id.artist_name); + + ImageButton previousButton = (ImageButton) findViewById(R.id.download_previous); + previousButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new SilentBackgroundTask(MainActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + if(getDownloadService() == null) { + return null; + } + + getDownloadService().previous(); + return null; + } + + @Override + protected void done(Void result) { + update(); + } + }.execute(); + } + }); + + startButton = (ImageButton) findViewById(R.id.download_start); + startButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new SilentBackgroundTask(MainActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + PlayerState state = getDownloadService().getPlayerState(); + if(state == PlayerState.STARTED) { + getDownloadService().pause(); + } else { + getDownloadService().start(); + } + + return null; + } + + @Override + protected void done(Void result) { + update(); + } + }.execute(); + } + }); + + ImageButton nextButton = (ImageButton) findViewById(R.id.download_next); + nextButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new SilentBackgroundTask(MainActivity.this) { + @Override + protected Void doInBackground() throws Throwable { + if(getDownloadService() == null) { + return null; + } + + if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) { + getDownloadService().next(); + } + return null; + } + + @Override + protected void done(Void result) { + update(); + } + }.execute(); + } + }); + + viewPager = (ViewPager) findViewById(R.id.pager); + pagerAdapter = new TabPagerAdapter(this, viewPager); + viewPager.setAdapter(pagerAdapter); + viewPager.setOnPageChangeListener(pagerAdapter); + + addTab("Home", MainFragment.class, null); + addTab("Library", SelectArtistFragment.class, null); + addTab("Playlists", SelectPlaylistFragment.class, null); + } + + @Override + public void onSaveInstanceState(Bundle savedInstanceState) { + + } + + @Override + protected void onPostCreate(Bundle bundle) { + super.onPostCreate(bundle); + + getSupportActionBar().setDisplayHomeAsUpEnabled(false); + getSupportActionBar().setHomeButtonEnabled(false); + getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + + showInfoDialog(); + } + + @Override + public void onResume() { + super.onResume(); + + final Handler handler = new Handler(); + Runnable runnable = new Runnable() { + @Override + public void run() { + handler.post(new Runnable() { + @Override + public void run() { + update(); + } + }); + } + }; + + executorService = Executors.newSingleThreadScheduledExecutor(); + executorService.scheduleWithFixedDelay(runnable, 0L, 1000L, TimeUnit.MILLISECONDS); + } + + @Override + public void onPause() { + super.onPause(); + executorService.shutdown(); + } + + @Override + public void onBackPressed() { + if(pagerAdapter.onBackPressed()) { + if(lastBackPressTime < (System.currentTimeMillis() - 4000)) { + lastBackPressTime = System.currentTimeMillis(); + Util.toast(this, R.string.main_back_confirm); + } else { + super.onBackPressed(); + } + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + if(pagerAdapter != null) { + com.actionbarsherlock.view.MenuInflater menuInflater = getSupportMenuInflater(); + pagerAdapter.onCreateOptionsMenu(menu, menuInflater); + } + return true; + } + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + return pagerAdapter.onOptionsItemSelected(item); + } + + private void update() { + if (getDownloadService() == null) { + return; + } + + DownloadFile current = getDownloadService().getCurrentPlaying(); + if(current == null) { + trackView.setText("Title"); + artistView.setText("Artist"); + getImageLoader().loadImage(coverArtView, null, false, false); + return; + } + + MusicDirectory.Entry song = current.getSong(); + trackView.setText(song.getTitle()); + artistView.setText(song.getArtist()); + getImageLoader().loadImage(coverArtView, song, false, false); + startButton.setImageResource((getDownloadService().getPlayerState() == PlayerState.STARTED) ? R.drawable.media_pause : R.drawable.media_start); + } + + private void showInfoDialog() { + if (!infoDialogDisplayed) { + infoDialogDisplayed = true; + if (Util.getRestUrl(this, null).contains("demo.subsonic.org")) { + Util.info(this, R.string.main_welcome_title, R.string.main_welcome_text); + } + } + } +} diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 5e89fbe6..a56cffba 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -21,7 +21,7 @@ import com.actionbarsherlock.app.SherlockFragment; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; import github.daneren2005.dsub.R; -import github.daneren2005.dsub.fragments.SubsonicTabFragment; +import github.daneren2005.dsub.fragments.SubsonicFragment; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.updates.Updater; @@ -225,7 +225,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { private SherlockFragmentActivity activity; private ViewPager pager; private ActionBar actionBar; - private SubsonicTabFragment currentFragment; + private SubsonicFragment currentFragment; private List tabs = new ArrayList(); private List frags = new ArrayList(); private int currentPosition; @@ -246,7 +246,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { fragStack.add(frag); frags.add(i, fragStack); if(currentFragment == null) { - currentFragment = (SubsonicTabFragment) frag; + currentFragment = (SubsonicFragment) frag; currentFragment.setPrimaryFragment(true); } return frag; @@ -295,7 +295,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { currentFragment.setPrimaryFragment(false); } List fragStack = (List)frags.get(position); - currentFragment = (SubsonicTabFragment) fragStack.get(fragStack.size() - 1); + currentFragment = (SubsonicFragment) fragStack.get(fragStack.size() - 1); if(currentFragment != null) { currentFragment.setPrimaryFragment(true); } @@ -316,7 +316,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { notifyDataSetChanged(); } - public void replaceCurrent(SubsonicTabFragment fragment, int id) { + public void replaceCurrent(SubsonicFragment fragment, int id) { if(currentFragment != null) { currentFragment.setPrimaryFragment(false); } @@ -339,7 +339,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { List fragStack = (List)frags.get(currentPosition); Fragment oldFrag = (Fragment)fragStack.remove(fragStack.size() - 1); - currentFragment = (SubsonicTabFragment) fragStack.get(fragStack.size() - 1); + currentFragment = (SubsonicFragment) fragStack.get(fragStack.size() - 1); currentFragment.setPrimaryFragment(true); activity.invalidateOptionsMenu(); @@ -366,7 +366,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { public void invalidate() { for (int i = 0; i < frags.size(); i++) { List fragStack = (List)frags.get(i); - SubsonicTabFragment frag = (SubsonicTabFragment)fragStack.get(fragStack.size() - 1); + SubsonicFragment frag = (SubsonicFragment)fragStack.get(fragStack.size() - 1); frag.invalidate(); } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java index 390f92fc..427c5098 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -29,7 +29,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class MainFragment extends SubsonicTabFragment { +public class MainFragment extends SubsonicFragment { private LayoutInflater inflater; private static final int MENU_GROUP_SERVER = 10; @@ -231,7 +231,7 @@ public class MainFragment extends SubsonicTabFragment { } private void showAlbumList(String type) { - SubsonicTabFragment fragment = new SelectDirectoryFragment(); + SubsonicFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); args.putString(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE, type); args.putInt(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 20); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java index 82c44913..ff12ac22 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -17,12 +17,11 @@ import android.widget.ListAdapter; import android.widget.ListView; import android.widget.TextView; import android.net.Uri; +import android.support.v4.app.FragmentTransaction; import android.view.ViewGroup; import com.actionbarsherlock.view.Menu; import github.daneren2005.dsub.R; -import github.daneren2005.dsub.activity.HelpActivity; import github.daneren2005.dsub.activity.SearchActivity; -import github.daneren2005.dsub.activity.SettingsActivity; import github.daneren2005.dsub.domain.Artist; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.SearchCritera; @@ -32,6 +31,7 @@ import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.view.ArtistAdapter; import github.daneren2005.dsub.util.BackgroundTask; +import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.view.EntryAdapter; import github.daneren2005.dsub.util.MergeAdapter; import github.daneren2005.dsub.util.TabBackgroundTask; @@ -261,18 +261,23 @@ public class SearchFragment extends SubsonicFragment { } private void onArtistSelected(Artist artist) { - /*Intent intent = new Intent(context, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); - Util.startActivityWithoutTransition(context, intent);*/ + SubsonicFragment fragment = new SelectDirectoryFragment(); + Bundle args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); + args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); + fragment.setArguments(args); + + replaceFragment(fragment, R.id.search_layout); } private void onAlbumSelected(MusicDirectory.Entry album, boolean autoplay) { - /*Intent intent = new Intent(context, SelectAlbumActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, album.getId()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, album.getTitle()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, autoplay); - Util.startActivityWithoutTransition(context, intent);*/ + SubsonicFragment fragment = new SelectDirectoryFragment(); + Bundle args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_ID, album.getId()); + args.putString(Constants.INTENT_EXTRA_NAME_NAME, album.getTitle()); + fragment.setArguments(args); + + replaceFragment(fragment, R.id.search_layout); } private void onSongSelected(MusicDirectory.Entry song, boolean save, boolean append, boolean autoplay, boolean playNext) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index dba70ce8..df49086d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -30,7 +30,7 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -public class SelectArtistFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { +public class SelectArtistFragment extends SubsonicFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectArtistFragment.class.getSimpleName(); private static final int MENU_GROUP_MUSIC_FOLDER = 10; @@ -158,7 +158,7 @@ public class SelectArtistFragment extends SubsonicTabFragment implements Adapter selectFolder(); } else { Artist artist = (Artist) parent.getItemAtPosition(position); - SubsonicTabFragment fragment = new SelectDirectoryFragment(); + SubsonicFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId()); args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName()); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index a12adff3..04d4fc65 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -42,7 +42,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; -public class SelectDirectoryFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { +public class SelectDirectoryFragment extends SubsonicFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectDirectoryFragment.class.getSimpleName(); private DragSortListView entryList; @@ -217,7 +217,7 @@ public class SelectDirectoryFragment extends SubsonicTabFragment implements Adap if (position >= 0) { MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position); if (entry.isDirectory()) { - SubsonicTabFragment fragment = new SelectDirectoryFragment(); + SubsonicFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); args.putString(Constants.INTENT_EXTRA_NAME_ID, entry.getId()); args.putString(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle()); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java index 79b8280a..68222385 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java @@ -31,7 +31,7 @@ import github.daneren2005.dsub.util.Util; import github.daneren2005.dsub.view.PlaylistAdapter; import java.util.List; -public class SelectPlaylistFragment extends SubsonicTabFragment implements AdapterView.OnItemClickListener { +public class SelectPlaylistFragment extends SubsonicFragment implements AdapterView.OnItemClickListener { private static final String TAG = SelectPlaylistFragment.class.getSimpleName(); private ListView list; @@ -92,7 +92,7 @@ public class SelectPlaylistFragment extends SubsonicTabFragment implements Adapt AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); Playlist playlist = (Playlist) list.getItemAtPosition(info.position); - SubsonicTabFragment fragment; + SubsonicFragment fragment; Bundle args; FragmentTransaction trans; switch (menuItem.getItemId()) { @@ -142,7 +142,7 @@ public class SelectPlaylistFragment extends SubsonicTabFragment implements Adapt public void onItemClick(AdapterView parent, View view, int position, long id) { Playlist playlist = (Playlist) parent.getItemAtPosition(position); - SubsonicTabFragment fragment = new SelectDirectoryFragment(); + SubsonicFragment fragment = new SelectDirectoryFragment(); Bundle args = new Bundle(); args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index e9da1827..67e05faa 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -72,6 +72,8 @@ public class SubsonicFragment extends SherlockFragment { protected SubsonicActivity context; protected CharSequence title = "DSub"; protected View rootView; + protected boolean primaryFragment = false; + protected boolean invalidated = false; @Override public void onCreate(Bundle bundle) { @@ -233,6 +235,31 @@ public class SubsonicFragment extends SherlockFragment { return true; } + + public void replaceFragment(SubsonicFragment fragment, int id) { + context.getPagerAdapter().replaceCurrent(fragment, id); + } + + public void setPrimaryFragment(boolean primary) { + primaryFragment = primary; + if(primary) { + if(context != null) { + context.setTitle(title); + } + if(invalidated) { + invalidated = false; + refresh(false); + } + } + } + + public void invalidate() { + if(primaryFragment) { + refresh(false); + } else { + invalidated = true; + } + } public DownloadService getDownloadService() { return context != null ? context.getDownloadService() : null; diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java deleted file mode 100644 index c4079816..00000000 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicTabFragment.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - This file is part of Subsonic. - - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see . - - Copyright 2009 (C) Sindre Mehus - */ -package github.daneren2005.dsub.fragments; - -import android.util.Log; -import android.view.MenuItem; - -public class SubsonicTabFragment extends SubsonicFragment { - private static final String TAG = SubsonicTabFragment.class.getSimpleName(); - protected boolean primaryFragment = false; - protected boolean invalidated = false; - - public void replaceFragment(SubsonicTabFragment fragment, int id) { - context.getPagerAdapter().replaceCurrent(fragment, id); - } - - public void setPrimaryFragment(boolean primary) { - primaryFragment = primary; - if(primary) { - if(context != null) { - context.setTitle(title); - } - if(invalidated) { - invalidated = false; - refresh(false); - } - } - } - - public void invalidate() { - if(primaryFragment) { - refresh(false); - } else { - invalidated = true; - } - } -} -- cgit v1.2.3 From 9f396015bf6cbf538871305dc8458d288b2ebd9a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 30 Apr 2013 20:55:27 -0700 Subject: Do own backStack logic for when not using tabs as well + apply to search activity --- .../daneren2005/dsub/activity/MainActivity.java | 2 +- .../daneren2005/dsub/activity/SearchActivity.java | 7 ++++ .../dsub/activity/SubsonicActivity.java | 45 ++++++++++++++++++++++ .../daneren2005/dsub/fragments/SearchFragment.java | 4 ++ .../dsub/fragments/SubsonicFragment.java | 2 +- 5 files changed, 58 insertions(+), 2 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index b5ff4abb..2504d040 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -189,7 +189,7 @@ public class MainActivity extends SubsonicActivity { @Override public void onBackPressed() { - if(pagerAdapter.onBackPressed()) { + if(onBackPressedSupport()) { if(lastBackPressTime < (System.currentTimeMillis() - 4000)) { lastBackPressTime = System.currentTimeMillis(); Util.toast(this, R.string.main_back_confirm); diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java index 53864e7d..7d2280e2 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java @@ -63,4 +63,11 @@ public class SearchActivity extends SubsonicActivity { public void onSupportNewIntent(Intent intent) { onNewIntent(intent); } + + @Override + public void onBackPressed() { + if(onBackPressedSupport()) { + super.onBackPressed(); + } + } } \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index a56cffba..8e9c147d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -39,6 +39,8 @@ public class SubsonicActivity extends SherlockFragmentActivity { private boolean destroyed = false; protected TabPagerAdapter pagerAdapter; protected ViewPager viewPager; + protected List backStack = new ArrayList(); + protected SubsonicFragment currentFragment; @Override protected void onCreate(Bundle bundle) { @@ -87,6 +89,49 @@ public class SubsonicActivity extends SherlockFragmentActivity { return super.onKeyDown(keyCode, event); } + public boolean onBackPressedSupport() { + if(pagerAdapter != null) { + return pagerAdapter.onBackPressed(); + } else { + if(backStack.size() > 0) { + if(currentFragment != null) { + currentFragment.setPrimaryFragment(false); + } + Fragment oldFrag = (Fragment)currentFragment; + + currentFragment = (SubsonicFragment) backStack.remove(backStack.size() - 1); + currentFragment.setPrimaryFragment(true); + invalidateOptionsMenu(); + + FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); + trans.remove(oldFrag); + trans.commit(); + return false; + } else { + return true; + } + } + } + + public void replaceFragment(SubsonicFragment fragment, int id) { + if(pagerAdapter != null) { + pagerAdapter.replaceCurrent(fragment, id); + } else { + if(currentFragment != null) { + currentFragment.setPrimaryFragment(false); + } + backStack.add(fragment); + + currentFragment = fragment; + currentFragment.setPrimaryFragment(true); + invalidateOptionsMenu(); + + FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); + trans.add(id, fragment); + trans.commit(); + } + } + protected void addTab(int titleRes, Class fragmentClass, Bundle args) { pagerAdapter.addTab(getString(titleRes), fragmentClass, args); } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java index ff12ac22..39bc4617 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -150,6 +150,10 @@ public class SearchFragment extends SubsonicFragment { @Override public boolean onContextItemSelected(MenuItem menuItem) { + if(!primaryFragment) { + return false; + } + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); Object selectedItem = list.getItemAtPosition(info.position); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 67e05faa..e1c8087b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -237,7 +237,7 @@ public class SubsonicFragment extends SherlockFragment { } public void replaceFragment(SubsonicFragment fragment, int id) { - context.getPagerAdapter().replaceCurrent(fragment, id); + context.replaceFragment(fragment, id); } public void setPrimaryFragment(boolean primary) { -- cgit v1.2.3 From 7dc30aa70593f6dfc612f681ff9b1f3b14d62e4a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 30 Apr 2013 21:21:58 -0700 Subject: Fix flat stack fragment option menu callbacks --- .../daneren2005/dsub/activity/MainActivity.java | 13 ----------- .../daneren2005/dsub/activity/SearchActivity.java | 26 ++++++++++++++++------ .../dsub/activity/SubsonicActivity.java | 22 +++++++++++++++++- .../daneren2005/dsub/fragments/SearchFragment.java | 2 -- 4 files changed, 40 insertions(+), 23 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 2504d040..53fb35ba 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -199,19 +199,6 @@ public class MainActivity extends SubsonicActivity { } } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - if(pagerAdapter != null) { - com.actionbarsherlock.view.MenuInflater menuInflater = getSupportMenuInflater(); - pagerAdapter.onCreateOptionsMenu(menu, menuInflater); - } - return true; - } - @Override - public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { - return pagerAdapter.onOptionsItemSelected(item); - } - private void update() { if (getDownloadService() == null) { return; diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java index 7d2280e2..ec19057c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java @@ -22,21 +22,20 @@ package github.daneren2005.dsub.activity; import github.daneren2005.dsub.R; import android.content.Intent; import android.os.Bundle; +import android.util.Log; import github.daneren2005.dsub.fragments.SearchFragment; import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.MergeAdapter; +import com.actionbarsherlock.view.MenuItem; public class SearchActivity extends SubsonicActivity { - SearchFragment fragment; - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.download_activity); if (findViewById(R.id.download_container) != null && savedInstanceState == null) { - fragment = new SearchFragment(); - getSupportFragmentManager().beginTransaction().add(R.id.download_container, fragment).commit(); + currentFragment = new SearchFragment(); + getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment).commit(); } getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -51,15 +50,28 @@ public class SearchActivity extends SubsonicActivity { boolean requestsearch = intent.getBooleanExtra(Constants.INTENT_EXTRA_REQUEST_SEARCH, false); if (query != null) { - fragment.search(query, autoplay); + ((SearchFragment)currentFragment).search(query, autoplay); } else { - fragment.populateList(); + ((SearchFragment)currentFragment).populateList(); if (requestsearch) { onSearchRequested(); } } } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if(item.getItemId() == android.R.id.home) { + Intent i = new Intent(); + i.setClass(this, MainActivity.class); + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(i); + return true; + } else { + return super.onOptionsItemSelected(item); + } + } + public void onSupportNewIntent(Intent intent) { onNewIntent(intent); } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 8e9c147d..8b48d74e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -74,6 +74,26 @@ public class SubsonicActivity extends SherlockFragmentActivity { super.finish(); Util.disablePendingTransition(this); } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + com.actionbarsherlock.view.MenuInflater menuInflater = getSupportMenuInflater(); + if(pagerAdapter != null) { + pagerAdapter.onCreateOptionsMenu(menu, menuInflater); + } else if(currentFragment != null) { + currentFragment.onCreateOptionsMenu(menu, menuInflater); + } + return true; + } + @Override + public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { + if(pagerAdapter != null) { + return pagerAdapter.onOptionsItemSelected(item); + } else if(currentFragment != null) { + return currentFragment.onOptionsItemSelected(item); + } + return true; + } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { @@ -120,7 +140,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { if(currentFragment != null) { currentFragment.setPrimaryFragment(false); } - backStack.add(fragment); + backStack.add(currentFragment); currentFragment = fragment; currentFragment.setPrimaryFragment(true); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java index 39bc4617..725f84bd 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SearchFragment.java @@ -71,8 +71,6 @@ public class SearchFragment extends SubsonicFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.search, container, false); - setHasOptionsMenu(true); - setTitle(R.string.search_title); View buttons = inflater.inflate(R.layout.search_buttons, null); -- cgit v1.2.3 From 7961a0d41fcdd6c6a6ebf35c3af518be8f37bbac Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 30 Apr 2013 21:25:29 -0700 Subject: Setup Download Activity to be able to use backStack as well --- .../github/daneren2005/dsub/activity/DownloadActivity.java | 11 +++++------ .../github/daneren2005/dsub/fragments/DownloadFragment.java | 1 - 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index 24f8181f..b78724da 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -44,7 +44,6 @@ import java.util.List; public class DownloadActivity extends SubsonicActivity { private static final String TAG = DownloadActivity.class.getSimpleName(); - private static DownloadFragment fragment; private EditText playlistNameView; /** @@ -56,8 +55,8 @@ public class DownloadActivity extends SubsonicActivity { setContentView(R.layout.download_activity); if (findViewById(R.id.download_container) != null && savedInstanceState == null) { - fragment = new DownloadFragment(); - getSupportFragmentManager().beginTransaction().add(R.id.download_container, fragment).commit(); + currentFragment = new DownloadFragment(); + getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment).commit(); } getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -73,14 +72,14 @@ public class DownloadActivity extends SubsonicActivity { startActivity(i); return true; } else { - return false; + return super.onOptionsItemSelected(item); } } @Override public boolean onTouchEvent(MotionEvent me) { - if(fragment != null) { - return fragment.getGestureDetector().onTouchEvent(me); + if(currentFragment != null) { + return ((DownloadFragment)currentFragment).getGestureDetector().onTouchEvent(me); } else { return false; } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 5093934b..7ec4d5c7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -116,7 +116,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { rootView = inflater.inflate(R.layout.download, container, false); - setHasOptionsMenu(true); setTitle(nowPlaying ? "Now Playing" : "Downloading"); WindowManager w = context.getWindowManager(); -- cgit v1.2.3 From 9b50d192a35c4d5ff14d18cdc0bc1dda4e93997d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 30 Apr 2013 21:36:42 -0700 Subject: Fix context menus on initial fragment --- .../src/github/daneren2005/dsub/activity/DownloadActivity.java | 1 + .../src/github/daneren2005/dsub/activity/SearchActivity.java | 1 + 2 files changed, 2 insertions(+) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index b78724da..f229421e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -56,6 +56,7 @@ public class DownloadActivity extends SubsonicActivity { if (findViewById(R.id.download_container) != null && savedInstanceState == null) { currentFragment = new DownloadFragment(); + currentFragment.setPrimaryFragment(true); getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment).commit(); } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java index ec19057c..c06203f7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java @@ -35,6 +35,7 @@ public class SearchActivity extends SubsonicActivity { if (findViewById(R.id.download_container) != null && savedInstanceState == null) { currentFragment = new SearchFragment(); + currentFragment.setPrimaryFragment(true); getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment).commit(); } -- cgit v1.2.3 From b59d47572ce3b7936328cc9c985355eefe24faa5 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 30 Apr 2013 21:38:28 -0700 Subject: After leaving search activity, remove it from activity stack --- .../github/daneren2005/dsub/fragments/SelectDirectoryFragment.java | 4 ++++ .../src/github/daneren2005/dsub/fragments/SubsonicFragment.java | 7 +++++++ 2 files changed, 11 insertions(+) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java index 04d4fc65..63c41546 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java @@ -25,6 +25,7 @@ import github.daneren2005.dsub.view.EntryAdapter; import java.util.List; import com.mobeta.android.dslv.*; import github.daneren2005.dsub.activity.DownloadActivity; +import github.daneren2005.dsub.activity.SearchActivity; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; @@ -478,6 +479,9 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter } if (autoplay) { Util.startActivityWithoutTransition(context, DownloadActivity.class); + if(context instanceof SearchActivity) { + context.finish(); + } } else if (save) { Util.toast(context, context.getResources().getQuantityString(R.plurals.select_album_n_songs_downloading, songs.size(), songs.size())); diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index e1c8087b..09d0e5d5 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -42,6 +42,7 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.DownloadActivity; import github.daneren2005.dsub.activity.HelpActivity; import github.daneren2005.dsub.activity.MainActivity; +import github.daneren2005.dsub.activity.SearchActivity; import github.daneren2005.dsub.activity.SettingsActivity; import github.daneren2005.dsub.activity.SubsonicActivity; import github.daneren2005.dsub.domain.Artist; @@ -195,6 +196,9 @@ public class SubsonicFragment extends SherlockFragment { getDownloadService().clear(); getDownloadService().download(songs, false, true, true, false); Util.startActivityWithoutTransition(context, DownloadActivity.class); + if(context instanceof SearchActivity) { + context.finish(); + } break; case R.id.song_menu_play_next: getDownloadService().download(songs, false, false, true, false); @@ -488,6 +492,9 @@ public class SubsonicFragment extends SherlockFragment { downloadService.download(songs, save, autoplay, false, shuffle); if(!append) { Util.startActivityWithoutTransition(context, DownloadActivity.class); + if(context instanceof SearchActivity) { + context.finish(); + } } } else { -- cgit v1.2.3 From 93d03bc7ab2b078e48baad33257606e06875f994 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 30 Apr 2013 21:44:33 -0700 Subject: Merge callbacks for artists so search fragment can use them --- .../dsub/fragments/SelectArtistFragment.java | 32 +--------------------- .../dsub/fragments/SubsonicFragment.java | 26 ++++++++++++++++++ 2 files changed, 27 insertions(+), 31 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index df49086d..95452eb6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -113,32 +113,10 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie } AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); - Artist artist = (Artist) artistList.getItemAtPosition(info.position); if (artist != null) { - switch (menuItem.getItemId()) { - case R.id.artist_menu_play_now: - downloadRecursively(artist.getId(), false, false, true, false, false); - break; - case R.id.artist_menu_play_shuffled: - downloadRecursively(artist.getId(), false, false, true, true, false); - break; - case R.id.artist_menu_play_last: - downloadRecursively(artist.getId(), false, true, false, false, false); - break; - case R.id.artist_menu_download: - downloadRecursively(artist.getId(), false, true, false, false, true); - break; - case R.id.artist_menu_pin: - downloadRecursively(artist.getId(), true, true, false, false, true); - break; - case R.id.artist_menu_delete: - deleteRecursively(artist); - break; - default: - return super.onContextItemSelected(menuItem); - } + return onContextItemSelected(menuItem, artist); } else if (info.position == 0) { MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId()); String musicFolderId = selectedFolder == null ? null : selectedFolder.getId(); @@ -217,12 +195,4 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie private void selectFolder() { folderButton.showContextMenu(); } - - public void deleteRecursively(Artist artist) { - File dir = FileUtil.getArtistDirectory(context, artist); - Util.recursiveDelete(dir); - if(Util.isOffline(context)) { - refresh(); - } - } } diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 09d0e5d5..1284a99a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -171,6 +171,24 @@ public class SubsonicFragment extends SherlockFragment { songs.add(entry); switch (menuItem.getItemId()) { + case R.id.artist_menu_play_now: + downloadRecursively(artist.getId(), false, false, true, false, false); + break; + case R.id.artist_menu_play_shuffled: + downloadRecursively(artist.getId(), false, false, true, true, false); + break; + case R.id.artist_menu_play_last: + downloadRecursively(artist.getId(), false, true, false, false, false); + break; + case R.id.artist_menu_download: + downloadRecursively(artist.getId(), false, true, false, false, true); + break; + case R.id.artist_menu_pin: + downloadRecursively(artist.getId(), true, true, false, false, true); + break; + case R.id.artist_menu_delete: + deleteRecursively(artist); + break; case R.id.album_menu_play_now: downloadRecursively(entry.getId(), false, false, true, false, false); break; @@ -688,6 +706,14 @@ public class SubsonicFragment extends SherlockFragment { return check.isCompleteFileAvailable(); } + public void deleteRecursively(Artist artist) { + File dir = FileUtil.getArtistDirectory(context, artist); + Util.recursiveDelete(dir); + if(Util.isOffline(context)) { + refresh(); + } + } + public void deleteRecursively(MusicDirectory.Entry album) { File dir = FileUtil.getAlbumDirectory(context, album); Util.recursiveDelete(dir); -- cgit v1.2.3 From 8dce8788a454eb5262865aca82701473b8511f2e Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 1 May 2013 20:43:08 -0700 Subject: Removed a bunch of unused references to SubsonicTabActivity --- .../src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 5 ----- .../src/github/daneren2005/dsub/util/ShufflePlayBuffer.java | 1 - .../github/daneren2005/dsub/util/compat/RemoteControlClientICS.java | 6 +++--- .../src/github/daneren2005/dsub/view/ArtistAdapter.java | 1 - 4 files changed, 3 insertions(+), 10 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index bdd1d4e1..1457c4da 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -62,12 +62,7 @@ import android.os.IBinder; import android.os.Looper; import android.os.PowerManager; import android.util.Log; -import github.daneren2005.dsub.activity.SubsonicTabActivity; -import github.daneren2005.dsub.util.FileUtil; import java.net.URLEncoder; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; /** * @author Sindre Mehus diff --git a/subsonic-android/src/github/daneren2005/dsub/util/ShufflePlayBuffer.java b/subsonic-android/src/github/daneren2005/dsub/util/ShufflePlayBuffer.java index 6b5d0996..3bc022ac 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/ShufflePlayBuffer.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/ShufflePlayBuffer.java @@ -27,7 +27,6 @@ import java.util.concurrent.TimeUnit; import android.content.Context; import android.content.SharedPreferences; import android.util.Log; -import github.daneren2005.dsub.activity.SubsonicTabActivity; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; diff --git a/subsonic-android/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java b/subsonic-android/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java index 52361fd4..a8fed63d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java @@ -10,7 +10,7 @@ import android.content.Intent; import android.media.AudioManager; import android.media.MediaMetadataRetriever; import android.media.RemoteControlClient; -import github.daneren2005.dsub.activity.SubsonicTabActivity; +import github.daneren2005.dsub.activity.SubsonicActivity; @TargetApi(14) public class RemoteControlClientICS extends RemoteControlClientHelper { @@ -40,7 +40,7 @@ public class RemoteControlClientICS extends RemoteControlClientHelper { RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP); - imageLoader = SubsonicTabActivity.getStaticImageLoader(context); + imageLoader = SubsonicActivity.getStaticImageLoader(context); } public void unregister(final Context context) { @@ -56,7 +56,7 @@ public class RemoteControlClientICS extends RemoteControlClientHelper { public void updateMetadata(final Context context, final MusicDirectory.Entry currentSong) { if(imageLoader == null) { - imageLoader = SubsonicTabActivity.getStaticImageLoader(context); + imageLoader = SubsonicActivity.getStaticImageLoader(context); } // Update the remote controls diff --git a/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java b/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java index 64e5f055..7e9bf218 100644 --- a/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java +++ b/subsonic-android/src/github/daneren2005/dsub/view/ArtistAdapter.java @@ -25,7 +25,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.SectionIndexer; -import github.daneren2005.dsub.activity.SubsonicTabActivity; import github.daneren2005.dsub.domain.Artist; import java.util.ArrayList; import java.util.LinkedHashSet; -- cgit v1.2.3 From db6be0ef0c9141eb6eebeb9b5ccdc00c13868c54 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 1 May 2013 22:01:30 -0700 Subject: Turn Lyrics into fragment, get rid of extra baggage --- subsonic-android/res/layout-land/download.xml | 1 + subsonic-android/res/layout-port/download.xml | 7 +- .../dsub/activity/DownloadActivity.java | 7 + .../daneren2005/dsub/activity/LyricsActivity.java | 72 --- .../dsub/activity/SubsonicTabActivity.java | 630 --------------------- .../dsub/fragments/DownloadFragment.java | 18 +- .../daneren2005/dsub/fragments/LyricsFragment.java | 80 +++ .../dsub/util/TabActivityBackgroundTask.java | 67 --- 8 files changed, 103 insertions(+), 779 deletions(-) delete mode 100644 subsonic-android/src/github/daneren2005/dsub/activity/LyricsActivity.java delete mode 100644 subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java create mode 100644 subsonic-android/src/github/daneren2005/dsub/fragments/LyricsFragment.java delete mode 100644 subsonic-android/src/github/daneren2005/dsub/util/TabActivityBackgroundTask.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout-land/download.xml b/subsonic-android/res/layout-land/download.xml index f7ea3162..21096235 100644 --- a/subsonic-android/res/layout-land/download.xml +++ b/subsonic-android/res/layout-land/download.xml @@ -1,5 +1,6 @@ diff --git a/subsonic-android/res/layout-port/download.xml b/subsonic-android/res/layout-port/download.xml index 33c94e1f..c7912266 100644 --- a/subsonic-android/res/layout-port/download.xml +++ b/subsonic-android/res/layout-port/download.xml @@ -1,8 +1,9 @@ + android:id="@+id/download_layout" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent"> . - - Copyright 2009 (C) Sindre Mehus - */ - -package github.daneren2005.dsub.activity; - -import android.os.Bundle; -import android.widget.TextView; -import github.daneren2005.dsub.R; -import github.daneren2005.dsub.domain.Lyrics; -import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; -import github.daneren2005.dsub.util.BackgroundTask; -import github.daneren2005.dsub.util.Constants; -import github.daneren2005.dsub.util.TabActivityBackgroundTask; - -/** - * Displays song lyrics. - * - * @author Sindre Mehus - */ -public final class LyricsActivity extends SubsonicTabActivity { - - @Override - protected void onCreate(Bundle bundle) { - super.onCreate(bundle); - setContentView(R.layout.lyrics); - load(); - } - - private void load() { - BackgroundTask task = new TabActivityBackgroundTask(this) { - @Override - protected Lyrics doInBackground() throws Throwable { - String artist = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ARTIST); - String title = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_TITLE); - MusicService musicService = MusicServiceFactory.getMusicService(LyricsActivity.this); - return musicService.getLyrics(artist, title, LyricsActivity.this, this); - } - - @Override - protected void done(Lyrics result) { - TextView artistView = (TextView) findViewById(R.id.lyrics_artist); - TextView titleView = (TextView) findViewById(R.id.lyrics_title); - TextView textView = (TextView) findViewById(R.id.lyrics_text); - if (result != null && result.getArtist() != null) { - artistView.setText(result.getArtist()); - titleView.setText(result.getTitle()); - textView.setText(result.getText()); - } else { - artistView.setText(R.string.lyrics_nomatch); - } - } - }; - task.execute(); - } -} \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java deleted file mode 100644 index 6bb7da6f..00000000 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicTabActivity.java +++ /dev/null @@ -1,630 +0,0 @@ -/* - This file is part of Subsonic. - - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see . - - Copyright 2009 (C) Sindre Mehus - */ -package github.daneren2005.dsub.activity; - -import java.io.File; -import java.io.PrintWriter; -import java.util.LinkedList; -import java.util.List; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.PackageInfo; -import android.media.AudioManager; -import android.media.MediaMetadataRetriever; -import android.os.Build; -import android.os.Bundle; -import android.os.Environment; -import android.util.Log; -import android.view.KeyEvent; -import android.view.View; -import android.view.Window; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.TextView; -import github.daneren2005.dsub.R; -import com.actionbarsherlock.app.SherlockActivity; -import github.daneren2005.dsub.domain.Artist; -import github.daneren2005.dsub.domain.MusicDirectory; -import github.daneren2005.dsub.domain.Playlist; -import github.daneren2005.dsub.service.*; -import github.daneren2005.dsub.updates.Updater; -import github.daneren2005.dsub.util.*; -import java.util.ArrayList; -import java.util.Arrays; - -/** - * @author Sindre Mehus - */ -public class SubsonicTabActivity extends SherlockActivity { - - private static final String TAG = SubsonicTabActivity.class.getSimpleName(); - private static ImageLoader IMAGE_LOADER; - protected static String theme; - - private boolean destroyed; - private View homeButton; - private View musicButton; - private View playlistButton; - private View nowPlayingButton; - - private static final int SHUFFLE_EVERYTHING = 0; - private static final int SHUFFLE_YEAR = 1; - private static final int SHUFFLE_YEAR_RANGE = 2; - private static final int SHUFFLE_GENRE = 3; - - @Override - protected void onCreate(Bundle bundle) { - setUncaughtExceptionHandler(); - applyTheme(); - super.onCreate(bundle); - startService(new Intent(this, DownloadServiceImpl.class)); - setVolumeControlStream(AudioManager.STREAM_MUSIC); - } - - @Override - protected void onPostCreate(Bundle bundle) { - super.onPostCreate(bundle); - - /*homeButton = findViewById(R.id.button_bar_home); - homeButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(SubsonicTabActivity.this, MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent); - } - }); - - musicButton = findViewById(R.id.button_bar_music); - musicButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(SubsonicTabActivity.this, SelectArtistActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent); - } - }); - - playlistButton = findViewById(R.id.button_bar_playlists); - playlistButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(SubsonicTabActivity.this, SelectPlaylistActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent); - } - }); - - nowPlayingButton = findViewById(R.id.button_bar_now_playing); - nowPlayingButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Util.startActivityWithoutTransition(SubsonicTabActivity.this, DownloadActivity.class); - } - }); - - /*if (this instanceof MainActivity) { - homeButton.setEnabled(false); - } else if (this instanceof SelectAlbumActivity || this instanceof SelectArtistActivity) { - musicButton.setEnabled(false); - } else if (this instanceof SelectPlaylistActivity) { - playlistButton.setEnabled(false); - } else if (this instanceof DownloadActivity || this instanceof LyricsActivity) { - nowPlayingButton.setEnabled(false); - }*/ - } - - @Override - protected void onResume() { - super.onResume(); - Util.registerMediaButtonEventReceiver(this); - - // Make sure to update theme - if (theme != null && !theme.equals(Util.getTheme(this))) { - restart(); - } - } - - @Override - protected void onDestroy() { - super.onDestroy(); - destroyed = true; - getImageLoader().clear(); - } - - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - boolean isVolumeDown = keyCode == KeyEvent.KEYCODE_VOLUME_DOWN; - boolean isVolumeUp = keyCode == KeyEvent.KEYCODE_VOLUME_UP; - boolean isVolumeAdjust = isVolumeDown || isVolumeUp; - boolean isJukebox = getDownloadService() != null && getDownloadService().isJukeboxEnabled(); - - if (isVolumeAdjust && isJukebox) { - getDownloadService().adjustJukeboxVolume(isVolumeUp); - return true; - } - return super.onKeyDown(keyCode, event); - } - - protected void restart() { - Intent intent = new Intent(this, this.getClass()); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.putExtras(getIntent()); - Util.startActivityWithoutTransition(this, intent); - } - - @Override - public void finish() { - super.finish(); - Util.disablePendingTransition(this); - } - - private void applyTheme() { - theme = Util.getTheme(this); - if ("dark".equals(theme)) { - setTheme(R.style.Theme_DSub_Dark); - } else if ("light".equals(theme)) { - setTheme(R.style.Theme_DSub_Light); - } else if ("dark_fullscreen".equals(theme)) { - setTheme(R.style.Theme_DSub_Dark_Fullscreen); - } else if ("light_fullscreen".equals(theme)) { - setTheme(R.style.Theme_DSub_Light_Fullscreen); - } else if("holo".equals(theme)) { - setTheme(R.style.Theme_DSub_Holo); - } else if("holo_fullscreen".equals(theme)) { - setTheme(R.style.Theme_DSub_Holo_Fullscreen); - }else { - setTheme(R.style.Theme_DSub_Holo); - } - } - - public boolean isDestroyed() { - return destroyed; - } - - public void toggleStarred(final MusicDirectory.Entry entry) { - final boolean starred = !entry.isStarred(); - entry.setStarred(starred); - - new SilentBackgroundTask(this) { - @Override - protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this); - musicService.setStarred(entry.getId(), starred, SubsonicTabActivity.this, null); - return null; - } - - @Override - protected void done(Void result) { - // UpdateView - Util.toast(SubsonicTabActivity.this, getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getTitle())); - } - - @Override - protected void error(Throwable error) { - entry.setStarred(!starred); - - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = getResources().getString(R.string.starring_content_error, entry.getTitle()) + " " + getErrorMessage(error); - } - - Util.toast(SubsonicTabActivity.this, msg, false); - } - }.execute(); - } - public void toggleStarred(final Artist entry) { - final boolean starred = !entry.isStarred(); - entry.setStarred(starred); - - new SilentBackgroundTask(this) { - @Override - protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this); - musicService.setStarred(entry.getId(), starred, SubsonicTabActivity.this, null); - return null; - } - - @Override - protected void done(Void result) { - // UpdateView - Util.toast(SubsonicTabActivity.this, getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getName())); - } - - @Override - protected void error(Throwable error) { - entry.setStarred(!starred); - - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = getResources().getString(R.string.starring_content_error, entry.getName()) + " " + getErrorMessage(error); - } - - Util.toast(SubsonicTabActivity.this, msg, false); - } - }.execute(); - } - - public void setProgressVisible(boolean visible) { - View view = findViewById(R.id.tab_progress); - if (view != null) { - view.setVisibility(visible ? View.VISIBLE : View.GONE); - } - } - - public void updateProgress(String message) { - TextView view = (TextView) findViewById(R.id.tab_progress_message); - if (view != null) { - view.setText(message); - } - } - - public DownloadService getDownloadService() { - // If service is not available, request it to start and wait for it. - for (int i = 0; i < 5; i++) { - DownloadService downloadService = DownloadServiceImpl.getInstance(); - if (downloadService != null) { - return downloadService; - } - Log.w(TAG, "DownloadService not running. Attempting to start it."); - startService(new Intent(this, DownloadServiceImpl.class)); - Util.sleepQuietly(50L); - } - return DownloadServiceImpl.getInstance(); - } - - protected void warnIfNetworkOrStorageUnavailable() { - if (!Util.isExternalStoragePresent()) { - Util.toast(this, R.string.select_album_no_sdcard); - } else if (!Util.isOffline(this) && !Util.isNetworkConnected(this)) { - Util.toast(this, R.string.select_album_no_network); - } - } - - protected synchronized ImageLoader getImageLoader() { - if (IMAGE_LOADER == null) { - IMAGE_LOADER = new ImageLoader(this); - } - return IMAGE_LOADER; - } - public synchronized static ImageLoader getStaticImageLoader(Context context) { - if (IMAGE_LOADER == null) { - IMAGE_LOADER = new ImageLoader(context); - } - return IMAGE_LOADER; - } - - protected void downloadRecursively(final String id, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { - downloadRecursively(id, "", true, save, append, autoplay, shuffle, background); - } - protected void downloadPlaylist(final String id, final String name, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { - downloadRecursively(id, name, false, save, append, autoplay, shuffle, background); - } - protected void downloadRecursively(final String id, final String name, final boolean isDirectory, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) { - ModalBackgroundTask> task = new ModalBackgroundTask>(this, false) { - private static final int MAX_SONGS = 500; - - @Override - protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this); - MusicDirectory root; - if(isDirectory) - root = musicService.getMusicDirectory(id, name, false, SubsonicTabActivity.this, this); - else - root = musicService.getPlaylist(id, name, SubsonicTabActivity.this, this); - List songs = new LinkedList(); - getSongsRecursively(root, songs); - return songs; - } - - private void getSongsRecursively(MusicDirectory parent, List songs) throws Exception { - if (songs.size() > MAX_SONGS) { - return; - } - - for (MusicDirectory.Entry song : parent.getChildren(false, true)) { - if (!song.isVideo()) { - songs.add(song); - } - } - for (MusicDirectory.Entry dir : parent.getChildren(true, false)) { - MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this); - getSongsRecursively(musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, SubsonicTabActivity.this, this), songs); - } - } - - @Override - protected void done(List songs) { - DownloadService downloadService = getDownloadService(); - if (!songs.isEmpty() && downloadService != null) { - if (!append) { - downloadService.clear(); - } - warnIfNetworkOrStorageUnavailable(); - if(!background) { - downloadService.download(songs, save, autoplay, false, shuffle); - if(!append) { - Util.startActivityWithoutTransition(SubsonicTabActivity.this, DownloadActivity.class); - } - } - else { - downloadService.downloadBackground(songs, save); - } - } - } - }; - - task.execute(); - } - - protected void addToPlaylist(final List songs) { - if(songs.isEmpty()) { - Util.toast(this, "No songs selected"); - return; - } - - /*new LoadingTask>(this, true) { - @Override - protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this); - return musicService.getPlaylists(false, SubsonicTabActivity.this, this); - } - - @Override - protected void done(final List playlists) { - List names = new ArrayList(); - for(Playlist playlist: playlists) { - names.add(playlist.getName()); - } - - AlertDialog.Builder builder = new AlertDialog.Builder(SubsonicTabActivity.this); - builder.setTitle("Add to Playlist") - .setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - addToPlaylist(playlists.get(which), songs); - } - }); - AlertDialog dialog = builder.create(); - dialog.show(); - } - - @Override - protected void error(Throwable error) { - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = getResources().getString(R.string.playlist_error) + " " + getErrorMessage(error); - } - - Util.toast(SubsonicTabActivity.this, msg, false); - } - }.execute();*/ - } - - private void addToPlaylist(final Playlist playlist, final List songs) { - new SilentBackgroundTask(this) { - @Override - protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this); - musicService.addToPlaylist(playlist.getId(), songs, SubsonicTabActivity.this, null); - return null; - } - - @Override - protected void done(Void result) { - Util.toast(SubsonicTabActivity.this, getResources().getString(R.string.updated_playlist, songs.size(), playlist.getName())); - } - - @Override - protected void error(Throwable error) { - String msg; - if (error instanceof OfflineException || error instanceof ServerTooOldException) { - msg = getErrorMessage(error); - } else { - msg = getResources().getString(R.string.updated_playlist_error, playlist.getName()) + " " + getErrorMessage(error); - } - - Util.toast(SubsonicTabActivity.this, msg, false); - } - }.execute(); - } - - protected void onShuffleRequested() { - if(Util.isOffline(this)) { - Intent intent = new Intent(SubsonicTabActivity.this, DownloadActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); - Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent); - return; - } - - View dialogView = getLayoutInflater().inflate(R.layout.shuffle_dialog, null); - final EditText startYearBox = (EditText)dialogView.findViewById(R.id.start_year); - final EditText endYearBox = (EditText)dialogView.findViewById(R.id.end_year); - final EditText genreBox = (EditText)dialogView.findViewById(R.id.genre); - - final SharedPreferences prefs = Util.getPreferences(SubsonicTabActivity.this); - final String oldStartYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, ""); - final String oldEndYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, ""); - final String oldGenre = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, ""); - - startYearBox.setText(oldStartYear); - endYearBox.setText(oldEndYear); - genreBox.setText(oldGenre); - - AlertDialog.Builder builder = new AlertDialog.Builder(SubsonicTabActivity.this); - builder.setTitle("Shuffle By") - .setView(dialogView) - .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - Intent intent = new Intent(SubsonicTabActivity.this, DownloadActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true); - String genre = genreBox.getText().toString(); - String startYear = startYearBox.getText().toString(); - String endYear = endYearBox.getText().toString(); - - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYear); - editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYear); - editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre); - editor.commit(); - - Util.startActivityWithoutTransition(SubsonicTabActivity.this, intent); - } - }) - .setNegativeButton(R.string.common_cancel, null); - AlertDialog dialog = builder.create(); - dialog.show(); - } - - public void displaySongInfo(final MusicDirectory.Entry song) { - Integer bitrate = null; - String format = null; - long size = 0; - try { - DownloadFile downloadFile = new DownloadFile(SubsonicTabActivity.this, song, false); - File file = downloadFile.getCompleteFile(); - if(file.exists()) { - MediaMetadataRetriever metadata = new MediaMetadataRetriever(); - metadata.setDataSource(file.getAbsolutePath()); - String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE); - bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000; - format = FileUtil.getExtension(file.getName()); - size = file.length(); - - if(Util.isOffline(SubsonicTabActivity.this)) { - song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)); - String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR); - song.setYear(Integer.parseInt((year != null) ? year : "0")); - } - } - } catch(Exception e) { - Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver"); - } - - String msg = ""; - if(!song.isVideo()) { - msg += "Artist: " + song.getArtist() + "\nAlbum: " + song.getAlbum(); - } - if(song.getTrack() != null && song.getTrack() != 0) { - msg += "\nTrack: " + song.getTrack(); - } - if(song.getGenre() != null && !"".equals(song.getGenre())) { - msg += "\nGenre: " + song.getGenre(); - } - if(song.getYear() != null && song.getYear() != 0) { - msg += "\nYear: " + song.getYear(); - } - if(!Util.isOffline(SubsonicTabActivity.this)) { - msg += "\nServer Format: " + song.getSuffix(); - if(song.getBitRate() != null && song.getBitRate() != 0) { - msg += "\nServer Bitrate: " + song.getBitRate() + " kpbs"; - } - } - if(format != null && !"".equals(format)) { - msg += "\nCached Format: " + format; - } - if(bitrate != null && bitrate != 0) { - msg += "\nCached Bitrate: " + bitrate + " kpbs"; - } - if(size != 0) { - msg += "\nSize: " + Util.formatBytes(size); - } - if(song.getDuration() != null && song.getDuration() != 0) { - msg += "\nLength: " + Util.formatDuration(song.getDuration()); - } - - new AlertDialog.Builder(this) - .setIcon(android.R.drawable.ic_dialog_alert) - .setTitle(song.getTitle()) - .setMessage(msg) - .show(); - } - - public void checkUpdates() { - try { - String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; - int ver = Integer.parseInt(version.replace(".", "")); - Updater updater = new Updater(ver); - updater.checkUpdates(SubsonicTabActivity.this); - } - catch(Exception e) { - - } - } - - private void setUncaughtExceptionHandler() { - Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); - if (!(handler instanceof SubsonicUncaughtExceptionHandler)) { - Thread.setDefaultUncaughtExceptionHandler(new SubsonicUncaughtExceptionHandler(this)); - } - } - - /** - * Logs the stack trace of uncaught exceptions to a file on the SD card. - */ - private static class SubsonicUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { - - private final Thread.UncaughtExceptionHandler defaultHandler; - private final Context context; - - private SubsonicUncaughtExceptionHandler(Context context) { - this.context = context; - defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); - } - - @Override - public void uncaughtException(Thread thread, Throwable throwable) { - File file = null; - PrintWriter printWriter = null; - try { - - PackageInfo packageInfo = context.getPackageManager().getPackageInfo("github.daneren2005.dsub", 0); - file = new File(Environment.getExternalStorageDirectory(), "subsonic-stacktrace.txt"); - printWriter = new PrintWriter(file); - printWriter.println("Android API level: " + Build.VERSION.SDK); - printWriter.println("Subsonic version name: " + packageInfo.versionName); - printWriter.println("Subsonic version code: " + packageInfo.versionCode); - printWriter.println(); - throwable.printStackTrace(printWriter); - Log.i(TAG, "Stack trace written to " + file); - } catch (Throwable x) { - Log.e(TAG, "Failed to write stack trace to " + file, x); - } finally { - Util.close(printWriter); - if (defaultHandler != null) { - defaultHandler.uncaughtException(thread, throwable); - } - - } - } - } -} - diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 7ec4d5c7..c507aa1c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -60,9 +60,7 @@ import java.util.ArrayList; import java.util.concurrent.ScheduledFuture; import com.mobeta.android.dslv.*; import github.daneren2005.dsub.activity.EqualizerActivity; -import github.daneren2005.dsub.activity.LyricsActivity; import github.daneren2005.dsub.activity.SubsonicActivity; -import github.daneren2005.dsub.service.DownloadServiceImpl; public class DownloadFragment extends SubsonicFragment implements OnGestureListener { private static final String TAG = DownloadFragment.class.getSimpleName(); @@ -504,13 +502,16 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe @Override public boolean onContextItemSelected(android.view.MenuItem menuItem) { + if(!primaryFragment) { + return false; + } + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); DownloadFile downloadFile = (DownloadFile) playlistView.getItemAtPosition(info.position); return menuItemSelected(menuItem.getItemId(), downloadFile) || super.onContextItemSelected(menuItem); } private boolean menuItemSelected(int menuItemId, final DownloadFile song) { - Intent intent; switch (menuItemId) { case R.id.menu_show_album: /*Intent intent = new Intent(context, SelectAlbumActivity.class); @@ -519,10 +520,13 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe Util.startActivityWithoutTransition(context, intent);*/ return true; case R.id.menu_lyrics: - intent = new Intent(context, LyricsActivity.class); - intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, song.getSong().getArtist()); - intent.putExtra(Constants.INTENT_EXTRA_NAME_TITLE, song.getSong().getTitle()); - Util.startActivityWithoutTransition(context, intent); + SubsonicFragment fragment = new LyricsFragment(); + Bundle args = new Bundle(); + args.putString(Constants.INTENT_EXTRA_NAME_ARTIST, song.getSong().getArtist()); + args.putString(Constants.INTENT_EXTRA_NAME_TITLE, song.getSong().getTitle()); + fragment.setArguments(args); + + replaceFragment(fragment, R.id.download_layout); return true; case R.id.menu_remove: new SilentBackgroundTask(context) { diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/LyricsFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/LyricsFragment.java new file mode 100644 index 00000000..3f6a4146 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/LyricsFragment.java @@ -0,0 +1,80 @@ +/* + This file is part of Subsonic. + + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + + Copyright 2009 (C) Sindre Mehus + */ + +package github.daneren2005.dsub.fragments; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import github.daneren2005.dsub.R; +import github.daneren2005.dsub.domain.Lyrics; +import github.daneren2005.dsub.service.MusicService; +import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.util.BackgroundTask; +import github.daneren2005.dsub.util.Constants; +import github.daneren2005.dsub.util.TabBackgroundTask; + +/** + * Displays song lyrics. + * + * @author Sindre Mehus + */ +public final class LyricsFragment extends SubsonicFragment { + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { + rootView = inflater.inflate(R.layout.lyrics, container, false); + load(); + + return rootView; + } + + private void load() { + BackgroundTask task = new TabBackgroundTask(this) { + @Override + protected Lyrics doInBackground() throws Throwable { + String artist = getArguments().getString(Constants.INTENT_EXTRA_NAME_ARTIST); + String title = getArguments().getString(Constants.INTENT_EXTRA_NAME_TITLE); + MusicService musicService = MusicServiceFactory.getMusicService(context); + return musicService.getLyrics(artist, title, context, this); + } + + @Override + protected void done(Lyrics result) { + TextView artistView = (TextView) rootView.findViewById(R.id.lyrics_artist); + TextView titleView = (TextView) rootView.findViewById(R.id.lyrics_title); + TextView textView = (TextView) rootView.findViewById(R.id.lyrics_text); + if (result != null && result.getArtist() != null) { + artistView.setText(result.getArtist()); + titleView.setText(result.getTitle()); + textView.setText(result.getText()); + } else { + artistView.setText(R.string.lyrics_nomatch); + } + } + }; + task.execute(); + } +} \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/util/TabActivityBackgroundTask.java b/subsonic-android/src/github/daneren2005/dsub/util/TabActivityBackgroundTask.java deleted file mode 100644 index f5cf94b9..00000000 --- a/subsonic-android/src/github/daneren2005/dsub/util/TabActivityBackgroundTask.java +++ /dev/null @@ -1,67 +0,0 @@ -package github.daneren2005.dsub.util; - -import github.daneren2005.dsub.activity.SubsonicTabActivity; - -/** - * @author Sindre Mehus - * @version $Id$ - */ -public abstract class TabActivityBackgroundTask extends BackgroundTask { - - private final SubsonicTabActivity tabActivity; - - public TabActivityBackgroundTask(SubsonicTabActivity activity) { - super(activity); - tabActivity = activity; - } - - @Override - public void execute() { - tabActivity.setProgressVisible(true); - - new Thread() { - @Override - public void run() { - try { - final T result = doInBackground(); - if (isCancelled()) { - return; - } - - getHandler().post(new Runnable() { - @Override - public void run() { - tabActivity.setProgressVisible(false); - done(result); - } - }); - } catch (final Throwable t) { - if (isCancelled()) { - return; - } - getHandler().post(new Runnable() { - @Override - public void run() { - tabActivity.setProgressVisible(false); - error(t); - } - }); - } - } - }.start(); - } - - private boolean isCancelled() { - return tabActivity.isDestroyed(); - } - - @Override - public void updateProgress(final String message) { - getHandler().post(new Runnable() { - @Override - public void run() { - tabActivity.updateProgress(message); - } - }); - } -} -- cgit v1.2.3 From a5a195f12dc018020679f1514481a46a344463f0 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 4 May 2013 20:31:57 -0700 Subject: Fix folder picker showing in offline mode --- subsonic-android/res/layout/select_artist.xml | 1 + .../daneren2005/dsub/fragments/SelectArtistFragment.java | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout/select_artist.xml b/subsonic-android/res/layout/select_artist.xml index fef51d3c..b1e64e17 100644 --- a/subsonic-android/res/layout/select_artist.xml +++ b/subsonic-android/res/layout/select_artist.xml @@ -10,6 +10,7 @@ android:layout_height="1px" android:background="@color/dividerColor"/> + task = new TabBackgroundTask(this) { -- cgit v1.2.3 From f704656fdb6ac7c29d96f5d1f8ddde1ceeb2944f Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 4 May 2013 20:36:03 -0700 Subject: Fix artist list being blank when starting offline --- .../src/github/daneren2005/dsub/fragments/SelectArtistFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index bf4b80f8..35daaa83 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -186,8 +186,8 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie } } } - artistList.setVisibility(View.VISIBLE); } + artistList.setVisibility(View.VISIBLE); } }; task.execute(); -- cgit v1.2.3 From 25ca86a5e390a14e3040e53f745f5ae4d1f7b70b Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 4 May 2013 21:39:44 -0700 Subject: Added orientation support for simple back stack --- .../dsub/activity/DownloadActivity.java | 1 + .../daneren2005/dsub/activity/MainActivity.java | 5 --- .../daneren2005/dsub/activity/SearchActivity.java | 1 + .../dsub/activity/SubsonicActivity.java | 36 ++++++++++++++++++++++ .../github/daneren2005/dsub/util/Constants.java | 3 ++ 5 files changed, 41 insertions(+), 5 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java index 0cba202a..9141ae01 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -57,6 +57,7 @@ public class DownloadActivity extends SubsonicActivity { if (findViewById(R.id.download_container) != null && savedInstanceState == null) { currentFragment = new DownloadFragment(); currentFragment.setPrimaryFragment(true); + currentFragmentId = R.id.download_container; getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment).commit(); } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 53fb35ba..c41050b6 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -144,11 +144,6 @@ public class MainActivity extends SubsonicActivity { addTab("Playlists", SelectPlaylistFragment.class, null); } - @Override - public void onSaveInstanceState(Bundle savedInstanceState) { - - } - @Override protected void onPostCreate(Bundle bundle) { super.onPostCreate(bundle); diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java index c06203f7..6877fd2a 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SearchActivity.java @@ -36,6 +36,7 @@ public class SearchActivity extends SubsonicActivity { if (findViewById(R.id.download_container) != null && savedInstanceState == null) { currentFragment = new SearchFragment(); currentFragment.setPrimaryFragment(true); + currentFragmentId = R.id.download_container; getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment).commit(); } diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 8b48d74e..0d004771 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -8,6 +8,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; @@ -25,6 +26,7 @@ import github.daneren2005.dsub.fragments.SubsonicFragment; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.updates.Updater; +import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ImageLoader; import github.daneren2005.dsub.util.Util; import java.io.File; @@ -40,7 +42,9 @@ public class SubsonicActivity extends SherlockFragmentActivity { protected TabPagerAdapter pagerAdapter; protected ViewPager viewPager; protected List backStack = new ArrayList(); + protected List backStackId = new ArrayList(); protected SubsonicFragment currentFragment; + protected int currentFragmentId; @Override protected void onCreate(Bundle bundle) { @@ -75,6 +79,35 @@ public class SubsonicActivity extends SherlockFragmentActivity { Util.disablePendingTransition(this); } + @Override + public void onSaveInstanceState(Bundle savedInstanceState) { + if(viewPager == null) { + super.onSaveInstanceState(savedInstanceState); + int[] ids = new int[backStackId.size() + 1]; + ids[0] = currentFragmentId; + int i = 1; + for(Integer id: backStackId) { + ids[i] = id; + i++; + } + savedInstanceState.putIntArray(Constants.MAIN_BACK_STACK, ids); + savedInstanceState.putInt(Constants.MAIN_BACK_STACK_SIZE, backStackId.size() + 1); + } + } + @Override + public void onRestoreInstanceState(Bundle savedInstanceState) { + if(viewPager == null) { + super.onRestoreInstanceState(savedInstanceState); + + int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE); + int[] ids = savedInstanceState.getIntArray(Constants.MAIN_BACK_STACK); + FragmentManager fm = getSupportFragmentManager(); + currentFragment = (SubsonicFragment)fm.findFragmentById(ids[0]); + currentFragmentId = ids[0]; + currentFragment.setPrimaryFragment(true); + } + } + @Override public boolean onCreateOptionsMenu(Menu menu) { com.actionbarsherlock.view.MenuInflater menuInflater = getSupportMenuInflater(); @@ -120,6 +153,7 @@ public class SubsonicActivity extends SherlockFragmentActivity { Fragment oldFrag = (Fragment)currentFragment; currentFragment = (SubsonicFragment) backStack.remove(backStack.size() - 1); + backStackId.remove(backStackId.size() - 1); currentFragment.setPrimaryFragment(true); invalidateOptionsMenu(); @@ -141,9 +175,11 @@ public class SubsonicActivity extends SherlockFragmentActivity { currentFragment.setPrimaryFragment(false); } backStack.add(currentFragment); + backStackId.add(currentFragmentId); currentFragment = fragment; currentFragment.setPrimaryFragment(true); + currentFragmentId = id; invalidateOptionsMenu(); FragmentTransaction trans = getSupportFragmentManager().beginTransaction(); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java index a35573a6..57d305a7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java @@ -92,6 +92,9 @@ public final class Constants { public static final String PREFERENCES_EQUALIZER_SETTINGS = "equalizerSettings"; public static final String PREFERENCES_KEY_PERSISTENT_NOTIFICATION = "persistentNotification"; public static final String PREFERENCES_KEY_GAPLESS_PLAYBACK = "gaplessPlayback"; + + public static final String MAIN_BACK_STACK = "backStackIds"; + public static final String MAIN_BACK_STACK_SIZE = "backStackIdsSize"; // Name of the preferences file. public static final String PREFERENCES_FILE_NAME = "github.daneren2005.dsub_preferences"; -- cgit v1.2.3 From a661acca1c84bb4b7158999fd0b51e7ef22757ca Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 4 May 2013 21:43:09 -0700 Subject: Fix the rest of the back stack on orientation change --- .../src/github/daneren2005/dsub/activity/SubsonicActivity.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 0d004771..9881a8c7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -105,6 +105,10 @@ public class SubsonicActivity extends SherlockFragmentActivity { currentFragment = (SubsonicFragment)fm.findFragmentById(ids[0]); currentFragmentId = ids[0]; currentFragment.setPrimaryFragment(true); + for(int i = 1; i < size; i++) { + backStack.add((SubsonicFragment)fm.findFragmentById(ids[i])); + backStackId.add(ids[i]); + } } } -- cgit v1.2.3 From 746cd4ea17b4a2e060a058beccc12965a6f1b27c Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 5 May 2013 07:22:51 -0700 Subject: Just finish activity on double back instead of expecting back press to do it --- subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index c41050b6..32ddaad8 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -189,7 +189,7 @@ public class MainActivity extends SubsonicActivity { lastBackPressTime = System.currentTimeMillis(); Util.toast(this, R.string.main_back_confirm); } else { - super.onBackPressed(); + finish(); } } } -- cgit v1.2.3 From 7d44c64368d9fb016db622a3817b3ecf0ebd5fa2 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 5 May 2013 13:55:55 -0700 Subject: Fix controls showing through on DownloadFragment -> LyricsFragment --- .../daneren2005/dsub/fragments/DownloadFragment.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java index c507aa1c..52359782 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -44,8 +44,6 @@ import github.daneren2005.dsub.domain.PlayerState; import github.daneren2005.dsub.domain.RepeatMode; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.DownloadService; -import github.daneren2005.dsub.service.MusicService; -import github.daneren2005.dsub.service.MusicServiceFactory; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.HorizontalSlider; import github.daneren2005.dsub.util.SilentBackgroundTask; @@ -526,7 +524,7 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe args.putString(Constants.INTENT_EXTRA_NAME_TITLE, song.getSong().getTitle()); fragment.setArguments(args); - replaceFragment(fragment, R.id.download_layout); + replaceFragment(fragment, R.id.download_container); return true; case R.id.menu_remove: new SilentBackgroundTask(context) { @@ -674,6 +672,18 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe visualizerView.setActive(false); } } + + @Override + public void setPrimaryFragment(boolean primary) { + super.setPrimaryFragment(primary); + if(rootView != null) { + if(primary) { + rootView.setVisibility(View.VISIBLE); + } else { + rootView.setVisibility(View.GONE); + } + } + } private void scheduleHideControls() { if (hideControlsFuture != null) { -- cgit v1.2.3 From 9a556cde9e3c430245d32422f3e797b742ed1574 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 5 May 2013 15:12:25 -0700 Subject: Always make sure main activity is on back stack when entering app --- .../src/github/daneren2005/dsub/activity/MainActivity.java | 6 +++++- subsonic-android/src/github/daneren2005/dsub/util/Constants.java | 1 + subsonic-android/src/github/daneren2005/dsub/util/Util.java | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java index 32ddaad8..e3d6d46c 100644 --- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java @@ -46,7 +46,11 @@ public class MainActivity extends SubsonicActivity { if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) { stopService(new Intent(this, DownloadServiceImpl.class)); finish(); - } + } else if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD)) { + Intent intent = new Intent(); + intent.setClass(this, DownloadActivity.class); + startActivity(intent); + } setContentView(R.layout.main); View bottomBar = findViewById(R.id.bottom_bar); diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java index 57d305a7..878324b7 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Constants.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Constants.java @@ -50,6 +50,7 @@ public final class Constants { public static final String INTENT_EXTRA_NAME_REFRESH = "subsonic.refresh"; public static final String INTENT_EXTRA_REQUEST_SEARCH = "subsonic.requestsearch"; public static final String INTENT_EXTRA_NAME_EXIT = "subsonic.exit" ; + public static final String INTENT_EXTRA_NAME_DOWNLOAD = "subsonic.download"; // Notification IDs. public static final int NOTIFICATION_ID_PLAYING = 100; diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index 8fc03879..5ace632b 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -52,7 +52,7 @@ import android.widget.RemoteViews; import android.widget.TextView; import android.widget.Toast; import github.daneren2005.dsub.R; -import github.daneren2005.dsub.activity.DownloadActivity; +import github.daneren2005.dsub.activity.MainActivity; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.PlayerState; import github.daneren2005.dsub.domain.RepeatMode; @@ -659,7 +659,9 @@ public final class Util { setupViews(smallContentView, context, song, playing); notification.contentView = smallContentView; - Intent notificationIntent = new Intent(context, DownloadActivity.class); + Intent notificationIntent = new Intent(context, MainActivity.class); + notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true); + notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); handler.post(new Runnable() { -- cgit v1.2.3 From ccbf4a2bb324b7f354ba39519e6a7bdad8d56024 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 5 May 2013 15:44:19 -0700 Subject: Make widget intent names a little more unique --- .../src/github/daneren2005/dsub/provider/DSubWidgetProvider.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java index c6861f0a..ef0ab956 100644 --- a/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java +++ b/subsonic-android/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java @@ -43,6 +43,7 @@ import github.daneren2005.dsub.activity.MainActivity; import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; +import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.FileUtil; /** @@ -217,19 +218,19 @@ public class DSubWidgetProvider extends AppWidgetProvider { views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent); // Emulate media button clicks. - intent = new Intent("1"); + intent = new Intent("DSub.PLAY_PAUSE"); intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_play, pendingIntent); - intent = new Intent("2"); // Use a unique action name to ensure a different PendingIntent to be created. + intent = new Intent("DSub.NEXT"); // Use a unique action name to ensure a different PendingIntent to be created. intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.control_next, pendingIntent); - intent = new Intent("3"); // Use a unique action name to ensure a different PendingIntent to be created. + intent = new Intent("DSub.PREVIOUS"); // Use a unique action name to ensure a different PendingIntent to be created. intent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS)); pendingIntent = PendingIntent.getService(context, 0, intent, 0); -- cgit v1.2.3 From 18b801bb82c448d73ab6402e8ccce92b77ff652a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 5 May 2013 15:51:44 -0700 Subject: Better method of handling artist folder button in header --- subsonic-android/res/layout/select_artist.xml | 1 - .../res/layout/select_artist_header.xml | 65 ++++++++++++---------- .../dsub/fragments/SelectArtistFragment.java | 4 +- 3 files changed, 38 insertions(+), 32 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout/select_artist.xml b/subsonic-android/res/layout/select_artist.xml index b1e64e17..fef51d3c 100644 --- a/subsonic-android/res/layout/select_artist.xml +++ b/subsonic-android/res/layout/select_artist.xml @@ -10,7 +10,6 @@ android:layout_height="1px" android:background="@color/dividerColor"/> - + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="wrap_content"> + - + - + - + - + - + + \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java index 35daaa83..1ed5bb43 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SelectArtistFragment.java @@ -51,8 +51,10 @@ public class SelectArtistFragment extends SubsonicFragment implements AdapterVie artistList = (ListView) rootView.findViewById(R.id.select_artist_list); artistList.setOnItemClickListener(this); - folderButton = rootView.findViewById(R.id.select_artist_folder); + folderButton = inflater.inflate(R.layout.select_artist_header, artistList, false); folderName = (TextView) folderButton.findViewById(R.id.select_artist_folder_2); + artistList.addHeaderView(folderButton); + folderButton = folderButton.findViewById(R.id.select_artist_folder); registerForContextMenu(artistList); invalidated = true; -- cgit v1.2.3 From ce8f467cebc86240422ae8bb555f008e6f237bfa Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 7 May 2013 22:12:56 -0700 Subject: Fix orientation change for download fragment and showing controls at the same time --- subsonic-android/res/layout-land/download.xml | 248 +++++++++---------- subsonic-android/res/layout-port/download.xml | 267 +++++++++++---------- .../dsub/fragments/DownloadFragment.java | 12 +- 3 files changed, 272 insertions(+), 255 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/res/layout-land/download.xml b/subsonic-android/res/layout-land/download.xml index 21096235..a125d77e 100644 --- a/subsonic-android/res/layout-land/download.xml +++ b/subsonic-android/res/layout-land/download.xml @@ -1,128 +1,134 @@ - + - - - + + - + + + + + + + + - - - - - - - - - - -