"Up" navigation now brings you back to the selected label
This commit is contained in:
parent
edd1124c32
commit
9af80f008d
@ -35,8 +35,8 @@ public abstract class DetailActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int id = item.getItemId();
|
switch (item.getItemId()) {
|
||||||
if (id == android.R.id.home) {
|
case android.R.id.home:
|
||||||
// This ID represents the Home or Up button. In the case of this
|
// This ID represents the Home or Up button. In the case of this
|
||||||
// activity, the Up button is shown. Use NavUtils to allow users
|
// activity, the Up button is shown. Use NavUtils to allow users
|
||||||
// to navigate up one level in the application structure. For
|
// to navigate up one level in the application structure. For
|
||||||
@ -46,7 +46,8 @@ public abstract class DetailActivity extends AppCompatActivity {
|
|||||||
//
|
//
|
||||||
NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
|
NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
|
||||||
return true;
|
return true;
|
||||||
}
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -91,6 +91,7 @@ import static ch.dissem.apps.abit.service.BitmessageService.isRunning;
|
|||||||
public class MainActivity extends AppCompatActivity
|
public class MainActivity extends AppCompatActivity
|
||||||
implements ListSelectionListener<Serializable>, ActionBarListener {
|
implements ListSelectionListener<Serializable>, ActionBarListener {
|
||||||
public static final String EXTRA_SHOW_MESSAGE = "ch.dissem.abit.ShowMessage";
|
public static final String EXTRA_SHOW_MESSAGE = "ch.dissem.abit.ShowMessage";
|
||||||
|
public static final String EXTRA_SHOW_LABEL = "ch.dissem.abit.ShowLabel";
|
||||||
public static final String EXTRA_REPLY_TO_MESSAGE = "ch.dissem.abit.ReplyToMessage";
|
public static final String EXTRA_REPLY_TO_MESSAGE = "ch.dissem.abit.ReplyToMessage";
|
||||||
public static final String ACTION_SHOW_INBOX = "ch.dissem.abit.ShowInbox";
|
public static final String ACTION_SHOW_INBOX = "ch.dissem.abit.ShowInbox";
|
||||||
|
|
||||||
@ -122,7 +123,9 @@ public class MainActivity extends AppCompatActivity
|
|||||||
instance = new WeakReference<>(this);
|
instance = new WeakReference<>(this);
|
||||||
bmc = Singleton.getBitmessageContext(this);
|
bmc = Singleton.getBitmessageContext(this);
|
||||||
List<Label> labels = bmc.messages().getLabels();
|
List<Label> labels = bmc.messages().getLabels();
|
||||||
if (selectedLabel == null) {
|
if (getIntent().hasExtra(EXTRA_SHOW_LABEL)) {
|
||||||
|
selectedLabel = (Label) getIntent().getSerializableExtra(EXTRA_SHOW_LABEL);
|
||||||
|
} else if (selectedLabel == null) {
|
||||||
selectedLabel = labels.get(0);
|
selectedLabel = labels.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,15 +511,16 @@ public class MainActivity extends AppCompatActivity
|
|||||||
// In single-pane mode, simply start the detail activity
|
// In single-pane mode, simply start the detail activity
|
||||||
// for the selected item ID.
|
// for the selected item ID.
|
||||||
Intent detailIntent;
|
Intent detailIntent;
|
||||||
if (item instanceof Plaintext)
|
if (item instanceof Plaintext) {
|
||||||
detailIntent = new Intent(this, MessageDetailActivity.class);
|
detailIntent = new Intent(this, MessageDetailActivity.class);
|
||||||
else if (item instanceof BitmessageAddress)
|
detailIntent.putExtra(EXTRA_SHOW_LABEL, selectedLabel);
|
||||||
|
} else if (item instanceof BitmessageAddress) {
|
||||||
detailIntent = new Intent(this, AddressDetailActivity.class);
|
detailIntent = new Intent(this, AddressDetailActivity.class);
|
||||||
else
|
} else {
|
||||||
throw new IllegalArgumentException("Plaintext or BitmessageAddress expected, but " +
|
throw new IllegalArgumentException("Plaintext or BitmessageAddress expected, but " +
|
||||||
"was "
|
"was "
|
||||||
+ item.getClass().getSimpleName());
|
+ item.getClass().getSimpleName());
|
||||||
|
}
|
||||||
detailIntent.putExtra(MessageDetailFragment.ARG_ITEM, item);
|
detailIntent.putExtra(MessageDetailFragment.ARG_ITEM, item);
|
||||||
startActivity(detailIntent);
|
startActivity(detailIntent);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package ch.dissem.apps.abit;
|
package ch.dissem.apps.abit;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.NavUtils;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,6 +18,7 @@ import android.os.Bundle;
|
|||||||
* more than a {@link MessageDetailFragment}.
|
* more than a {@link MessageDetailFragment}.
|
||||||
*/
|
*/
|
||||||
public class MessageDetailActivity extends DetailActivity {
|
public class MessageDetailActivity extends DetailActivity {
|
||||||
|
private Label label;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -28,6 +34,7 @@ public class MessageDetailActivity extends DetailActivity {
|
|||||||
// http://developer.android.com/guide/components/fragments.html
|
// http://developer.android.com/guide/components/fragments.html
|
||||||
//
|
//
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
|
label = (Label) getIntent().getSerializableExtra(MainActivity.EXTRA_SHOW_LABEL);
|
||||||
// Create the detail fragment and add it to the activity
|
// Create the detail fragment and add it to the activity
|
||||||
// using a fragment transaction.
|
// using a fragment transaction.
|
||||||
Bundle arguments = new Bundle();
|
Bundle arguments = new Bundle();
|
||||||
@ -40,4 +47,17 @@ public class MessageDetailActivity extends DetailActivity {
|
|||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
Intent parentIntent = new Intent(this, MainActivity.class);
|
||||||
|
parentIntent.putExtra(MainActivity.EXTRA_SHOW_LABEL, label);
|
||||||
|
NavUtils.navigateUpTo(this, parentIntent);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user