Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-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
AloqaIM-Android
Commits
d9b4841d
Commit
d9b4841d
authored
Dec 09, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
createChannel, createPrivateGroup, createDirectMessage
parent
ce7d453d
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
102 additions
and
20 deletions
+102
-20
MethodCallHelper.java
...c/main/java/chat/rocket/android/api/MethodCallHelper.java
+21
-0
AbstractAddRoomDialogFragment.java
...ragment/sidebar/dialog/AbstractAddRoomDialogFragment.java
+30
-0
AddChannelDialogFragment.java
...oid/fragment/sidebar/dialog/AddChannelDialogFragment.java
+13
-9
AddDirectMessageDialogFragment.java
...agment/sidebar/dialog/AddDirectMessageDialogFragment.java
+9
-1
SuggestUserAdapter.java
...droid/layouthelper/sidebar/dialog/SuggestUserAdapter.java
+5
-3
RealmAutoCompleteAdapter.java
...rocket/android/realm_helper/RealmAutoCompleteAdapter.java
+24
-7
No files found.
app/src/main/java/chat/rocket/android/api/MethodCallHelper.java
View file @
d9b4841d
...
...
@@ -283,6 +283,27 @@ public class MethodCallHelper {
.
onSuccessTask
(
CONVERT_TO_JSON_OBJECT
);
}
public
Task
<
Void
>
createChannel
(
final
String
name
,
final
boolean
readOnly
)
{
return
call
(
"createChannel"
,
TIMEOUT_MS
,
()
->
new
JSONArray
()
.
put
(
name
)
.
put
(
new
JSONArray
())
.
put
(
readOnly
))
.
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
public
Task
<
Void
>
createPrivateGroup
(
final
String
name
,
final
boolean
readOnly
)
{
return
call
(
"createPrivateGroup"
,
TIMEOUT_MS
,
()
->
new
JSONArray
()
.
put
(
name
)
.
put
(
new
JSONArray
())
.
put
(
readOnly
))
.
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
public
Task
<
Void
>
createDirectMessage
(
final
String
username
)
{
return
call
(
"createDirectMessage"
,
TIMEOUT_MS
,
()
->
new
JSONArray
().
put
(
username
))
.
onSuccessTask
(
task
->
Task
.
forResult
(
null
));
}
/**
* send message.
*/
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/dialog/AbstractAddRoomDialogFragment.java
View file @
d9b4841d
...
...
@@ -5,6 +5,11 @@ import android.os.Bundle;
import
android.support.annotation.LayoutRes
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.view.View
;
import
android.widget.Toast
;
import
bolts.Task
;
import
chat.rocket.android.R
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
com.trello.rxlifecycle.components.support.RxAppCompatDialogFragment
;
...
...
@@ -12,6 +17,7 @@ import com.trello.rxlifecycle.components.support.RxAppCompatDialogFragment;
public
abstract
class
AbstractAddRoomDialogFragment
extends
RxAppCompatDialogFragment
{
protected
RealmHelper
realmHelper
;
protected
MethodCallHelper
methodCall
;
protected
String
hostname
;
protected
@LayoutRes
abstract
int
getLayout
();
...
...
@@ -30,6 +36,7 @@ public abstract class AbstractAddRoomDialogFragment extends RxAppCompatDialogFra
protected
void
handleArgs
(
@NonNull
Bundle
args
)
{
String
serverConfigId
=
args
.
getString
(
"serverConfigId"
);
realmHelper
=
RealmStore
.
get
(
serverConfigId
);
methodCall
=
new
MethodCallHelper
(
getContext
(),
serverConfigId
);
hostname
=
args
.
getString
(
"hostname"
);
}
...
...
@@ -38,4 +45,27 @@ public abstract class AbstractAddRoomDialogFragment extends RxAppCompatDialogFra
dialog
.
setContentView
(
getLayout
());
onSetupDialog
();
}
protected
final
void
showOrHideWaitingView
(
boolean
show
)
{
View
waiting
=
getDialog
().
findViewById
(
R
.
id
.
waiting
);
if
(
waiting
!=
null
)
{
waiting
.
setVisibility
(
show
?
View
.
VISIBLE
:
View
.
GONE
);
}
}
protected
abstract
Task
<
Void
>
getMethodCallForSubmitAction
();
protected
final
void
createRoom
()
{
showOrHideWaitingView
(
true
);
getMethodCallForSubmitAction
().
continueWith
(
task
->
{
showOrHideWaitingView
(
false
);
if
(
task
.
isFaulted
())
{
Toast
.
makeText
(
getContext
(),
task
.
getError
().
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
dismiss
();
}
return
null
;
});
}
}
app/src/main/java/chat/rocket/android/fragment/sidebar/dialog/AddChannelDialogFragment.java
View file @
d9b4841d
...
...
@@ -3,6 +3,7 @@ package chat.rocket.android.fragment.sidebar.dialog;
import
android.view.View
;
import
android.widget.CompoundButton
;
import
android.widget.TextView
;
import
bolts.Task
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.TextUtils
;
import
com.jakewharton.rxbinding.view.RxView
;
...
...
@@ -26,13 +27,7 @@ public class AddChannelDialogFragment extends AbstractAddRoomDialogFragment {
.
compose
(
bindToLifecycle
())
.
subscribe
(
RxView
.
enabled
(
buttonAddChannel
));
buttonAddChannel
.
setOnClickListener
(
view
->
{
TextView
channelNameText
=
(
TextView
)
getDialog
().
findViewById
(
R
.
id
.
editor_channel_name
);
String
channelName
=
channelNameText
.
getText
().
toString
();
boolean
isPrivate
=
isChecked
(
R
.
id
.
checkbox_private
);
boolean
isReadOnly
=
isChecked
(
R
.
id
.
checkbox_read_only
);
createChannel
(
channelName
,
isPrivate
,
isReadOnly
);
});
buttonAddChannel
.
setOnClickListener
(
view
->
createRoom
());
}
private
boolean
isChecked
(
int
viewId
)
{
...
...
@@ -40,7 +35,16 @@ public class AddChannelDialogFragment extends AbstractAddRoomDialogFragment {
return
check
.
isChecked
();
}
private
void
createChannel
(
String
name
,
boolean
isPrivate
,
boolean
isReadOnly
)
{
@Override
protected
Task
<
Void
>
getMethodCallForSubmitAction
()
{
TextView
channelNameText
=
(
TextView
)
getDialog
().
findViewById
(
R
.
id
.
editor_channel_name
);
String
channelName
=
channelNameText
.
getText
().
toString
();
boolean
isPrivate
=
isChecked
(
R
.
id
.
checkbox_private
);
boolean
isReadOnly
=
isChecked
(
R
.
id
.
checkbox_read_only
);
if
(
isPrivate
)
{
return
methodCall
.
createPrivateGroup
(
channelName
,
isReadOnly
);
}
else
{
return
methodCall
.
createChannel
(
channelName
,
isReadOnly
);
}
}
}
app/src/main/java/chat/rocket/android/fragment/sidebar/dialog/AddDirectMessageDialogFragment.java
View file @
d9b4841d
...
...
@@ -2,6 +2,8 @@ package chat.rocket.android.fragment.sidebar.dialog;
import
android.view.View
;
import
android.widget.AutoCompleteTextView
;
import
android.widget.TextView
;
import
bolts.Task
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.sidebar.dialog.SuggestUserAdapter
;
...
...
@@ -38,6 +40,12 @@ public class AddDirectMessageDialogFragment extends AbstractAddRoomDialogFragmen
.
compose
(
bindToLifecycle
())
.
subscribe
(
RxView
.
enabled
(
buttonAddDirectMessage
));
//buttonAddDirectMessage.setOnClick...
buttonAddDirectMessage
.
setOnClickListener
(
view
->
createRoom
());
}
@Override
protected
Task
<
Void
>
getMethodCallForSubmitAction
()
{
String
username
=
((
TextView
)
getDialog
().
findViewById
(
R
.
id
.
editor_username
)).
getText
().
toString
();
return
methodCall
.
createDirectMessage
(
username
);
}
}
app/src/main/java/chat/rocket/android/layouthelper/sidebar/dialog/SuggestUserAdapter.java
View file @
d9b4841d
...
...
@@ -3,7 +3,6 @@ package chat.rocket.android.layouthelper.sidebar.dialog;
import
android.content.Context
;
import
android.view.View
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.realm_helper.RealmAutoCompleteAdapter
;
...
...
@@ -25,8 +24,7 @@ public class SuggestUserAdapter extends RealmAutoCompleteAdapter<User> {
@Override
protected
void
onBindItemView
(
View
itemView
,
User
user
)
{
new
UserRenderer
(
itemView
.
getContext
(),
user
)
.
statusColorInto
((
ImageView
)
itemView
.
findViewById
(
R
.
id
.
room_user_status
))
.
avatarInto
((
ImageView
)
itemView
.
findViewById
(
R
.
id
.
room_user_avatar
),
hostname
)
.
usernameInto
((
TextView
)
itemView
.
findViewById
(
R
.
id
.
room_user_name
));
.
avatarInto
((
ImageView
)
itemView
.
findViewById
(
R
.
id
.
room_user_avatar
),
hostname
);
}
@Override
protected
void
filterList
(
List
<
User
>
users
,
String
text
)
{
...
...
@@ -39,4 +37,8 @@ public class SuggestUserAdapter extends RealmAutoCompleteAdapter<User> {
}
}
}
@Override
protected
String
getStringForSelectedItem
(
User
user
)
{
return
user
.
getUsername
();
}
}
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmAutoCompleteAdapter.java
View file @
d9b4841d
...
...
@@ -7,6 +7,7 @@ import android.view.View;
import
android.view.ViewGroup
;
import
android.widget.ArrayAdapter
;
import
android.widget.Filter
;
import
android.widget.TextView
;
import
io.realm.Realm
;
import
io.realm.RealmObject
;
import
io.realm.RealmResults
;
...
...
@@ -28,7 +29,10 @@ public abstract class RealmAutoCompleteAdapter<T extends RealmObject> extends Ar
protected
void
filterList
(
List
<
T
>
items
,
String
text
)
{
}
public
class
AutoCompleteFilter
<
T
extends
RealmObject
>
extends
Filter
{
/**
* Filter for completion.
*/
private
class
AutoCompleteFilter
<
T
extends
RealmObject
>
extends
Filter
{
private
final
RealmAutoCompleteAdapter
<
T
>
adapter
;
private
final
RealmFilter
<
T
>
realmFilter
;
...
...
@@ -62,17 +66,23 @@ public abstract class RealmAutoCompleteAdapter<T extends RealmObject> extends Ar
adapter
.
addAll
((
List
<
T
>)
filterResults
.
values
);
}
}
@Override
public
CharSequence
convertResultToString
(
Object
resultValue
)
{
return
adapter
.
getStringForSelectedItem
((
T
)
resultValue
);
}
}
private
RealmHelper
realmHelper
;
private
AutoCompleteFilter
filter
;
private
final
int
textViewResourceId
;
protected
RealmAutoCompleteAdapter
(
Context
context
,
int
resource
)
{
super
(
context
,
resource
);
}
/**
* NOTE
* getStringForSelectedItem(T model) is automatically set to the TextView(id=textViewResourceId).
*/
protected
RealmAutoCompleteAdapter
(
Context
context
,
int
resource
,
int
textViewResourceId
)
{
super
(
context
,
resource
,
textViewResourceId
);
this
.
textViewResourceId
=
textViewResourceId
;
}
/*package*/
RealmAutoCompleteAdapter
<
T
>
initializeWith
(
RealmHelper
realmHelper
,
...
...
@@ -87,11 +97,18 @@ public abstract class RealmAutoCompleteAdapter<T extends RealmObject> extends Ar
return
filter
;
}
@NonNull
@Override
public
final
View
getView
(
int
position
,
View
convertView
,
ViewGroup
parent
)
{
@NonNull
@Override
public
final
View
getView
(
int
position
,
View
convertView
,
@NonNull
ViewGroup
parent
)
{
View
itemView
=
super
.
getView
(
position
,
convertView
,
parent
);
onBindItemView
(
itemView
,
getItem
(
position
));
T
item
=
getItem
(
position
);
TextView
textView
=
(
TextView
)
itemView
.
findViewById
(
textViewResourceId
);
textView
.
setText
(
getStringForSelectedItem
(
item
));
onBindItemView
(
itemView
,
item
);
return
itemView
;
}
protected
abstract
void
onBindItemView
(
View
itemView
,
T
model
);
protected
abstract
String
getStringForSelectedItem
(
T
model
);
}
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