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
ce7d453d
Commit
ce7d453d
authored
Dec 09, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement ui
parent
3f276e03
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
423 additions
and
0 deletions
+423
-0
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+23
-0
AbstractAddRoomDialogFragment.java
...ragment/sidebar/dialog/AbstractAddRoomDialogFragment.java
+41
-0
AddChannelDialogFragment.java
...oid/fragment/sidebar/dialog/AddChannelDialogFragment.java
+46
-0
AddDirectMessageDialogFragment.java
...agment/sidebar/dialog/AddDirectMessageDialogFragment.java
+43
-0
SuggestUserAdapter.java
...droid/layouthelper/sidebar/dialog/SuggestUserAdapter.java
+42
-0
dialog_add_channel.xml
app/src/main/res/layout/dialog_add_channel.xml
+72
-0
dialog_add_direct_message.xml
app/src/main/res/layout/dialog_add_direct_message.xml
+47
-0
fragment_sidebar_main.xml
app/src/main/res/layout/fragment_sidebar_main.xml
+2
-0
strings.xml
app/src/main/res/values/strings.xml
+3
-0
RealmAutoCompleteAdapter.java
...rocket/android/realm_helper/RealmAutoCompleteAdapter.java
+97
-0
RealmHelper.java
...in/java/chat/rocket/android/realm_helper/RealmHelper.java
+7
-0
No files found.
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
ce7d453d
...
...
@@ -2,6 +2,7 @@ package chat.rocket.android.fragment.sidebar;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.DialogFragment
;
import
android.widget.CompoundButton
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
...
...
@@ -10,6 +11,9 @@ import chat.rocket.android.R;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.fragment.AbstractFragment
;
import
chat.rocket.android.fragment.sidebar.dialog.AbstractAddRoomDialogFragment
;
import
chat.rocket.android.fragment.sidebar.dialog.AddDirectMessageDialogFragment
;
import
chat.rocket.android.fragment.sidebar.dialog.AddChannelDialogFragment
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.chatroom.RoomListManager
;
...
...
@@ -91,6 +95,7 @@ public class SidebarMainFragment extends AbstractFragment {
setupUserActionToggle
();
setupUserStatusButtons
();
setupLogoutButton
();
setupAddChannelButton
();
roomListManager
=
new
RoomListManager
(
(
LinearLayout
)
rootView
.
findViewById
(
R
.
id
.
channels_container
),
...
...
@@ -158,6 +163,24 @@ public class SidebarMainFragment extends AbstractFragment {
}
}
private
void
setupAddChannelButton
()
{
rootView
.
findViewById
(
R
.
id
.
btn_add_channel
).
setOnClickListener
(
view
->
{
showAddRoomDialog
(
new
AddChannelDialogFragment
());
});
rootView
.
findViewById
(
R
.
id
.
btn_add_direct_message
).
setOnClickListener
(
view
->
{
showAddRoomDialog
(
new
AddDirectMessageDialogFragment
());
});
}
private
void
showAddRoomDialog
(
DialogFragment
dialog
)
{
Bundle
args
=
new
Bundle
();
args
.
putString
(
"serverConfigId"
,
serverConfigId
);
args
.
putString
(
"hostname"
,
hostname
);
dialog
.
setArguments
(
args
);
dialog
.
show
(
getFragmentManager
(),
AbstractAddRoomDialogFragment
.
class
.
getSimpleName
());
}
@Override
public
void
onResume
()
{
super
.
onResume
();
if
(
roomsObserver
!=
null
)
{
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/dialog/AbstractAddRoomDialogFragment.java
0 → 100644
View file @
ce7d453d
package
chat
.
rocket
.
android
.
fragment
.
sidebar
.
dialog
;
import
android.app.Dialog
;
import
android.os.Bundle
;
import
android.support.annotation.LayoutRes
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
chat.rocket.android.realm_helper.RealmHelper
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
com.trello.rxlifecycle.components.support.RxAppCompatDialogFragment
;
public
abstract
class
AbstractAddRoomDialogFragment
extends
RxAppCompatDialogFragment
{
protected
RealmHelper
realmHelper
;
protected
String
hostname
;
protected
@LayoutRes
abstract
int
getLayout
();
protected
abstract
void
onSetupDialog
();
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
Bundle
args
=
getArguments
();
if
(
args
!=
null
)
{
handleArgs
(
args
);
}
}
protected
void
handleArgs
(
@NonNull
Bundle
args
)
{
String
serverConfigId
=
args
.
getString
(
"serverConfigId"
);
realmHelper
=
RealmStore
.
get
(
serverConfigId
);
hostname
=
args
.
getString
(
"hostname"
);
}
@Override
public
final
void
setupDialog
(
Dialog
dialog
,
int
style
)
{
super
.
setupDialog
(
dialog
,
style
);
dialog
.
setContentView
(
getLayout
());
onSetupDialog
();
}
}
app/src/main/java/chat/rocket/android/fragment/sidebar/dialog/AddChannelDialogFragment.java
0 → 100644
View file @
ce7d453d
package
chat
.
rocket
.
android
.
fragment
.
sidebar
.
dialog
;
import
android.view.View
;
import
android.widget.CompoundButton
;
import
android.widget.TextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.TextUtils
;
import
com.jakewharton.rxbinding.view.RxView
;
import
com.jakewharton.rxbinding.widget.RxTextView
;
/**
* add Channel, add Private-group.
*/
public
class
AddChannelDialogFragment
extends
AbstractAddRoomDialogFragment
{
public
AddChannelDialogFragment
()
{}
@Override
protected
int
getLayout
()
{
return
R
.
layout
.
dialog_add_channel
;
}
@Override
protected
void
onSetupDialog
()
{
View
buttonAddChannel
=
getDialog
().
findViewById
(
R
.
id
.
btn_add_channel
);
RxTextView
.
textChanges
((
TextView
)
getDialog
().
findViewById
(
R
.
id
.
editor_channel_name
))
.
map
(
text
->
!
TextUtils
.
isEmpty
(
text
))
.
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
);
});
}
private
boolean
isChecked
(
int
viewId
)
{
CompoundButton
check
=
(
CompoundButton
)
getDialog
().
findViewById
(
viewId
);
return
check
.
isChecked
();
}
private
void
createChannel
(
String
name
,
boolean
isPrivate
,
boolean
isReadOnly
)
{
}
}
app/src/main/java/chat/rocket/android/fragment/sidebar/dialog/AddDirectMessageDialogFragment.java
0 → 100644
View file @
ce7d453d
package
chat
.
rocket
.
android
.
fragment
.
sidebar
.
dialog
;
import
android.view.View
;
import
android.widget.AutoCompleteTextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.sidebar.dialog.SuggestUserAdapter
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.realm_helper.RealmAutoCompleteAdapter
;
import
com.jakewharton.rxbinding.view.RxView
;
import
com.jakewharton.rxbinding.widget.RxTextView
;
import
io.realm.Case
;
/**
* add Direct Message.
*/
public
class
AddDirectMessageDialogFragment
extends
AbstractAddRoomDialogFragment
{
public
AddDirectMessageDialogFragment
()
{}
@Override
protected
int
getLayout
()
{
return
R
.
layout
.
dialog_add_direct_message
;
}
@Override
protected
void
onSetupDialog
()
{
View
buttonAddDirectMessage
=
getDialog
().
findViewById
(
R
.
id
.
btn_add_direct_message
);
AutoCompleteTextView
autoCompleteTextView
=
(
AutoCompleteTextView
)
getDialog
().
findViewById
(
R
.
id
.
editor_username
);
RealmAutoCompleteAdapter
<
User
>
adapter
=
realmHelper
.
createAutoCompleteAdapter
(
getContext
(),
(
realm
,
text
)
->
realm
.
where
(
User
.
class
)
.
contains
(
"username"
,
text
,
Case
.
INSENSITIVE
)
.
findAllSorted
(
"username"
),
context
->
new
SuggestUserAdapter
(
context
,
hostname
));
autoCompleteTextView
.
setAdapter
(
adapter
);
RxTextView
.
textChanges
(
autoCompleteTextView
)
.
map
(
text
->
!
TextUtils
.
isEmpty
(
text
))
.
compose
(
bindToLifecycle
())
.
subscribe
(
RxView
.
enabled
(
buttonAddDirectMessage
));
//buttonAddDirectMessage.setOnClick...
}
}
app/src/main/java/chat/rocket/android/layouthelper/sidebar/dialog/SuggestUserAdapter.java
0 → 100644
View file @
ce7d453d
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
;
import
chat.rocket.android.renderer.UserRenderer
;
import
java.util.Iterator
;
import
java.util.List
;
/**
* adapter to suggest user names.
*/
public
class
SuggestUserAdapter
extends
RealmAutoCompleteAdapter
<
User
>
{
private
final
String
hostname
;
public
SuggestUserAdapter
(
Context
context
,
String
hostname
)
{
super
(
context
,
R
.
layout
.
listitem_room_user
,
R
.
id
.
room_user_name
);
this
.
hostname
=
hostname
;
}
@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
));
}
@Override
protected
void
filterList
(
List
<
User
>
users
,
String
text
)
{
Iterator
<
User
>
itUsers
=
users
.
iterator
();
final
String
prefix
=
text
.
toLowerCase
();
while
(
itUsers
.
hasNext
())
{
User
user
=
itUsers
.
next
();
if
(!
user
.
getUsername
().
toLowerCase
().
startsWith
(
prefix
))
{
itUsers
.
remove
();
}
}
}
}
app/src/main/res/layout/dialog_add_channel.xml
0 → 100644
View file @
ce7d453d
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:orientation=
"vertical"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:minWidth=
"288dp"
android:padding=
"@dimen/margin_24"
>
<android.support.design.widget.TextInputLayout
android:id=
"@+id/text_input_channel_name"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<android.support.design.widget.TextInputEditText
android:id=
"@+id/editor_channel_name"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:inputType=
"textWebEmailAddress"
android:hint=
"@string/dialog_add_channel_name"
/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:layout_marginTop=
"@dimen/margin_16"
android:layout_marginStart=
"@dimen/margin_8"
android:layout_marginEnd=
"@dimen/margin_8"
>
<CheckBox
android:id=
"@+id/checkbox_private"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:text=
"@string/dialog_add_channel_private"
/>
<CheckBox
android:id=
"@+id/checkbox_read_only"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:text=
"@string/dialog_add_channel_read_only"
/>
</LinearLayout>
<Space
android:layout_width=
"match_parent"
android:layout_height=
"@dimen/margin_16"
/>
<android.support.design.widget.FloatingActionButton
android:id=
"@+id/btn_add_channel"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"end|bottom"
app:elevation=
"2dp"
app:fabSize=
"mini"
app:srcCompat=
"@drawable/ic_arrow_forward_white_24dp"
/>
<chat.rocket.android.widget.WaitingView
android:id=
"@+id/waiting"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:visibility=
"gone"
app:dotCount=
"5"
app:dotSize=
"12dp"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/dialog_add_direct_message.xml
0 → 100644
View file @
ce7d453d
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:orientation=
"vertical"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:minWidth=
"288dp"
android:padding=
"@dimen/margin_24"
>
<android.support.design.widget.TextInputLayout
android:id=
"@+id/text_input_username"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<android.support.v7.widget.AppCompatAutoCompleteTextView
android:id=
"@+id/editor_username"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"username"
android:completionThreshold=
"3"
/>
</android.support.design.widget.TextInputLayout>
<Space
android:layout_width=
"match_parent"
android:layout_height=
"@dimen/margin_16"
/>
<android.support.design.widget.FloatingActionButton
android:id=
"@+id/btn_add_direct_message"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"end|bottom"
app:elevation=
"2dp"
app:fabSize=
"mini"
app:srcCompat=
"@drawable/ic_arrow_forward_white_24dp"
/>
<chat.rocket.android.widget.WaitingView
android:id=
"@+id/waiting"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:visibility=
"gone"
app:dotCount=
"5"
app:dotSize=
"12dp"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_sidebar_main.xml
View file @
ce7d453d
...
...
@@ -78,6 +78,7 @@
android:textStyle=
"bold"
/>
<chat.rocket.android.widget.FontAwesomeButton
android:id=
"@+id/btn_add_channel"
style=
"@style/Widget.AppCompat.Button.Borderless"
android:layout_width=
"48dp"
android:layout_height=
"48dp"
...
...
@@ -109,6 +110,7 @@
android:textStyle=
"bold"
/>
<chat.rocket.android.widget.FontAwesomeButton
android:id=
"@+id/btn_add_direct_message"
style=
"@style/Widget.AppCompat.Button.Borderless"
android:layout_width=
"48dp"
android:layout_height=
"48dp"
...
...
app/src/main/res/values/strings.xml
View file @
ce7d453d
...
...
@@ -7,6 +7,9 @@
<string
name=
"user_status_busy"
>
Busy
</string>
<string
name=
"user_status_invisible"
>
Invisible
</string>
<string
name=
"fragment_sidebar_main_logout_title"
>
Logout
</string>
<string
name=
"dialog_add_channel_name"
>
name
</string>
<string
name=
"dialog_add_channel_private"
>
private
</string>
<string
name=
"dialog_add_channel_read_only"
>
read only
</string>
<string
name=
"start_of_conversation"
>
Start of conversation
</string>
<string
name=
"users_of_room_title"
>
Members List
</string>
...
...
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmAutoCompleteAdapter.java
0 → 100644
View file @
ce7d453d
package
chat
.
rocket
.
android
.
realm_helper
;
import
android.content.Context
;
import
android.support.annotation.NonNull
;
import
android.text.TextUtils
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ArrayAdapter
;
import
android.widget.Filter
;
import
io.realm.Realm
;
import
io.realm.RealmObject
;
import
io.realm.RealmResults
;
import
java.util.Collections
;
import
java.util.List
;
/**
* ListAdapter for AutoCompleteTextView.
*/
public
abstract
class
RealmAutoCompleteAdapter
<
T
extends
RealmObject
>
extends
ArrayAdapter
<
T
>
{
public
interface
Constructor
<
T
extends
RealmObject
>
{
RealmAutoCompleteAdapter
<
T
>
getNewInstance
(
Context
context
);
}
public
interface
RealmFilter
<
T
extends
RealmObject
>
{
RealmResults
<
T
>
filterItems
(
Realm
realm
,
String
text
);
}
protected
void
filterList
(
List
<
T
>
items
,
String
text
)
{
}
public
class
AutoCompleteFilter
<
T
extends
RealmObject
>
extends
Filter
{
private
final
RealmAutoCompleteAdapter
<
T
>
adapter
;
private
final
RealmFilter
<
T
>
realmFilter
;
/*package*/
AutoCompleteFilter
(
RealmAutoCompleteAdapter
<
T
>
adapter
,
RealmFilter
<
T
>
realmFilter
)
{
this
.
adapter
=
adapter
;
this
.
realmFilter
=
realmFilter
;
}
@Override
protected
FilterResults
performFiltering
(
CharSequence
charSequence
)
{
FilterResults
results
=
new
FilterResults
();
if
(
TextUtils
.
isEmpty
(
charSequence
))
{
results
.
values
=
Collections
.
emptyList
();
results
.
count
=
0
;
return
results
;
}
String
text
=
charSequence
.
toString
();
List
<
T
>
filteredItems
=
realmHelper
.
executeTransactionForReadResults
(
realm
->
realmFilter
.
filterItems
(
realm
,
text
));
adapter
.
filterList
(
filteredItems
,
text
);
results
.
values
=
filteredItems
;
results
.
count
=
filteredItems
.
size
();
return
results
;
}
@Override
protected
void
publishResults
(
CharSequence
charSequence
,
FilterResults
filterResults
)
{
adapter
.
clear
();
if
(
filterResults
.
count
>
0
)
{
adapter
.
addAll
((
List
<
T
>)
filterResults
.
values
);
}
}
}
private
RealmHelper
realmHelper
;
private
AutoCompleteFilter
filter
;
protected
RealmAutoCompleteAdapter
(
Context
context
,
int
resource
)
{
super
(
context
,
resource
);
}
protected
RealmAutoCompleteAdapter
(
Context
context
,
int
resource
,
int
textViewResourceId
)
{
super
(
context
,
resource
,
textViewResourceId
);
}
/*package*/
RealmAutoCompleteAdapter
<
T
>
initializeWith
(
RealmHelper
realmHelper
,
RealmFilter
<
T
>
itemFilter
)
{
this
.
realmHelper
=
realmHelper
;
this
.
filter
=
new
AutoCompleteFilter
<
T
>(
this
,
itemFilter
);
return
this
;
}
@NonNull
@Override
public
Filter
getFilter
()
{
return
filter
;
}
@NonNull
@Override
public
final
View
getView
(
int
position
,
View
convertView
,
ViewGroup
parent
)
{
View
itemView
=
super
.
getView
(
position
,
convertView
,
parent
);
onBindItemView
(
itemView
,
getItem
(
position
));
return
itemView
;
}
protected
abstract
void
onBindItemView
(
View
itemView
,
T
model
);
}
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmHelper.java
View file @
ce7d453d
...
...
@@ -142,4 +142,11 @@ public class RealmHelper {
RealmModelListAdapter
.
Constructor
<
T
,
VM
,
VH
>
constructor
)
{
return
constructor
.
getNewInstance
(
context
).
initializeWith
(
this
,
query
);
}
public
<
T
extends
RealmObject
>
RealmAutoCompleteAdapter
<
T
>
createAutoCompleteAdapter
(
Context
context
,
RealmAutoCompleteAdapter
.
RealmFilter
<
T
>
filter
,
RealmAutoCompleteAdapter
.
Constructor
constructor
)
{
return
constructor
.
getNewInstance
(
context
).
initializeWith
(
this
,
filter
);
}
}
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