-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toolbar management rework and toolbar style alignment
- Loading branch information
Showing
82 changed files
with
275 additions
and
744 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Toolbar management rework. Toolbar title's and subtitle's text appearance now controlled by theme without local overrides. Helper class introduced to | ||
help with toolbar configuration. Toolbar title, subtitle and navigation button widgets are removed where it is possible and replaced with built-in | ||
toolbar widgets. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
vector/src/main/java/im/vector/app/core/platform/ToolbarConfigurable.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
vector/src/main/java/im/vector/app/core/utils/ToolbarConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.core.utils | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.appcompat.content.res.AppCompatResources | ||
import com.google.android.material.appbar.MaterialToolbar | ||
import im.vector.app.R | ||
|
||
/** | ||
* Helper class to configure toolbar. | ||
* Wraps [MaterialToolbar] providing set of methods to configure it | ||
*/ | ||
class ToolbarConfig(val activity: AppCompatActivity, val toolbar: MaterialToolbar) { | ||
private var customBackResId: Int? = null | ||
|
||
fun setup() = apply { | ||
activity.setSupportActionBar(toolbar) | ||
} | ||
|
||
/** | ||
* Delegating property for [toolbar.title] | ||
* */ | ||
var title: CharSequence? by toolbar::title | ||
|
||
/** | ||
* Delegating property for [toolbar.subtitle] | ||
* */ | ||
var subtitle: CharSequence? by toolbar::subtitle | ||
|
||
/** | ||
* Sets toolbar's title text | ||
* */ | ||
fun setTitle(title: CharSequence?) = apply { toolbar.title = title } | ||
|
||
/** | ||
* Sets toolbar's title text using provided string resource | ||
* */ | ||
fun setTitle(@StringRes titleRes: Int) = apply { toolbar.setTitle(titleRes) } | ||
|
||
/** | ||
* Sets toolbar's subtitle text | ||
* */ | ||
fun setSubtitle(subtitle: String?) = apply { toolbar.subtitle = subtitle } | ||
|
||
/** | ||
* Sets toolbar's title text using provided string resource | ||
* */ | ||
fun setSubtitle(@StringRes subtitleRes: Int) = apply { toolbar.subtitle = activity.getString(subtitleRes) } | ||
|
||
/** | ||
* Enables/disables navigate back button | ||
* | ||
* @param isAllowed defines if back button is enabled. Default [true] | ||
* @param useCross defines if cross icon should be used instead of arrow. Default [false] | ||
* */ | ||
fun allowBack(isAllowed: Boolean = true, useCross: Boolean = false) = apply { | ||
activity.supportActionBar?.let { | ||
it.setDisplayShowHomeEnabled(isAllowed) | ||
it.setDisplayHomeAsUpEnabled(isAllowed) | ||
if (isAllowed && useCross) { | ||
val navResId = customBackResId ?: R.drawable.ic_x_18dp | ||
toolbar.navigationIcon = AppCompatResources.getDrawable(activity, navResId) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.