mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-11 00:40:00 +00:00
Added "up" navigation to musikdroid.
This commit is contained in:
parent
3aab13b7fb
commit
c433073abe
@ -17,7 +17,6 @@ import org.json.JSONObject;
|
|||||||
import static io.casey.musikcube.remote.Messages.Key;
|
import static io.casey.musikcube.remote.Messages.Key;
|
||||||
|
|
||||||
public class AlbumBrowseActivity extends WebSocketActivityBase implements Filterable {
|
public class AlbumBrowseActivity extends WebSocketActivityBase implements Filterable {
|
||||||
public static final String EXTRA_TITLE = "extra_title";
|
|
||||||
private static final String EXTRA_CATEGORY_NAME = "extra_category_name";
|
private static final String EXTRA_CATEGORY_NAME = "extra_category_name";
|
||||||
private static final String EXTRA_CATEGORY_ID = "extra_category_id";
|
private static final String EXTRA_CATEGORY_ID = "extra_category_id";
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ public class AlbumBrowseActivity extends WebSocketActivityBase implements Filter
|
|||||||
|
|
||||||
if (Strings.notEmpty(categoryValue)) {
|
if (Strings.notEmpty(categoryValue)) {
|
||||||
intent.putExtra(
|
intent.putExtra(
|
||||||
AlbumBrowseActivity.EXTRA_TITLE,
|
Views.EXTRA_TITLE,
|
||||||
context.getString(R.string.albums_by_title, categoryValue));
|
context.getString(R.string.albums_by_title, categoryValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,12 +70,9 @@ public class AlbumBrowseActivity extends WebSocketActivityBase implements Filter
|
|||||||
this.categoryId = getIntent().getLongExtra(EXTRA_CATEGORY_ID, categoryId);
|
this.categoryId = getIntent().getLongExtra(EXTRA_CATEGORY_ID, categoryId);
|
||||||
|
|
||||||
setContentView(R.layout.recycler_view_activity);
|
setContentView(R.layout.recycler_view_activity);
|
||||||
setTitle(R.string.albums_title);
|
|
||||||
|
|
||||||
final String title = getIntent().getStringExtra(EXTRA_TITLE);
|
Views.setTitle(this, R.string.albums_title);
|
||||||
if (Strings.notEmpty(title)) {
|
Views.enableUpNavigation(this);
|
||||||
setTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.wss = getWebSocketService();
|
this.wss = getWebSocketService();
|
||||||
this.adapter = new Adapter();
|
this.adapter = new Adapter();
|
||||||
|
@ -70,6 +70,8 @@ public class CategoryBrowseActivity extends WebSocketActivityBase implements Fil
|
|||||||
|
|
||||||
setContentView(R.layout.recycler_view_activity);
|
setContentView(R.layout.recycler_view_activity);
|
||||||
|
|
||||||
|
Views.enableUpNavigation(this);
|
||||||
|
|
||||||
if (CATEGORY_NAME_TO_TITLE.containsKey(category)) {
|
if (CATEGORY_NAME_TO_TITLE.containsKey(category)) {
|
||||||
setTitle(CATEGORY_NAME_TO_TITLE.get(category));
|
setTitle(CATEGORY_NAME_TO_TITLE.get(category));
|
||||||
}
|
}
|
||||||
@ -87,6 +89,7 @@ public class CategoryBrowseActivity extends WebSocketActivityBase implements Fil
|
|||||||
if (!Messages.Category.PLAYLISTS.equals(category)) { /* bleh */
|
if (!Messages.Category.PLAYLISTS.equals(category)) { /* bleh */
|
||||||
Views.initSearchMenu(this, menu, this);
|
Views.initSearchMenu(this, menu, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +104,14 @@ public class MainActivity extends WebSocketActivityBase {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
|
boolean connected = wss.getState() == WebSocketService.State.Connected;
|
||||||
|
menu.findItem(R.id.action_playlists).setEnabled(connected);
|
||||||
|
menu.findItem(R.id.action_genres).setEnabled(connected);
|
||||||
|
return super.onPrepareOptionsMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
@ -32,7 +32,9 @@ public class PlayQueueActivity extends WebSocketActivityBase {
|
|||||||
this.wss = getWebSocketService();
|
this.wss = getWebSocketService();
|
||||||
|
|
||||||
setContentView(R.layout.recycler_view_activity);
|
setContentView(R.layout.recycler_view_activity);
|
||||||
setTitle(R.string.play_queue_title);
|
|
||||||
|
Views.setTitle(this, R.string.play_queue_title);
|
||||||
|
Views.enableUpNavigation(this);
|
||||||
|
|
||||||
this.adapter = new Adapter();
|
this.adapter = new Adapter();
|
||||||
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||||
@ -46,6 +48,7 @@ public class PlayQueueActivity extends WebSocketActivityBase {
|
|||||||
getIntent().getIntExtra(EXTRA_PLAYING_INDEX, -1));
|
getIntent().getIntExtra(EXTRA_PLAYING_INDEX, -1));
|
||||||
|
|
||||||
Views.addTransportFragment(this);
|
Views.addTransportFragment(this);
|
||||||
|
Views.enableUpNavigation(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,6 +6,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@ -31,10 +32,21 @@ public class SettingsActivity extends AppCompatActivity {
|
|||||||
rebindUi();
|
rebindUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.getItemId() == android.R.id.home) {
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
private void rebindUi() {
|
private void rebindUi() {
|
||||||
Views.setTextAndMoveCursorToEnd(this.addressText, prefs.getString("address", "192.168.1.100"));
|
Views.setTextAndMoveCursorToEnd(this.addressText, prefs.getString("address", "192.168.1.100"));
|
||||||
Views.setTextAndMoveCursorToEnd(this.portText, String.format(Locale.ENGLISH, "%d", prefs.getInt("port", 7905)));
|
Views.setTextAndMoveCursorToEnd(this.portText, String.format(Locale.ENGLISH, "%d", prefs.getInt("port", 7905)));
|
||||||
Views.setTextAndMoveCursorToEnd(this.passwordText, prefs.getString("password", ""));
|
Views.setTextAndMoveCursorToEnd(this.passwordText, prefs.getString("password", ""));
|
||||||
|
Views.enableUpNavigation(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindEventListeners() {
|
private void bindEventListeners() {
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -16,7 +17,6 @@ import org.json.JSONObject;
|
|||||||
import static io.casey.musikcube.remote.TrackListScrollCache.QueryFactory;
|
import static io.casey.musikcube.remote.TrackListScrollCache.QueryFactory;
|
||||||
|
|
||||||
public class TrackListActivity extends WebSocketActivityBase implements Filterable {
|
public class TrackListActivity extends WebSocketActivityBase implements Filterable {
|
||||||
public static String EXTRA_TITLE = "extra_title";
|
|
||||||
private static String EXTRA_CATEGORY_TYPE = "extra_category_type";
|
private static String EXTRA_CATEGORY_TYPE = "extra_category_type";
|
||||||
private static String EXTRA_SELECTED_ID = "extra_selected_id";
|
private static String EXTRA_SELECTED_ID = "extra_selected_id";
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public class TrackListActivity extends WebSocketActivityBase implements Filterab
|
|||||||
|
|
||||||
if (Strings.notEmpty(categoryValue)) {
|
if (Strings.notEmpty(categoryValue)) {
|
||||||
intent.putExtra(
|
intent.putExtra(
|
||||||
TrackListActivity.EXTRA_TITLE,
|
Views.EXTRA_TITLE,
|
||||||
context.getString(R.string.songs_from_category, categoryValue));
|
context.getString(R.string.songs_from_category, categoryValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,12 +59,9 @@ public class TrackListActivity extends WebSocketActivityBase implements Filterab
|
|||||||
categoryId = getIntent().getLongExtra(EXTRA_SELECTED_ID, 0);
|
categoryId = getIntent().getLongExtra(EXTRA_SELECTED_ID, 0);
|
||||||
|
|
||||||
setContentView(R.layout.recycler_view_activity);
|
setContentView(R.layout.recycler_view_activity);
|
||||||
setTitle(R.string.songs_title);
|
|
||||||
|
|
||||||
final String title = getIntent().getStringExtra(EXTRA_TITLE);
|
Views.setTitle(this, R.string.songs_title);
|
||||||
if (Strings.notEmpty(title)) {
|
Views.enableUpNavigation(this);
|
||||||
setTitle(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
final QueryFactory queryFactory =
|
final QueryFactory queryFactory =
|
||||||
createCategoryQueryFactory(categoryType, categoryId);
|
createCategoryQueryFactory(categoryType, categoryId);
|
||||||
|
@ -4,6 +4,7 @@ import android.app.SearchManager;
|
|||||||
import android.app.SearchableInfo;
|
import android.app.SearchableInfo;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.support.v7.widget.DividerItemDecoration;
|
import android.support.v7.widget.DividerItemDecoration;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
@ -19,6 +20,8 @@ import android.widget.CheckBox;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
public final class Views {
|
public final class Views {
|
||||||
|
public static String EXTRA_TITLE = "extra_title";
|
||||||
|
|
||||||
public static void setCheckWithoutEvent(final CheckBox cb,
|
public static void setCheckWithoutEvent(final CheckBox cb,
|
||||||
final boolean checked,
|
final boolean checked,
|
||||||
final CheckBox.OnCheckedChangeListener listener) {
|
final CheckBox.OnCheckedChangeListener listener) {
|
||||||
@ -118,6 +121,22 @@ public final class Views {
|
|||||||
return animator;
|
return animator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void enableUpNavigation(final AppCompatActivity activity) {
|
||||||
|
final ActionBar ab = activity.getSupportActionBar();
|
||||||
|
if (ab != null) {
|
||||||
|
ab.setDisplayHomeAsUpEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setTitle(final AppCompatActivity activity, int defaultId) {
|
||||||
|
final String title = activity.getIntent().getStringExtra(EXTRA_TITLE);
|
||||||
|
if (Strings.notEmpty(title)) {
|
||||||
|
activity.setTitle(title);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
activity.setTitle(defaultId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Views() {
|
private Views() {
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import android.os.Bundle;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
public abstract class WebSocketActivityBase extends AppCompatActivity {
|
public abstract class WebSocketActivityBase extends AppCompatActivity {
|
||||||
private WebSocketService wss;
|
private WebSocketService wss;
|
||||||
@ -50,6 +51,16 @@ public abstract class WebSocketActivityBase extends AppCompatActivity {
|
|||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (item.getItemId() == android.R.id.home) {
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
protected final boolean isPaused() {
|
protected final boolean isPaused() {
|
||||||
return this.paused;
|
return this.paused;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user