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
d21901cb
Commit
d21901cb
authored
Aug 31, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement in home presenter the load call for the currently logged in servers
parent
35a75978
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
44 deletions
+83
-44
MainActivity.java
.../main/java/chat/rocket/android/activity/MainActivity.java
+44
-42
MainContract.java
.../main/java/chat/rocket/android/activity/MainContract.java
+7
-0
MainPresenter.java
...main/java/chat/rocket/android/activity/MainPresenter.java
+32
-2
No files found.
app/src/main/java/chat/rocket/android/activity/MainActivity.java
View file @
d21901cb
...
...
@@ -14,6 +14,8 @@ import android.widget.LinearLayout;
import
com.facebook.drawee.backends.pipeline.Fresco
;
import
com.facebook.drawee.view.SimpleDraweeView
;
import
java.util.List
;
import
chat.rocket.android.LaunchUtil
;
import
chat.rocket.android.R
;
import
chat.rocket.android.RocketChatCache
;
...
...
@@ -28,6 +30,9 @@ import chat.rocket.android.widget.helper.AvatarHelper;
import
chat.rocket.core.interactors.CanCreateRoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.SessionInteractor
;
import
chat.rocket.core.repositories.PublicSettingRepository
;
import
chat.rocket.core.utils.Pair
;
import
chat.rocket.persistence.realm.repositories.RealmPublicSettingRepository
;
import
chat.rocket.persistence.realm.repositories.RealmRoomRepository
;
import
chat.rocket.persistence.realm.repositories.RealmSessionRepository
;
import
chat.rocket.persistence.realm.repositories.RealmUserRepository
;
...
...
@@ -60,6 +65,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
super
.
onResume
();
if
(
presenter
!=
null
)
{
presenter
.
bindViewOnly
(
this
);
presenter
.
loadSignedInServers
(
hostname
);
}
}
...
...
@@ -119,8 +125,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
closeUserActionContainer
();
}
});
updateServerListBar
();
}
private
void
showAddServerActivity
()
{
...
...
@@ -159,6 +163,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
new
RealmSessionRepository
(
hostname
)
);
PublicSettingRepository
publicSettingRepository
=
new
RealmPublicSettingRepository
(
hostname
);
presenter
=
new
MainPresenter
(
roomInteractor
,
...
...
@@ -166,7 +171,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
sessionInteractor
,
new
MethodCallHelper
(
this
,
hostname
),
ConnectivityManager
.
getInstance
(
getApplicationContext
()),
new
RocketChatCache
(
this
)
new
RocketChatCache
(
this
),
publicSettingRepository
);
updateSidebarMainFragment
();
...
...
@@ -174,45 +180,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
presenter
.
bindView
(
this
);
}
@DebugLog
private
void
updateServerListBar
()
{
final
SlidingPaneLayout
subPane
=
(
SlidingPaneLayout
)
findViewById
(
R
.
id
.
sub_sliding_pane
);
if
(
subPane
!=
null
)
{
RocketChatCache
rocketChatCache
=
new
RocketChatCache
(
getApplicationContext
());
//TODO: get the server avatar uri and set
rocketChatCache
.
addHostname
(
hostname
,
null
);
LinearLayout
serverListContainer
=
subPane
.
findViewById
(
R
.
id
.
server_list_bar
);
for
(
String
serverHostname
:
rocketChatCache
.
getServerList
())
{
if
(
serverListContainer
.
findViewWithTag
(
serverHostname
)
==
null
)
{
int
serverCount
=
serverListContainer
.
getChildCount
();
SimpleDraweeView
serverButton
=
(
SimpleDraweeView
)
LayoutInflater
.
from
(
this
).
inflate
(
R
.
layout
.
server_button
,
serverListContainer
,
false
);
serverButton
.
setTag
(
serverHostname
);
serverButton
.
setOnClickListener
(
view
->
changeServerIfNeeded
(
serverHostname
));
Drawable
drawable
=
AvatarHelper
.
INSTANCE
.
getTextDrawable
(
serverHostname
,
this
);
serverButton
.
getHierarchy
().
setPlaceholderImage
(
drawable
);
serverButton
.
setController
(
Fresco
.
newDraweeControllerBuilder
().
setAutoPlayAnimations
(
true
).
build
());
serverListContainer
.
addView
(
serverButton
,
serverCount
-
1
);
serverListContainer
.
requestLayout
();
}
}
}
}
private
void
changeServerIfNeeded
(
String
serverHostname
)
{
if
(!
hostname
.
equalsIgnoreCase
(
serverHostname
))
{
closeSidebarIfNeeded
();
RocketChatCache
rocketChatCache
=
new
RocketChatCache
(
getApplicationContext
());
rocketChatCache
.
setSelectedServerHostname
(
serverHostname
);
recreate
();
}
}
private
void
updateSidebarMainFragment
()
{
getSupportFragmentManager
().
beginTransaction
()
.
replace
(
R
.
id
.
sidebar_fragment_container
,
SidebarMainFragment
.
create
(
hostname
))
...
...
@@ -287,6 +254,41 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
statusTicker
.
updateStatus
(
StatusTicker
.
STATUS_DISMISS
,
null
);
}
@Override
public
void
showSignedInServers
(
List
<
Pair
<
String
,
String
>>
serverList
)
{
final
SlidingPaneLayout
subPane
=
(
SlidingPaneLayout
)
findViewById
(
R
.
id
.
sub_sliding_pane
);
if
(
subPane
!=
null
)
{
LinearLayout
serverListContainer
=
subPane
.
findViewById
(
R
.
id
.
server_list_bar
);
for
(
Pair
<
String
,
String
>
server
:
serverList
)
{
if
(
serverListContainer
.
findViewWithTag
(
server
.
first
)
==
null
)
{
int
serverCount
=
serverListContainer
.
getChildCount
();
SimpleDraweeView
serverButton
=
(
SimpleDraweeView
)
LayoutInflater
.
from
(
this
).
inflate
(
R
.
layout
.
server_button
,
serverListContainer
,
false
);
serverButton
.
setTag
(
server
.
first
);
serverButton
.
setOnClickListener
(
view
->
changeServerIfNeeded
(
server
.
first
));
Drawable
drawable
=
AvatarHelper
.
INSTANCE
.
getTextDrawable
(
server
.
first
,
this
);
serverButton
.
getHierarchy
().
setPlaceholderImage
(
drawable
);
serverButton
.
setController
(
Fresco
.
newDraweeControllerBuilder
().
setUri
(
server
.
second
).
setAutoPlayAnimations
(
true
).
build
());
serverListContainer
.
addView
(
serverButton
,
serverCount
-
1
);
serverListContainer
.
requestLayout
();
}
}
}
}
private
void
changeServerIfNeeded
(
String
serverHostname
)
{
if
(!
hostname
.
equalsIgnoreCase
(
serverHostname
))
{
closeSidebarIfNeeded
();
RocketChatCache
rocketChatCache
=
new
RocketChatCache
(
getApplicationContext
());
rocketChatCache
.
setSelectedServerHostname
(
serverHostname
);
recreate
();
}
}
//TODO: consider this class to define in layouthelper for more complicated operation.
private
static
class
StatusTicker
{
public
static
final
int
STATUS_DISMISS
=
0
;
...
...
app/src/main/java/chat/rocket/android/activity/MainContract.java
View file @
d21901cb
package
chat
.
rocket
.
android
.
activity
;
import
java.util.List
;
import
chat.rocket.android.shared.BaseContract
;
import
chat.rocket.core.utils.Pair
;
public
interface
MainContract
{
...
...
@@ -21,6 +24,8 @@ public interface MainContract {
void
showConnecting
();
void
showConnectionOk
();
void
showSignedInServers
(
List
<
Pair
<
String
,
String
>>
serverList
);
}
interface
Presenter
extends
BaseContract
.
Presenter
<
View
>
{
...
...
@@ -30,5 +35,7 @@ public interface MainContract {
void
onRetryLogin
();
void
bindViewOnly
(
View
view
);
void
loadSignedInServers
(
String
hostname
);
}
}
app/src/main/java/chat/rocket/android/activity/MainPresenter.java
View file @
d21901cb
package
chat
.
rocket
.
android
.
activity
;
import
android.support.annotation.NonNull
;
import
android.support.v4.util.Pair
;
import
com.hadisatrio.optional.Optional
;
import
org.jetbrains.annotations.NotNull
;
import
org.json.JSONObject
;
import
chat.rocket.android.BackgroundLooper
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.helper.LogIfError
;
import
chat.rocket.android.helper.Logger
;
import
chat.rocket.android.log.RCLog
;
import
chat.rocket.android.service.ConnectivityManagerApi
;
import
chat.rocket.android.service.ServerConnectivity
;
import
chat.rocket.android.shared.BasePresenter
;
import
chat.rocket.core.PublicSettingsConstants
;
import
chat.rocket.core.interactors.CanCreateRoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.SessionInteractor
;
import
chat.rocket.core.models.Session
;
import
chat.rocket.core.models.User
;
import
chat.rocket.core.repositories.PublicSettingRepository
;
import
chat.rocket.core.utils.Pair
;
import
hu.akarnokd.rxjava.interop.RxJavaInterop
;
import
io.reactivex.Flowable
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
...
...
@@ -30,19 +38,21 @@ public class MainPresenter extends BasePresenter<MainContract.View>
private
final
MethodCallHelper
methodCallHelper
;
private
final
ConnectivityManagerApi
connectivityManagerApi
;
private
final
RocketChatCache
rocketChatCache
;
private
final
PublicSettingRepository
publicSettingRepository
;
public
MainPresenter
(
RoomInteractor
roomInteractor
,
CanCreateRoomInteractor
canCreateRoomInteractor
,
SessionInteractor
sessionInteractor
,
MethodCallHelper
methodCallHelper
,
ConnectivityManagerApi
connectivityManagerApi
,
RocketChatCache
rocketChatCache
)
{
RocketChatCache
rocketChatCache
,
PublicSettingRepository
publicSettingRepository
)
{
this
.
roomInteractor
=
roomInteractor
;
this
.
canCreateRoomInteractor
=
canCreateRoomInteractor
;
this
.
sessionInteractor
=
sessionInteractor
;
this
.
methodCallHelper
=
methodCallHelper
;
this
.
connectivityManagerApi
=
connectivityManagerApi
;
this
.
rocketChatCache
=
rocketChatCache
;
this
.
publicSettingRepository
=
publicSettingRepository
;
}
@Override
...
...
@@ -53,6 +63,26 @@ public class MainPresenter extends BasePresenter<MainContract.View>
setUserOnline
();
}
@Override
public
void
loadSignedInServers
(
@NotNull
String
hostname
)
{
final
Disposable
disposable
=
publicSettingRepository
.
getById
(
PublicSettingsConstants
.
Assets
.
TILE_144
)
.
filter
(
Optional:
:
isPresent
)
.
map
(
Optional:
:
get
)
.
map
(
publicSetting
->
{
JSONObject
jsonObject
=
new
JSONObject
(
publicSetting
.
getValue
());
rocketChatCache
.
addHostname
(
hostname
,
jsonObject
.
optString
(
"defaultUrl"
));
return
rocketChatCache
.
getServerList
();
})
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
view:
:
showSignedInServers
,
RCLog:
:
e
);
addSubscription
(
disposable
);
}
@Override
public
void
bindView
(
@NonNull
MainContract
.
View
view
)
{
super
.
bindView
(
view
);
...
...
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