android: hide new post button when navigating
Fixes: https://github.com/damus-io/notedeck/issues/898 Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
storage,
|
storage,
|
||||||
subscriptions::{SubKind, Subscriptions},
|
subscriptions::{SubKind, Subscriptions},
|
||||||
support::Support,
|
support::Support,
|
||||||
timeline::{self, thread::Threads, TimelineCache},
|
timeline::{self, kind::ListKind, thread::Threads, TimelineCache, TimelineKind},
|
||||||
ui::{self, DesktopSidePanel},
|
ui::{self, DesktopSidePanel},
|
||||||
view_state::ViewState,
|
view_state::ViewState,
|
||||||
Result,
|
Result,
|
||||||
@@ -581,25 +581,70 @@ fn render_damus_mobile(
|
|||||||
.is_some();
|
.is_some();
|
||||||
let darkmode = ui.ctx().style().visuals.dark_mode;
|
let darkmode = ui.ctx().style().visuals.dark_mode;
|
||||||
|
|
||||||
if ui
|
// only show the compose button on profile pages and on home
|
||||||
.put(
|
if should_show_compose_button(&app.decks_cache, app_ctx.accounts) {
|
||||||
|
let compose_resp = ui.put(
|
||||||
rect,
|
rect,
|
||||||
ui::post::compose_note_button(is_interactive, darkmode),
|
ui::post::compose_note_button(is_interactive, darkmode),
|
||||||
)
|
);
|
||||||
.clicked()
|
if compose_resp.clicked() && !app.columns(app_ctx.accounts).columns().is_empty() {
|
||||||
&& !app.columns(app_ctx.accounts).columns().is_empty()
|
let router = app
|
||||||
{
|
.columns_mut(app_ctx.accounts)
|
||||||
let router = app.columns_mut(app_ctx.accounts).selected().router_mut();
|
.selected_mut()
|
||||||
if router.top() == &Route::ComposeNote {
|
.router_mut();
|
||||||
router.go_back();
|
if router.top() == &Route::ComposeNote {
|
||||||
} else {
|
router.go_back();
|
||||||
router.route_to(Route::ComposeNote);
|
} else {
|
||||||
|
router.route_to(Route::ComposeNote);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app_action
|
app_action
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Should we show the compose button? When in threads we should hide it, etc
|
||||||
|
fn should_show_compose_button(decks: &DecksCache, accounts: &Accounts) -> bool {
|
||||||
|
let Some(col) = decks.selected_column(accounts) else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
match col.router().top() {
|
||||||
|
Route::Timeline(timeline_kind) => {
|
||||||
|
match timeline_kind {
|
||||||
|
TimelineKind::List(list_kind) => match list_kind {
|
||||||
|
ListKind::Contact(_pk) => true,
|
||||||
|
},
|
||||||
|
|
||||||
|
TimelineKind::Algo(_pk) => true,
|
||||||
|
TimelineKind::Profile(_pk) => true,
|
||||||
|
TimelineKind::Universe => true,
|
||||||
|
TimelineKind::Generic(_) => true,
|
||||||
|
TimelineKind::Hashtag(_) => true,
|
||||||
|
|
||||||
|
// no!
|
||||||
|
TimelineKind::Search(_) => false,
|
||||||
|
TimelineKind::Notifications(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Route::Thread(_) => false,
|
||||||
|
Route::Accounts(_) => false,
|
||||||
|
Route::Reply(_) => false,
|
||||||
|
Route::Quote(_) => false,
|
||||||
|
Route::Relays => false,
|
||||||
|
Route::ComposeNote => false,
|
||||||
|
Route::AddColumn(_) => false,
|
||||||
|
Route::EditProfile(_) => false,
|
||||||
|
Route::Support => false,
|
||||||
|
Route::NewDeck => false,
|
||||||
|
Route::Search => false,
|
||||||
|
Route::EditDeck(_) => false,
|
||||||
|
Route::Wallet(_) => false,
|
||||||
|
Route::CustomizeZapAmount(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[profiling::function]
|
#[profiling::function]
|
||||||
fn render_damus_desktop(
|
fn render_damus_desktop(
|
||||||
app: &mut Damus,
|
app: &mut Damus,
|
||||||
|
|||||||
@@ -158,7 +158,12 @@ impl Columns {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn selected(&mut self) -> &mut Column {
|
pub fn selected(&self) -> &Column {
|
||||||
|
&self.columns[self.selected as usize]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn selected_mut(&mut self) -> &mut Column {
|
||||||
&mut self.columns[self.selected as usize]
|
&mut self.columns[self.selected as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,10 +32,15 @@ impl Default for DecksCache {
|
|||||||
impl DecksCache {
|
impl DecksCache {
|
||||||
/// Gets the first column in the currently active user's active deck
|
/// Gets the first column in the currently active user's active deck
|
||||||
pub fn selected_column_mut(&mut self, accounts: ¬edeck::Accounts) -> Option<&mut Column> {
|
pub fn selected_column_mut(&mut self, accounts: ¬edeck::Accounts) -> Option<&mut Column> {
|
||||||
self.active_columns_mut(accounts).map(|ad| ad.selected())
|
self.active_columns_mut(accounts)
|
||||||
|
.map(|ad| ad.selected_mut())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the active columns
|
pub fn selected_column(&self, accounts: ¬edeck::Accounts) -> Option<&Column> {
|
||||||
|
self.active_columns(accounts).map(|ad| ad.selected())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets a mutable reference to the active columns
|
||||||
pub fn active_columns_mut(&mut self, accounts: ¬edeck::Accounts) -> Option<&mut Columns> {
|
pub fn active_columns_mut(&mut self, accounts: ¬edeck::Accounts) -> Option<&mut Columns> {
|
||||||
let account = accounts.get_selected_account();
|
let account = accounts.get_selected_account();
|
||||||
|
|
||||||
@@ -44,6 +49,15 @@ impl DecksCache {
|
|||||||
.map(|ad| ad.columns_mut())
|
.map(|ad| ad.columns_mut())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets an immutable reference to the active columns
|
||||||
|
pub fn active_columns(&self, accounts: ¬edeck::Accounts) -> Option<&Columns> {
|
||||||
|
let account = accounts.get_selected_account();
|
||||||
|
|
||||||
|
self.decks(&account.key.pubkey)
|
||||||
|
.active_deck()
|
||||||
|
.map(|ad| ad.columns())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(mut account_to_decks: HashMap<Pubkey, Decks>) -> Self {
|
pub fn new(mut account_to_decks: HashMap<Pubkey, Decks>) -> Self {
|
||||||
let fallback_pubkey = FALLBACK_PUBKEY();
|
let fallback_pubkey = FALLBACK_PUBKEY();
|
||||||
account_to_decks.entry(fallback_pubkey).or_default();
|
account_to_decks.entry(fallback_pubkey).or_default();
|
||||||
@@ -187,7 +201,7 @@ impl Decks {
|
|||||||
&self.decks
|
&self.decks
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn active_deck_mut(&mut self) -> Option<&mut Deck> {
|
fn active_deck_index(&self) -> Option<usize> {
|
||||||
if self.decks.is_empty() {
|
if self.decks.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -197,7 +211,15 @@ impl Decks {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(&mut self.decks[active])
|
Some(active)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn active_deck(&self) -> Option<&Deck> {
|
||||||
|
self.active_deck_index().map(|ind| &self.decks[ind])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn active_deck_mut(&mut self) -> Option<&mut Deck> {
|
||||||
|
self.active_deck_index().map(|ind| &mut self.decks[ind])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decks_mut(&mut self) -> &mut Vec<Deck> {
|
pub fn decks_mut(&mut self) -> &mut Vec<Deck> {
|
||||||
|
|||||||
@@ -41,14 +41,10 @@ fn note_follows(contacts_note: Note<'_>, pk: &[u8; 32]) -> bool {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(t) = tag.get_str(0) else {
|
let Some("p") = tag.get_str(0) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
if t != "p" {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let Some(author) = tag.get_id(1) else {
|
let Some(author) = tag.get_id(1) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ use egui::{
|
|||||||
};
|
};
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
fonts::get_font_size, note::MediaAction, show_one_error_message, supported_mime_hosted_at_url,
|
fonts::get_font_size, note::MediaAction, show_one_error_message, supported_mime_hosted_at_url,
|
||||||
ui::is_narrow, GifState, GifStateMap, Images, JobPool, MediaCache, MediaCacheType,
|
GifState, GifStateMap, Images, JobPool, MediaCache, MediaCacheType, NotedeckTextStyle,
|
||||||
NotedeckTextStyle, TexturedImage, TexturesCache, UrlMimes,
|
TexturedImage, TexturesCache, UrlMimes,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -30,8 +30,8 @@ pub(crate) fn image_carousel(
|
|||||||
) -> Option<MediaAction> {
|
) -> Option<MediaAction> {
|
||||||
// let's make sure everything is within our area
|
// let's make sure everything is within our area
|
||||||
|
|
||||||
let height = if is_narrow(ui.ctx()) { 90.0 } else { 360.0 };
|
//let height = if is_narrow(ui.ctx()) { 90.0 } else { 360.0 };
|
||||||
|
let height = 360.0;
|
||||||
let width = ui.available_width();
|
let width = ui.available_width();
|
||||||
|
|
||||||
let show_popup = get_show_popup(ui, popup_id(carousel_id));
|
let show_popup = get_show_popup(ui, popup_id(carousel_id));
|
||||||
|
|||||||
Reference in New Issue
Block a user