Skip to content

Commit

Permalink
Retrofit work begins, ZulipServices and dependencies.
Browse files Browse the repository at this point in the history
touch ups

reset pointless auto styling fixes

Removed line space, fix spelling based on pr. Fixes: nodejs#147

Removed fabricKey, removed extra line

Removed line

Added some crashlytics logging for potential breadcrumbs on failure.

Started working on retrofit implementation.

Backup save. Nearly reached completion of modeling responses.

Backup. Working through weird bug on formatting for updating pointer

 realized wrong encoding was being used.
  • Loading branch information
oorosc authored and niftynei committed Sep 10, 2016
1 parent a694de8 commit 1e194d5
Show file tree
Hide file tree
Showing 18 changed files with 696 additions and 38 deletions.
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ dependencies {
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-auth:8.4.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.j256.ormlite:ormlite-core:5.0'
compile 'com.j256.ormlite:ormlite-android:5.0'
compile 'commons-lang:commons-lang:2.6'
Expand All @@ -86,7 +90,6 @@ dependencies {
}
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
transitive = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ public void testAGOMFetch() throws SQLException, InterruptedException,

private Message sampleMessage(ZulipApp app, int id) throws SQLException {
Message rtr = new Message(app);
rtr.setSender(Person.getOrUpdate(app, "Test User",
rtr.setSender(Person.getOrUpdate(app, "UserConfigurationResponse User",
TESTUSER_EXAMPLE_COM, ""));
rtr.setContent("Test message");
rtr.setContent("UserConfigurationResponse message");
rtr.setType(MessageType.PRIVATE_MESSAGE);
rtr.setRecipient(new String[] {TESTUSER_EXAMPLE_COM});
rtr.setID(id);
Expand Down
76 changes: 63 additions & 13 deletions app/src/main/java/com/zulip/android/ZulipApp.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package com.zulip.android;

import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;
import java.util.Queue;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
Expand All @@ -21,6 +9,7 @@
import android.os.Handler;
import android.util.Log;

import com.crashlytics.android.Crashlytics;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.j256.ormlite.misc.TransactionManager;
Expand All @@ -32,12 +21,35 @@
import com.zulip.android.models.Presence;
import com.zulip.android.models.Stream;
import com.zulip.android.networking.AsyncUnreadMessagesUpdate;
import com.zulip.android.util.BuildHelper;
import com.zulip.android.networking.ZulipInterceptor;
import com.zulip.android.service.ZulipServices;
import com.zulip.android.util.ZLog;

import org.json.JSONArray;
import org.json.JSONException;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;

import io.fabric.sdk.android.Fabric;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.ResponseBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
* Stores the global variables which are frequently used.
*
Expand All @@ -60,6 +72,10 @@ public class ZulipApp extends Application {
private DatabaseHelper databaseHelper;
private Set<String> mutedTopics;
private static final String MUTED_TOPIC_KEY = "mutedTopics";
private ZulipServices zulipServices;

public Request goodRequest;
public Request badRequest;
private ZulipActivity zulipActivity;

public ZulipActivity getZulipActivity() {
Expand Down Expand Up @@ -159,6 +175,24 @@ private void afterLogin() {
setupEmoji();
}

public ZulipServices getZulipServices() {
if(zulipServices == null) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);

zulipServices = new Retrofit.Builder()
.client(new OkHttpClient.Builder().readTimeout(60, TimeUnit.SECONDS)
.addInterceptor(new ZulipInterceptor())
.addInterceptor(logging)
.build())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(getServerURI())
.build()
.create(ZulipServices.class);
}
return zulipServices;
}

/**
* Fills the Emoji Table with the existing emoticons saved in the assets folder.
*/
Expand Down Expand Up @@ -389,4 +423,20 @@ private static void setInstance(ZulipApp instance) {
public boolean isTopicMute(int id, String subject) {
return mutedTopics.contains(id + subject);
}

public void syncPointer(final int mID) {

getZulipServices().updatePointer(Integer.toString(mID))
.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
setPointer(mID);
}

@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
//do nothing.. don't want to mis-update the pointer.
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.zulip.android.models.MessageType;
import com.zulip.android.models.Person;
import com.zulip.android.models.Stream;
import com.zulip.android.networking.AsyncPointerUpdate;
import com.zulip.android.util.OnItemClickListener;
import com.zulip.android.util.ZLog;
import com.zulip.android.viewholders.LoadingHolder;
Expand Down Expand Up @@ -139,8 +138,7 @@ public void onItemClick(int viewId, int position) {
try {
int mID = msg.getID();
if (zulipApp.getPointer() < mID) {
(new AsyncPointerUpdate(zulipApp)).execute(mID);
zulipApp.setPointer(mID);
zulipApp.syncPointer(mID);
}
} catch (NullPointerException e) {
ZLog.logException(e);
Expand Down Expand Up @@ -394,8 +392,7 @@ private void markThisMessageAsRead(Message message) {
try {
int mID = message.getID();
if (!startedFromFilter && zulipApp.getPointer() < mID) {
(new AsyncPointerUpdate(zulipApp)).execute(mID);
zulipApp.setPointer(mID);
zulipApp.syncPointer(mID);
}
if (!message.getMessageRead()) {
try {
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/zulip/android/activities/ZulipActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import com.zulip.android.R;
import com.zulip.android.models.Stream;
import com.zulip.android.networking.AsyncSend;
import com.zulip.android.networking.response.UserConfigurationResponse;
import com.zulip.android.util.AnimationHelper;
import com.zulip.android.util.SwipeRemoveLinearLayout;
import com.zulip.android.util.ZLog;
Expand All @@ -96,6 +97,11 @@

import org.json.JSONObject;

import okhttp3.Response;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;

/**
* The main Activity responsible for holding the {@link MessageListFragment} which has the list to the
* messages
Expand Down Expand Up @@ -1466,6 +1472,20 @@ protected void onResume() {
narrowedList.onActivityResume();
}
startRequests();
final Handler handler = new Handler();
ZulipApp.get().getZulipServices()
.register()
.enqueue(new Callback<UserConfigurationResponse>() {
@Override
public void onResponse(Call<UserConfigurationResponse> call, retrofit2.Response<UserConfigurationResponse> response) {
String k = "";
}

@Override
public void onFailure(Call<UserConfigurationResponse> call, Throwable t) {
String k = "";
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.zulip.android.models.updated;

import com.google.gson.annotations.SerializedName;

/**
* Created by patrykpoborca on 8/25/16.
*/

public class ChatStatusWrapper {

@SerializedName("website")
private UserChatStatus website;

public UserChatStatus getWebsite() {
return website;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.zulip.android.models.updated;

/**
* Created by patrykpoborca on 8/25/16.
*/

public class JenkinsType {
private String source_url;
private String display_url;

public String getSource_url() {
return source_url;
}

public String getDisplay_url() {
return display_url;
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/com/zulip/android/models/updated/Referrals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.zulip.android.models.updated;

import com.google.gson.annotations.SerializedName;

/**
* Created by patrykpoborca on 8/25/16.
*/

public class Referrals {
@SerializedName("granted")
private int granted;
@SerializedName("used")
private int used;

public int getGranted() {
return granted;
}

public void setGranted(int granted) {
this.granted = granted;
}

public int getUsed() {
return used;
}

public void setUsed(int used) {
this.used = used;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.zulip.android.models.updated;

import com.google.gson.annotations.SerializedName;

/**
* Created by patrykpoborca on 8/25/16.
*/

public class UserChatStatus {

@SerializedName("status")
private String status;
@SerializedName("timestamp")
private int timestamp;
@SerializedName("client")
private String client;
@SerializedName("pushable")
private boolean pushable;

public String getStatus() {
return status;
}

public int getTimestamp() {
return timestamp;
}

public String getClient() {
return client;
}

public boolean isPushable() {
return pushable;
}
}
Loading

0 comments on commit 1e194d5

Please sign in to comment.