mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-05 18:39:55 +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;
|
||||
|
||||
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_ID = "extra_category_id";
|
||||
|
||||
@ -40,7 +39,7 @@ public class AlbumBrowseActivity extends WebSocketActivityBase implements Filter
|
||||
|
||||
if (Strings.notEmpty(categoryValue)) {
|
||||
intent.putExtra(
|
||||
AlbumBrowseActivity.EXTRA_TITLE,
|
||||
Views.EXTRA_TITLE,
|
||||
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);
|
||||
|
||||
setContentView(R.layout.recycler_view_activity);
|
||||
setTitle(R.string.albums_title);
|
||||
|
||||
final String title = getIntent().getStringExtra(EXTRA_TITLE);
|
||||
if (Strings.notEmpty(title)) {
|
||||
setTitle(title);
|
||||
}
|
||||
Views.setTitle(this, R.string.albums_title);
|
||||
Views.enableUpNavigation(this);
|
||||
|
||||
this.wss = getWebSocketService();
|
||||
this.adapter = new Adapter();
|
||||
|
@ -70,6 +70,8 @@ public class CategoryBrowseActivity extends WebSocketActivityBase implements Fil
|
||||
|
||||
setContentView(R.layout.recycler_view_activity);
|
||||
|
||||
Views.enableUpNavigation(this);
|
||||
|
||||
if (CATEGORY_NAME_TO_TITLE.containsKey(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 */
|
||||
Views.initSearchMenu(this, menu, this);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -104,6 +104,14 @@ public class MainActivity extends WebSocketActivityBase {
|
||||
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
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
@ -32,7 +32,9 @@ public class PlayQueueActivity extends WebSocketActivityBase {
|
||||
this.wss = getWebSocketService();
|
||||
|
||||
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();
|
||||
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||
@ -46,6 +48,7 @@ public class PlayQueueActivity extends WebSocketActivityBase {
|
||||
getIntent().getIntExtra(EXTRA_PLAYING_INDEX, -1));
|
||||
|
||||
Views.addTransportFragment(this);
|
||||
Views.enableUpNavigation(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,6 +6,7 @@ import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
@ -31,10 +32,21 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
rebindUi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void rebindUi() {
|
||||
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.passwordText, prefs.getString("password", ""));
|
||||
Views.enableUpNavigation(this);
|
||||
}
|
||||
|
||||
private void bindEventListeners() {
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@ -16,7 +17,6 @@ import org.json.JSONObject;
|
||||
import static io.casey.musikcube.remote.TrackListScrollCache.QueryFactory;
|
||||
|
||||
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_SELECTED_ID = "extra_selected_id";
|
||||
|
||||
@ -34,7 +34,7 @@ public class TrackListActivity extends WebSocketActivityBase implements Filterab
|
||||
|
||||
if (Strings.notEmpty(categoryValue)) {
|
||||
intent.putExtra(
|
||||
TrackListActivity.EXTRA_TITLE,
|
||||
Views.EXTRA_TITLE,
|
||||
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);
|
||||
|
||||
setContentView(R.layout.recycler_view_activity);
|
||||
setTitle(R.string.songs_title);
|
||||
|
||||
final String title = getIntent().getStringExtra(EXTRA_TITLE);
|
||||
if (Strings.notEmpty(title)) {
|
||||
setTitle(title);
|
||||
}
|
||||
Views.setTitle(this, R.string.songs_title);
|
||||
Views.enableUpNavigation(this);
|
||||
|
||||
final QueryFactory queryFactory =
|
||||
createCategoryQueryFactory(categoryType, categoryId);
|
||||
|
@ -4,6 +4,7 @@ import android.app.SearchManager;
|
||||
import android.app.SearchableInfo;
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
@ -19,6 +20,8 @@ import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
|
||||
public final class Views {
|
||||
public static String EXTRA_TITLE = "extra_title";
|
||||
|
||||
public static void setCheckWithoutEvent(final CheckBox cb,
|
||||
final boolean checked,
|
||||
final CheckBox.OnCheckedChangeListener listener) {
|
||||
@ -118,6 +121,22 @@ public final class Views {
|
||||
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() {
|
||||
|
||||
|
@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public abstract class WebSocketActivityBase extends AppCompatActivity {
|
||||
private WebSocketService wss;
|
||||
@ -50,6 +51,16 @@ public abstract class WebSocketActivityBase extends AppCompatActivity {
|
||||
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() {
|
||||
return this.paused;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user