Android: EventBus 3

This commit is contained in:
jendib 2016-02-09 22:44:24 +01:00
parent e23ca4b8c1
commit 7f325e3eb5
13 changed files with 50 additions and 30 deletions

View File

@ -107,16 +107,16 @@
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" /> <orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="android-easing-1.0.3" level="project" /> <orderEntry type="library" exported="" name="android-easing-1.0.3" level="project" />
<orderEntry type="library" exported="" name="imagezoom-1.0.5" level="project" /> <orderEntry type="library" exported="" name="imagezoom-1.0.5" level="project" />
<orderEntry type="library" exported="" name="okhttp-urlconnection-3.1.1" level="project" />
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" /> <orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
<orderEntry type="library" exported="" name="eventbus-2.4.1" level="project" />
<orderEntry type="library" exported="" name="okhttp-urlconnection-3.0.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" /> <orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" /> <orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="fab-0.0.6" level="project" /> <orderEntry type="library" exported="" name="fab-0.0.6" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" /> <orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="okhttp-3.1.1" level="project" />
<orderEntry type="library" exported="" name="okio-1.6.0" level="project" /> <orderEntry type="library" exported="" name="okio-1.6.0" level="project" />
<orderEntry type="library" exported="" name="picasso2-okhttp3-downloader-1.0.2" level="project" /> <orderEntry type="library" exported="" name="picasso2-okhttp3-downloader-1.0.2" level="project" />
<orderEntry type="library" exported="" name="tokenautocomplete-1.2.1" level="project" /> <orderEntry type="library" exported="" name="tokenautocomplete-1.2.1" level="project" />
<orderEntry type="library" exported="" name="okhttp-3.0.1" level="project" /> <orderEntry type="library" exported="" name="eventbus-3.0.0" level="project" />
</component> </component>
</module> </module>

View File

@ -53,10 +53,10 @@ dependencies {
compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1' compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'it.sephiroth.android.library.imagezoom:imagezoom:1.0.5' compile 'it.sephiroth.android.library.imagezoom:imagezoom:1.0.5'
compile 'de.greenrobot:eventbus:2.4.1' compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.shamanland:fab:0.0.6' compile 'com.shamanland:fab:0.0.6'
compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp3:okhttp:3.0.1' compile 'com.squareup.okhttp3:okhttp:3.1.1'
compile "com.squareup.okhttp3:okhttp-urlconnection:3.0.1" compile "com.squareup.okhttp3:okhttp-urlconnection:3.1.1"
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.0.2' compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.0.2'
} }

View File

@ -24,6 +24,7 @@ import com.sismics.docs.ui.view.DatePickerView;
import com.sismics.docs.ui.view.TagsCompleteTextView; import com.sismics.docs.ui.view.TagsCompleteTextView;
import com.sismics.docs.util.PreferenceUtil; import com.sismics.docs.util.PreferenceUtil;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -34,8 +35,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import de.greenrobot.event.EventBus;
/** /**
* Document edition activity. * Document edition activity.
* *

View File

@ -55,6 +55,9 @@ import com.sismics.docs.service.FileUploadService;
import com.sismics.docs.util.PreferenceUtil; import com.sismics.docs.util.PreferenceUtil;
import com.sismics.docs.util.TagUtil; import com.sismics.docs.util.TagUtil;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -63,8 +66,6 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import de.greenrobot.event.EventBus;
/** /**
* Document activity. * Document activity.
* *
@ -506,6 +507,7 @@ public class DocumentViewActivity extends AppCompatActivity {
* *
* @param event Document fullscreen event * @param event Document fullscreen event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(DocumentFullscreenEvent event) { public void onEventMainThread(DocumentFullscreenEvent event) {
findViewById(R.id.detailLayout).setVisibility(event.isFullscreen() ? View.GONE : View.VISIBLE); findViewById(R.id.detailLayout).setVisibility(event.isFullscreen() ? View.GONE : View.VISIBLE);
} }
@ -515,6 +517,7 @@ public class DocumentViewActivity extends AppCompatActivity {
* *
* @param event Document edit event * @param event Document edit event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(DocumentEditEvent event) { public void onEventMainThread(DocumentEditEvent event) {
if (document == null) return; if (document == null) return;
if (event.getDocument().optString("id").equals(document.optString("id"))) { if (event.getDocument().optString("id").equals(document.optString("id"))) {
@ -528,6 +531,7 @@ public class DocumentViewActivity extends AppCompatActivity {
* *
* @param event Document delete event * @param event Document delete event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(DocumentDeleteEvent event) { public void onEventMainThread(DocumentDeleteEvent event) {
if (document == null) return; if (document == null) return;
if (event.getDocumentId().equals(document.optString("id"))) { if (event.getDocumentId().equals(document.optString("id"))) {
@ -541,6 +545,7 @@ public class DocumentViewActivity extends AppCompatActivity {
* *
* @param event File delete event * @param event File delete event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(FileDeleteEvent event) { public void onEventMainThread(FileDeleteEvent event) {
if (filePagerAdapter == null) return; if (filePagerAdapter == null) return;
filePagerAdapter.remove(event.getFileId()); filePagerAdapter.remove(event.getFileId());
@ -553,6 +558,7 @@ public class DocumentViewActivity extends AppCompatActivity {
* *
* @param event File add event * @param event File add event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(FileAddEvent event) { public void onEventMainThread(FileAddEvent event) {
if (document == null) return; if (document == null) return;
if (document.optString("id").equals(event.getDocumentId())) { if (document.optString("id").equals(event.getDocumentId())) {
@ -565,6 +571,7 @@ public class DocumentViewActivity extends AppCompatActivity {
* *
* @param event Comment add event * @param event Comment add event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(CommentAddEvent event) { public void onEventMainThread(CommentAddEvent event) {
if (commentListAdapter == null) return; if (commentListAdapter == null) return;
TextView emptyView = (TextView) findViewById(R.id.commentEmptyView); TextView emptyView = (TextView) findViewById(R.id.commentEmptyView);
@ -579,6 +586,7 @@ public class DocumentViewActivity extends AppCompatActivity {
* *
* @param event Comment add event * @param event Comment add event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(CommentDeleteEvent event) { public void onEventMainThread(CommentDeleteEvent event) {
if (commentListAdapter == null) return; if (commentListAdapter == null) return;
TextView emptyView = (TextView) findViewById(R.id.commentEmptyView); TextView emptyView = (TextView) findViewById(R.id.commentEmptyView);

View File

@ -30,10 +30,11 @@ import com.sismics.docs.resource.TagResource;
import com.sismics.docs.resource.UserResource; import com.sismics.docs.resource.UserResource;
import com.sismics.docs.util.PreferenceUtil; import com.sismics.docs.util.PreferenceUtil;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject; import org.json.JSONObject;
import de.greenrobot.event.EventBus;
/** /**
* Main activity. * Main activity.
* *
@ -265,6 +266,7 @@ public class MainActivity extends AppCompatActivity {
* *
* @param event Advanced search event * @param event Advanced search event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(AdvancedSearchEvent event) { public void onEventMainThread(AdvancedSearchEvent event) {
searchQuery(event.getQuery()); searchQuery(event.getQuery());
} }

View File

@ -36,11 +36,6 @@ public class FilePagerAdapter extends PagerAdapter {
*/ */
private Context context; private Context context;
/**
* Auth token used to download files.
*/
private String authToken;
/** /**
* File pager adapter. * File pager adapter.
* *
@ -53,7 +48,6 @@ public class FilePagerAdapter extends PagerAdapter {
files.add(filesArray.optJSONObject(i)); files.add(filesArray.optJSONObject(i));
} }
this.context = context; this.context = context;
this.authToken = PreferenceUtil.getAuthToken(context);
} }
@Override @Override

View File

@ -12,14 +12,13 @@ import com.sismics.docs.R;
import com.sismics.docs.event.ShareDeleteEvent; import com.sismics.docs.event.ShareDeleteEvent;
import com.sismics.docs.event.ShareSendEvent; import com.sismics.docs.event.ShareSendEvent;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.greenrobot.event.EventBus;
/** /**
* Share list adapter. * Share list adapter.
* *

View File

@ -20,6 +20,7 @@ import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
/** /**
* Tag list adapter. * Tag list adapter.
@ -99,7 +100,7 @@ public class TagListAdapter extends BaseAdapter {
TextView tagTextView = (TextView) view.findViewById(R.id.tagTextView); TextView tagTextView = (TextView) view.findViewById(R.id.tagTextView);
tagTextView.setText(tagItem.name); tagTextView.setText(tagItem.name);
TextView tagCountTextView = (TextView) view.findViewById(R.id.tagCountTextView); TextView tagCountTextView = (TextView) view.findViewById(R.id.tagCountTextView);
tagCountTextView.setText(String.format("%d", tagItem.count)); tagCountTextView.setText(String.format(Locale.ENGLISH, "%d", tagItem.count));
// Label color filtering // Label color filtering
ImageView labelImageView = (ImageView) view.findViewById(R.id.labelImageView); ImageView labelImageView = (ImageView) view.findViewById(R.id.labelImageView);

View File

@ -27,10 +27,11 @@ import com.sismics.docs.resource.DocumentResource;
import com.sismics.docs.ui.view.DividerItemDecoration; import com.sismics.docs.ui.view.DividerItemDecoration;
import com.sismics.docs.ui.view.EmptyRecyclerView; import com.sismics.docs.ui.view.EmptyRecyclerView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject; import org.json.JSONObject;
import de.greenrobot.event.EventBus;
/** /**
* @author bgamard. * @author bgamard.
*/ */
@ -99,7 +100,7 @@ public class DocListFragment extends Fragment {
})); }));
// Infinite scrolling // Infinite scrolling
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy); super.onScrolled(recyclerView, dx, dy);
@ -149,6 +150,7 @@ public class DocListFragment extends Fragment {
* *
* @param event Search event * @param event Search event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(SearchEvent event) { public void onEventMainThread(SearchEvent event) {
query = event.getQuery(); query = event.getQuery();
loadDocuments(getView(), true); loadDocuments(getView(), true);
@ -159,6 +161,7 @@ public class DocListFragment extends Fragment {
* *
* @param event Document edit event * @param event Document edit event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(DocumentEditEvent event) { public void onEventMainThread(DocumentEditEvent event) {
adapter.updateDocument(event.getDocument()); adapter.updateDocument(event.getDocument());
} }
@ -168,6 +171,7 @@ public class DocListFragment extends Fragment {
* *
* @param event Document delete event * @param event Document delete event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(DocumentDeleteEvent event) { public void onEventMainThread(DocumentDeleteEvent event) {
adapter.deleteDocument(event.getDocumentId()); adapter.deleteDocument(event.getDocumentId());
} }
@ -177,6 +181,7 @@ public class DocListFragment extends Fragment {
* *
* @param event Document add event * @param event Document add event
*/ */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(DocumentAddEvent event) { public void onEventMainThread(DocumentAddEvent event) {
// Refresh the list, maybe the new document fit in it // Refresh the list, maybe the new document fit in it
loadDocuments(getView(), true); loadDocuments(getView(), true);

View File

@ -26,11 +26,12 @@ import com.sismics.docs.resource.DocumentResource;
import com.sismics.docs.resource.ShareResource; import com.sismics.docs.resource.ShareResource;
import com.sismics.docs.util.PreferenceUtil; import com.sismics.docs.util.PreferenceUtil;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import de.greenrobot.event.EventBus;
/** /**
* Document sharing dialog fragment. * Document sharing dialog fragment.
* *
@ -139,6 +140,12 @@ public class DocShareFragment extends DialogFragment {
}); });
} }
/**
* A share delete event has been fired.
*
* @param event Share delete event
*/
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(ShareDeleteEvent event) { public void onEventMainThread(ShareDeleteEvent event) {
ShareResource.delete(getActivity(), event.getId(), new HttpCallback() { ShareResource.delete(getActivity(), event.getId(), new HttpCallback() {
@Override @Override
@ -153,6 +160,12 @@ public class DocShareFragment extends DialogFragment {
}); });
} }
/**
* A share send event has been fired.
*
* @param event Share send event
*/
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(ShareSendEvent event) { public void onEventMainThread(ShareSendEvent event) {
if (document == null) return; if (document == null) return;

View File

@ -22,14 +22,13 @@ import com.sismics.docs.ui.view.TagsCompleteTextView;
import com.sismics.docs.util.PreferenceUtil; import com.sismics.docs.util.PreferenceUtil;
import com.sismics.docs.util.SearchQueryBuilder; import com.sismics.docs.util.SearchQueryBuilder;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.greenrobot.event.EventBus;
/** /**
* Advanced search fragment. * Advanced search fragment.
* *

View File

@ -29,7 +29,7 @@ public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListen
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) { public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
View childView = view.findChildViewUnder(e.getX(), e.getY()); View childView = view.findChildViewUnder(e.getX(), e.getY());
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) { if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
mListener.onItemClick(childView, view.getChildPosition(childView)); mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
} }
return false; return false;
} }

View File

@ -15,12 +15,12 @@ import com.sismics.docs.event.FileAddEvent;
import com.sismics.docs.listener.HttpCallback; import com.sismics.docs.listener.HttpCallback;
import com.sismics.docs.resource.FileResource; import com.sismics.docs.resource.FileResource;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import de.greenrobot.event.EventBus;
import okhttp3.internal.Util; import okhttp3.internal.Util;
/** /**