"Up" navigation now brings you back to the selected label

This commit is contained in:
Christian Basler 2016-11-02 20:55:56 +01:00
parent edd1124c32
commit 9af80f008d
3 changed files with 45 additions and 20 deletions

View File

@ -35,8 +35,8 @@ public abstract class DetailActivity extends AppCompatActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// 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));
return true;
}
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@ -91,6 +91,7 @@ import static ch.dissem.apps.abit.service.BitmessageService.isRunning;
public class MainActivity extends AppCompatActivity
implements ListSelectionListener<Serializable>, ActionBarListener {
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 ACTION_SHOW_INBOX = "ch.dissem.abit.ShowInbox";
@ -122,7 +123,9 @@ public class MainActivity extends AppCompatActivity
instance = new WeakReference<>(this);
bmc = Singleton.getBitmessageContext(this);
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);
}
@ -508,15 +511,16 @@ public class MainActivity extends AppCompatActivity
// In single-pane mode, simply start the detail activity
// for the selected item ID.
Intent detailIntent;
if (item instanceof Plaintext)
if (item instanceof Plaintext) {
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);
else
} else {
throw new IllegalArgumentException("Plaintext or BitmessageAddress expected, but " +
"was "
+ item.getClass().getSimpleName());
}
detailIntent.putExtra(MessageDetailFragment.ARG_ITEM, item);
startActivity(detailIntent);
}

View File

@ -1,6 +1,11 @@
package ch.dissem.apps.abit;
import android.content.Intent;
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}.
*/
public class MessageDetailActivity extends DetailActivity {
private Label label;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -28,6 +34,7 @@ public class MessageDetailActivity extends DetailActivity {
// http://developer.android.com/guide/components/fragments.html
//
if (savedInstanceState == null) {
label = (Label) getIntent().getSerializableExtra(MainActivity.EXTRA_SHOW_LABEL);
// Create the detail fragment and add it to the activity
// using a fragment transaction.
Bundle arguments = new Bundle();
@ -40,4 +47,17 @@ public class MessageDetailActivity extends DetailActivity {
.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);
}
}
}