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
52ffd997
Commit
52ffd997
authored
May 23, 2013
by
Alexander Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace group rename dialog builder with dialog fragment.
parent
708f2871
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
333 additions
and
21 deletions
+333
-21
ContactList.java
src/com/xabber/android/ui/ContactList.java
+7
-21
AbstractDialogFragment.java
src/com/xabber/android/ui/dialog/AbstractDialogFragment.java
+76
-0
ConfirmDialogFragment.java
src/com/xabber/android/ui/dialog/ConfirmDialogFragment.java
+166
-0
GroupRenameDialogFragment.java
...m/xabber/android/ui/dialog/GroupRenameDialogFragment.java
+84
-0
No files found.
src/com/xabber/android/ui/ContactList.java
View file @
52ffd997
...
...
@@ -83,7 +83,7 @@ import com.xabber.android.ui.dialog.AccountChooseDialogBuilder;
import
com.xabber.android.ui.dialog.ConfirmDialogBuilder
;
import
com.xabber.android.ui.dialog.ConfirmDialogListener
;
import
com.xabber.android.ui.dialog.DialogBuilder
;
import
com.xabber.android.ui.dialog.GroupRenameDialog
Builder
;
import
com.xabber.android.ui.dialog.GroupRenameDialog
Fragment
;
import
com.xabber.android.ui.helper.ManagedListActivity
;
import
com.xabber.androiddev.R
;
import
com.xabber.xmpp.address.Jid
;
...
...
@@ -152,7 +152,6 @@ public class ContactList extends ManagedListActivity implements
private
static
final
int
DIALOG_DELETE_CONTACT_ID
=
0x50
;
private
static
final
int
DIALOG_DELETE_GROUP_ID
=
0x51
;
private
static
final
int
DIALOG_RENAME_GROUP_ID
=
0x52
;
private
static
final
int
DIALOG_START_AT_BOOT_ID
=
0x53
;
private
static
final
int
DIALOG_CONTACT_INTEGRATION_ID
=
0x54
;
private
static
final
int
DIALOG_OPEN_WITH_ACCOUNT_ID
=
0x55
;
...
...
@@ -709,7 +708,12 @@ public class ContactList extends ManagedListActivity implements
// Group
case
CONTEXT_MENU_GROUP_RENAME_ID:
showDialog
(
DIALOG_RENAME_GROUP_ID
);
GroupRenameDialogFragment
.
newInstance
(
actionWithAccount
==
GroupManager
.
NO_ACCOUNT
?
null
:
actionWithAccount
,
actionWithGroup
==
GroupManager
.
NO_GROUP
?
null
:
actionWithGroup
).
show
(
getSupportFragmentManager
(),
"GROUP_RENAME"
);
return
true
;
case
CONTEXT_MENU_GROUP_DELETE_ID:
showDialog
(
DIALOG_DELETE_GROUP_ID
);
...
...
@@ -792,10 +796,6 @@ public class ContactList extends ManagedListActivity implements
.
setMessage
(
getString
(
R
.
string
.
group_remove_confirm
,
actionWithGroup
)).
create
();
case
DIALOG_RENAME_GROUP_ID:
return
new
GroupRenameDialogBuilder
(
this
,
DIALOG_RENAME_GROUP_ID
,
this
,
actionWithGroup
==
GroupManager
.
NO_GROUP
?
""
:
actionWithGroup
).
create
();
case
DIALOG_START_AT_BOOT_ID:
return
new
ConfirmDialogBuilder
(
this
,
DIALOG_START_AT_BOOT_ID
,
this
)
.
setMessage
(
getString
(
R
.
string
.
start_at_boot_suggest
))
...
...
@@ -1048,20 +1048,6 @@ public class ContactList extends ManagedListActivity implements
Application
.
getInstance
().
onError
(
e
);
}
break
;
case
DIALOG_RENAME_GROUP_ID:
String
name
=
((
GroupRenameDialogBuilder
)
dialogBuilder
).
getName
();
String
source
=
actionWithGroup
==
GroupManager
.
NO_GROUP
?
null
:
actionWithGroup
;
try
{
if
(
actionWithAccount
==
GroupManager
.
NO_ACCOUNT
)
RosterManager
.
getInstance
().
renameGroup
(
source
,
name
);
else
RosterManager
.
getInstance
().
renameGroup
(
actionWithAccount
,
source
,
name
);
}
catch
(
NetworkException
e
)
{
Application
.
getInstance
().
onError
(
e
);
}
break
;
case
DIALOG_START_AT_BOOT_ID:
SettingsManager
.
setStartAtBootSuggested
();
SettingsManager
.
setConnectionStartAtBoot
(
true
);
...
...
src/com/xabber/android/ui/dialog/
GroupRenameDialogBuilder
.java
→
src/com/xabber/android/ui/dialog/
AbstractDialogFragment
.java
View file @
52ffd997
...
...
@@ -14,42 +14,63 @@
*/
package
com
.
xabber
.
android
.
ui
.
dialog
;
import
android.app.Activity
;
import
android.content.DialogInterface
;
import
android.view.View
;
import
android.widget.EditText
;
import
android.widget.Toast
;
import
com.xabber.androiddev.R
;
public
class
GroupRenameDialogBuilder
extends
ConfirmDialogBuilder
{
private
final
EditText
nameView
;
public
GroupRenameDialogBuilder
(
Activity
activity
,
int
dialogId
,
ConfirmDialogListener
listener
,
String
group
)
{
super
(
activity
,
dialogId
,
listener
);
setTitle
(
R
.
string
.
group_rename
);
View
layout
=
activity
.
getLayoutInflater
().
inflate
(
R
.
layout
.
group_name
,
null
);
nameView
=
(
EditText
)
layout
.
findViewById
(
R
.
id
.
group_name
);
nameView
.
setText
(
group
);
setView
(
layout
);
import
android.app.AlertDialog
;
import
android.app.AlertDialog.Builder
;
import
android.app.Dialog
;
import
android.os.Bundle
;
import
android.support.v4.app.DialogFragment
;
/**
* Base dialog fragment.
*
* CONVENTION: Subclass should implement <code>newInstance</code> static method.
* Activities or Fragments should use this method to instantiate DialogFragment.
*
* @author alexander.ivanov
*
*/
public
abstract
class
AbstractDialogFragment
extends
DialogFragment
{
private
Bundle
initArguments
()
{
Bundle
bundle
=
getArguments
();
if
(
bundle
==
null
)
{
bundle
=
new
Bundle
();
setArguments
(
bundle
);
}
return
bundle
;
}
protected
AbstractDialogFragment
putAgrument
(
String
key
,
String
value
)
{
initArguments
().
putString
(
key
,
value
);
return
this
;
}
protected
AbstractDialogFragment
putAgrument
(
String
key
,
boolean
value
)
{
initArguments
().
putBoolean
(
key
,
value
);
return
this
;
}
@Override
public
void
onAccept
(
DialogInterface
dialog
)
{
if
(
""
.
equals
(
getName
()))
{
Toast
.
makeText
(
activity
,
activity
.
getString
(
R
.
string
.
group_is_empty
),
Toast
.
LENGTH_LONG
).
show
();
return
;
}
super
.
onAccept
(
dialog
);
public
Dialog
onCreateDialog
(
Bundle
savedInstanceState
)
{
Builder
builder
=
getBuilder
();
return
getDialog
(
builder
);
}
public
String
getName
()
{
return
nameView
.
getText
().
toString
();
/**
* Constructs {@link AlertDialog.Builder} instance.
*
* @return
*/
protected
abstract
Builder
getBuilder
();
/**
* Constructs {@link Dialog} instance.
*
* @param builder
* @return
*/
protected
Dialog
getDialog
(
Builder
builder
)
{
return
builder
.
create
();
}
}
src/com/xabber/android/ui/dialog/ConfirmDialogFragment.java
0 → 100644
View file @
52ffd997
/**
* 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/.
*/
package
com
.
xabber
.
android
.
ui
.
dialog
;
import
android.annotation.TargetApi
;
import
android.app.AlertDialog
;
import
android.app.AlertDialog.Builder
;
import
android.app.Dialog
;
import
android.content.DialogInterface
;
import
android.content.DialogInterface.OnClickListener
;
import
android.content.DialogInterface.OnShowListener
;
import
android.os.Build
;
import
android.view.View
;
import
android.widget.Button
;
/**
* Base yes / no dialog fragment.
*
* Provides callback methods and option to abort dialog dismissing on button
* click (starting from FROYO version).
*
* @author alexander.ivanov
*
*/
public
abstract
class
ConfirmDialogFragment
extends
AbstractDialogFragment
{
private
final
OnClickListener
positiveListener
=
new
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
if
(
onPositiveClick
())
supportDismiss
(
dialog
);
}
};
private
final
OnClickListener
neutralListener
=
new
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
if
(
onNegativeClicked
())
supportDismiss
(
dialog
);
}
};
private
final
OnClickListener
negativeListener
=
new
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
if
(
onNegativeClicked
())
supportDismiss
(
dialog
);
}
};
@Override
protected
Dialog
getDialog
(
Builder
builder
)
{
if
(
hasPositiveButton
())
builder
.
setPositiveButton
(
getPositiveTextId
(),
positiveListener
);
if
(
hasNeutralButton
())
builder
.
setNeutralButton
(
getNeutralTextId
(),
neutralListener
);
if
(
hasNegativeButton
())
builder
.
setNegativeButton
(
getNegativeTextId
(),
negativeListener
);
AlertDialog
dialog
=
builder
.
create
();
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
FROYO
)
setOnShowListener
(
dialog
);
return
dialog
;
}
private
void
supportDismiss
(
DialogInterface
dialog
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
FROYO
)
dialog
.
dismiss
();
}
@TargetApi
(
Build
.
VERSION_CODES
.
FROYO
)
private
void
setOnShowListener
(
final
AlertDialog
alertDialog
)
{
alertDialog
.
setOnShowListener
(
new
OnShowListener
()
{
private
void
setListener
(
final
int
whichButton
,
final
OnClickListener
listener
)
{
Button
button
=
alertDialog
.
getButton
(
whichButton
);
if
(
button
==
null
)
return
;
button
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
listener
.
onClick
(
alertDialog
,
whichButton
);
}
});
}
@Override
public
void
onShow
(
DialogInterface
dialog
)
{
setListener
(
AlertDialog
.
BUTTON_POSITIVE
,
positiveListener
);
setListener
(
AlertDialog
.
BUTTON_NEUTRAL
,
neutralListener
);
setListener
(
AlertDialog
.
BUTTON_NEGATIVE
,
negativeListener
);
}
});
}
protected
boolean
hasPositiveButton
()
{
return
true
;
}
protected
boolean
hasNeutralButton
()
{
return
false
;
}
protected
boolean
hasNegativeButton
()
{
return
true
;
}
protected
int
getPositiveTextId
()
{
return
android
.
R
.
string
.
ok
;
}
protected
int
getNeutralTextId
()
{
return
android
.
R
.
string
.
unknownName
;
}
protected
int
getNegativeTextId
()
{
return
android
.
R
.
string
.
cancel
;
}
/**
* Processes positive button click.
*
* @return Whether dialog can be dismissed.
*/
protected
boolean
onPositiveClick
()
{
return
true
;
}
/**
* Processes neutral button click.
*
* @return Whether dialog can be dismissed.
*/
protected
boolean
onNeutralClicked
()
{
return
true
;
}
/**
* Processes negative button click.
*
* @return Whether dialog can be dismissed.
*/
protected
boolean
onNegativeClicked
()
{
return
true
;
}
}
src/com/xabber/android/ui/dialog/GroupRenameDialogFragment.java
0 → 100644
View file @
52ffd997
/**
* 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/.
*/
package
com
.
xabber
.
android
.
ui
.
dialog
;
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.android.data.Application
;
import
com.xabber.android.data.NetworkException
;
import
com.xabber.android.data.roster.RosterManager
;
import
com.xabber.androiddev.R
;
public
class
GroupRenameDialogFragment
extends
ConfirmDialogFragment
{
private
static
final
String
ACCOUNT
=
"ACCOUNT"
;
private
static
final
String
GROUP
=
"GROUP"
;
/**
* @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
(
String
account
,
String
group
)
{
return
new
GroupRenameDialogFragment
().
putAgrument
(
ACCOUNT
,
account
)
.
putAgrument
(
GROUP
,
group
);
}
private
String
group
;
private
String
account
;
private
EditText
nameView
;
@Override
protected
Builder
getBuilder
()
{
group
=
getArguments
().
getString
(
GROUP
);
account
=
getArguments
().
getString
(
ACCOUNT
);
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
getActivity
());
builder
.
setTitle
(
R
.
string
.
group_rename
);
View
layout
=
getActivity
().
getLayoutInflater
().
inflate
(
R
.
layout
.
group_name
,
null
);
nameView
=
(
EditText
)
layout
.
findViewById
(
R
.
id
.
group_name
);
nameView
.
setText
(
group
==
null
?
""
:
group
);
builder
.
setView
(
layout
);
return
builder
;
}
@Override
protected
boolean
onPositiveClick
()
{
String
newName
=
nameView
.
getText
().
toString
();
if
(
""
.
equals
(
newName
))
{
Toast
.
makeText
(
getActivity
(),
getString
(
R
.
string
.
group_is_empty
),
Toast
.
LENGTH_LONG
).
show
();
return
false
;
}
try
{
if
(
account
==
null
)
RosterManager
.
getInstance
().
renameGroup
(
group
,
newName
);
else
RosterManager
.
getInstance
()
.
renameGroup
(
account
,
group
,
newName
);
}
catch
(
NetworkException
e
)
{
Application
.
getInstance
().
onError
(
e
);
}
return
true
;
}
}
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