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
ff6d0d8f
Commit
ff6d0d8f
authored
May 28, 2013
by
Alexander Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move contact list into separate fragment.
parent
23e3e407
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
352 additions
and
260 deletions
+352
-260
contact_list.xml
res/layout/contact_list.xml
+51
-86
contact_list_fragment.xml
res/layout/contact_list_fragment.xml
+69
-0
ContactList.java
src/com/xabber/android/ui/ContactList.java
+30
-172
ContactListFragment.java
src/com/xabber/android/ui/ContactListFragment.java
+199
-0
ContactListAdapter.java
src/com/xabber/android/ui/adapter/ContactListAdapter.java
+3
-2
No files found.
res/layout/contact_list.xml
View file @
ff6d0d8f
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013, Redsolution LTD. All rights reserved.
<!--
Copyright (c) 2013, Redsolution LTD. All rights reserved.
This file is part of Xabber project; you can redistribute it and/or
This file is part of Xabber project; you can redistribute it and/or
modify it under the terms of the GNU General Public License, Version 3.
modify it under the terms of the GNU General Public License, Version 3.
...
@@ -12,47 +13,47 @@
...
@@ -12,47 +13,47 @@
You should have received a copy of the GNU General Public License,
You should have received a copy of the GNU General Public License,
along with this program. If not, see http://www.gnu.org/licenses/.
along with this program. If not, see http://www.gnu.org/licenses/.
-->
-->
<LinearLayout
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
>
>
<RelativeLayout
<RelativeLayout
android:id=
"@android:id/title"
android:id=
"@android:id/title"
android:orientation=
"horizontal"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"@dimen/title_height"
android:layout_height=
"@dimen/title_height"
android:background=
"@drawable/title_main_background_dark"
android:layout_alignParentTop=
"true"
>
android:background=
"@drawable/title_main_background_dark"
>
<ImageButton
<ImageButton
android:id=
"@+id/back_button"
android:id=
"@+id/back_button"
android:background=
"@drawable/title_logo"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:layout_alignParentLeft=
"true"
android:layout_alignParentLeft=
"true"
/>
android:background=
"@drawable/title_logo"
tools:ignore=
"ContentDescription"
/>
<LinearLayout
<LinearLayout
android:orientation=
"horizontal
"
android:layout_width=
"wrap_content
"
android:layout_width=
"wrap_cont
ent"
android:layout_height=
"match_par
ent"
android:layout_height=
"match_parent
"
android:layout_alignParentRight=
"true
"
android:layout_marginRight=
"@dimen/contact_list_status_mode_width"
android:layout_marginRight=
"@dimen/contact_list_status_mode_width"
android:layout_toRightOf=
"@id/back_button"
android:layout_toRightOf=
"@id/back_button"
android:
layout_alignParentRight=
"true"
android:
orientation=
"horizontal"
>
>
<HorizontalScrollView
<HorizontalScrollView
android:id=
"@+id/account_bar"
android:id=
"@+id/account_bar"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginRight=
"72dip"
android:layout_marginRight=
"72dip"
>
>
<LinearLayout
<LinearLayout
android:id=
"@+id/account_list"
android:id=
"@+id/account_list"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:orientation=
"horizontal"
>
>
<!--
<!--
<RelativeLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/account_bg"
android:id="@+id/account_bg"
...
@@ -97,78 +98,42 @@
...
@@ -97,78 +98,42 @@
android:background="@drawable/ic_status_connection_account"
android:background="@drawable/ic_status_connection_account"
/>
/>
</RelativeLayout>
</RelativeLayout>
-->
-->
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
</HorizontalScrollView>
<TextView
<TextView
android:id=
"@+id/common_status_text"
android:id=
"@+id/common_status_text"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:layout_gravity=
"left"
android:layout_marginLeft=
"-72dip"
android:layout_marginLeft=
"-72dip"
android:textColor=
"?android:attr/textColorPrimary"
android:gravity=
"left|center_vertical"
android:text=
"online"
android:padding=
"2dip"
android:padding=
"2dip"
android:singleLine=
"true"
android:singleLine=
"true"
android:
gravity=
"left|center_vertical
"
android:
text=
"online
"
android:
layout_gravity=
"left"
android:
textColor=
"?android:attr/textColorPrimary"
/>
/>
</LinearLayout>
</LinearLayout>
<ImageButton
<ImageButton
android:id=
"@+id/common_status_mode"
android:id=
"@+id/common_status_mode"
android:src=
"@drawable/ic_status"
android:paddingLeft=
"@dimen/active_chat_padding_right"
android:paddingRight=
"@dimen/active_chat_padding_right"
android:background=
"@drawable/btn_status_mode"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:layout_alignParentRight=
"true"
android:layout_alignParentRight=
"true"
/>
android:background=
"@drawable/btn_status_mode"
android:paddingLeft=
"@dimen/active_chat_padding_right"
android:paddingRight=
"@dimen/active_chat_padding_right"
android:src=
"@drawable/ic_status"
/>
</RelativeLayout>
</RelativeLayout>
<ListView
android:id=
"@android:id/list"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:textFilterEnabled=
"true"
/>
<RelativeLayout
<RelativeLayout
android:id=
"@+id/
info
"
android:id=
"@+id/
container
"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:layout_weight=
"1"
android:layout_below=
"@android:id/title"
/>
android:gravity=
"center_vertical"
>
</RelativeLayout>
<ImageView
android:id=
"@+id/connected"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:src=
"@drawable/ic_connect"
/>
<ImageView
android:id=
"@+id/disconnected"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:src=
"@drawable/ic_disconnect"
/>
<TextView
android:id=
"@+id/text"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textColor=
"?android:attr/textColorSecondary"
android:layout_below=
"@id/connected"
android:layout_centerHorizontal=
"true"
android:text=
"@string/application_state_starting"
/>
<Button
android:id=
"@+id/button"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"20dip"
android:layout_below=
"@id/text"
android:visibility=
"gone"
android:text=
"@string/application_action_waiting"
/>
</RelativeLayout>
</LinearLayout>
\ No newline at end of file
res/layout/contact_list_fragment.xml
0 → 100644
View file @
ff6d0d8f
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2013, Redsolution LTD. All rights reserved.
This file is part of Xabber project; you can redistribute it and/or
modify it under the terms of the GNU General Public License, Version 3.
Xabber is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License,
along with this program. If not, see http://www.gnu.org/licenses/.
-->
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<ListView
android:id=
"@android:id/list"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:textFilterEnabled=
"true"
/>
<RelativeLayout
android:id=
"@+id/info"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:gravity=
"center_vertical"
>
<ImageView
android:id=
"@+id/connected"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:src=
"@drawable/ic_connect"
tools:ignore=
"ContentDescription"
/>
<ImageView
android:id=
"@+id/disconnected"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:src=
"@drawable/ic_disconnect"
tools:ignore=
"ContentDescription"
/>
<TextView
android:id=
"@+id/text"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@id/connected"
android:layout_centerHorizontal=
"true"
android:text=
"@string/application_state_starting"
android:textColor=
"?android:attr/textColorSecondary"
/>
<Button
android:id=
"@+id/button"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@id/text"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"20dip"
android:text=
"@string/application_action_waiting"
/>
</RelativeLayout>
</RelativeLayout>
src/com/xabber/android/ui/ContactList.java
View file @
ff6d0d8f
This diff is collapsed.
Click to expand it.
src/com/xabber/android/ui/ContactListFragment.java
0 → 100644
View file @
ff6d0d8f
package
com
.
xabber
.
android
.
ui
;
import
java.util.Collection
;
import
android.os.Bundle
;
import
android.os.SystemClock
;
import
android.support.v4.app.Fragment
;
import
android.view.ContextMenu
;
import
android.view.ContextMenu.ContextMenuInfo
;
import
android.view.LayoutInflater
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.AdapterView
;
import
android.widget.AdapterView.AdapterContextMenuInfo
;
import
android.widget.AdapterView.OnItemClickListener
;
import
android.widget.ListView
;
import
com.xabber.android.data.Application
;
import
com.xabber.android.data.SettingsManager
;
import
com.xabber.android.data.account.AccountManager
;
import
com.xabber.android.data.account.OnAccountChangedListener
;
import
com.xabber.android.data.entity.BaseEntity
;
import
com.xabber.android.data.message.OnChatChangedListener
;
import
com.xabber.android.data.roster.AbstractContact
;
import
com.xabber.android.data.roster.OnContactChangedListener
;
import
com.xabber.android.ui.adapter.AccountConfiguration
;
import
com.xabber.android.ui.adapter.ContactListAdapter
;
import
com.xabber.android.ui.adapter.GroupConfiguration
;
import
com.xabber.android.ui.adapter.UpdatableAdapter
;
import
com.xabber.android.ui.helper.ContextMenuHelper
;
import
com.xabber.androiddev.R
;
public
class
ContactListFragment
extends
Fragment
implements
OnAccountChangedListener
,
OnContactChangedListener
,
OnChatChangedListener
,
OnItemClickListener
{
private
ContactListAdapter
adapter
;
private
ListView
listView
;
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
View
view
=
inflater
.
inflate
(
R
.
layout
.
contact_list_fragment
,
container
,
false
);
listView
=
(
ListView
)
view
.
findViewById
(
android
.
R
.
id
.
list
);
listView
.
setOnItemClickListener
(
this
);
listView
.
setItemsCanFocus
(
true
);
registerForContextMenu
(
listView
);
adapter
=
new
ContactListAdapter
(
getActivity
(),
listView
,
view
.
findViewById
(
R
.
id
.
info
));
listView
.
setAdapter
(
adapter
);
return
view
;
}
@Override
public
void
onResume
()
{
super
.
onResume
();
Application
.
getInstance
().
addUIListener
(
OnAccountChangedListener
.
class
,
this
);
Application
.
getInstance
().
addUIListener
(
OnContactChangedListener
.
class
,
this
);
Application
.
getInstance
().
addUIListener
(
OnChatChangedListener
.
class
,
this
);
adapter
.
onChange
();
}
@Override
public
void
onPause
()
{
super
.
onPause
();
unregisterListeners
();
}
@Override
public
void
onCreateContextMenu
(
ContextMenu
menu
,
View
view
,
ContextMenuInfo
menuInfo
)
{
AdapterContextMenuInfo
info
=
(
AdapterContextMenuInfo
)
menuInfo
;
BaseEntity
baseEntity
=
(
BaseEntity
)
listView
.
getItemAtPosition
(
info
.
position
);
if
(
baseEntity
instanceof
AbstractContact
)
{
ContextMenuHelper
.
createContactContextMenu
(
getActivity
(),
adapter
,
(
AbstractContact
)
baseEntity
,
menu
);
}
else
if
(
baseEntity
instanceof
AccountConfiguration
)
{
ContextMenuHelper
.
createAccountContextMenu
(
getActivity
(),
adapter
,
baseEntity
.
getAccount
(),
menu
);
}
else
if
(
baseEntity
instanceof
GroupConfiguration
)
{
ContextMenuHelper
.
createGroupContextMenu
(
getActivity
(),
adapter
,
baseEntity
.
getAccount
(),
baseEntity
.
getUser
(),
menu
);
}
else
throw
new
IllegalStateException
();
}
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
Object
object
=
parent
.
getAdapter
().
getItem
(
position
);
if
(
object
instanceof
AbstractContact
)
{
((
OnContactClickListener
)
getActivity
())
.
onContactClick
((
AbstractContact
)
object
);
}
else
if
(
object
instanceof
GroupConfiguration
)
{
GroupConfiguration
groupConfiguration
=
(
GroupConfiguration
)
object
;
adapter
.
setExpanded
(
groupConfiguration
.
getAccount
(),
groupConfiguration
.
getUser
(),
!
groupConfiguration
.
isExpanded
());
}
else
throw
new
IllegalStateException
();
}
@Override
public
void
onContactsChanged
(
Collection
<
BaseEntity
>
addresses
)
{
adapter
.
refreshRequest
();
}
@Override
public
void
onAccountsChanged
(
Collection
<
String
>
accounts
)
{
adapter
.
refreshRequest
();
}
@Override
public
void
onChatChanged
(
String
account
,
String
user
,
boolean
incoming
)
{
if
(
incoming
)
adapter
.
refreshRequest
();
}
/**
* Force stop contact list updates before pause or application close.
*/
void
unregisterListeners
()
{
Application
.
getInstance
().
removeUIListener
(
OnAccountChangedListener
.
class
,
this
);
Application
.
getInstance
().
removeUIListener
(
OnContactChangedListener
.
class
,
this
);
Application
.
getInstance
().
removeUIListener
(
OnChatChangedListener
.
class
,
this
);
adapter
.
removeRefreshRequests
();
}
UpdatableAdapter
getAdapter
()
{
return
adapter
;
}
/**
* Scroll contact list to specified account.
*
* @param account
*/
void
scrollTo
(
String
account
)
{
long
count
=
listView
.
getCount
();
for
(
int
position
=
0
;
position
<
(
int
)
count
;
position
++)
{
BaseEntity
baseEntity
=
(
BaseEntity
)
listView
.
getItemAtPosition
(
position
);
if
(
baseEntity
!=
null
&&
baseEntity
instanceof
AccountConfiguration
&&
baseEntity
.
getAccount
().
equals
(
account
))
{
stopMovement
();
listView
.
setSelection
(
position
);
break
;
}
}
}
/**
* Filter out contact list for selected account.
*
* @param account
*/
void
setSelectedAccount
(
String
account
)
{
if
(
account
.
equals
(
AccountManager
.
getInstance
().
getSelectedAccount
()))
SettingsManager
.
setContactsSelectedAccount
(
""
);
else
SettingsManager
.
setContactsSelectedAccount
(
account
);
stopMovement
();
adapter
.
onChange
();
}
/**
* Scroll to the top of contact list.
*/
void
scrollUp
()
{
if
(
listView
.
getCount
()
>
0
)
listView
.
setSelection
(
0
);
stopMovement
();
}
/**
* Stop fling scrolling.
*/
private
void
stopMovement
()
{
listView
.
onTouchEvent
(
MotionEvent
.
obtain
(
SystemClock
.
uptimeMillis
(),
SystemClock
.
uptimeMillis
(),
MotionEvent
.
ACTION_CANCEL
,
0
,
0
,
0
));
}
public
interface
OnContactClickListener
{
void
onContactClick
(
AbstractContact
contact
);
}
}
src/com/xabber/android/ui/adapter/ContactListAdapter.java
View file @
ff6d0d8f
...
@@ -121,10 +121,11 @@ public class ContactListAdapter extends
...
@@ -121,10 +121,11 @@ public class ContactListAdapter extends
*/
*/
private
Date
nextRefresh
;
private
Date
nextRefresh
;
public
ContactListAdapter
(
Activity
activity
,
ListView
listView
)
{
public
ContactListAdapter
(
Activity
activity
,
ListView
listView
,
View
infoView
)
{
super
(
activity
,
listView
,
new
ChatContactInflater
(
activity
),
super
(
activity
,
listView
,
new
ChatContactInflater
(
activity
),
GroupManager
.
getInstance
());
GroupManager
.
getInstance
());
infoView
=
activity
.
findViewById
(
R
.
id
.
info
)
;
this
.
infoView
=
infoView
;
if
(
infoView
!=
null
)
{
if
(
infoView
!=
null
)
{
connectedView
=
infoView
.
findViewById
(
R
.
id
.
connected
);
connectedView
=
infoView
.
findViewById
(
R
.
id
.
connected
);
disconnectedView
=
infoView
.
findViewById
(
R
.
id
.
disconnected
);
disconnectedView
=
infoView
.
findViewById
(
R
.
id
.
disconnected
);
...
...
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