Skip to content

Commit

Permalink
removed or reduced EventBus dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsguy committed Feb 12, 2017
1 parent 0b99786 commit 8d7aeb2
Show file tree
Hide file tree
Showing 52 changed files with 226 additions and 574 deletions.
11 changes: 5 additions & 6 deletions Diagnostics/Activity/app/build.gradle
@@ -1,20 +1,19 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'


dependencies { dependencies {
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.retrofit2:converter-gson:2.1.0'
} }


android { android {
compileSdkVersion 19 compileSdkVersion 25
buildToolsVersion "21.1.2" buildToolsVersion "25.0.2"


defaultConfig { defaultConfig {
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
minSdkVersion 11 minSdkVersion 15
targetSdkVersion 17 targetSdkVersion 25
} }


signingConfigs { signingConfigs {
Expand Down
Expand Up @@ -18,9 +18,9 @@
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import de.greenrobot.event.EventBus;


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


@Override @Override
public void onStart() { public void onQuestion(Item question) {
super.onStart();
EventBus.getDefault().register(this);
}

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

public void onEventMainThread(QuestionClickedEvent event) {
startActivity(new Intent(Intent.ACTION_VIEW, startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(event.item.link))); Uri.parse(question.link)));
} }
} }

This file was deleted.

Expand Up @@ -28,14 +28,18 @@
import android.widget.Toast; import android.widget.Toast;
import java.util.List; import java.util.List;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import de.greenrobot.event.EventBus; import retrofit2.Call;
import retrofit.Callback; import retrofit2.Callback;
import retrofit.RestAdapter; import retrofit2.Response;
import retrofit.RetrofitError; import retrofit2.Retrofit;
import retrofit.client.Response; import retrofit2.converter.gson.GsonConverterFactory;


public class QuestionsFragment extends ListFragment implements public class QuestionsFragment extends ListFragment implements
Callback<SOQuestions> { Callback<SOQuestions> {
interface Contract {
void onQuestion(Item question);
}

@Override @Override
public View onCreateView(LayoutInflater inflater, public View onCreateView(LayoutInflater inflater,
ViewGroup container, ViewGroup container,
Expand All @@ -45,13 +49,15 @@ public View onCreateView(LayoutInflater inflater,


setRetainInstance(true); setRetainInstance(true);


RestAdapter restAdapter= Retrofit retrofit=
new RestAdapter.Builder().setEndpoint("https://api.stackexchange.com") new Retrofit.Builder()
.build(); .baseUrl("https://api.stackexchange.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
StackOverflowInterface so= StackOverflowInterface so=
restAdapter.create(StackOverflowInterface.class); retrofit.create(StackOverflowInterface.class);


so.questions("android", this); so.questions("android").enqueue(this);


return(result); return(result);
} }
Expand All @@ -60,20 +66,21 @@ public View onCreateView(LayoutInflater inflater,
public void onListItemClick(ListView l, View v, int position, long id) { public void onListItemClick(ListView l, View v, int position, long id) {
Item item=((ItemsAdapter)getListAdapter()).getItem(position); Item item=((ItemsAdapter)getListAdapter()).getItem(position);


EventBus.getDefault().post(new QuestionClickedEvent(item)); ((Contract)getActivity()).onQuestion(item);
} }


@Override @Override
public void failure(RetrofitError exception) { public void onResponse(Call<SOQuestions> call,
Toast.makeText(getActivity(), exception.getMessage(), Response<SOQuestions> response) {
Toast.LENGTH_LONG).show(); setListAdapter(new ItemsAdapter(response.body().items));
Log.e(getClass().getSimpleName(),
"Exception from Retrofit request to StackOverflow", exception);
} }


@Override @Override
public void success(SOQuestions questions, Response response) { public void onFailure(Call<SOQuestions> call, Throwable t) {
setListAdapter(new ItemsAdapter(questions.items)); Toast.makeText(getActivity(), t.getMessage(),
Toast.LENGTH_LONG).show();
Log.e(getClass().getSimpleName(),
"Exception from Retrofit request to StackOverflow", t);
} }


class ItemsAdapter extends ArrayAdapter<Item> { class ItemsAdapter extends ArrayAdapter<Item> {
Expand Down
Expand Up @@ -14,11 +14,11 @@


package com.commonsware.android.debug.activity; package com.commonsware.android.debug.activity;


import retrofit.Callback; import retrofit2.Call;
import retrofit.http.GET; import retrofit2.http.GET;
import retrofit.http.Query; import retrofit2.http.Query;


public interface StackOverflowInterface { public interface StackOverflowInterface {
@GET("/2.1/questions?order=desc&sort=creation&site=stackoverflow") @GET("/2.1/questions?order=desc&sort=creation&site=stackoverflow")
void questions(@Query("tagged") String tags, Callback<SOQuestions> cb); Call<SOQuestions> questions(@Query("tagged") String tags);
} }
13 changes: 7 additions & 6 deletions HTTP/OkHttpProgress/app/build.gradle
@@ -1,15 +1,16 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'


dependencies { dependencies {
compile 'com.android.support:support-v13:21.0.3' compile 'com.android.support:support-v13:25.1.0'
compile 'com.squareup.okhttp3:okhttp:3.1.2' compile 'com.squareup.okhttp3:okhttp:3.1.2'
} }


android { android {
compileSdkVersion 21 compileSdkVersion 25
buildToolsVersion "21.1.2" buildToolsVersion "25.0.2"


defaultConfig { defaultConfig {
targetSdkVersion 17 minSdkVersion 15
} targetSdkVersion 25
}
} }
5 changes: 0 additions & 5 deletions HTTP/OkHttpProgress/app/src/main/AndroidManifest.xml
Expand Up @@ -10,12 +10,7 @@
android:normalScreens="true" android:normalScreens="true"
android:smallScreens="true"/> android:smallScreens="true"/>


<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="18"/>

<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />


<application <application
Expand Down
Expand Up @@ -53,8 +53,7 @@ public void onHandleIntent(Intent i) {


startForeground(FOREGROUND_ID, builder.build()); startForeground(FOREGROUND_ID, builder.build());


File root= File root=getExternalFilesDir(null);
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);


root.mkdirs(); root.mkdirs();


Expand Down
10 changes: 7 additions & 3 deletions HTTP/Picasso/app/build.gradle
@@ -1,12 +1,16 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'


dependencies { dependencies {
compile 'de.greenrobot:eventbus:2.4.0'
compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.retrofit:retrofit:1.9.0'
} }


android { android {
compileSdkVersion 19 compileSdkVersion 25
buildToolsVersion "21.1.2" buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 15
targetSdkVersion 25
}
} }
Expand Up @@ -18,9 +18,9 @@
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import de.greenrobot.event.EventBus;


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


@Override @Override
public void onResume() { public void onQuestion(Item question) {
super.onResume();
EventBus.getDefault().register(this);
}

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

public void onEventMainThread(QuestionClickedEvent event) {
startActivity(new Intent(Intent.ACTION_VIEW, startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(event.item.link))); Uri.parse(question.link)));
} }
} }

This file was deleted.

Expand Up @@ -26,16 +26,19 @@
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.util.List;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import de.greenrobot.event.EventBus; import java.util.List;
import retrofit.Callback; import retrofit.Callback;
import retrofit.RestAdapter; import retrofit.RestAdapter;
import retrofit.RetrofitError; import retrofit.RetrofitError;
import retrofit.client.Response; import retrofit.client.Response;


public class QuestionsFragment extends ListFragment implements public class QuestionsFragment extends ListFragment implements
Callback<SOQuestions> { Callback<SOQuestions> {
public interface Contract {
void onQuestion(Item question);
}

@Override @Override
public View onCreateView(LayoutInflater inflater, public View onCreateView(LayoutInflater inflater,
ViewGroup container, ViewGroup container,
Expand All @@ -60,7 +63,7 @@ public View onCreateView(LayoutInflater inflater,
public void onListItemClick(ListView l, View v, int position, long id) { public void onListItemClick(ListView l, View v, int position, long id) {
Item item=((ItemsAdapter)getListAdapter()).getItem(position); Item item=((ItemsAdapter)getListAdapter()).getItem(position);


EventBus.getDefault().post(new QuestionClickedEvent(item)); ((Contract)getActivity()).onQuestion(item);
} }


@Override @Override
Expand Down
9 changes: 4 additions & 5 deletions HTTP/RetroLoader/app/build.gradle
@@ -1,17 +1,16 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'


dependencies { dependencies {
compile 'com.squareup.retrofit:retrofit:1.6.1' compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'de.greenrobot:eventbus:2.2.1'
} }


android { android {
compileSdkVersion 19 compileSdkVersion 25
buildToolsVersion "21.1.2" buildToolsVersion "25.0.2"


defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 19 targetSdkVersion 25
applicationId "com.commonsware.android.retrofit.loader" applicationId "com.commonsware.android.retrofit.loader"
} }
} }
Expand Up @@ -18,9 +18,9 @@
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import de.greenrobot.event.EventBus;


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


@Override @Override
public void onResume() { public void onQuestion(Item question) {
super.onResume();
EventBus.getDefault().register(this);
}

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

public void onEventMainThread(QuestionClickedEvent event) {
startActivity(new Intent(Intent.ACTION_VIEW, startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(event.item.link))); Uri.parse(question.link)));
} }
} }

0 comments on commit 8d7aeb2

Please sign in to comment.