Permalink
Browse files

Lots of kotlin

  • Loading branch information...
kpgalligan committed Jul 20, 2014
1 parent 2612399 commit 06490bea9d71746e5b49e791d9aa49c796ea06bf
@@ -61,6 +61,8 @@ dependencies {
compile 'com.github.johnpersano:supertoasts:1.3.4.1@aar'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.google.android.gms:play-services:4.4.52'

compile 'javax.validation:validation-api:1.1.0.Final'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

}
@@ -10,7 +10,7 @@
import android.widget.EditText;
import co.touchlab.android.threading.tasks.TaskQueue;
import co.touchlab.droidconandroid.data.AppPrefs;
import co.touchlab.droidconandroid.tasks.GoogleLoginOpTask;
import co.touchlab.droidconandroid.tasks.GoogleLoginTask;
import co.touchlab.droidconandroid.utils.Toaster;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
@@ -28,7 +28,7 @@
@Override
public void onReceive(Context context, Intent intent)
{
uuidEntry.setText(intent.getStringExtra(GoogleLoginOpTask.GOOGLE_LOGIN_UUID));
uuidEntry.setText(intent.getStringExtra(GoogleLoginTask.GOOGLE_LOGIN_UUID));
}
};

@@ -67,7 +67,7 @@ public void onClick(View v)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();

LocalBroadcastManager.getInstance(this).registerReceiver(uuidReceiver, new IntentFilter(GoogleLoginOpTask.GOOGLE_LOGIN_COMPLETE));
LocalBroadcastManager.getInstance(this).registerReceiver(uuidReceiver, new IntentFilter(GoogleLoginTask.GOOGLE_LOGIN_COMPLETE));
}

@Override
@@ -127,7 +127,7 @@ public void onConnected(Bundle bundle)
}
}

TaskQueue.execute(DebugEnterUuidActivity.this, new GoogleLoginOpTask(accountName, person.getDisplayName(), imageURL));
TaskQueue.execute(DebugEnterUuidActivity.this, new GoogleLoginTask(accountName, person.getDisplayName(), imageURL));
}

@Override
@@ -11,7 +11,7 @@
import android.widget.TextView;
import co.touchlab.android.threading.tasks.TaskQueue;
import co.touchlab.droidconandroid.data.Event;
import co.touchlab.droidconandroid.tasks.AddRsvpTask;
import co.touchlab.droidconandroid.tasks.AddRsvpTaskKot;
import co.touchlab.droidconandroid.tasks.SimpleEventDataLoadTask;
import de.greenrobot.event.EventBus;

@@ -33,7 +33,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Event event = adapter.getItem(position);
TaskQueue.execute(DebugScheduleDisplayActivity.this, new AddRsvpTask(DebugScheduleDisplayActivity.this, event.id));
TaskQueue.execute(DebugScheduleDisplayActivity.this, new AddRsvpTaskKot(DebugScheduleDisplayActivity.this, event.id));
}
});
EventBus.getDefault().register(this);
@@ -10,7 +10,7 @@
import android.widget.ImageView;
import android.widget.TextView;
import co.touchlab.android.threading.tasks.BsyncTaskManager;
import co.touchlab.droidconandroid.tasks.FindUserTask;
import co.touchlab.droidconandroid.tasks.FindUserTaskKot;
import co.touchlab.droidconandroid.utils.Toaster;
import com.squareup.picasso.Picasso;

@@ -45,7 +45,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void onClick(View v)
{
String userCodeVal = userCode.getText().toString();
bsyncTaskManager.post(FindUser.this, new FindUserTask(userCodeVal));
bsyncTaskManager.post(FindUser.this, new FindUserTaskKot(userCodeVal));
}
});

@@ -65,17 +65,17 @@ protected void onDestroy()
bsyncTaskManager.unregister();
}

public void showResult(FindUserTask findUserTask)
public void showResult(FindUserTaskKot findUserTask)
{
if(findUserTask.isError())
{
Toaster.showMessage(this, findUserTask.errorStringCode);
}
else
{
if(findUserTask.userData.avatarKey != null)
Picasso.with(this).load(HTTPS_S3_AMAZONAWS_COM_DROIDCONIMAGES + findUserTask.userData.avatarKey).into(userAvatar);
userName.setText(findUserTask.userData.name);
if(findUserTask.getUserData().getAvatarKey() != null)
Picasso.with(this).load(HTTPS_S3_AMAZONAWS_COM_DROIDCONIMAGES + findUserTask.getUserData().getAvatarKey()).into(userAvatar);
userName.setText(findUserTask.getUserData().getName());
}
}

@@ -11,26 +11,21 @@
import co.touchlab.droidconandroid.BuildConfig;
import co.touchlab.droidconandroid.R;
import co.touchlab.droidconandroid.data.AppPrefs;
import co.touchlab.droidconandroid.data.DatabaseHelper;
import co.touchlab.droidconandroid.data.Event;
import co.touchlab.droidconandroid.data.Venue;
import co.touchlab.droidconandroid.tasks.GoogleLoginOpTask;
import com.j256.ormlite.dao.Dao;
import co.touchlab.droidconandroid.tasks.GoogleLoginTask;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.turbomanage.httpclient.HttpResponse;
import com.turbomanage.httpclient.ParameterMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.android.AndroidLog;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
* Created by kgalligan on 6/28/14.
@@ -62,8 +57,8 @@ void jsonReply(JSONObject json) throws JSONException
{
String uuid = json.getString("uuid");
AppPrefs.getInstance(context).setUserUuid(uuid);
Intent intent = new Intent(GoogleLoginOpTask.GOOGLE_LOGIN_COMPLETE);
intent.putExtra(GoogleLoginOpTask.GOOGLE_LOGIN_UUID, uuid);
Intent intent = new Intent(GoogleLoginTask.GOOGLE_LOGIN_COMPLETE);
intent.putExtra(GoogleLoginTask.GOOGLE_LOGIN_UUID, uuid);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
});
@@ -185,9 +180,14 @@ public void intercept(RequestFacade request)
request.addHeader("Accept", "application/json");
}
};
Gson gson = new GsonBuilder().create();
GsonConverter gsonConverter = new GsonConverter(gson);

return new RestAdapter.Builder()
.setErrorHandler(new RetrofitBusErrorHandler())
.setRequestInterceptor(requestInterceptor)
.setConverter(gsonConverter)
.setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("DroidconApp"))
.setEndpoint(context.getString(R.string.base_url));
}
}
@@ -0,0 +1,104 @@
package co.touchlab.droidconandroid.network;

import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import org.apache.commons.io.IOUtils;
import retrofit.converter.ConversionException;
import retrofit.converter.Converter;
import retrofit.mime.MimeUtil;
import retrofit.mime.TypedInput;
import retrofit.mime.TypedOutput;

import java.io.*;
import java.lang.reflect.Type;

/**
* Created by kgalligan on 7/20/14.
*/
public class GsonConverter implements Converter
{
private final Gson gson;
private String encoding;

/**
* Create an instance using the supplied {@link Gson} object for conversion. Encoding to JSON and
* decoding from JSON (when no charset is specified by a header) will use UTF-8.
*/
public GsonConverter(Gson gson) {
this(gson, "UTF-8");
}

/**
* Create an instance using the supplied {@link Gson} object for conversion. Encoding to JSON and
* decoding from JSON (when no charset is specified by a header) will use the specified encoding.
*/
public GsonConverter(Gson gson, String encoding) {
this.gson = gson;
this.encoding = encoding;
}

@Override public Object fromBody(TypedInput body, Type type) throws ConversionException
{
String charset = "UTF-8";
if (body.mimeType() != null) {
charset = MimeUtil.parseCharset(body.mimeType());
}
InputStreamReader isr = null;
try {
InputStream in = body.in();
byte[] bytes = IOUtils.toByteArray(in);

String bodyString = new String(bytes);
Log.w("Gson", bodyString);

isr = new InputStreamReader(new ByteArrayInputStream(bytes), charset);
return gson.fromJson(isr, type);
} catch (IOException e) {
throw new ConversionException(e);
} catch (JsonParseException e) {
throw new ConversionException(e);
} finally {
if (isr != null) {
try {
isr.close();
} catch (IOException ignored) {
}
}
}
}

@Override public TypedOutput toBody(Object object) {
try {
return new JsonTypedOutput(gson.toJson(object).getBytes(encoding), encoding);
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
}

private static class JsonTypedOutput implements TypedOutput {
private final byte[] jsonBytes;
private final String mimeType;

JsonTypedOutput(byte[] jsonBytes, String encode) {
this.jsonBytes = jsonBytes;
this.mimeType = "application/json; charset=" + encode;
}

@Override public String fileName() {
return null;
}

@Override public String mimeType() {
return mimeType;
}

@Override public long length() {
return jsonBytes.length;
}

@Override public void writeTo(OutputStream out) throws IOException {
out.write(jsonBytes);
}
}
}
@@ -27,7 +27,7 @@
{
@FormUrlEncoded
@POST("/dataTest/rsvpEvent/{eventId}")
BasicIdResult addRsvp(@Path("eventId") Long eventId, @Field("uuid") String uuid, @Field("rsvpUuid") String rsvpUuid);
BasicIdResult addRsvp(@Path("eventId") Long eventId, @Field("uuid") String uuid, @Field("rsvpUuid") String rsvpUuid)throws TransientException, PermanentException;
}

public AddRsvpCommand()

This file was deleted.

Oops, something went wrong.
@@ -4,6 +4,8 @@
import co.touchlab.android.threading.tasks.TaskQueue;
import co.touchlab.droidconandroid.data.DatabaseHelper;

import javax.validation.constraints.NotNull;

/**
* Created by kgalligan on 6/28/14.
*/
@@ -16,6 +18,7 @@ protected DatabaseTask(Context context)
databaseHelper = DatabaseHelper.getInstance(context);
}

@NotNull
protected DatabaseHelper getDatabase()
{
return databaseHelper;
Oops, something went wrong.

0 comments on commit 06490be

Please sign in to comment.