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
52d0e56d
Commit
52d0e56d
authored
May 24, 2013
by
Alexander Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement group add using DialogFragment.
parent
de3f566b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
40 deletions
+103
-40
ContactAdd.java
src/com/xabber/android/ui/ContactAdd.java
+0
-3
GroupListActivity.java
src/com/xabber/android/ui/GroupListActivity.java
+14
-37
AbstractDialogFragment.java
src/com/xabber/android/ui/dialog/AbstractDialogFragment.java
+8
-0
GroupAddDialogFragment.java
src/com/xabber/android/ui/dialog/GroupAddDialogFragment.java
+81
-0
No files found.
src/com/xabber/android/ui/ContactAdd.java
View file @
52d0e56d
...
...
@@ -205,7 +205,6 @@ public class ContactAdd extends GroupListActivity implements
@Override
public
void
onAccept
(
DialogBuilder
dialogBuilder
)
{
super
.
onAccept
(
dialogBuilder
);
switch
(
dialogBuilder
.
getDialogId
())
{
case
DIALOG_SUBSCRIPTION_REQUEST_ID:
try
{
...
...
@@ -222,7 +221,6 @@ public class ContactAdd extends GroupListActivity implements
@Override
public
void
onDecline
(
DialogBuilder
dialogBuilder
)
{
super
.
onDecline
(
dialogBuilder
);
switch
(
dialogBuilder
.
getDialogId
())
{
case
DIALOG_SUBSCRIPTION_REQUEST_ID:
try
{
...
...
@@ -239,7 +237,6 @@ public class ContactAdd extends GroupListActivity implements
@Override
public
void
onCancel
(
DialogBuilder
dialogBuilder
)
{
super
.
onCancel
(
dialogBuilder
);
switch
(
dialogBuilder
.
getDialogId
())
{
case
DIALOG_SUBSCRIPTION_REQUEST_ID:
finish
();
...
...
src/com/xabber/android/ui/GroupListActivity.java
View file @
52d0e56d
...
...
@@ -18,7 +18,6 @@ import java.util.ArrayList;
import
java.util.Collection
;
import
java.util.Collections
;
import
android.app.Dialog
;
import
android.os.Bundle
;
import
android.view.LayoutInflater
;
import
android.view.Menu
;
...
...
@@ -30,9 +29,8 @@ import android.widget.ArrayAdapter;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
com.xabber.android.ui.dialog.ConfirmDialogListener
;
import
com.xabber.android.ui.dialog.DialogBuilder
;
import
com.xabber.android.ui.dialog.GroupAddDialogBuilder
;
import
com.xabber.android.ui.dialog.GroupAddDialogFragment
;
import
com.xabber.android.ui.dialog.GroupAddDialogFragment.OnGroupAddConfirmed
;
import
com.xabber.android.ui.helper.ManagedListActivity
;
import
com.xabber.androiddev.R
;
...
...
@@ -43,15 +41,13 @@ import com.xabber.androiddev.R;
*
*/
public
abstract
class
GroupListActivity
extends
ManagedListActivity
implements
ConfirmDialogListener
,
OnItemClickListener
{
OnItemClickListener
,
OnGroupAddConfirmed
{
private
static
final
String
SAVED_GROUPS
=
"com.xabber.android.ui.ContactList.SAVED_GROUPS"
;
private
static
final
String
SAVED_SELECTED
=
"com.xabber.android.ui.ContactList.SAVED_SELECTED"
;
static
final
int
OPTION_MENU_ADD_GROUP_ID
=
1
;
static
final
int
DIALOG_ADD_GROUP_ID
=
0x10
;
private
ArrayAdapter
<
String
>
arrayAdapter
;
private
ListView
listView
;
...
...
@@ -148,29 +144,22 @@ public abstract class GroupListActivity extends ManagedListActivity implements
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
switch
(
item
.
getItemId
())
{
case
OPTION_MENU_ADD_GROUP_ID:
show
Dialog
(
DIALOG_ADD_GROUP_ID
);
show
GroupAddDialog
(
);
return
true
;
}
return
false
;
}
@Override
protected
Dialog
onCreateDialog
(
int
id
)
{
super
.
onCreateDialog
(
id
);
switch
(
id
)
{
case
DIALOG_ADD_GROUP_ID:
return
new
GroupAddDialogBuilder
(
this
,
DIALOG_ADD_GROUP_ID
,
this
,
getGroups
()).
create
();
default
:
return
null
;
}
private
void
showGroupAddDialog
()
{
GroupAddDialogFragment
.
newInstance
(
getGroups
()).
show
(
getSupportFragmentManager
(),
"GROUP-ADD"
);
}
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
if
(
listView
.
getItemAtPosition
(
position
)
==
null
)
// Footer
show
Dialog
(
DIALOG_ADD_GROUP_ID
);
show
GroupAddDialog
(
);
}
/**
...
...
@@ -192,24 +181,12 @@ public abstract class GroupListActivity extends ManagedListActivity implements
}
@Override
public
void
onAccept
(
DialogBuilder
dialog
)
{
switch
(
dialog
.
getDialogId
())
{
case
DIALOG_ADD_GROUP_ID:
String
group
=
((
GroupAddDialogBuilder
)
dialog
).
getName
();
ArrayList
<
String
>
groups
=
getGroups
();
groups
.
add
(
group
);
ArrayList
<
String
>
selected
=
getSelected
();
selected
.
add
(
group
);
setGroups
(
groups
,
selected
);
}
}
@Override
public
void
onDecline
(
DialogBuilder
dialog
)
{
}
@Override
public
void
onCancel
(
DialogBuilder
dialog
)
{
public
void
onGroupAddConfirmed
(
String
group
)
{
ArrayList
<
String
>
groups
=
getGroups
();
groups
.
add
(
group
);
ArrayList
<
String
>
selected
=
getSelected
();
selected
.
add
(
group
);
setGroups
(
groups
,
selected
);
}
}
src/com/xabber/android/ui/dialog/AbstractDialogFragment.java
View file @
52d0e56d
...
...
@@ -14,6 +14,8 @@
*/
package
com
.
xabber
.
android
.
ui
.
dialog
;
import
java.util.ArrayList
;
import
android.app.AlertDialog
;
import
android.app.AlertDialog.Builder
;
import
android.app.Dialog
;
...
...
@@ -45,6 +47,12 @@ public abstract class AbstractDialogFragment extends DialogFragment {
return
this
;
}
protected
AbstractDialogFragment
putAgrument
(
String
key
,
ArrayList
<
String
>
value
)
{
initArguments
().
putStringArrayList
(
key
,
value
);
return
this
;
}
protected
AbstractDialogFragment
putAgrument
(
String
key
,
boolean
value
)
{
initArguments
().
putBoolean
(
key
,
value
);
return
this
;
...
...
src/com/xabber/android/ui/dialog/GroupAddDialog
Builder
.java
→
src/com/xabber/android/ui/dialog/GroupAddDialog
Fragment
.java
View file @
52d0e56d
...
...
@@ -14,51 +14,68 @@
*/
package
com
.
xabber
.
android
.
ui
.
dialog
;
import
java.util.
Collection
;
import
java.util.
ArrayList
;
import
android.app.Activity
;
import
android.content.DialogInterface
;
import
android.app.AlertDialog
;
import
android.app.AlertDialog.Builder
;
import
android.support.v4.app.DialogFragment
;
import
android.view.View
;
import
android.widget.EditText
;
import
android.widget.Toast
;
import
com.xabber.androiddev.R
;
public
class
GroupAddDialog
Builder
extends
ConfirmDialogBuilder
{
public
class
GroupAddDialog
Fragment
extends
ConfirmDialogFragment
{
private
final
Collection
<
String
>
groups
;
private
final
EditText
nameView
;
private
static
final
String
GROUPS
=
"GROUPS"
;
public
GroupAddDialogBuilder
(
Activity
activity
,
int
dialogId
,
ConfirmDialogListener
listener
,
Collection
<
String
>
groups
)
{
super
(
activity
,
dialogId
,
listener
);
setTitle
(
R
.
string
.
group_add
);
this
.
groups
=
groups
;
View
layout
=
activity
.
getLayoutInflater
().
inflate
(
R
.
layout
.
group_name
,
null
);
/**
* @param account
* can be <code>null</code> to be used for all accounts.
* @param group
* can be <code>null</code> to be used for "no group".
* @return
*/
public
static
DialogFragment
newInstance
(
ArrayList
<
String
>
groups
)
{
return
new
GroupAddDialogFragment
().
putAgrument
(
GROUPS
,
groups
);
}
private
ArrayList
<
String
>
groups
;
private
EditText
nameView
;
@Override
protected
Builder
getBuilder
()
{
groups
=
getArguments
().
getStringArrayList
(
GROUPS
);
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
getActivity
());
builder
.
setTitle
(
R
.
string
.
group_add
);
View
layout
=
getActivity
().
getLayoutInflater
().
inflate
(
R
.
layout
.
group_name
,
null
);
nameView
=
(
EditText
)
layout
.
findViewById
(
R
.
id
.
group_name
);
setView
(
layout
);
builder
.
setView
(
layout
);
return
builder
;
}
@Override
public
void
onAccept
(
DialogInterface
dialog
)
{
String
name
=
nameView
.
getText
().
toString
();
if
(
""
.
equals
(
name
))
{
Toast
.
makeText
(
activity
,
activity
.
getString
(
R
.
string
.
group_is_empty
),
protected
boolean
onPositiveClick
()
{
String
group
=
nameView
.
getText
().
toString
();
if
(
""
.
equals
(
group
))
{
Toast
.
makeText
(
getActivity
(),
getString
(
R
.
string
.
group_is_empty
),
Toast
.
LENGTH_LONG
).
show
();
return
;
return
false
;
}
if
(
groups
.
contains
(
name
))
{
Toast
.
makeText
(
activity
,
activity
.
getString
(
R
.
string
.
group_exists
),
if
(
groups
.
contains
(
group
))
{
Toast
.
makeText
(
getActivity
(),
getString
(
R
.
string
.
group_exists
),
Toast
.
LENGTH_LONG
).
show
();
return
;
return
false
;
}
super
.
onAccept
(
dialog
);
((
OnGroupAddConfirmed
)
getActivity
()).
onGroupAddConfirmed
(
group
);
return
true
;
}
public
String
getName
()
{
return
nameView
.
getText
().
toString
();
public
interface
OnGroupAddConfirmed
{
void
onGroupAddConfirmed
(
String
group
);
}
}
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