From 6b134a84035dbc540127566615fb816e10df8d61 Mon Sep 17 00:00:00 2001 From: Anton Chekulaev Date: Fri, 18 Sep 2020 16:54:40 +1000 Subject: [PATCH] Back button for landing activities. --- res/drawable/ic_baseline_arrow_back_24.xml | 10 +++++ .../session_logo_action_bar_content.xml | 32 ++++++++++++++ .../loki/activities/LandingActivity.kt | 2 +- .../loki/utilities/ActivityUtilities.kt | 42 ++++++++++++------- 4 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 res/drawable/ic_baseline_arrow_back_24.xml create mode 100644 res/layout/session_logo_action_bar_content.xml diff --git a/res/drawable/ic_baseline_arrow_back_24.xml b/res/drawable/ic_baseline_arrow_back_24.xml new file mode 100644 index 0000000000..bab545a707 --- /dev/null +++ b/res/drawable/ic_baseline_arrow_back_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/res/layout/session_logo_action_bar_content.xml b/res/layout/session_logo_action_bar_content.xml new file mode 100644 index 0000000000..52f99ecdea --- /dev/null +++ b/res/layout/session_logo_action_bar_content.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/activities/LandingActivity.kt b/src/org/thoughtcrime/securesms/loki/activities/LandingActivity.kt index d19a0002ab..383a39352e 100644 --- a/src/org/thoughtcrime/securesms/loki/activities/LandingActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/activities/LandingActivity.kt @@ -40,7 +40,7 @@ class LandingActivity : BaseActionBarActivity(), LinkDeviceSlaveModeDialogDelega override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_landing) - setUpActionBarSessionLogo() + setUpActionBarSessionLogo(true) fakeChatView.startAnimating() registerButton.setOnClickListener { register() } restoreButton.setOnClickListener { restore() } diff --git a/src/org/thoughtcrime/securesms/loki/utilities/ActivityUtilities.kt b/src/org/thoughtcrime/securesms/loki/utilities/ActivityUtilities.kt index 656de0436f..6fd9250e0d 100644 --- a/src/org/thoughtcrime/securesms/loki/utilities/ActivityUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/utilities/ActivityUtilities.kt @@ -1,24 +1,36 @@ package org.thoughtcrime.securesms.loki.utilities import android.content.Intent -import androidx.appcompat.app.ActionBar +import android.view.View import androidx.appcompat.app.AppCompatActivity -import android.view.Gravity -import android.widget.ImageView -import android.widget.RelativeLayout +import androidx.appcompat.widget.Toolbar import network.loki.messenger.R +import org.thoughtcrime.securesms.BaseActionBarActivity -fun AppCompatActivity.setUpActionBarSessionLogo() { - supportActionBar!!.setDisplayShowHomeEnabled(false) - supportActionBar!!.setDisplayShowTitleEnabled(false) - val logoImageView = ImageView(this) - logoImageView.setImageResource(R.drawable.session_logo) - val logoImageViewContainer = RelativeLayout(this) - logoImageViewContainer.addView(logoImageView) - logoImageViewContainer.gravity = Gravity.CENTER - val logoImageViewContainerLayoutParams = ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT) - supportActionBar!!.setCustomView(logoImageViewContainer, logoImageViewContainerLayoutParams) - supportActionBar!!.setDisplayShowCustomEnabled(true) +fun BaseActionBarActivity.setUpActionBarSessionLogo(hideBackButton: Boolean = false) { + val actionbar = supportActionBar!! + + actionbar.setDisplayShowHomeEnabled(false) + actionbar.setDisplayShowTitleEnabled(false) + actionbar.setDisplayHomeAsUpEnabled(false) + actionbar.setHomeButtonEnabled(false) + + actionbar.setCustomView(R.layout.session_logo_action_bar_content) + actionbar.setDisplayShowCustomEnabled(true) + + val rootView: Toolbar = actionbar.customView!!.parent as Toolbar + rootView.setPadding(0,0,0,0) + rootView.setContentInsetsAbsolute(0,0); + + val backButton = actionbar.customView!!.findViewById(R.id.back_button) + if (hideBackButton) { + backButton.visibility = View.GONE + } else { + backButton.visibility = View.VISIBLE + backButton.setOnClickListener { + onSupportNavigateUp() + } + } } val AppCompatActivity.defaultSessionRequestCode: Int