Commit aecf5aea authored by Rafael Kellermann Streit's avatar Rafael Kellermann Streit Committed by GitHub

Merge branch 'develop' into iss424

parents 74c79b79 9b235e50
# Contributing to Rocket.Chat
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
The following is a set of guidelines for contributing to Rocket.Chat and its packages, which are hosted in the [Rocket.Chat Organization](https://github.com/RocketChat) on GitHub.
__Note:__ If there's a feature you'd like, there's a bug you'd like to fix, or you'd just like to get involved please raise an issue and start a conversation. We'll help as much as we can so you can get contributing - although we may not always be able to respond right away :)
## Coding standards
We are following / moving to [Google Java Style](https://google.github.io/styleguide/javaguide.html). There's a nice IntelliJ style file for the project in `config/quality/style-guide` for code formatting. (Note: We'll be hosting the style guide file until it's updated in the official repo)
We are evaluating the Google's IntelliJ (and therefore Android Studio) [plugin](https://plugins.jetbrains.com/plugin/8527) for code formatting.
We acknowledge all the code does not meet these standards but we are working to change this over time.
### Syntax check
Before submitting a PR you should get no errors on `checkstyle`.
Just run:
```
./gradlew checkstyle
```
Your Rocket.Chat.Android version: (make sure you are running the latest) Before writing an issue, please make sure you're talking about the native application and not the Cordova one. If you are looking to open an issue to the Cordova application, go to this URL: https://github.com/RocketChat/Rocket.Chat.Cordova.
<!-- Version can be found by opening the side menu and then clicking on the chevron alongside username -->
<!-- Found a bug? List all devices that reproduced it and all that doesn't --> - Your Rocket.Chat.Android app version: ####
Mobile device model and OS version: (e.g. "Nexus 7 - Android 6.0.1") <!-- Make sure you are running the latest version (which can be found on the hostname screen or by opening the side menu and then clicking on the chevron alongside username -->
<!-- Don't forget to list the steps to reproduce. Stack traces may help too :) --> - Your Rocket.Chat server version: ####
- Device model (or emulator) you're running with: ####
<!-- e.g. Nexus 7 - Android 6.0.1 -->
- Steps to reproduce:
<!-- Stack traces may help too. -->
**The app isn't connecting to your server?**
Make sure your server supports WebSocket. These are the minimum requirements for Apache 2.4 and Nginx 1.3 or greater.
# Contributing Guidelines - Rocket.Chat.Android
Great to have you here! Here are a few ways you can help make this project better!
## Reporting an Issue
[Github Issues](https://github.com/RocketChat/Rocket.Chat.Android/issues) are used to track todos, bugs, feature requests, and more.
## Setting up a development environment
In case you're interested in playing around with the code or giving something back, here are some instructions on how to set up your project:
### Pre-requisites
1. [Android Studio and SDK Tools](https://developer.android.com/studio/index.html).
2. Clone this repo:
```
git clone https://github.com/RocketChat/Rocket.Chat.Android
```
3. Build the project.
### Code style guide
Before submitting a PR you should follow our [Coding Style](https://github.com/filipedelimabrito/Rocket.Chat.Android/blob/develop/CODING_STYLE.md).
...@@ -174,7 +174,7 @@ public class DDPClientImpl { ...@@ -174,7 +174,7 @@ public class DDPClientImpl {
disposables.clear(); disposables.clear();
} }
}, },
err -> task.setError(new DDPClientCallback.Ping.Timeout(client)) err -> task.trySetError(new DDPClientCallback.Ping.Timeout(client))
) )
); );
...@@ -213,7 +213,7 @@ public class DDPClientImpl { ...@@ -213,7 +213,7 @@ public class DDPClientImpl {
"error")) { "error")) {
String _id = response.optString("id"); String _id = response.optString("id");
if (id.equals(_id)) { if (id.equals(_id)) {
task.setError(new DDPSubscription.NoSub.Error(client, id, task.trySetError(new DDPSubscription.NoSub.Error(client, id,
response.optJSONObject("error"))); response.optJSONObject("error")));
disposables.clear(); disposables.clear();
} }
...@@ -284,7 +284,7 @@ public class DDPClientImpl { ...@@ -284,7 +284,7 @@ public class DDPClientImpl {
String _id = response.optString("id"); String _id = response.optString("id");
if (id.equals(_id)) { if (id.equals(_id)) {
if (!response.isNull("error")) { if (!response.isNull("error")) {
task.setError(new DDPClientCallback.RPC.Error(client, id, task.trySetError(new DDPClientCallback.RPC.Error(client, id,
response.optJSONObject("error"))); response.optJSONObject("error")));
} else { } else {
String result = response.optString("result"); String result = response.optString("result");
...@@ -296,7 +296,7 @@ public class DDPClientImpl { ...@@ -296,7 +296,7 @@ public class DDPClientImpl {
}, },
err -> { err -> {
if (err instanceof TimeoutException) { if (err instanceof TimeoutException) {
task.setError(new DDPClientCallback.RPC.Timeout(client)); task.trySetError(new DDPClientCallback.RPC.Timeout(client));
} }
} }
) )
...@@ -427,7 +427,7 @@ public class DDPClientImpl { ...@@ -427,7 +427,7 @@ public class DDPClientImpl {
} }
}, },
err -> { err -> {
task.trySetError(new Exception(err)); setTaskError(task, new Exception(err));
disposables.clear(); disposables.clear();
} }
) )
...@@ -442,7 +442,10 @@ public class DDPClientImpl { ...@@ -442,7 +442,10 @@ public class DDPClientImpl {
} }
} }
private void setTaskError(TaskCompletionSource<? extends RxWebSocketCallback.Base> task, Throwable throwable) { private void setTaskError(TaskCompletionSource task, Throwable throwable) {
if (task.getTask().isCompleted()) {
return;
}
if (throwable instanceof Exception) { if (throwable instanceof Exception) {
task.setError((Exception) throwable); task.setError((Exception) throwable);
} else { } else {
......
...@@ -46,8 +46,8 @@ android { ...@@ -46,8 +46,8 @@ android {
applicationId "chat.rocket.android" applicationId "chat.rocket.android"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion rootProject.ext.targetSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 40 versionCode 41
versionName "1.0.20" versionName "1.0.21"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
multiDexEnabled true multiDexEnabled true
......
...@@ -36,7 +36,7 @@ public class RocketChatApplicationDebug extends RocketChatApplication { ...@@ -36,7 +36,7 @@ public class RocketChatApplicationDebug extends RocketChatApplication {
private void enableStetho() { private void enableStetho() {
Stetho.initialize(Stetho.newInitializerBuilder(this) Stetho.initialize(Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this)) .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build()) .enableWebKitInspector(RealmInspectorModulesProvider.builder(this).withLimit(Long.MAX_VALUE).build())
.build()); .build());
} }
} }
\ No newline at end of file
...@@ -121,14 +121,14 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -121,14 +121,14 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
} }
} }
}); });
}
if (toolbar != null) { if (toolbar != null) {
toolbar.setNavigationOnClickListener(view -> { toolbar.setNavigationOnClickListener(view -> {
if (pane.isSlideable() && !pane.isOpen()) { if (pane.isSlideable() && !pane.isOpen()) {
pane.openPane(); pane.openPane();
} }
}); });
}
} }
} }
...@@ -251,12 +251,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -251,12 +251,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
R.string.server_config_activity_authenticating, Snackbar.LENGTH_INDEFINITE)); R.string.server_config_activity_authenticating, Snackbar.LENGTH_INDEFINITE));
} }
public void showLogoutMessage() {
statusTicker.updateStatus(StatusTicker.STATUS_LOGGING_OUT,
Snackbar.make(findViewById(getLayoutContainerForFragment()),
"Logging Out...", Snackbar.LENGTH_INDEFINITE));
}
@Override @Override
public void showConnectionOk() { public void showConnectionOk() {
statusTicker.updateStatus(StatusTicker.STATUS_DISMISS, null); statusTicker.updateStatus(StatusTicker.STATUS_DISMISS, null);
...@@ -314,11 +308,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -314,11 +308,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
} }
} }
@DebugLog
public void hideLogoutMessage() {
statusTicker.updateStatus(StatusTicker.STATUS_DISMISS, null);
}
@DebugLog @DebugLog
public void onLogout() { public void onLogout() {
if (new RocketChatCache(getApplicationContext()).getSelectedServerHostname() == null) { if (new RocketChatCache(getApplicationContext()).getSelectedServerHostname() == null) {
......
...@@ -34,6 +34,7 @@ import chat.rocket.android.fragment.sidebar.SidebarMainFragment; ...@@ -34,6 +34,7 @@ import chat.rocket.android.fragment.sidebar.SidebarMainFragment;
import chat.rocket.android.helper.AbsoluteUrlHelper; import chat.rocket.android.helper.AbsoluteUrlHelper;
import chat.rocket.android.helper.FileUploadHelper; import chat.rocket.android.helper.FileUploadHelper;
import chat.rocket.android.helper.LoadMoreScrollListener; import chat.rocket.android.helper.LoadMoreScrollListener;
import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.OnBackPressListener; import chat.rocket.android.helper.OnBackPressListener;
import chat.rocket.android.helper.RecyclerViewAutoScrollManager; import chat.rocket.android.helper.RecyclerViewAutoScrollManager;
import chat.rocket.android.helper.RecyclerViewScrolledToBottomListener; import chat.rocket.android.helper.RecyclerViewScrolledToBottomListener;
...@@ -49,6 +50,7 @@ import chat.rocket.android.layouthelper.extra_action.upload.AbstractUploadAction ...@@ -49,6 +50,7 @@ import chat.rocket.android.layouthelper.extra_action.upload.AbstractUploadAction
import chat.rocket.android.layouthelper.extra_action.upload.AudioUploadActionItem; import chat.rocket.android.layouthelper.extra_action.upload.AudioUploadActionItem;
import chat.rocket.android.layouthelper.extra_action.upload.ImageUploadActionItem; import chat.rocket.android.layouthelper.extra_action.upload.ImageUploadActionItem;
import chat.rocket.android.layouthelper.extra_action.upload.VideoUploadActionItem; import chat.rocket.android.layouthelper.extra_action.upload.VideoUploadActionItem;
import chat.rocket.android.log.RCLog;
import chat.rocket.android.renderer.RocketChatUserStatusProvider; import chat.rocket.android.renderer.RocketChatUserStatusProvider;
import chat.rocket.android.service.ConnectivityManager; import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.android.service.temp.DeafultTempSpotlightRoomCaller; import chat.rocket.android.service.temp.DeafultTempSpotlightRoomCaller;
...@@ -340,28 +342,30 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -340,28 +342,30 @@ public class RoomFragment extends AbstractChatRoomFragment implements
SlidingPaneLayout subPane = getActivity().findViewById(R.id.sub_sliding_pane); SlidingPaneLayout subPane = getActivity().findViewById(R.id.sub_sliding_pane);
sidebarFragment = (SidebarMainFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.sidebar_fragment_container); sidebarFragment = (SidebarMainFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.sidebar_fragment_container);
pane.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() { if (pane != null) {
@Override pane.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() {
public void onPanelSlide(View view, float v) { @Override
messageFormManager.enableComposingText(false); public void onPanelSlide(View view, float v) {
sidebarFragment.clearSearchViewFocus(); messageFormManager.enableComposingText(false);
//Ref: ActionBarDrawerToggle#setProgress sidebarFragment.clearSearchViewFocus();
toolbar.setNavigationIconProgress(v); //Ref: ActionBarDrawerToggle#setProgress
} toolbar.setNavigationIconProgress(v);
}
@Override @Override
public void onPanelOpened(View view) { public void onPanelOpened(View view) {
toolbar.setNavigationIconVerticalMirror(true); toolbar.setNavigationIconVerticalMirror(true);
} }
@Override @Override
public void onPanelClosed(View view) { public void onPanelClosed(View view) {
messageFormManager.enableComposingText(true); messageFormManager.enableComposingText(true);
toolbar.setNavigationIconVerticalMirror(false); toolbar.setNavigationIconVerticalMirror(false);
subPane.closePane(); subPane.closePane();
closeUserActionContainer(); closeUserActionContainer();
} }
}); });
}
} }
public void closeUserActionContainer() { public void closeUserActionContainer() {
...@@ -537,6 +541,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -537,6 +541,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements
try { try {
inputContentInfo.releasePermission(); inputContentInfo.releasePermission();
} catch (Exception e) { } catch (Exception e) {
RCLog.e(e);
Logger.report(e);
} }
return true; return true;
...@@ -552,9 +558,11 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -552,9 +558,11 @@ public class RoomFragment extends AbstractChatRoomFragment implements
@Override @Override
public void setupWith(RocketChatAbsoluteUrl rocketChatAbsoluteUrl) { public void setupWith(RocketChatAbsoluteUrl rocketChatAbsoluteUrl) {
token = rocketChatAbsoluteUrl.getToken(); if (rocketChatAbsoluteUrl != null) {
userId = rocketChatAbsoluteUrl.getUserId(); token = rocketChatAbsoluteUrl.getToken();
messageListAdapter.setAbsoluteUrl(rocketChatAbsoluteUrl); userId = rocketChatAbsoluteUrl.getUserId();
messageListAdapter.setAbsoluteUrl(rocketChatAbsoluteUrl);
}
} }
@Override @Override
...@@ -657,12 +665,16 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -657,12 +665,16 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
private void showRoomListFragment(int actionId) { private void showRoomListFragment(int actionId) {
Intent intent = new Intent(getActivity(), RoomActivity.class).putExtra("actionId", actionId) //TODO: oddly sometimes getActivity() yields null. Investigate the situations this might happen
.putExtra("roomId", roomId) //and fix it, removing this null-check
.putExtra("roomType", roomType) if (getActivity() != null) {
.putExtra("hostname", hostname) Intent intent = new Intent(getActivity(), RoomActivity.class).putExtra("actionId", actionId)
.putExtra("token", token) .putExtra("roomId", roomId)
.putExtra("userId", userId); .putExtra("roomType", roomType)
startActivity(intent); .putExtra("hostname", hostname)
.putExtra("token", token)
.putExtra("userId", userId);
startActivity(intent);
}
} }
} }
\ No newline at end of file
...@@ -19,6 +19,7 @@ import com.jakewharton.rxbinding2.support.v7.widget.RxSearchView; ...@@ -19,6 +19,7 @@ import com.jakewharton.rxbinding2.support.v7.widget.RxSearchView;
import com.jakewharton.rxbinding2.widget.RxCompoundButton; import com.jakewharton.rxbinding2.widget.RxCompoundButton;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import bolts.Task; import bolts.Task;
...@@ -58,7 +59,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -58,7 +59,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
private RoomListAdapter adapter; private RoomListAdapter adapter;
private SearchView searchView; private SearchView searchView;
private TextView loadMoreResultsText; private TextView loadMoreResultsText;
private List<RoomSidebar> roomSidebarList; private List<RoomSidebar> roomSidebarList = Collections.emptyList();
private Disposable spotlightDisposable; private Disposable spotlightDisposable;
private String hostname; private String hostname;
private static final String HOSTNAME = "hostname"; private static final String HOSTNAME = "hostname";
...@@ -325,7 +326,6 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -325,7 +326,6 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
public void onLogoutCleanUp() { public void onLogoutCleanUp() {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null && activity instanceof MainActivity) { if (activity != null && activity instanceof MainActivity) {
((MainActivity) activity).hideLogoutMessage();
((MainActivity) activity).onLogout(); ((MainActivity) activity).onLogout();
presenter.onLogout(task -> { presenter.onLogout(task -> {
if (task.isFaulted()) { if (task.isFaulted()) {
...@@ -343,7 +343,6 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -343,7 +343,6 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
presenter.beforeLogoutCleanUp(); presenter.beforeLogoutCleanUp();
final Activity activity = getActivity(); final Activity activity = getActivity();
if (activity != null && activity instanceof MainActivity) { if (activity != null && activity instanceof MainActivity) {
((MainActivity) activity).showLogoutMessage();
// Clear subscriptions on MainPresenter. // Clear subscriptions on MainPresenter.
((MainActivity) activity).beforeLogoutCleanUp(); ((MainActivity) activity).beforeLogoutCleanUp();
} }
......
...@@ -2,6 +2,7 @@ package chat.rocket.android.fragment.sidebar; ...@@ -2,6 +2,7 @@ package chat.rocket.android.fragment.sidebar;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.webkit.CookieManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -154,7 +155,8 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -154,7 +155,8 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
String currentHostname = rocketChatCache.getSelectedServerHostname(); String currentHostname = rocketChatCache.getSelectedServerHostname();
RealmHelper realmHelper = RealmStore.getOrCreate(currentHostname); RealmHelper realmHelper = RealmStore.getOrCreate(currentHostname);
realmHelper.executeTransaction(realm -> { realmHelper.executeTransaction(realm -> {
realm.deleteAll(); realm.executeTransactionAsync(realmObj -> realmObj.deleteAll());
CookieManager.getInstance().removeAllCookie();
ConnectivityManagerApi connectivityManagerApi = ConnectivityManager.getInstance(RocketChatApplication.getInstance()); ConnectivityManagerApi connectivityManagerApi = ConnectivityManager.getInstance(RocketChatApplication.getInstance());
connectivityManagerApi.removeServer(currentHostname); connectivityManagerApi.removeServer(currentHostname);
rocketChatCache.removeHostname(currentHostname); rocketChatCache.removeHostname(currentHostname);
......
...@@ -12,6 +12,7 @@ import java.util.HashMap; ...@@ -12,6 +12,7 @@ import java.util.HashMap;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import chat.rocket.android.helper.Logger;
import chat.rocket.persistence.realm.RealmStore; import chat.rocket.persistence.realm.RealmStore;
import hugo.weaving.DebugLog; import hugo.weaving.DebugLog;
import rx.Observable; import rx.Observable;
...@@ -113,6 +114,10 @@ public class RocketChatService extends Service implements ConnectivityServiceInt ...@@ -113,6 +114,10 @@ public class RocketChatService extends Service implements ConnectivityServiceInt
.doOnSuccess(thread -> { .doOnSuccess(thread -> {
webSocketThreads.put(hostname, thread); webSocketThreads.put(hostname, thread);
webSocketThreadLock.release(); webSocketThreadLock.release();
})
.doOnError(throwable -> {
Logger.report(throwable);
webSocketThreadLock.release();
}); });
}); });
} }
......
...@@ -122,7 +122,7 @@ public class RealmHelper { ...@@ -122,7 +122,7 @@ public class RealmHelper {
return task.getTask(); return task.getTask();
} }
private Task<Void> executeTransactionAsync(final RealmHelper.Transaction transaction) { public Task<Void> executeTransactionAsync(final RealmHelper.Transaction transaction) {
final TaskCompletionSource<Void> task = new TaskCompletionSource<>(); final TaskCompletionSource<Void> task = new TaskCompletionSource<>();
final Realm realm = instance(); final Realm realm = instance();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment