Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xabber-android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
xabber-android
Commits
661a8da4
Commit
661a8da4
authored
Jun 30, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Contact list contact context menu rewritten using xml menu resource.
parent
d2a58391
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
192 additions
and
114 deletions
+192
-114
ContextMenuHelper.java
.../java/com/xabber/android/ui/helper/ContextMenuHelper.java
+154
-114
contact_list_contact_context_menu.xml
app/src/main/res/menu/contact_list_contact_context_menu.xml
+38
-0
No files found.
app/src/main/java/com/xabber/android/ui/helper/ContextMenuHelper.java
View file @
661a8da4
...
...
@@ -20,6 +20,7 @@ import android.content.DialogInterface;
import
android.support.v4.app.FragmentActivity
;
import
android.view.ContextMenu
;
import
android.view.Menu
;
import
android.view.MenuInflater
;
import
android.view.MenuItem
;
import
com.xabber.android.R
;
...
...
@@ -66,7 +67,18 @@ public class ContextMenuHelper {
final
String
account
=
abstractContact
.
getAccount
();
final
String
user
=
abstractContact
.
getUser
();
menu
.
setHeaderTitle
(
abstractContact
.
getName
());
menu
.
add
(
R
.
string
.
chat_viewer
).
setOnMenuItemClickListener
(
MenuInflater
inflater
=
activity
.
getMenuInflater
();
inflater
.
inflate
(
R
.
menu
.
contact_list_contact_context_menu
,
menu
);
setContactContextMenuActions
(
activity
,
adapter
,
menu
,
account
,
user
);
setContactContextMenuItemsVisibilty
(
abstractContact
,
menu
,
account
,
user
);
}
private
static
void
setContactContextMenuActions
(
final
FragmentActivity
activity
,
final
UpdatableAdapter
adapter
,
ContextMenu
menu
,
final
String
account
,
final
String
user
)
{
menu
.
findItem
(
R
.
id
.
action_chat
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
...
...
@@ -78,138 +90,166 @@ public class ContextMenuHelper {
}
});
if
(
MUCManager
.
getInstance
().
hasRoom
(
account
,
user
))
{
if
(!
MUCManager
.
getInstance
().
inUse
(
account
,
user
))
menu
.
add
(
R
.
string
.
muc_edit
).
setIntent
(
ConferenceAdd
.
createIntent
(
activity
,
account
,
user
));
menu
.
add
(
R
.
string
.
muc_delete
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
MUCDeleteDialogFragment
.
newInstance
(
account
,
user
)
.
show
(
activity
.
getFragmentManager
(),
"MUC_DELETE"
);
return
true
;
}
});
if
(
MUCManager
.
getInstance
().
isDisabled
(
account
,
user
))
{
menu
.
add
(
R
.
string
.
muc_join
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
MUCManager
.
getInstance
().
joinRoom
(
account
,
user
,
true
);
return
true
;
}
});
}
else
{
menu
.
add
(
R
.
string
.
muc_leave
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
menu
.
findItem
(
R
.
id
.
action_edit_conference
).
setIntent
(
ConferenceAdd
.
createIntent
(
activity
,
account
,
user
));
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
MUCManager
.
getInstance
().
leaveRoom
(
account
,
user
);
MessageManager
.
getInstance
().
closeChat
(
account
,
user
);
NotificationManager
.
getInstance
()
.
removeMessageNotification
(
account
,
user
);
adapter
.
onChange
();
return
true
;
}
menu
.
findItem
(
R
.
id
.
action_delete_conference
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
MUCDeleteDialogFragment
.
newInstance
(
account
,
user
)
.
show
(
activity
.
getFragmentManager
(),
"MUC_DELETE"
);
return
true
;
}
});
});
}
}
else
{
menu
.
add
(
R
.
string
.
contact_viewer
).
setIntent
(
ContactEditor
.
createIntent
(
activity
,
account
,
user
));
menu
.
add
(
R
.
string
.
edit_contact_groups
).
setIntent
(
GroupEditor
.
createIntent
(
activity
,
account
,
user
));
menu
.
findItem
(
R
.
id
.
action_join_conference
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
MUCManager
.
getInstance
().
joinRoom
(
account
,
user
,
true
);
return
true
;
}
});
menu
.
add
(
R
.
string
.
contact_delet
e
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
menu
.
findItem
(
R
.
id
.
action_leave_conferenc
e
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
ContactDeleteDialogFragment
.
newInstance
(
account
,
user
).
show
(
activity
.
getFragmentManager
(),
"CONTACT_DELETE"
);
return
true
;
}
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
MUCManager
.
getInstance
().
leaveRoom
(
account
,
user
);
MessageManager
.
getInstance
().
closeChat
(
account
,
user
);
NotificationManager
.
getInstance
().
removeMessageNotification
(
account
,
user
);
adapter
.
onChange
();
return
true
;
}
});
if
(
MessageManager
.
getInstance
().
hasActiveChat
(
account
,
user
))
{
menu
.
add
(
R
.
string
.
close_chat
).
setOnMenuItemClickListener
(
});
menu
.
findItem
(
R
.
id
.
action_contact_info
).
setIntent
(
ContactEditor
.
createIntent
(
activity
,
account
,
user
));
menu
.
findItem
(
R
.
id
.
action_edit_contact_groups
).
setIntent
(
GroupEditor
.
createIntent
(
activity
,
account
,
user
));
menu
.
findItem
(
R
.
id
.
action_delete_contact
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
ContactDeleteDialogFragment
.
newInstance
(
account
,
user
).
show
(
activity
.
getFragmentManager
(),
"CONTACT_DELETE"
);
return
true
;
}
});
menu
.
findItem
(
R
.
id
.
action_close_chat
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
MessageManager
.
getInstance
().
closeChat
(
account
,
user
);
NotificationManager
.
getInstance
()
.
removeMessageNotification
(
account
,
user
);
adapter
.
onChange
();
return
true
;
}
});
menu
.
findItem
(
R
.
id
.
action_request_subscription
)
.
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
MessageManager
.
getInstance
().
closeChat
(
account
,
user
);
NotificationManager
.
getInstance
()
.
removeMessageNotification
(
account
,
user
);
adapter
.
onChange
();
try
{
PresenceManager
.
getInstance
()
.
requestSubscription
(
account
,
user
);
}
catch
(
NetworkException
e
)
{
Application
.
getInstance
()
.
onError
(
e
);
}
return
true
;
}
});
menu
.
findItem
(
R
.
id
.
action_accept_subscription
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
try
{
PresenceManager
.
getInstance
().
acceptSubscription
(
account
,
user
);
}
catch
(
NetworkException
e
)
{
Application
.
getInstance
().
onError
(
e
);
}
activity
.
startActivity
(
GroupEditor
.
createIntent
(
activity
,
account
,
user
));
return
true
;
}
});
menu
.
findItem
(
R
.
id
.
action_discard_subscription
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
try
{
PresenceManager
.
getInstance
()
.
discardSubscription
(
account
,
user
);
}
catch
(
NetworkException
e
)
{
Application
.
getInstance
().
onError
(
e
);
}
return
true
;
}
});
}
private
static
void
setContactContextMenuItemsVisibilty
(
AbstractContact
abstractContact
,
ContextMenu
menu
,
String
account
,
String
user
)
{
// all menu items are visible by default
// it allows to hide items in xml file without touching code
if
(!
MUCManager
.
getInstance
().
hasRoom
(
account
,
user
))
{
// is not conference
menu
.
findItem
(
R
.
id
.
action_edit_conference
).
setVisible
(
false
);
menu
.
findItem
(
R
.
id
.
action_delete_conference
).
setVisible
(
false
);
menu
.
findItem
(
R
.
id
.
action_leave_conference
).
setVisible
(
false
);
menu
.
findItem
(
R
.
id
.
action_join_conference
).
setVisible
(
false
);
if
(!
MessageManager
.
getInstance
().
hasActiveChat
(
account
,
user
))
{
menu
.
findItem
(
R
.
id
.
action_close_chat
).
setVisible
(
false
);
}
if
(
abstractContact
.
getStatusMode
()
==
StatusMode
.
unsubscribed
)
{
menu
.
add
(
R
.
string
.
request_subscription
)
.
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
try
{
PresenceManager
.
getInstance
()
.
requestSubscription
(
account
,
user
);
}
catch
(
NetworkException
e
)
{
Application
.
getInstance
()
.
onError
(
e
);
}
return
true
;
}
});
if
(
abstractContact
.
getStatusMode
()
!=
StatusMode
.
unsubscribed
)
{
menu
.
findItem
(
R
.
id
.
action_request_subscription
).
setVisible
(
false
);
}
}
if
(
PresenceManager
.
getInstance
().
hasSubscriptionRequest
(
account
,
user
))
{
menu
.
add
(
R
.
string
.
accept_subscription
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
}
else
{
// is conference
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
try
{
PresenceManager
.
getInstance
()
.
acceptSubscription
(
account
,
user
);
}
catch
(
NetworkException
e
)
{
Application
.
getInstance
().
onError
(
e
);
}
activity
.
startActivity
(
GroupEditor
.
createIntent
(
activity
,
account
,
user
));
return
true
;
}
menu
.
findItem
(
R
.
id
.
action_contact_info
).
setVisible
(
false
);
menu
.
findItem
(
R
.
id
.
action_edit_contact_groups
).
setVisible
(
false
);
menu
.
findItem
(
R
.
id
.
action_delete_contact
).
setVisible
(
false
);
menu
.
findItem
(
R
.
id
.
action_close_chat
).
setVisible
(
false
);
menu
.
findItem
(
R
.
id
.
action_request_subscription
).
setVisible
(
false
);
});
menu
.
add
(
R
.
string
.
discard_subscription
).
setOnMenuItemClickListener
(
new
MenuItem
.
OnMenuItemClickListener
()
{
if
(
MUCManager
.
getInstance
().
inUse
(
account
,
user
))
{
menu
.
findItem
(
R
.
id
.
action_edit_conference
).
setVisible
(
false
);
}
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
try
{
PresenceManager
.
getInstance
()
.
discardSubscription
(
account
,
user
);
}
catch
(
NetworkException
e
)
{
Application
.
getInstance
().
onError
(
e
);
}
return
true
;
}
if
(
MUCManager
.
getInstance
().
isDisabled
(
account
,
user
))
{
menu
.
findItem
(
R
.
id
.
action_leave_conference
).
setVisible
(
false
);
}
else
{
menu
.
findItem
(
R
.
id
.
action_join_conference
).
setVisible
(
false
);
}
});
}
if
(!
PresenceManager
.
getInstance
().
hasSubscriptionRequest
(
account
,
user
))
{
menu
.
findItem
(
R
.
id
.
action_accept_subscription
).
setVisible
(
false
);
menu
.
findItem
(
R
.
id
.
action_discard_subscription
).
setVisible
(
false
);
}
}
...
...
app/src/main/res/menu/contact_list_contact_context_menu.xml
0 → 100644
View file @
661a8da4
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<item
android:id=
"@+id/action_chat"
android:title=
"@string/chat_viewer"
/>
<item
android:id=
"@+id/action_edit_conference"
android:title=
"@string/muc_edit"
/>
<item
android:id=
"@+id/action_delete_conference"
android:title=
"@string/muc_delete"
/>
<item
android:id=
"@+id/action_join_conference"
android:title=
"@string/muc_join"
/>
<item
android:id=
"@+id/action_leave_conference"
android:title=
"@string/muc_leave"
/>
<item
android:id=
"@+id/action_contact_info"
android:title=
"@string/contact_viewer"
/>
<item
android:id=
"@+id/action_edit_contact_groups"
android:title=
"@string/edit_contact_groups"
/>
<item
android:id=
"@+id/action_delete_contact"
android:title=
"@string/contact_delete"
/>
<item
android:id=
"@+id/action_close_chat"
android:title=
"@string/close_chat"
/>
<item
android:id=
"@+id/action_request_subscription"
android:title=
"@string/request_subscription"
/>
<item
android:id=
"@+id/action_accept_subscription"
android:title=
"@string/accept_subscription"
/>
<item
android:id=
"@+id/action_discard_subscription"
android:title=
"@string/discard_subscription"
/>
</menu>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment