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
Show 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;
...
@@ -14,6 +14,8 @@ import android.widget.LinearLayout;
import
com.facebook.drawee.backends.pipeline.Fresco
;
import
com.facebook.drawee.backends.pipeline.Fresco
;
import
com.facebook.drawee.view.SimpleDraweeView
;
import
com.facebook.drawee.view.SimpleDraweeView
;
import
java.util.List
;
import
chat.rocket.android.LaunchUtil
;
import
chat.rocket.android.LaunchUtil
;
import
chat.rocket.android.R
;
import
chat.rocket.android.R
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.RocketChatCache
;
...
@@ -28,6 +30,9 @@ import chat.rocket.android.widget.helper.AvatarHelper;
...
@@ -28,6 +30,9 @@ import chat.rocket.android.widget.helper.AvatarHelper;
import
chat.rocket.core.interactors.CanCreateRoomInteractor
;
import
chat.rocket.core.interactors.CanCreateRoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.SessionInteractor
;
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.RealmRoomRepository
;
import
chat.rocket.persistence.realm.repositories.RealmSessionRepository
;
import
chat.rocket.persistence.realm.repositories.RealmSessionRepository
;
import
chat.rocket.persistence.realm.repositories.RealmUserRepository
;
import
chat.rocket.persistence.realm.repositories.RealmUserRepository
;
...
@@ -60,6 +65,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -60,6 +65,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
super
.
onResume
();
super
.
onResume
();
if
(
presenter
!=
null
)
{
if
(
presenter
!=
null
)
{
presenter
.
bindViewOnly
(
this
);
presenter
.
bindViewOnly
(
this
);
presenter
.
loadSignedInServers
(
hostname
);
}
}
}
}
...
@@ -119,8 +125,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -119,8 +125,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
closeUserActionContainer
();
closeUserActionContainer
();
}
}
});
});
updateServerListBar
();
}
}
private
void
showAddServerActivity
()
{
private
void
showAddServerActivity
()
{
...
@@ -159,6 +163,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -159,6 +163,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
new
RealmSessionRepository
(
hostname
)
new
RealmSessionRepository
(
hostname
)
);
);
PublicSettingRepository
publicSettingRepository
=
new
RealmPublicSettingRepository
(
hostname
);
presenter
=
new
MainPresenter
(
presenter
=
new
MainPresenter
(
roomInteractor
,
roomInteractor
,
...
@@ -166,7 +171,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -166,7 +171,8 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
sessionInteractor
,
sessionInteractor
,
new
MethodCallHelper
(
this
,
hostname
),
new
MethodCallHelper
(
this
,
hostname
),
ConnectivityManager
.
getInstance
(
getApplicationContext
()),
ConnectivityManager
.
getInstance
(
getApplicationContext
()),
new
RocketChatCache
(
this
)
new
RocketChatCache
(
this
),
publicSettingRepository
);
);
updateSidebarMainFragment
();
updateSidebarMainFragment
();
...
@@ -174,45 +180,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -174,45 +180,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
presenter
.
bindView
(
this
);
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
()
{
private
void
updateSidebarMainFragment
()
{
getSupportFragmentManager
().
beginTransaction
()
getSupportFragmentManager
().
beginTransaction
()
.
replace
(
R
.
id
.
sidebar_fragment_container
,
SidebarMainFragment
.
create
(
hostname
))
.
replace
(
R
.
id
.
sidebar_fragment_container
,
SidebarMainFragment
.
create
(
hostname
))
...
@@ -287,6 +254,41 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
...
@@ -287,6 +254,41 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
statusTicker
.
updateStatus
(
StatusTicker
.
STATUS_DISMISS
,
null
);
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.
//TODO: consider this class to define in layouthelper for more complicated operation.
private
static
class
StatusTicker
{
private
static
class
StatusTicker
{
public
static
final
int
STATUS_DISMISS
=
0
;
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
;
package
chat
.
rocket
.
android
.
activity
;
import
java.util.List
;
import
chat.rocket.android.shared.BaseContract
;
import
chat.rocket.android.shared.BaseContract
;
import
chat.rocket.core.utils.Pair
;
public
interface
MainContract
{
public
interface
MainContract
{
...
@@ -21,6 +24,8 @@ public interface MainContract {
...
@@ -21,6 +24,8 @@ public interface MainContract {
void
showConnecting
();
void
showConnecting
();
void
showConnectionOk
();
void
showConnectionOk
();
void
showSignedInServers
(
List
<
Pair
<
String
,
String
>>
serverList
);
}
}
interface
Presenter
extends
BaseContract
.
Presenter
<
View
>
{
interface
Presenter
extends
BaseContract
.
Presenter
<
View
>
{
...
@@ -30,5 +35,7 @@ public interface MainContract {
...
@@ -30,5 +35,7 @@ public interface MainContract {
void
onRetryLogin
();
void
onRetryLogin
();
void
bindViewOnly
(
View
view
);
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
;
package
chat
.
rocket
.
android
.
activity
;
import
android.support.annotation.NonNull
;
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.BackgroundLooper
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.helper.LogIfError
;
import
chat.rocket.android.helper.LogIfError
;
import
chat.rocket.android.helper.Logger
;
import
chat.rocket.android.helper.Logger
;
import
chat.rocket.android.log.RCLog
;
import
chat.rocket.android.service.ConnectivityManagerApi
;
import
chat.rocket.android.service.ConnectivityManagerApi
;
import
chat.rocket.android.service.ServerConnectivity
;
import
chat.rocket.android.service.ServerConnectivity
;
import
chat.rocket.android.shared.BasePresenter
;
import
chat.rocket.android.shared.BasePresenter
;
import
chat.rocket.core.PublicSettingsConstants
;
import
chat.rocket.core.interactors.CanCreateRoomInteractor
;
import
chat.rocket.core.interactors.CanCreateRoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.RoomInteractor
;
import
chat.rocket.core.interactors.SessionInteractor
;
import
chat.rocket.core.interactors.SessionInteractor
;
import
chat.rocket.core.models.Session
;
import
chat.rocket.core.models.Session
;
import
chat.rocket.core.models.User
;
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
hu.akarnokd.rxjava.interop.RxJavaInterop
;
import
io.reactivex.Flowable
;
import
io.reactivex.Flowable
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
...
@@ -30,19 +38,21 @@ public class MainPresenter extends BasePresenter<MainContract.View>
...
@@ -30,19 +38,21 @@ public class MainPresenter extends BasePresenter<MainContract.View>
private
final
MethodCallHelper
methodCallHelper
;
private
final
MethodCallHelper
methodCallHelper
;
private
final
ConnectivityManagerApi
connectivityManagerApi
;
private
final
ConnectivityManagerApi
connectivityManagerApi
;
private
final
RocketChatCache
rocketChatCache
;
private
final
RocketChatCache
rocketChatCache
;
private
final
PublicSettingRepository
publicSettingRepository
;
public
MainPresenter
(
RoomInteractor
roomInteractor
,
public
MainPresenter
(
RoomInteractor
roomInteractor
,
CanCreateRoomInteractor
canCreateRoomInteractor
,
CanCreateRoomInteractor
canCreateRoomInteractor
,
SessionInteractor
sessionInteractor
,
SessionInteractor
sessionInteractor
,
MethodCallHelper
methodCallHelper
,
MethodCallHelper
methodCallHelper
,
ConnectivityManagerApi
connectivityManagerApi
,
ConnectivityManagerApi
connectivityManagerApi
,
RocketChatCache
rocketChatCache
)
{
RocketChatCache
rocketChatCache
,
PublicSettingRepository
publicSettingRepository
)
{
this
.
roomInteractor
=
roomInteractor
;
this
.
roomInteractor
=
roomInteractor
;
this
.
canCreateRoomInteractor
=
canCreateRoomInteractor
;
this
.
canCreateRoomInteractor
=
canCreateRoomInteractor
;
this
.
sessionInteractor
=
sessionInteractor
;
this
.
sessionInteractor
=
sessionInteractor
;
this
.
methodCallHelper
=
methodCallHelper
;
this
.
methodCallHelper
=
methodCallHelper
;
this
.
connectivityManagerApi
=
connectivityManagerApi
;
this
.
connectivityManagerApi
=
connectivityManagerApi
;
this
.
rocketChatCache
=
rocketChatCache
;
this
.
rocketChatCache
=
rocketChatCache
;
this
.
publicSettingRepository
=
publicSettingRepository
;
}
}
@Override
@Override
...
@@ -53,6 +63,26 @@ public class MainPresenter extends BasePresenter<MainContract.View>
...
@@ -53,6 +63,26 @@ public class MainPresenter extends BasePresenter<MainContract.View>
setUserOnline
();
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
@Override
public
void
bindView
(
@NonNull
MainContract
.
View
view
)
{
public
void
bindView
(
@NonNull
MainContract
.
View
view
)
{
super
.
bindView
(
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