Skip to content

Commit

Permalink
Set activity titles
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Jul 9, 2016
1 parent 40df0fe commit b54f11a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.preference.PreferenceManager;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
Expand Down Expand Up @@ -64,6 +65,19 @@ public void setToolbarActionBarEnabled(boolean toolbarActionBarEnabled) {
mToolbarActionBarEnabled = toolbarActionBarEnabled;
}

// Avoids IDE warnings about null pointers
@NonNull
public final ActionBar getSupportActionBarOrThrow() {

final ActionBar result = getSupportActionBar();

if(result == null) {
throw new RuntimeException("Action bar is null");
}

return result;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

getSupportActionBarOrThrow().setTitle(R.string.edit_comment_actionbar);

textEdit = (EditText) getLayoutInflater().inflate(R.layout.comment_edit, null);

if(getIntent() != null && getIntent().hasExtra("commentIdAndType")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

getSupportActionBarOrThrow().setTitle(R.string.submit_comment_actionbar);

final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.comment_reply, null);

usernameSpinner = (Spinner)layout.findViewById(R.id.comment_reply_username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

getSupportActionBarOrThrow().setTitle(R.string.pm_send_actionbar);

final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.pm_send, null);

usernameSpinner = (Spinner)layout.findViewById(R.id.pm_send_username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

getSupportActionBarOrThrow().setTitle(R.string.submit_post_actionbar);

getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Expand Down
5 changes: 5 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,9 @@
<string name="error_too_long_title">Too long</string>
<string name="error_too_long_message">Reddit says that the text you entered is too long.</string>

<string name="pm_send_actionbar">Send Message</string>
<string name="submit_post_actionbar">Submit Post</string>
<string name="submit_comment_actionbar">Submit Comment</string>
<string name="edit_comment_actionbar">Edit Comment</string>

</resources>

0 comments on commit b54f11a

Please sign in to comment.