aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-03-09 09:47:10 -0800
committerScott Jackson <daneren2005@gmail.com>2013-03-09 09:47:10 -0800
commit5169f1181a45c0cefbb812c8a68f7e492dcef45f (patch)
treed677e1c3bf2af669b39d0f24154dab952667be08 /subsonic-android
parentaceed12eba9a311860f9774b6c3a655042251913 (diff)
downloaddsub-5169f1181a45c0cefbb812c8a68f7e492dcef45f.tar.gz
dsub-5169f1181a45c0cefbb812c8a68f7e492dcef45f.tar.bz2
dsub-5169f1181a45c0cefbb812c8a68f7e492dcef45f.zip
Switch MusicActivity to MainActivity
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/AndroidManifest.xml2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java416
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/MusicActivity.java110
3 files changed, 85 insertions, 443 deletions
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 @@
<application android:label="@string/common.appname" android:icon="@drawable/launch2" android:theme="@style/Theme.DSub.Holo">
- <activity android:name="github.daneren2005.dsub.activity.MusicActivity"
+ <activity android:name="github.daneren2005.dsub.activity.MainActivity"
android:label="DSub"
android:configChanges="orientation|keyboardHidden"
android:launchMode="standard">
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 <http://www.gnu.org/licenses/>.
-
- 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<File>(this, false) {
- @Override
- protected File doInBackground() throws Throwable {
- updateProgress("Gathering Logs");
- File logcat = new File(FileUtil.getSubsonicDirectory(), "logcat.txt");
- Process logcatProc = null;
- try {
- List<String> progs = new ArrayList<String>();
- 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];
- }
- }
-}