Commit 5c501bda authored by Yusuke Iwaki's avatar Yusuke Iwaki

checkpoint1: DDP.connect

parent cba1604a
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
apply plugin: 'com.jakewharton.hugo'
android { android {
compileSdkVersion 25 compileSdkVersion 25
...@@ -10,6 +13,8 @@ android { ...@@ -10,6 +13,8 @@ android {
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
} }
buildTypes { buildTypes {
release { release {
...@@ -17,9 +22,34 @@ android { ...@@ -17,9 +22,34 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
mavenCentral()
maven { url 'https://github.com/YusukeIwaki/realm-java-helpers/raw/master/repo' }
maven { url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo' }
maven { url 'https://github.com/RocketChat/Android-DDP/raw/master/repository' }
} }
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.0' compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'jp.co.crowdworks:realm-java-helpers:0.0.7'
compile 'jp.co.crowdworks:realm-java-helpers-bolts:0.0.7'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.facebook.stetho:stetho-okhttp3:1.4.1'
compile 'com.uphyca:stetho_realm:2.0.0'
compile 'chat.rocket:android-ddp:0.0.4'
compile 'com.jakewharton.timber:timber:4.3.1'
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
} }
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="chat.rocket.android"> package="chat.rocket.android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme"
android:name=".RocketChatApplication">
<activity android:name=".activity.MainActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activity.ServerConfigActivity"
android:windowSoftInputMode="adjustResize"/>
<service android:name=".service.RocketChatService"/>
</application> </application>
</manifest> </manifest>
package chat.rocket.android;
import android.content.Context;
import android.content.Intent;
import chat.rocket.android.activity.ServerConfigActivity;
public class LaunchUtil {
public static void showServerConfigActivity(Context context, String id) {
Intent intent = new Intent(context, ServerConfigActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("id", id);
context.startActivity(intent);
}
}
package chat.rocket.android;
import android.app.Application;
import com.facebook.stetho.Stetho;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import timber.log.Timber;
public class RocketChatApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Timber.plant(new Timber.DebugTree());
Realm.init(this);
Realm.setDefaultConfiguration(new RealmConfiguration.Builder()
.deleteRealmIfMigrationNeeded()
.build());
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
.build());
//TODO: add periodic trigger for RocketChatService.keepalive(this) here!
}
}
package chat.rocket.android.activity;
import android.support.v7.app.AppCompatActivity;
import java.util.List;
import java.util.UUID;
import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.service.RocketChatService;
import io.realm.Realm;
import io.realm.RealmResults;
import jp.co.crowdworks.realm_java_helpers.RealmListObserver;
import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
abstract class AbstractAuthedActivity extends AppCompatActivity {
private RealmListObserver<ServerConfig> mInsertEmptyRecordIfNoConfigurationExists = new RealmListObserver<ServerConfig>() {
@Override
protected RealmResults<ServerConfig> queryItems(Realm realm) {
return realm.where(ServerConfig.class).findAll();
}
@Override
protected void onCollectionChanged(List<ServerConfig> list) {
if (list.isEmpty()) {
final String newId = UUID.randomUUID().toString();
RealmHelperBolts
.executeTransaction(realm -> realm.createObject(ServerConfig.class, newId))
.continueWith(new LogcatIfError());
}
}
};
private RealmListObserver<ServerConfig> mShowConfigActivityIfNeeded = new RealmListObserver<ServerConfig>() {
@Override
protected RealmResults<ServerConfig> queryItems(Realm realm) {
return ServerConfig.queryLoginRequiredConnections(realm).findAll();
}
@Override
protected void onCollectionChanged(List<ServerConfig> list) {
ServerConfigActivity.launchFor(AbstractAuthedActivity.this, list);
}
};
@Override
protected void onResume() {
super.onResume();
RocketChatService.keepalive(this);
mInsertEmptyRecordIfNoConfigurationExists.sub();
mShowConfigActivityIfNeeded.sub();
}
@Override
protected void onPause() {
mShowConfigActivityIfNeeded.unsub();
mInsertEmptyRecordIfNoConfigurationExists.unsub();
super.onPause();
}
}
package chat.rocket.android.activity;
import android.support.annotation.IdRes;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import chat.rocket.android.helper.OnBackPressListener;
abstract class AbstractFragmentActivity extends AppCompatActivity {
protected abstract @IdRes int getLayoutContainerForFragment();
@Override
public void onBackPressed(){
Fragment f = getSupportFragmentManager().findFragmentById(getLayoutContainerForFragment());
if(f instanceof OnBackPressListener &&
((OnBackPressListener) f).onBackPressed()){
//consumed. do nothing.
}
else super.onBackPressed();
}
protected void showFragment(Fragment f) {
getSupportFragmentManager().beginTransaction()
.replace(getLayoutContainerForFragment(), f)
.commit();
}
protected void showFragmentWithBackStack(Fragment f) {
getSupportFragmentManager().beginTransaction()
.replace(getLayoutContainerForFragment(), f)
.addToBackStack(null)
.commit();
}
}
package chat.rocket.android.activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import chat.rocket.android.R;
import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.model.ServerConfig;
import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
public class MainActivity extends AbstractAuthedActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState==null) {
RealmHelperBolts.executeTransaction(realm -> {
for(ServerConfig config: ServerConfig.queryActiveConnections(realm).findAll()) {
config.setTokenVerified(false);
}
return null;
}).continueWith(new LogcatIfError());
}
}
}
package chat.rocket.android.activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import java.util.List;
import chat.rocket.android.LaunchUtil;
import chat.rocket.android.R;
import chat.rocket.android.fragment.server_config.ConnectingToHostFragment;
import chat.rocket.android.fragment.server_config.InputHostnameFragment;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.ServerAuthProvider;
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.service.RocketChatService;
import io.realm.Realm;
import io.realm.RealmList;
import io.realm.RealmQuery;
import jp.co.crowdworks.realm_java_helpers.RealmObjectObserver;
public class ServerConfigActivity extends AbstractFragmentActivity {
@Override
protected int getLayoutContainerForFragment() {
return R.id.content;
}
private String mServerConfigId;
private RealmObjectObserver<ServerConfig> mServerConfigObserver = new RealmObjectObserver<ServerConfig>() {
@Override
protected RealmQuery<ServerConfig> query(Realm realm) {
return realm.where(ServerConfig.class).equalTo("id", mServerConfigId);
}
@Override
protected void onChange(ServerConfig config) {
onRenderServerConfig(config);
}
};
public static boolean launchFor(Context context, List<ServerConfig> configList) {
for (ServerConfig config: configList) {
if (TextUtils.isEmpty(config.getHostname())) {
return launchFor(context, config);
}
else if (!TextUtils.isEmpty(config.getConnectionError())) {
return launchFor(context, config);
}
}
for (ServerConfig config: configList) {
if (config.getProviders().isEmpty()) {
return launchFor(context, config);
}
}
for (ServerConfig config: configList) {
if (TextUtils.isEmpty(config.getSelectedProviderName())) {
return launchFor(context, config);
}
}
for (ServerConfig config: configList) {
if (TextUtils.isEmpty(config.getToken())) {
return launchFor(context, config);
}
}
for (ServerConfig config: configList) {
if (!config.isTokenVerified()) {
return launchFor(context, config);
}
}
return false;
}
private static boolean launchFor(Context context, ServerConfig config) {
LaunchUtil.showServerConfigActivity(context, config.getId());
return true;
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent==null || intent.getExtras()==null) {
finish();
return;
}
mServerConfigId = intent.getStringExtra("id");
if (TextUtils.isEmpty(mServerConfigId)) {
finish();
return;
}
setContentView(R.layout.simple_screen);
}
@Override
protected void onResume() {
super.onResume();
RocketChatService.keepalive(this);
mServerConfigObserver.sub();
}
@Override
protected void onPause() {
mServerConfigObserver.unsub();
super.onPause();
}
private void onRenderServerConfig(ServerConfig config) {
if (config==null) {
finish();
return;
}
if (config.isTokenVerified()) {
finish();
return;
}
final String token = config.getToken();
if (!TextUtils.isEmpty(token)) {
return;
}
final String selectedProviderName = config.getSelectedProviderName();
if (!TextUtils.isEmpty(selectedProviderName)) {
return;
}
RealmList<ServerAuthProvider> providers = config.getProviders();
if (!providers.isEmpty()) {
return;
}
final String error = config.getConnectionError();
String hostname = config.getHostname();
if (!TextUtils.isEmpty(hostname) && TextUtils.isEmpty(error)) {
showFragment(new ConnectingToHostFragment());
return;
}
showFragment(new InputHostnameFragment());
}
@Override
protected void showFragment(Fragment f) {
injectIdArgTo(f);
super.showFragment(f);
}
@Override
protected void showFragmentWithBackStack(Fragment f) {
injectIdArgTo(f);
super.showFragmentWithBackStack(f);
}
private void injectIdArgTo(Fragment f) {
Bundle args = f.getArguments();
if(args==null) args = new Bundle();
args.putString("id", mServerConfigId);
f.setArguments(args);
}
@Override
public void onBackPressed() {
if (ServerConfig.hasActiveConnection()) {
super.onBackPressed();
}
else {
moveTaskToBack(true);
}
}
}
package chat.rocket.android.fragment;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public abstract class AbstractFragment extends Fragment {
protected View mRootView;
protected abstract @LayoutRes int getLayout();
protected abstract void onSetupView();
@Nullable
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mRootView = inflater.inflate(getLayout(), container,false);
onSetupView();
return mRootView;
}
protected void finish() {
if(getFragmentManager().getBackStackEntryCount()==0){
getActivity().finish();
}
else {
getFragmentManager().popBackStack();
}
}
}
package chat.rocket.android.fragment.server_config;
import android.os.Bundle;
import android.support.annotation.Nullable;
import chat.rocket.android.fragment.AbstractFragment;
import chat.rocket.android.helper.TextUtils;
abstract class AbstractServerConfigFragment extends AbstractFragment {
protected String mServerConfigId;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
if (args==null) {
finish();
return;
}
mServerConfigId = args.getString("id");
if (TextUtils.isEmpty(mServerConfigId)) {
finish();
return;
}
}
}
package chat.rocket.android.fragment.server_config;
import chat.rocket.android.R;
public class ConnectingToHostFragment extends AbstractServerConfigFragment {
@Override
protected int getLayout() {
return R.layout.fragment_wait_for_connection;
}
@Override
protected void onSetupView() {
}
}
package chat.rocket.android.fragment.server_config;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONObject;
import chat.rocket.android.R;
import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.ServerConfig;
import io.realm.Realm;
import io.realm.RealmQuery;
import jp.co.crowdworks.realm_java_helpers.RealmObjectObserver;
import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
public class InputHostnameFragment extends AbstractServerConfigFragment {
public InputHostnameFragment(){}
@Override
protected int getLayout() {
return R.layout.fragment_input_hostname;
}
RealmObjectObserver<ServerConfig> mObserver = new RealmObjectObserver<ServerConfig>() {
@Override
protected RealmQuery<ServerConfig> query(Realm realm) {
return realm.where(ServerConfig.class).equalTo("id", mServerConfigId);
}
@Override
protected void onChange(ServerConfig config) {
onRenderServerConfig(config);
}
};
@Override
protected void onSetupView() {
final TextView editor = (TextView) mRootView.findViewById(R.id.editor_hostname);
final View btnConnect = mRootView.findViewById(R.id.btn_connect);
btnConnect.setOnClickListener(v -> {
final String hostname = TextUtils.or(TextUtils.or(editor.getText(), editor.getHint()), "").toString();
RealmHelperBolts
.executeTransaction(realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
.put("id", mServerConfigId)
.put("hostname", hostname)
.put("connectionError", JSONObject.NULL)))
.continueWith(new LogcatIfError());
});
mObserver.sub();
}
@Override
public void onResume() {
super.onResume();
mObserver.keepalive();
}
@Override
public void onDestroyView() {
mObserver.unsub();
super.onDestroyView();
}
private Handler mShowError = new Handler() {
@Override
public void handleMessage(Message msg) {
Toast.makeText(mRootView.getContext(), (String) msg.obj, Toast.LENGTH_SHORT).show();
}
};
private void showError(String errString) {
mShowError.removeMessages(0);
Message m = Message.obtain(mShowError, 0, errString);
mShowError.sendMessageDelayed(m, 160);
}
private void onRenderServerConfig(ServerConfig config) {
final TextView editor = (TextView) mRootView.findViewById(R.id.editor_hostname);
if (!TextUtils.isEmpty(config.getHostname())) editor.setText(config.getHostname());
if (!TextUtils.isEmpty(config.getConnectionError())) {
clearConnectionErrorAndHostname();
showError(config.getConnectionError());
}
}
private void clearConnectionErrorAndHostname() {
RealmHelperBolts
.executeTransaction(realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
.put("id", mServerConfigId)
.put("hostname", JSONObject.NULL)
.put("connectionError", JSONObject.NULL)))
.continueWith(new LogcatIfError());
}
}
package chat.rocket.android.helper;
import bolts.Continuation;
import bolts.Task;
import timber.log.Timber;
public class LogcatIfError implements Continuation {
@Override
public Object then(Task task) throws Exception {
if (task.isFaulted()) {
Timber.w(task.getError());
}
return task;
}
}
package chat.rocket.android.helper;
import com.facebook.stetho.okhttp3.StethoInterceptor;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
public class OkHttpHelper {
private static OkHttpClient sHttpClientForWS;
public static OkHttpClient getClientForWebSocket() {
if (sHttpClientForWS==null) {
sHttpClientForWS = new OkHttpClient.Builder()
.readTimeout(0, TimeUnit.NANOSECONDS)
.addNetworkInterceptor(new StethoInterceptor())
.build();
}
return sHttpClientForWS;
}
}
package chat.rocket.android.helper;
public interface OnBackPressListener {
boolean onBackPressed();
}
package chat.rocket.android.helper;
public class TextUtils {
public static boolean isEmpty(CharSequence str) {
// same definition as android.text.TextUtils#isEmpty().
return str == null || str.length() == 0;
}
public static CharSequence or(CharSequence str, CharSequence defaultValue) {
if (isEmpty(str)) return defaultValue;
return str;
}
}
package chat.rocket.android.model;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
public class ServerAuthProvider extends RealmObject {
@PrimaryKey
private String name; //email, twitter, github, ...
}
package chat.rocket.android.model;
import org.json.JSONObject;
import chat.rocket.android.helper.LogcatIfError;
import hugo.weaving.DebugLog;
import io.realm.Realm;
import io.realm.RealmList;
import io.realm.RealmObject;
import io.realm.RealmQuery;
import io.realm.annotations.PrimaryKey;
import jp.co.crowdworks.realm_java_helpers.RealmHelper;
import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
public class ServerConfig extends RealmObject {
@PrimaryKey
private String id;
private String hostname;
private String connectionError;
private String token;
private boolean tokenVerified;
private RealmList<ServerAuthProvider> providers;
private String selectedProviderName;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getHostname() {
return hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public String getConnectionError() {
return connectionError;
}
public void setConnectionError(String connectionError) {
this.connectionError = connectionError;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public boolean isTokenVerified() {
return tokenVerified;
}
public void setTokenVerified(boolean tokenVerified) {
this.tokenVerified = tokenVerified;
}
public RealmList<ServerAuthProvider> getProviders() {
return providers;
}
public void setProviders(RealmList<ServerAuthProvider> providers) {
this.providers = providers;
}
public String getSelectedProviderName() {
return selectedProviderName;
}
public void setSelectedProviderName(String selectedProviderName) {
this.selectedProviderName = selectedProviderName;
}
public static RealmQuery<ServerConfig> queryLoginRequiredConnections(Realm realm) {
return realm.where(ServerConfig.class)
.equalTo("tokenVerified", false);
}
public static RealmQuery<ServerConfig> queryActiveConnections(Realm realm) {
return realm.where(ServerConfig.class)
.isNotNull("token");
}
public static boolean hasActiveConnection() {
ServerConfig config = RealmHelper.executeTransactionForRead(realm ->
queryActiveConnections(realm).findFirst());
return config != null;
}
@DebugLog
public static void logError(String id, Exception e) {
RealmHelperBolts
.executeTransaction(realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class, new JSONObject()
.put("id", id)
.put("connectionError", e.getMessage())))
.continueWith(new LogcatIfError());
}
}
package chat.rocket.android.service;
public interface Registerable {
void register();
void keepalive();
void unregister();
}
package chat.rocket.android.service;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import bolts.Task;
import chat.rocket.android.model.ServerConfig;
import io.realm.Realm;
import io.realm.RealmResults;
import jp.co.crowdworks.realm_java_helpers.RealmListObserver;
public class RocketChatService extends Service {
public static void keepalive(Context context) {
context.startService(new Intent(context, RocketChatService.class));
}
public static void kill(Context context) {
context.stopService(new Intent(context, RocketChatService.class));
}
private HashMap<String, RocketChatWebSocketThread> mWebSocketThreads;
private RealmListObserver<ServerConfig> mConnectionRequiredServerConfigObserver = new RealmListObserver<ServerConfig>() {
@Override
protected RealmResults<ServerConfig> queryItems(Realm realm) {
return realm.where(ServerConfig.class)
.isNotNull("hostname")
.isNull("connectionError")
.findAll();
}
@Override
protected void onCollectionChanged(List<ServerConfig> list) {
syncWebSocketThreadsWith(list);
}
};
@Override
public void onCreate() {
super.onCreate();
mWebSocketThreads = new HashMap<>();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mConnectionRequiredServerConfigObserver.keepalive();
return START_STICKY;
}
private void syncWebSocketThreadsWith(List<ServerConfig> configList) {
final Iterator<Map.Entry<String, RocketChatWebSocketThread>> it = mWebSocketThreads.entrySet().iterator();
while(it.hasNext()) {
Map.Entry<String, RocketChatWebSocketThread> e = it.next();
String id = e.getKey();
boolean found = false;
for(ServerConfig config: configList) {
if (id.equals(config.getId())) {
found = true;
break;
}
}
if (!found) {
RocketChatWebSocketThread.terminate(e.getValue());
it.remove();
}
}
for(ServerConfig config: configList) {
findOrCreateWebSocketThread(config).onSuccess(task -> {
RocketChatWebSocketThread thread = task.getResult();
thread.syncStateWith(config);
return null;
});
}
}
private Task<RocketChatWebSocketThread> findOrCreateWebSocketThread(final ServerConfig config) {
final String id = config.getId();
if (mWebSocketThreads.containsKey(id)) {
return Task.forResult(mWebSocketThreads.get(id));
}
else {
return RocketChatWebSocketThread.getStarted(getApplicationContext(), config).onSuccessTask(task -> {
mWebSocketThreads.put(id, task.getResult());
return task;
});
}
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
\ No newline at end of file
package chat.rocket.android.service;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Iterator;
import bolts.Task;
import bolts.TaskCompletionSource;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.ws.RocketChatWebSocketAPI;
import hugo.weaving.DebugLog;
import jp.co.crowdworks.realm_java_helpers.RealmHelper;
import timber.log.Timber;
import static android.content.ContentValues.TAG;
public class RocketChatWebSocketThread extends HandlerThread {
private final Context mAppContext;
private final String mServerConfigId;
private RocketChatWebSocketAPI mWebSocketAPI;
private boolean mSocketExists;
private boolean mListenersRegistered;
private RocketChatWebSocketThread(Context appContext, String id) {
super("RC_thread_"+id);
mServerConfigId = id;
mAppContext = appContext;
}
@DebugLog
public static Task<RocketChatWebSocketThread> getStarted(Context appContext, ServerConfig config) {
TaskCompletionSource<RocketChatWebSocketThread> task = new TaskCompletionSource<>();
new RocketChatWebSocketThread(appContext, config.getId()){
@Override
protected void onLooperPrepared() {
try {
super.onLooperPrepared();
task.setResult(this);
}
catch (Exception e) {
task.setError(e);
}
}
}.start();
return task.getTask();
}
@DebugLog
public static void terminate(RocketChatWebSocketThread t) {
t.quit();
}
private Task<Void> ensureConnection() {
if (mWebSocketAPI == null || !mWebSocketAPI.isConnected()) {
return registerListeners();
}
else return Task.forResult(null);
}
@DebugLog
public void syncStateWith(ServerConfig config) {
if (config == null || TextUtils.isEmpty(config.getHostname()) || !TextUtils.isEmpty(config.getConnectionError())) {
quit();
}
else {
ensureConnection()
.continueWith(task -> {
new Handler(getLooper()).post(() -> {
keepaliveListeners();
});
return null;
});
}
}
@Override
protected void onLooperPrepared() {
super.onLooperPrepared();
registerListeners();
}
@Override
public boolean quit() {
scheduleUnregisterListeners();
return super.quit();
}
@Override
public boolean quitSafely() {
scheduleUnregisterListeners();
return super.quitSafely();
}
private void scheduleUnregisterListeners() {
new Handler(getLooper()).post(() -> {
Timber.d("thread %s: quit()", Thread.currentThread().getId());
unregisterListeners();
});
}
private static final Class[] REGISTERABLE_CLASSES = {
};
private final ArrayList<Registerable> mListeners = new ArrayList<>();
private void prepareWebSocket() {
ServerConfig config = RealmHelper.executeTransactionForRead(realm -> realm.where(ServerConfig.class).equalTo("id", mServerConfigId).findFirst());
if (mWebSocketAPI == null || !mWebSocketAPI.isConnected()) {
mWebSocketAPI = RocketChatWebSocketAPI.create(config.getHostname());
}
}
@DebugLog
private Task<Void> registerListeners(){
if (mSocketExists) return Task.forResult(null);
mSocketExists = true;
prepareWebSocket();
return mWebSocketAPI.connect().onSuccess(task -> {
registerListenersActually();
// just for debugging.
task.getResult().client.getSubscriptionCallback().subscribe(event -> {
Timber.d(TAG, "Callback [DEBUG] < " + event);
});
return null;
}).continueWith(task -> {
if (task.isFaulted()) {
ServerConfig.logError(mServerConfigId, task.getError());
}
return null;
});
}
//@DebugLog
private void registerListenersActually() {
if (mListenersRegistered) return;
mListenersRegistered = true;
for(Class clazz: REGISTERABLE_CLASSES){
try {
Constructor ctor = clazz.getConstructor(Context.class, RocketChatWebSocketAPI.class);
Object obj = ctor.newInstance(mAppContext, mWebSocketAPI);
if(obj instanceof Registerable) {
Registerable l = (Registerable) obj;
l.register();
mListeners.add(l);
}
} catch (Exception e) {
Timber.w(e);
}
}
}
//@DebugLog
private void keepaliveListeners(){
if (!mSocketExists || !mListenersRegistered) return;
for (Registerable l : mListeners) l.keepalive();
}
//@DebugLog
private void unregisterListeners(){
if (!mSocketExists || !mListenersRegistered) return;
Iterator<Registerable> it = mListeners.iterator();
while(it.hasNext()){
Registerable l = it.next();
l.unregister();
it.remove();
}
if (mWebSocketAPI != null) {
mWebSocketAPI.close();
mWebSocketAPI = null;
}
mListenersRegistered = false;
mSocketExists = false;
}
}
package chat.rocket.android.view;
import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
abstract class AbstractCustomFontTextView extends AppCompatTextView {
protected abstract String getFont();
public AbstractCustomFontTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public AbstractCustomFontTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public AbstractCustomFontTextView(Context context) {
super(context);
init();
}
private void init() {
String font = getFont();
if (font!=null) {
Typeface tf = TypefaceHelper.getTypeface(getContext(), font);
if (tf!=null) setTypeface(tf);
}
}
}
package chat.rocket.android.view;
import android.content.Context;
import android.util.AttributeSet;
public class FontAwesomeTextView extends AbstractCustomFontTextView {
public FontAwesomeTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public FontAwesomeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FontAwesomeTextView(Context context) {
super(context);
}
@Override
protected String getFont() {
return "fontawesome-webfont.ttf";
}
}
package chat.rocket.android.view;
import android.content.Context;
import android.util.AttributeSet;
public class FontelloTextView extends AbstractCustomFontTextView {
public FontelloTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public FontelloTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FontelloTextView(Context context) {
super(context);
}
@Override
protected String getFont() {
return "fontello.ttf";
}
}
package chat.rocket.android.view;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import java.util.Hashtable;
// ref:https://code.google.com/p/android/issues/detail?id=9904#c7
public class TypefaceHelper {
private static final String TAG = TypefaceHelper.class.getName();
private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();
public static Typeface getTypeface(Context c, String assetPath) {
synchronized (cache) {
if (!cache.containsKey(assetPath)) {
try {
Typeface t = Typeface.createFromAsset(c.getAssets(),
assetPath);
cache.put(assetPath, t);
} catch (Exception e) {
Log.e(TAG, "Could not get typeface '" + assetPath
+ "' because " + e.getMessage());
return null;
}
}
return cache.get(assetPath);
}
}
}
package chat.rocket.android.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import java.util.ArrayList;
import chat.rocket.android.R;
public class WaitingView extends LinearLayout {
private ArrayList<View> mDots;
public WaitingView(Context context) {
super(context);
initialize(context, null);
}
public WaitingView(Context context, AttributeSet attrs) {
super(context, attrs);
initialize(context, attrs);
}
public WaitingView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize(context, attrs);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public WaitingView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initialize(context, attrs);
}
private void initialize(Context context, AttributeSet attrs) {
int size = context.getResources().getDimensionPixelSize(R.dimen.def_waiting_view_dot_size);
int count = 3;
if (attrs != null) {
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.WaitingView, 0, 0);
size = a.getDimensionPixelSize(R.styleable.WaitingView_dotSize, size);
count = a.getInteger(R.styleable.WaitingView_dotCount, count);
a.recycle();
}
mDots = new ArrayList<>();
setOrientation(HORIZONTAL);
for (int i=0; i<count; i++) addDot(context, size);
addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View view) {
start();
}
@Override
public void onViewDetachedFromWindow(View view) {
cancel();
}
});
}
private void addDot(Context context, int size) {
FrameLayout f = new FrameLayout(context);
f.setLayoutParams(new LinearLayoutCompat.LayoutParams(size*3/2, size*3/2));
ImageView dot = new ImageView(context);
dot.setImageResource(R.drawable.white_circle);
dot.setLayoutParams(new FrameLayout.LayoutParams(size, size, Gravity.CENTER));
f.addView(dot);
addView(f);
mDots.add(dot);
}
private void start() {
for(int i=0; i<mDots.size(); i++) {
animateDot(mDots.get(i), 160*i, 480, 480);
}
}
private void animateDot(final View dot, final long startDelay, final long duration, final long interval) {
dot.setScaleX(0);
dot.setScaleY(0);
dot.animate()
.scaleX(1).scaleY(1)
.setDuration(duration)
.setStartDelay(startDelay)
.withEndAction(() -> {
dot.animate()
.scaleX(0).scaleY(0)
.setDuration(duration)
.setStartDelay(0)
.withEndAction(() -> {
animateDot(dot, interval, duration, interval);
})
.start();
})
.start();
}
private void cancel() {
for(View dot: mDots) {
dot.clearAnimation();
}
}
}
package chat.rocket.android.ws;
import bolts.Task;
import chat.rocket.android.helper.OkHttpHelper;
import chat.rocket.android_ddp.DDPClient;
import chat.rocket.android_ddp.DDPClientCallback;
public class RocketChatWebSocketAPI {
private final DDPClient mDDPClient;
private final String mHostName;
private RocketChatWebSocketAPI(String hostname) {
mDDPClient = new DDPClient(OkHttpHelper.getClientForWebSocket());
mHostName = hostname;
}
public static RocketChatWebSocketAPI create(String hostname) {
return new RocketChatWebSocketAPI(hostname);
}
public Task<DDPClientCallback.Connect> connect() {
return mDDPClient.connect("wss://" + mHostName + "/websocket");
}
public boolean isConnected() {
return mDDPClient.isConnected();
}
public void close() {
mDDPClient.close();
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M12,4l-1.41,1.41L16.17,11H4v2h12.17l-5.58,5.59L12,20l8,-8z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--item android:state_enabled="false" android:color="@color/textColorLink" /-->
<item android:color="@color/textColorLink" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/userstatus_away"/>
<stroke android:width="1dp" android:color="@color/userstatus_away_outline" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/userstatus_busy"/>
<stroke android:width="1dp" android:color="@color/userstatus_busy_outline" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/userstatus_offline"/>
<stroke android:width="1dp" android:color="@color/userstatus_offline_outline" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/userstatus_online"/>
<stroke android:width="1dp" android:color="@color/userstatus_online_outline" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@android:color/white"/>
</shape>
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/sidebar" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/app_name"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/activity_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/sidebar" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/app_name"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/activity_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SlidingPaneLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/avatar_image_size_large" android:layout_height="@dimen/avatar_image_size_large">
<FrameLayout
android:id="@+id/avatar_color"
android:layout_width="@dimen/avatar_image_size_large"
android:layout_height="@dimen/avatar_image_size_large"
android:layout_gravity="center">
<TextView
android:id="@+id/avatar_initials"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/avatar_text_size_large"
android:layout_gravity="center"/>
</FrameLayout>
<ImageView
android:id="@+id/avatar_img"
android:layout_width="@dimen/avatar_image_size_large"
android:layout_height="@dimen/avatar_image_size_large"
android:src="@drawable/ic_default_avatar"
android:scaleType="centerInside"/>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/avatar_image_size_normal" android:layout_height="@dimen/avatar_image_size_normal">
<FrameLayout
android:id="@+id/avatar_color"
android:layout_width="@dimen/avatar_image_size_normal"
android:layout_height="@dimen/avatar_image_size_normal"
android:layout_gravity="center">
<TextView
android:id="@+id/avatar_initials"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/avatar_text_size_normal"
android:layout_gravity="center"/>
</FrameLayout>
<ImageView
android:id="@+id/avatar_img"
android:layout_width="@dimen/avatar_image_size_normal"
android:layout_height="@dimen/avatar_image_size_normal"
android:src="@drawable/ic_default_avatar"
android:scaleType="centerInside"/>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?attr/colorPrimaryDark">
<LinearLayout
android:layout_width="wrap_content"
android:minWidth="288dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
android:padding="@dimen/margin_24"
android:layout_gravity="center">
<LinearLayout
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hostname"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"/>
<EditText
android:id="@+id/editor_hostname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="demo.rocket.chat"
android:imeOptions="actionGo"
android:inputType="textWebEditText"/>
</LinearLayout>
<Space
android:layout_width="@dimen/margin_8"
android:layout_height="wrap_content" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/btn_connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
app:srcCompat="@drawable/ic_arrow_forward_white_24dp"
app:elevation="2dp"
android:layout_gravity="end|bottom"/>
</LinearLayout>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimaryDark">
<chat.rocket.android.view.WaitingView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="288dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/colorPrimary"
android:orientation="vertical"
android:theme="@style/AppTheme.Dark">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="?attr/colorPrimaryDark">
<LinearLayout
android:id="@+id/user_info_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="@dimen/margin_16"
android:background="?attr/selectableItemBackground">
<ImageView
android:id="@+id/img_userstatus"
android:layout_width="8dp"
android:layout_height="8dp"
android:src="@drawable/userstatus_online"/>
<Space
android:layout_width="@dimen/margin_8"
android:layout_height="wrap_content"/>
<include layout="@layout/avatar_container_large"/>
<FrameLayout
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="@dimen/margin_8"
android:layout_marginRight="@dimen/margin_8">
<TextView
android:id="@+id/txt_account_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_gravity="center_vertical"
android:text="John Doe"/>
</FrameLayout>
<chat.rocket.android.view.FontAwesomeTextView
android:id="@+id/img_user_action_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fa_chevron_down"
android:textSize="16dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorPrimary">#3F51B5</color> <color name="colorPrimary">#00426B</color>
<color name="colorPrimaryDark">#303F9F</color> <color name="colorPrimaryDark">#FF001E31</color>
<color name="colorAccent">#FF4081</color> <color name="colorAccent">#FF2D91FA</color>
<color name="colorAccentLight">#FF6CB1FA</color>
<color name="colorAccentDark">#FF287DD7</color>
<color name="colorAccent_a40">#662D91FA</color>
<color name="textColorLink">#008ce3</color>
<color name="divider">#FFEEEEEE</color>
<color name="white">#FFFEFEFF</color>
</resources> </resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="avatar_image_size_normal">24dp</dimen>
<dimen name="avatar_image_size_large">48dp</dimen>
<dimen name="avatar_text_size_normal">11sp</dimen>
<dimen name="avatar_text_size_large">28sp</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string translatable="false" name="fa_chevron_down">&#xf078;</string>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="margin_8">8dp</dimen>
<dimen name="margin_16">16dp</dimen>
<dimen name="margin_24">24dp</dimen>
</resources>
\ No newline at end of file
<resources> <resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorLink">@drawable/selector_text_color_link</item>
<item name="android:listDivider">@color/divider</item>
<item name="colorControlActivated">@color/colorAccentDark</item>
<item name="android:textColorHighlight">@color/colorAccent_a40</item>
<item name="actionModeBackground">?attr/colorPrimaryDark</item>
<item name="android:statusBarColor" tools:targetApi="21">?attr/colorPrimaryDark</item>
<item name="android:navigationBarColor" tools:targetApi="21">?attr/colorPrimaryDark</item>
</style>
<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorLink">@drawable/selector_text_color_link</item>
<item name="android:listDivider">@color/divider</item>
<item name="colorControlActivated">@color/colorAccentDark</item>
<item name="android:textColorHighlight">@color/colorAccent_a40</item>
<item name="actionModeBackground">?attr/colorPrimaryDark</item>
<item name="android:statusBarColor" tools:targetApi="21">?attr/colorPrimaryDark</item>
<item name="android:navigationBarColor" tools:targetApi="21">?attr/colorPrimaryDark</item>
</style> </style>
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorLink">@drawable/selector_text_color_link</item>
<item name="android:listDivider">@color/divider</item>
<item name="colorControlActivated">@color/colorAccentDark</item>
<item name="android:textColorHighlight">@color/colorAccent_a40</item>
</style>
</resources> </resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="userstatus_online">#35ac19</color>
<color name="userstatus_online_outline">#2c9210</color>
<color name="userstatus_away">#fcb316</color>
<color name="userstatus_away_outline">#e69200</color>
<color name="userstatus_busy">#d30230</color>
<color name="userstatus_busy_outline">#9f0030</color>
<color name="userstatus_offline">#7b7b7b</color>
<color name="userstatus_offline_outline">#666</color>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="WaitingView">
<attr name="dotSize" format="dimension" />
<attr name="dotCount" format="integer" />
</declare-styleable>
<dimen name="def_waiting_view_dot_size">16dp</dimen>
</resources>
\ No newline at end of file
...@@ -3,12 +3,16 @@ ...@@ -3,12 +3,16 @@
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.2' classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
classpath 'me.tatarka:gradle-retrolambda:3.3.1'
classpath "io.realm:realm-gradle-plugin:2.1.1"
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
} }
} }
......
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