Skip to content

Commit

Permalink
rewrote to support event bus, plus Retrofit upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsguy committed Sep 3, 2014
1 parent 60f69a0 commit 8650f19
Show file tree
Hide file tree
Showing 21 changed files with 174 additions and 220 deletions.
11 changes: 8 additions & 3 deletions HTTP/Ion/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'com.android.tools.build:gradle:0.12.2'
}
}
apply plugin: 'android'

repositories {
mavenCentral()
}

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.koushikdutta.ion:ion:1.1.8'
compile 'de.greenrobot:eventbus:2.2.1'
}

android {
compileSdkVersion 18
buildToolsVersion "19.0.1"
buildToolsVersion "19.1.0"

sourceSets {
main {
Expand Down
Binary file added HTTP/Ion/libs/eventbus-2.2.1.jar
Binary file not shown.
53 changes: 0 additions & 53 deletions HTTP/Ion/src/com/commonsware/android/ion/ContractListFragment.java

This file was deleted.

26 changes: 17 additions & 9 deletions HTTP/Ion/src/com/commonsware/android/ion/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***
Copyright (c) 2013 CommonsWare, LLC
Copyright (c) 2013-2014 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
Expand All @@ -18,10 +18,9 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import com.google.gson.JsonObject;
import de.greenrobot.event.EventBus;

public class MainActivity extends Activity implements
QuestionsFragment.Contract {
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -34,11 +33,20 @@ protected void onCreate(Bundle savedInstanceState) {
}

@Override
public void showItem(JsonObject item) {
Intent iCanHazBrowser=
new Intent(Intent.ACTION_VIEW, Uri.parse(item.get("link")
.getAsString()));
public void onResume() {
super.onResume();
EventBus.getDefault().register(this);
}

@Override
public void onPause() {
EventBus.getDefault().unregister(this);
super.onPause();
}

startActivity(iCanHazBrowser);
public void onEventMainThread(QuestionClickedEvent event) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(event.item.get("link")
.getAsString())));
}
}
25 changes: 25 additions & 0 deletions HTTP/Ion/src/com/commonsware/android/ion/QuestionClickedEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/***
Copyright (c) 2013-2014 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
From _The Busy Coder's Guide to Android Development_
http://commonsware.com/Android
*/

package com.commonsware.android.ion;

import com.google.gson.JsonObject;

public class QuestionClickedEvent {
final JsonObject item;

QuestionClickedEvent(JsonObject item) {
this.item=item;
}
}
15 changes: 7 additions & 8 deletions HTTP/Ion/src/com/commonsware/android/ion/QuestionsFragment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***
Copyright (c) 2013 CommonsWare, LLC
Copyright (c) 2013-2014 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
Expand All @@ -14,6 +14,7 @@

package com.commonsware.android.ion;

import android.app.ListFragment;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
Expand All @@ -31,9 +32,9 @@
import com.google.gson.JsonObject;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;
import de.greenrobot.event.EventBus;

public class QuestionsFragment extends
ContractListFragment<QuestionsFragment.Contract> implements
public class QuestionsFragment extends ListFragment implements
FutureCallback<JsonObject> {
@Override
public View onCreateView(LayoutInflater inflater,
Expand All @@ -54,7 +55,9 @@ public View onCreateView(LayoutInflater inflater,

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
getContract().showItem(((ItemsAdapter)getListAdapter()).getItem(position));
JsonObject item=((ItemsAdapter)getListAdapter()).getItem(position);

EventBus.getDefault().post(new QuestionClickedEvent(item));
}

@Override
Expand Down Expand Up @@ -110,8 +113,4 @@ public View getView(int position, View convertView, ViewGroup parent) {
return(row);
}
}

interface Contract {
void showItem(JsonObject item);
}
}
16 changes: 11 additions & 5 deletions HTTP/Picasso/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'com.android.tools.build:gradle:0.12.2'
}
}
apply plugin: 'android'
apply plugin: 'com.android.application'

repositories {
mavenCentral()
}

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'de.greenrobot:eventbus:2.2.1'
compile 'com.squareup.picasso:picasso:2.3.3'
compile 'com.squareup.retrofit:retrofit:1.6.1'
}

android {
compileSdkVersion 18
buildToolsVersion "19.0.1"
compileSdkVersion 19
buildToolsVersion "19.1.0"

sourceSets {
main {
Expand Down
Binary file added HTTP/Picasso/libs/eventbus-2.2.1.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion HTTP/Picasso/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-17
target=android-19

This file was deleted.

23 changes: 16 additions & 7 deletions HTTP/Picasso/src/com/commonsware/android/picasso/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***
Copyright (c) 2013 CommonsWare, LLC
Copyright (c) 2013-2014 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
Expand All @@ -18,9 +18,9 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import de.greenrobot.event.EventBus;

public class MainActivity extends Activity implements
QuestionsFragment.Contract {
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -33,10 +33,19 @@ protected void onCreate(Bundle savedInstanceState) {
}

@Override
public void showItem(Item item) {
Intent iCanHazBrowser=
new Intent(Intent.ACTION_VIEW, Uri.parse(item.link));
public void onResume() {
super.onResume();
EventBus.getDefault().register(this);
}

@Override
public void onPause() {
EventBus.getDefault().unregister(this);
super.onPause();
}

startActivity(iCanHazBrowser);
public void onEventMainThread(QuestionClickedEvent event) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(event.item.link)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/***
Copyright (c) 2013-2014 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
From _The Busy Coder's Guide to Android Development_
http://commonsware.com/Android
*/

package com.commonsware.android.picasso;

public class QuestionClickedEvent {
final Item item;

QuestionClickedEvent(Item item) {
this.item=item;
}
}
Loading

0 comments on commit 8650f19

Please sign in to comment.